blob: 12a5000c2fa3d40dd89b8ba76f86557a5eaa8c83 [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
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080017package com.android.server.wm;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
22import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
23import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
25import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070026import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
28import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
30import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
31import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
32import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070033import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
35import com.android.internal.app.IBatteryStats;
36import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080037import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070038import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import com.android.internal.view.IInputContext;
40import com.android.internal.view.IInputMethodClient;
41import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080042import com.android.internal.view.WindowManagerPolicyThread;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080043import com.android.server.AttributeCache;
44import com.android.server.EventLogTags;
45import com.android.server.PowerManagerService;
46import com.android.server.Watchdog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.server.am.BatteryStatsService;
48
49import android.Manifest;
50import android.app.ActivityManagerNative;
51import android.app.IActivityManager;
Joe Onoratoac0ee892011-01-30 15:38:30 -080052import android.app.StatusBarManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070056import android.content.Intent;
57import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080062import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.Matrix;
65import android.graphics.PixelFormat;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -070066import android.graphics.Point;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import 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;
75import android.os.LocalPowerManager;
76import android.os.Looper;
77import android.os.Message;
78import android.os.Parcel;
79import android.os.ParcelFileDescriptor;
80import android.os.Power;
81import android.os.PowerManager;
82import android.os.Process;
83import android.os.RemoteException;
84import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070085import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086import 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;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070095import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.view.Display;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.view.IApplicationToken;
98import android.view.IOnKeyguardExitResult;
99import android.view.IRotationWatcher;
100import android.view.IWindow;
101import android.view.IWindowManager;
102import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700103import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700104import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700105import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700106import android.view.InputHandler;
107import 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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.WindowManager;
114import android.view.WindowManagerImpl;
115import android.view.WindowManagerPolicy;
116import android.view.WindowManager.LayoutParams;
117import android.view.animation.Animation;
118import android.view.animation.AnimationUtils;
119import android.view.animation.Transformation;
120
121import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700122import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import java.io.File;
124import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700125import java.io.FileInputStream;
126import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127import 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;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800144 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 static final boolean DEBUG_FOCUS = false;
146 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800147 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800148 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 static final boolean DEBUG_LAYERS = false;
150 static final boolean DEBUG_INPUT = false;
151 static final boolean DEBUG_INPUT_METHOD = false;
152 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700153 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800154 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700156 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_APP_TRANSITIONS = false;
158 static final boolean DEBUG_STARTING_WINDOW = false;
159 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700160 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800161 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700163 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean PROFILE_ORIENTATION = false;
166 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700167 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** How much to multiply the policy's type layer, to reserve room
170 * for multiple windows of the same type and Z-ordering adjustment
171 * with TYPE_LAYER_OFFSET. */
172 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
175 * or below others in the same layer. */
176 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to increment the layer for each window, to reserve room
179 * for effect surfaces between them.
180 */
181 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700182
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800183 /**
184 * Dim surface layer is immediately below target window.
185 */
186 static final int LAYER_OFFSET_DIM = 1;
187
188 /**
189 * Blur surface layer is immediately below dim layer.
190 */
191 static final int LAYER_OFFSET_BLUR = 2;
192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 /** The maximum length we will accept for a loaded animation duration:
194 * this is 10 seconds.
195 */
196 static final int MAX_ANIMATION_DURATION = 10*1000;
197
198 /** Amount of time (in milliseconds) to animate the dim surface from one
199 * value to another, when no window animation is driving it.
200 */
201 static final int DEFAULT_DIM_DURATION = 200;
202
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700203 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
204 * compatible windows.
205 */
206 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
207
Dianne Hackborna1111872010-11-23 20:55:11 -0800208 /**
209 * If true, the window manager will do its own custom freezing and general
210 * management of the screen during rotation.
211 */
212 static final boolean CUSTOM_SCREEN_ROTATION = true;
213
Jeff Brown7fbdc842010-06-17 20:52:56 -0700214 // Maximum number of milliseconds to wait for input event injection.
215 // FIXME is this value reasonable?
216 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800217
218 // Maximum number of milliseconds to wait for input devices to be enumerated before
219 // proceding with safe mode detection.
220 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700221
222 // Default input dispatching timeout in nanoseconds.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 static final int UPDATE_FOCUS_NORMAL = 0;
226 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
227 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
228 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700231 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232
233 /**
234 * Condition waited on by {@link #reenableKeyguard} to know the call to
235 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500236 * This is set to true only if mKeyguardTokenWatcher.acquired() has
237 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500239 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240
Jim Miller284b62e2010-06-08 14:27:42 -0700241 private static final int ALLOW_DISABLE_YES = 1;
242 private static final int ALLOW_DISABLE_NO = 0;
243 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
244 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
245
Mike Lockwood983ee092009-11-22 01:42:24 -0500246 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
247 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700249 if (shouldAllowDisableKeyguard()) {
250 mPolicy.enableKeyguard(false);
251 mKeyguardDisabled = true;
252 } else {
253 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 }
256 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700257 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500258 synchronized (mKeyguardTokenWatcher) {
259 mKeyguardDisabled = false;
260 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 }
262 }
263 };
264
Jim Miller284b62e2010-06-08 14:27:42 -0700265 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
266 @Override
267 public void onReceive(Context context, Intent intent) {
268 mPolicy.enableKeyguard(true);
269 synchronized(mKeyguardTokenWatcher) {
270 // lazily evaluate this next time we're asked to disable keyguard
271 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
272 mKeyguardDisabled = false;
273 }
274 }
275 };
276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 final Context mContext;
278
279 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
284
285 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 /**
290 * All currently active sessions with clients.
291 */
292 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 /**
295 * Mapping from an IWindow IBinder to the server's Window object.
296 * This is also used as the lock for all of our state.
297 */
298 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
299
300 /**
301 * Mapping from a token IBinder to a WindowToken object.
302 */
303 final HashMap<IBinder, WindowToken> mTokenMap =
304 new HashMap<IBinder, WindowToken>();
305
306 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 * Window tokens that are in the process of exiting, but still
308 * on screen for animations.
309 */
310 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
311
312 /**
313 * Z-ordered (bottom-most first) list of all application tokens, for
314 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800315 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 */
317 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
318
319 /**
320 * Application tokens that are in the process of exiting, but still
321 * on screen for animations.
322 */
323 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
324
325 /**
326 * List of window tokens that have finished starting their application,
327 * and now need to have the policy remove their windows.
328 */
329 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
330
331 /**
332 * Z-ordered (bottom-most first) list of all Window objects.
333 */
Jeff Browne33348b2010-07-15 23:54:05 -0700334 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335
336 /**
337 * Windows that are being resized. Used so we can tell the client about
338 * the resize after closing the transaction in which we resized the
339 * underlying surface.
340 */
341 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
342
343 /**
344 * Windows whose animations have ended and now must be removed.
345 */
346 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
347
348 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800349 * Used when processing mPendingRemove to avoid working on the original array.
350 */
351 WindowState[] mPendingRemoveTmp = new WindowState[20];
352
353 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 * Windows whose surface should be destroyed.
355 */
356 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
357
358 /**
359 * Windows that have lost input focus and are waiting for the new
360 * focus window to be displayed before they are told about this.
361 */
362 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
363
364 /**
365 * This is set when we have run out of memory, and will either be an empty
366 * list or contain windows that need to be force removed.
367 */
368 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700369
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800370 /**
371 * Used when rebuilding window list to keep track of windows that have
372 * been removed.
373 */
374 WindowState[] mRebuildTmp = new WindowState[20];
375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700379 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 Surface mBlurSurface;
381 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700382 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800383 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800384 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 final float[] mTmpFloats = new float[9];
389
390 boolean mSafeMode;
391 boolean mDisplayEnabled = false;
392 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700393 int mInitialDisplayWidth = 0;
394 int mInitialDisplayHeight = 0;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -0700395 int mCurDisplayWidth = 0;
396 int mCurDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 int mRotation = 0;
398 int mRequestedRotation = 0;
399 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborndacea8c2011-04-21 17:26:39 -0700400 boolean mAltOrientation = false;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700401 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 ArrayList<IRotationWatcher> mRotationWatchers
403 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800404 int mDeferredRotation;
405 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 boolean mLayoutNeeded = true;
408 boolean mAnimationPending = false;
409 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 boolean mWindowsFreezingScreen = false;
412 long mFreezeGcPending = 0;
413 int mAppsFreezingScreen = 0;
414
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800415 int mLayoutSeq = 0;
416
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800417 // State while inside of layoutAndPlaceSurfacesLocked().
418 boolean mFocusMayChange;
419
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800420 Configuration mCurConfiguration = new Configuration();
421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // This is held as long as we have the screen frozen, to give us time to
423 // perform a rotation animation when turning off shows the lock screen which
424 // changes the orientation.
425 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 // State management of app transitions. When we are preparing for a
428 // transition, mNextAppTransition will be the kind of transition to
429 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
430 // mOpeningApps and mClosingApps are the lists of tokens that will be
431 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700432 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700433 String mNextAppTransitionPackage;
434 int mNextAppTransitionEnter;
435 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700437 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 boolean mAppTransitionTimeout = false;
439 boolean mStartingIconInTransition = false;
440 boolean mSkipAppTransitionAnimation = false;
441 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
442 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700443 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
444 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 H mH = new H();
449
450 WindowState mCurrentFocus = null;
451 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 // This just indicates the window the input method is on top of, not
454 // necessarily the window its input is going to.
455 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 boolean mInputMethodTargetWaitingAnim;
457 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 WindowState mInputMethodWindow = null;
460 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
461
Jeff Brown2992ea72011-01-28 22:04:14 -0800462 boolean mHardKeyboardAvailable;
463 boolean mHardKeyboardEnabled;
464 OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
465
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700466 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800467
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700468 // If non-null, this is the currently visible window that is associated
469 // with the wallpaper.
470 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700471 // If non-null, we are in the middle of animating from one wallpaper target
472 // to another, and this is the lower one in Z-order.
473 WindowState mLowerWallpaperTarget = null;
474 // If non-null, we are in the middle of animating from one wallpaper target
475 // to another, and this is the higher one in Z-order.
476 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800477 // Window currently running an animation that has requested it be detached
478 // from the wallpaper. This means we need to ensure the wallpaper is
479 // visible behind it in case it animates in a way that would allow it to be
480 // seen.
481 WindowState mWindowDetachedWallpaper = null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800482 DimSurface mWindowAnimationBackgroundSurface = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700483 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700484 float mLastWallpaperX = -1;
485 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800486 float mLastWallpaperXStep = -1;
487 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700488 // This is set when we are waiting for a wallpaper to tell us it is done
489 // changing its scroll position.
490 WindowState mWaitingOnWallpaper;
491 // The last time we had a timeout when waiting for a wallpaper.
492 long mLastWallpaperTimeoutTime;
493 // We give a wallpaper up to 150ms to finish scrolling.
494 static final long WALLPAPER_TIMEOUT = 150;
495 // Time we wait after a timeout before trying to wait again.
496 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 AppWindowToken mFocusedApp = null;
499
500 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 float mWindowAnimationScale = 1.0f;
503 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700504
Jeff Brown46b9ac02010-04-22 18:58:52 -0700505 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506
507 // Who is holding the screen on.
508 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700509 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700510
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700511 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800512
Christopher Tatea53146c2010-09-07 11:57:52 -0700513 DragState mDragState = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514 final InputHandler mDragInputHandler = new BaseInputHandler() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700516 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
517 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700518 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700519 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
520 && mDragState != null) {
521 boolean endDrag = false;
522 final float newX = event.getRawX();
523 final float newY = event.getRawY();
524
Christopher Tatea53146c2010-09-07 11:57:52 -0700525 switch (event.getAction()) {
526 case MotionEvent.ACTION_DOWN: {
527 if (DEBUG_DRAG) {
528 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
529 }
530 } break;
531
532 case MotionEvent.ACTION_MOVE: {
533 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700534 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700535 mDragState.notifyMoveLw(newX, newY);
536 }
537 } break;
538
539 case MotionEvent.ACTION_UP: {
540 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
541 + newX + "," + newY);
542 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700543 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700544 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700545 } break;
546
547 case MotionEvent.ACTION_CANCEL: {
548 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
549 endDrag = true;
550 } break;
551 }
552
553 if (endDrag) {
554 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
555 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700556 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700557 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700558 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700559 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700560
561 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700562 }
563 } catch (Exception e) {
564 Slog.e(TAG, "Exception caught by drag handleMotion", e);
565 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700566 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 }
568 }
569 };
570
571 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 * Whether the UI is currently running in touch mode (not showing
573 * navigational focus because the user is directly pressing the screen).
574 */
575 boolean mInTouchMode = false;
576
577 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700578 private ArrayList<WindowChangeListener> mWindowChangeListeners =
579 new ArrayList<WindowChangeListener>();
580 private boolean mWindowsChanged = false;
581
582 public interface WindowChangeListener {
583 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700584 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586
Dianne Hackbornc485a602009-03-24 22:39:49 -0700587 final Configuration mTempConfiguration = new Configuration();
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700588
589 // The frame use to limit the size of the app running in compatibility mode.
590 Rect mCompatibleScreenFrame = new Rect();
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400591 float mCompatibleScreenScale;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700592 // The surface used to fill the outer rim of the app running in compatibility mode.
593 Surface mBackgroundFillerSurface = null;
Dianne Hackbornac1471a2011-02-03 13:46:06 -0800594 WindowState mBackgroundFillerTarget = null;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 public static WindowManagerService main(Context context,
597 PowerManagerService pm, boolean haveInputMethods) {
598 WMThread thr = new WMThread(context, pm, haveInputMethods);
599 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 synchronized (thr) {
602 while (thr.mService == null) {
603 try {
604 thr.wait();
605 } catch (InterruptedException e) {
606 }
607 }
Jozef BABJAK06e57b52011-01-20 08:09:25 +0100608 return thr.mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 }
Romain Guy06882f82009-06-10 13:36:04 -0700611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 static class WMThread extends Thread {
613 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 private final Context mContext;
616 private final PowerManagerService mPM;
617 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 public WMThread(Context context, PowerManagerService pm,
620 boolean haveInputMethods) {
621 super("WindowManager");
622 mContext = context;
623 mPM = pm;
624 mHaveInputMethods = haveInputMethods;
625 }
Romain Guy06882f82009-06-10 13:36:04 -0700626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 public void run() {
628 Looper.prepare();
629 WindowManagerService s = new WindowManagerService(mContext, mPM,
630 mHaveInputMethods);
631 android.os.Process.setThreadPriority(
632 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700633 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 synchronized (this) {
636 mService = s;
637 notifyAll();
638 }
Romain Guy06882f82009-06-10 13:36:04 -0700639
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700640 // For debug builds, log event loop stalls to dropbox for analysis.
641 if (StrictMode.conditionallyEnableDebugLogging()) {
642 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
643 }
644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 Looper.loop();
646 }
647 }
648
649 static class PolicyThread extends Thread {
650 private final WindowManagerPolicy mPolicy;
651 private final WindowManagerService mService;
652 private final Context mContext;
653 private final PowerManagerService mPM;
654 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 public PolicyThread(WindowManagerPolicy policy,
657 WindowManagerService service, Context context,
658 PowerManagerService pm) {
659 super("WindowManagerPolicy");
660 mPolicy = policy;
661 mService = service;
662 mContext = context;
663 mPM = pm;
664 }
Romain Guy06882f82009-06-10 13:36:04 -0700665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 public void run() {
667 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800668 WindowManagerPolicyThread.set(this, Looper.myLooper());
669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 android.os.Process.setThreadPriority(
673 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700674 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 synchronized (this) {
678 mRunning = true;
679 notifyAll();
680 }
Romain Guy06882f82009-06-10 13:36:04 -0700681
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700682 // For debug builds, log event loop stalls to dropbox for analysis.
683 if (StrictMode.conditionallyEnableDebugLogging()) {
684 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
685 }
686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 Looper.loop();
688 }
689 }
690
691 private WindowManagerService(Context context, PowerManagerService pm,
692 boolean haveInputMethods) {
693 mContext = context;
694 mHaveInputMethods = haveInputMethods;
695 mLimitedAlphaCompositing = context.getResources().getBoolean(
696 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 mPowerManager = pm;
699 mPowerManager.setPolicy(mPolicy);
700 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
701 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
702 "SCREEN_FROZEN");
703 mScreenFrozenLock.setReferenceCounted(false);
704
705 mActivityManager = ActivityManagerNative.getDefault();
706 mBatteryStats = BatteryStatsService.getService();
707
708 // Get persisted window scale setting
709 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
710 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
711 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
712 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700713
Jim Miller284b62e2010-06-08 14:27:42 -0700714 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
715 IntentFilter filter = new IntentFilter();
716 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
717 mContext.registerReceiver(mBroadcastReceiver, filter);
718
Jeff Brown46b9ac02010-04-22 18:58:52 -0700719 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
720 "KEEP_SCREEN_ON_FLAG");
721 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722
Jeff Browne33348b2010-07-15 23:54:05 -0700723 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
726 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 synchronized (thr) {
729 while (!thr.mRunning) {
730 try {
731 thr.wait();
732 } catch (InterruptedException e) {
733 }
734 }
735 }
Romain Guy06882f82009-06-10 13:36:04 -0700736
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700737 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 // Add ourself to the Watchdog monitors.
740 Watchdog.getInstance().addMonitor(this);
741 }
742
743 @Override
744 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
745 throws RemoteException {
746 try {
747 return super.onTransact(code, data, reply, flags);
748 } catch (RuntimeException e) {
749 // The window manager only throws security exceptions, so let's
750 // log all others.
751 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800752 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 }
754 throw e;
755 }
756 }
757
Jeff Browne33348b2010-07-15 23:54:05 -0700758 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800760 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 TAG, "Adding window " + window + " at "
762 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
763 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700764 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
766
Jeff Browne33348b2010-07-15 23:54:05 -0700767 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800769 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 TAG, "Adding window " + window + " at "
771 + i + " of " + mWindows.size() + " (before " + pos + ")");
772 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700773 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
775
776 //This method finds out the index of a window that has the same app token as
777 //win. used for z ordering the windows in mWindows
778 private int findIdxBasedOnAppTokens(WindowState win) {
779 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700780 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 int jmax = localmWindows.size();
782 if(jmax == 0) {
783 return -1;
784 }
785 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700786 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 if(wentry.mAppToken == win.mAppToken) {
788 return j;
789 }
790 }
791 return -1;
792 }
Romain Guy06882f82009-06-10 13:36:04 -0700793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
795 final IWindow client = win.mClient;
796 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700797 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 final int N = localmWindows.size();
800 final WindowState attached = win.mAttachedWindow;
801 int i;
802 if (attached == null) {
803 int tokenWindowsPos = token.windows.size();
804 if (token.appWindowToken != null) {
805 int index = tokenWindowsPos-1;
806 if (index >= 0) {
807 // If this application has existing windows, we
808 // simply place the new window on top of them... but
809 // keep the starting window on top.
810 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
811 // Base windows go behind everything else.
812 placeWindowBefore(token.windows.get(0), win);
813 tokenWindowsPos = 0;
814 } else {
815 AppWindowToken atoken = win.mAppToken;
816 if (atoken != null &&
817 token.windows.get(index) == atoken.startingWindow) {
818 placeWindowBefore(token.windows.get(index), win);
819 tokenWindowsPos--;
820 } else {
821 int newIdx = findIdxBasedOnAppTokens(win);
822 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700823 //there is a window above this one associated with the same
824 //apptoken note that the window could be a floating window
825 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800827 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
828 Slog.v(TAG, "Adding window " + win + " at "
829 + (newIdx+1) + " of " + N);
830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700832 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
835 }
836 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800837 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 TAG, "Figuring out where to add app window "
839 + client.asBinder() + " (token=" + token + ")");
840 // Figure out where the window should go, based on the
841 // order of applications.
842 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700843 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 for (i=NA-1; i>=0; i--) {
845 AppWindowToken t = mAppTokens.get(i);
846 if (t == token) {
847 i--;
848 break;
849 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800850
Dianne Hackborna8f60182009-09-01 19:01:50 -0700851 // We haven't reached the token yet; if this token
852 // is not going to the bottom and has windows, we can
853 // use it as an anchor for when we do reach the token.
854 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 pos = t.windows.get(0);
856 }
857 }
858 // We now know the index into the apps. If we found
859 // an app window above, that gives us the position; else
860 // we need to look some more.
861 if (pos != null) {
862 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700863 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 if (atoken != null) {
865 final int NC = atoken.windows.size();
866 if (NC > 0) {
867 WindowState bottom = atoken.windows.get(0);
868 if (bottom.mSubLayer < 0) {
869 pos = bottom;
870 }
871 }
872 }
873 placeWindowBefore(pos, win);
874 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700875 // Continue looking down until we find the first
876 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 while (i >= 0) {
878 AppWindowToken t = mAppTokens.get(i);
879 final int NW = t.windows.size();
880 if (NW > 0) {
881 pos = t.windows.get(NW-1);
882 break;
883 }
884 i--;
885 }
886 if (pos != null) {
887 // Move in front of any windows attached to this
888 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700889 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 if (atoken != null) {
891 final int NC = atoken.windows.size();
892 if (NC > 0) {
893 WindowState top = atoken.windows.get(NC-1);
894 if (top.mSubLayer >= 0) {
895 pos = top;
896 }
897 }
898 }
899 placeWindowAfter(pos, win);
900 } else {
901 // Just search for the start of this layer.
902 final int myLayer = win.mBaseLayer;
903 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700904 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 if (w.mBaseLayer > myLayer) {
906 break;
907 }
908 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800909 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
910 Slog.v(TAG, "Adding window " + win + " at "
911 + i + " of " + N);
912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700914 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 }
916 }
917 }
918 } else {
919 // Figure out where window should go, based on layer.
920 final int myLayer = win.mBaseLayer;
921 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700922 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 i++;
924 break;
925 }
926 }
927 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800928 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700929 TAG, "Adding window " + win + " at "
930 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700932 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 }
934 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800935 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 token.windows.add(tokenWindowsPos, win);
937 }
938
939 } else {
940 // Figure out this window's ordering relative to the window
941 // it is attached to.
942 final int NA = token.windows.size();
943 final int sublayer = win.mSubLayer;
944 int largestSublayer = Integer.MIN_VALUE;
945 WindowState windowWithLargestSublayer = null;
946 for (i=0; i<NA; i++) {
947 WindowState w = token.windows.get(i);
948 final int wSublayer = w.mSubLayer;
949 if (wSublayer >= largestSublayer) {
950 largestSublayer = wSublayer;
951 windowWithLargestSublayer = w;
952 }
953 if (sublayer < 0) {
954 // For negative sublayers, we go below all windows
955 // in the same sublayer.
956 if (wSublayer >= sublayer) {
957 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800958 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 token.windows.add(i, win);
960 }
961 placeWindowBefore(
962 wSublayer >= 0 ? attached : w, win);
963 break;
964 }
965 } else {
966 // For positive sublayers, we go above all windows
967 // in the same sublayer.
968 if (wSublayer > sublayer) {
969 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800970 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 token.windows.add(i, win);
972 }
973 placeWindowBefore(w, win);
974 break;
975 }
976 }
977 }
978 if (i >= NA) {
979 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800980 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 token.windows.add(win);
982 }
983 if (sublayer < 0) {
984 placeWindowBefore(attached, win);
985 } else {
986 placeWindowAfter(largestSublayer >= 0
987 ? windowWithLargestSublayer
988 : attached,
989 win);
990 }
991 }
992 }
Romain Guy06882f82009-06-10 13:36:04 -0700993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 if (win.mAppToken != null && addToToken) {
995 win.mAppToken.allAppWindows.add(win);
996 }
997 }
Romain Guy06882f82009-06-10 13:36:04 -0700998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 static boolean canBeImeTarget(WindowState w) {
1000 final int fl = w.mAttrs.flags
1001 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001002 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1003 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1004 if (DEBUG_INPUT_METHOD) {
1005 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1006 if (!w.isVisibleOrAdding()) {
1007 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1008 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1009 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1010 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1011 if (w.mAppToken != null) {
1012 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1013 }
1014 }
1015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 return w.isVisibleOrAdding();
1017 }
1018 return false;
1019 }
Romain Guy06882f82009-06-10 13:36:04 -07001020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001022 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 final int N = localmWindows.size();
1024 WindowState w = null;
1025 int i = N;
1026 while (i > 0) {
1027 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001028 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001029
Dianne Hackborne75d8722011-01-27 19:37:40 -08001030 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1031 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001033 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 // Yet more tricksyness! If this window is a "starting"
1036 // window, we do actually want to be on top of it, but
1037 // it is not -really- where input will go. So if the caller
1038 // is not actually looking to move the IME, look down below
1039 // for a real window to target...
1040 if (!willMove
1041 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1042 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001043 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1045 i--;
1046 w = wb;
1047 }
1048 }
1049 break;
1050 }
1051 }
Romain Guy06882f82009-06-10 13:36:04 -07001052
Dianne Hackborne75d8722011-01-27 19:37:40 -08001053 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1054
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001055 // Now, a special case -- if the last target's window is in the
1056 // process of exiting, and is above the new target, keep on the
1057 // last target to avoid flicker. Consider for example a Dialog with
1058 // the IME shown: when the Dialog is dismissed, we want to keep
1059 // the IME above it until it is completely gone so it doesn't drop
1060 // behind the dialog or its full-screen scrim.
1061 if (mInputMethodTarget != null && w != null
1062 && mInputMethodTarget.isDisplayedLw()
1063 && mInputMethodTarget.mExiting) {
1064 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1065 w = mInputMethodTarget;
1066 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001067 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001068 }
1069 }
Romain Guy06882f82009-06-10 13:36:04 -07001070
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 if (willMove && w != null) {
1075 final WindowState curTarget = mInputMethodTarget;
1076 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 // Now some fun for dealing with window animations that
1079 // modify the Z order. We need to look at all windows below
1080 // the current target that are in this app, finding the highest
1081 // visible one in layering.
1082 AppWindowToken token = curTarget.mAppToken;
1083 WindowState highestTarget = null;
1084 int highestPos = 0;
1085 if (token.animating || token.animation != null) {
1086 int pos = 0;
1087 pos = localmWindows.indexOf(curTarget);
1088 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001089 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 if (win.mAppToken != token) {
1091 break;
1092 }
1093 if (!win.mRemoved) {
1094 if (highestTarget == null || win.mAnimLayer >
1095 highestTarget.mAnimLayer) {
1096 highestTarget = win;
1097 highestPos = pos;
1098 }
1099 }
1100 pos--;
1101 }
1102 }
Romain Guy06882f82009-06-10 13:36:04 -07001103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001105 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 + mNextAppTransition + " " + highestTarget
1107 + " animating=" + highestTarget.isAnimating()
1108 + " layer=" + highestTarget.mAnimLayer
1109 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001110
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001111 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 // If we are currently setting up for an animation,
1113 // hold everything until we can find out what will happen.
1114 mInputMethodTargetWaitingAnim = true;
1115 mInputMethodTarget = highestTarget;
1116 return highestPos + 1;
1117 } else if (highestTarget.isAnimating() &&
1118 highestTarget.mAnimLayer > w.mAnimLayer) {
1119 // If the window we are currently targeting is involved
1120 // with an animation, and it is on top of the next target
1121 // we will be over, then hold off on moving until
1122 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001123 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 mInputMethodTarget = highestTarget;
1125 return highestPos + 1;
1126 }
1127 }
1128 }
1129 }
Romain Guy06882f82009-06-10 13:36:04 -07001130
Joe Onorato8a9b2202010-02-26 18:56:32 -08001131 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 if (w != null) {
1133 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001134 if (DEBUG_INPUT_METHOD) {
1135 RuntimeException e = null;
1136 if (!HIDE_STACK_CRAWLS) {
1137 e = new RuntimeException();
1138 e.fillInStackTrace();
1139 }
1140 Slog.w(TAG, "Moving IM target from "
1141 + mInputMethodTarget + " to " + w, e);
1142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001144 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (w.mAppToken != null) {
1146 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1147 } else {
1148 setInputMethodAnimLayerAdjustment(0);
1149 }
1150 }
1151 return i+1;
1152 }
1153 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001154 if (DEBUG_INPUT_METHOD) {
1155 RuntimeException e = null;
1156 if (!HIDE_STACK_CRAWLS) {
1157 e = new RuntimeException();
1158 e.fillInStackTrace();
1159 }
1160 Slog.w(TAG, "Moving IM target from "
1161 + mInputMethodTarget + " to null", e);
1162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 mInputMethodTarget = null;
1164 setInputMethodAnimLayerAdjustment(0);
1165 }
1166 return -1;
1167 }
Romain Guy06882f82009-06-10 13:36:04 -07001168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 void addInputMethodWindowToListLocked(WindowState win) {
1170 int pos = findDesiredInputMethodWindowIndexLocked(true);
1171 if (pos >= 0) {
1172 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001173 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001174 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001176 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 moveInputMethodDialogsLocked(pos+1);
1178 return;
1179 }
1180 win.mTargetAppToken = null;
1181 addWindowToListInOrderLocked(win, true);
1182 moveInputMethodDialogsLocked(pos);
1183 }
Romain Guy06882f82009-06-10 13:36:04 -07001184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001186 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 mInputMethodAnimLayerAdjustment = adj;
1188 WindowState imw = mInputMethodWindow;
1189 if (imw != null) {
1190 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001191 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 + " anim layer: " + imw.mAnimLayer);
1193 int wi = imw.mChildWindows.size();
1194 while (wi > 0) {
1195 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001196 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001198 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 + " anim layer: " + cw.mAnimLayer);
1200 }
1201 }
1202 int di = mInputMethodDialogs.size();
1203 while (di > 0) {
1204 di --;
1205 imw = mInputMethodDialogs.get(di);
1206 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001207 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 + " anim layer: " + imw.mAnimLayer);
1209 }
1210 }
Romain Guy06882f82009-06-10 13:36:04 -07001211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1213 int wpos = mWindows.indexOf(win);
1214 if (wpos >= 0) {
1215 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001216 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001218 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 int NC = win.mChildWindows.size();
1220 while (NC > 0) {
1221 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001222 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 int cpos = mWindows.indexOf(cw);
1224 if (cpos >= 0) {
1225 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001226 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001227 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 mWindows.remove(cpos);
1229 }
1230 }
1231 }
1232 return interestingPos;
1233 }
Romain Guy06882f82009-06-10 13:36:04 -07001234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 private void reAddWindowToListInOrderLocked(WindowState win) {
1236 addWindowToListInOrderLocked(win, false);
1237 // This is a hack to get all of the child windows added as well
1238 // at the right position. Child windows should be rare and
1239 // this case should be rare, so it shouldn't be that big a deal.
1240 int wpos = mWindows.indexOf(win);
1241 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001242 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001243 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001245 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 reAddWindowLocked(wpos, win);
1247 }
1248 }
Romain Guy06882f82009-06-10 13:36:04 -07001249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 void logWindowList(String prefix) {
1251 int N = mWindows.size();
1252 while (N > 0) {
1253 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001254 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 }
1256 }
Romain Guy06882f82009-06-10 13:36:04 -07001257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 void moveInputMethodDialogsLocked(int pos) {
1259 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001262 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 for (int i=0; i<N; i++) {
1264 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1265 }
1266 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001267 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 logWindowList(" ");
1269 }
Romain Guy06882f82009-06-10 13:36:04 -07001270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 if (pos >= 0) {
1272 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1273 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001274 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 if (wp == mInputMethodWindow) {
1276 pos++;
1277 }
1278 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001279 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 for (int i=0; i<N; i++) {
1281 WindowState win = dialogs.get(i);
1282 win.mTargetAppToken = targetAppToken;
1283 pos = reAddWindowLocked(pos, win);
1284 }
1285 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001286 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 logWindowList(" ");
1288 }
1289 return;
1290 }
1291 for (int i=0; i<N; i++) {
1292 WindowState win = dialogs.get(i);
1293 win.mTargetAppToken = null;
1294 reAddWindowToListInOrderLocked(win);
1295 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001296 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 logWindowList(" ");
1298 }
1299 }
1300 }
Romain Guy06882f82009-06-10 13:36:04 -07001301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1303 final WindowState imWin = mInputMethodWindow;
1304 final int DN = mInputMethodDialogs.size();
1305 if (imWin == null && DN == 0) {
1306 return false;
1307 }
Romain Guy06882f82009-06-10 13:36:04 -07001308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1310 if (imPos >= 0) {
1311 // In this case, the input method windows are to be placed
1312 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 // First check to see if the input method windows are already
1315 // located here, and contiguous.
1316 final int N = mWindows.size();
1317 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001318 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 // Figure out the actual input method window that should be
1321 // at the bottom of their stack.
1322 WindowState baseImWin = imWin != null
1323 ? imWin : mInputMethodDialogs.get(0);
1324 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001325 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 if (cw.mSubLayer < 0) baseImWin = cw;
1327 }
Romain Guy06882f82009-06-10 13:36:04 -07001328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 if (firstImWin == baseImWin) {
1330 // The windows haven't moved... but are they still contiguous?
1331 // First find the top IM window.
1332 int pos = imPos+1;
1333 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001334 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 break;
1336 }
1337 pos++;
1338 }
1339 pos++;
1340 // Now there should be no more input method windows above.
1341 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001342 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 break;
1344 }
1345 pos++;
1346 }
1347 if (pos >= N) {
1348 // All is good!
1349 return false;
1350 }
1351 }
Romain Guy06882f82009-06-10 13:36:04 -07001352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 if (imWin != null) {
1354 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001355 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 logWindowList(" ");
1357 }
1358 imPos = tmpRemoveWindowLocked(imPos, imWin);
1359 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001360 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 logWindowList(" ");
1362 }
1363 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1364 reAddWindowLocked(imPos, imWin);
1365 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001366 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 logWindowList(" ");
1368 }
1369 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1370 } else {
1371 moveInputMethodDialogsLocked(imPos);
1372 }
Romain Guy06882f82009-06-10 13:36:04 -07001373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 } else {
1375 // In this case, the input method windows go in a fixed layer,
1376 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001379 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 tmpRemoveWindowLocked(0, imWin);
1381 imWin.mTargetAppToken = null;
1382 reAddWindowToListInOrderLocked(imWin);
1383 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001384 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 logWindowList(" ");
1386 }
1387 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1388 } else {
1389 moveInputMethodDialogsLocked(-1);;
1390 }
Romain Guy06882f82009-06-10 13:36:04 -07001391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 }
Romain Guy06882f82009-06-10 13:36:04 -07001393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 if (needAssignLayers) {
1395 assignLayersLocked();
1396 }
Romain Guy06882f82009-06-10 13:36:04 -07001397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 return true;
1399 }
Romain Guy06882f82009-06-10 13:36:04 -07001400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 void adjustInputMethodDialogsLocked() {
1402 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1403 }
Romain Guy06882f82009-06-10 13:36:04 -07001404
Dianne Hackborn25994b42009-09-04 14:21:19 -07001405 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001406 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001407 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1408 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1409 ? wallpaperTarget.mAppToken.animation : null)
1410 + " upper=" + mUpperWallpaperTarget
1411 + " lower=" + mLowerWallpaperTarget);
1412 return (wallpaperTarget != null
1413 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1414 && wallpaperTarget.mAppToken.animation != null)))
1415 || mUpperWallpaperTarget != null
1416 || mLowerWallpaperTarget != null;
1417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001418
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001419 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1420 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001421
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001422 int adjustWallpaperWindowsLocked() {
1423 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001424
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001425 final int dw = mCurDisplayWidth;
1426 final int dh = mCurDisplayHeight;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001427
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001428 // First find top-most window that has asked to be on top of the
1429 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001430 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001431 int N = localmWindows.size();
1432 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001433 WindowState foundW = null;
1434 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001435 WindowState topCurW = null;
1436 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001437 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001438 int i = N;
1439 while (i > 0) {
1440 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001441 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001442 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1443 if (topCurW == null) {
1444 topCurW = w;
1445 topCurI = i;
1446 }
1447 continue;
1448 }
1449 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001450 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001451 // If this window's app token is hidden and not animating,
1452 // it is of no interest to us.
1453 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001454 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001455 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001456 continue;
1457 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001459 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001460 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1461 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001462 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001463 && (mWallpaperTarget == w
1464 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001465 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001466 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001467 foundW = w;
1468 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001469 if (w == mWallpaperTarget && ((w.mAppToken != null
1470 && w.mAppToken.animation != null)
1471 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001472 // The current wallpaper target is animating, so we'll
1473 // look behind it for another possible target and figure
1474 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001475 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001476 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001477 continue;
1478 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001479 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001480 } else if (w == mWindowDetachedWallpaper) {
1481 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001482 }
1483 }
1484
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001485 if (foundW == null && windowDetachedI >= 0) {
1486 if (DEBUG_WALLPAPER) Slog.v(TAG,
1487 "Found animating detached wallpaper activity: #" + i + "=" + w);
1488 foundW = w;
1489 foundI = windowDetachedI;
1490 }
1491
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001492 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001493 // If we are currently waiting for an app transition, and either
1494 // the current target or the next target are involved with it,
1495 // then hold off on doing anything with the wallpaper.
1496 // Note that we are checking here for just whether the target
1497 // is part of an app token... which is potentially overly aggressive
1498 // (the app token may not be involved in the transition), but good
1499 // enough (we'll just wait until whatever transition is pending
1500 // executes).
1501 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001503 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001504 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001505 }
1506 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001508 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001509 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001510 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001511 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001512
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001513 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001514 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001515 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001516 + " oldTarget: " + mWallpaperTarget);
1517 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001518
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001519 mLowerWallpaperTarget = null;
1520 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001521
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001522 WindowState oldW = mWallpaperTarget;
1523 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001524
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001525 // Now what is happening... if the current and new targets are
1526 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001527 if (foundW != null && oldW != null) {
1528 boolean oldAnim = oldW.mAnimation != null
1529 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1530 boolean foundAnim = foundW.mAnimation != null
1531 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001532 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001533 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001534 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001535 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001536 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001537 int oldI = localmWindows.indexOf(oldW);
1538 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001539 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001540 }
1541 if (oldI >= 0) {
1542 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001544 + "=" + oldW + "; new#" + foundI
1545 + "=" + foundW);
1546 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001547
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001548 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001549 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001550 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001551 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001552 }
1553 mWallpaperTarget = oldW;
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001556 // Now set the upper and lower wallpaper targets
1557 // correctly, and make sure that we are positioning
1558 // the wallpaper below the lower.
1559 if (foundI > oldI) {
1560 // The new target is on top of the old one.
1561 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001563 }
1564 mUpperWallpaperTarget = foundW;
1565 mLowerWallpaperTarget = oldW;
1566 foundW = oldW;
1567 foundI = oldI;
1568 } else {
1569 // The new target is below the old one.
1570 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001571 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001572 }
1573 mUpperWallpaperTarget = oldW;
1574 mLowerWallpaperTarget = foundW;
1575 }
1576 }
1577 }
1578 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001579
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001580 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001581 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001582 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1583 || (mLowerWallpaperTarget.mAppToken != null
1584 && mLowerWallpaperTarget.mAppToken.animation != null);
1585 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1586 || (mUpperWallpaperTarget.mAppToken != null
1587 && mUpperWallpaperTarget.mAppToken.animation != null);
1588 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001589 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001590 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001591 }
1592 mLowerWallpaperTarget = null;
1593 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001594 }
1595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001597 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001598 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001599 // The window is visible to the compositor... but is it visible
1600 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001601 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001603
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001604 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001605 // its layer adjustment. Only do this if we are not transfering
1606 // between two wallpaper targets.
1607 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001608 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001609 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001610
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001611 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1612 * TYPE_LAYER_MULTIPLIER
1613 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001614
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001615 // Now w is the window we are supposed to be behind... but we
1616 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001617 // AND any starting window associated with it, AND below the
1618 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001619 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001620 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001621 if (wb.mBaseLayer < maxLayer &&
1622 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001623 (foundW.mAttachedWindow == null ||
1624 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001625 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001626 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001627 // This window is not related to the previous one in any
1628 // interesting way, so stop here.
1629 break;
1630 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001631 foundW = wb;
1632 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001633 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001634 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001635 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001637
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001638 if (foundW == null && topCurW != null) {
1639 // There is no wallpaper target, so it goes at the bottom.
1640 // We will assume it is the same place as last time, if known.
1641 foundW = topCurW;
1642 foundI = topCurI+1;
1643 } else {
1644 // Okay i is the position immediately above the wallpaper. Look at
1645 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001646 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001647 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001648
Dianne Hackborn284ac932009-08-28 10:34:25 -07001649 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 if (mWallpaperTarget.mWallpaperX >= 0) {
1651 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001652 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001653 }
1654 if (mWallpaperTarget.mWallpaperY >= 0) {
1655 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001656 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001657 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001659
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001660 // Start stepping backwards from here, ensuring that our wallpaper windows
1661 // are correctly placed.
1662 int curTokenIndex = mWallpaperTokens.size();
1663 while (curTokenIndex > 0) {
1664 curTokenIndex--;
1665 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001666 if (token.hidden == visible) {
1667 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1668 token.hidden = !visible;
1669 // Need to do a layout to ensure the wallpaper now has the
1670 // correct size.
1671 mLayoutNeeded = true;
1672 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001673
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001674 int curWallpaperIndex = token.windows.size();
1675 while (curWallpaperIndex > 0) {
1676 curWallpaperIndex--;
1677 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001678
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001679 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001680 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001682
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001683 // First, make sure the client has the current visibility
1684 // state.
1685 if (wallpaper.mWallpaperVisible != visible) {
1686 wallpaper.mWallpaperVisible = visible;
1687 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001688 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001689 "Setting visibility of wallpaper " + wallpaper
1690 + ": " + visible);
1691 wallpaper.mClient.dispatchAppVisibility(visible);
1692 } catch (RemoteException e) {
1693 }
1694 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001695
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001696 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001697 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001698 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001699
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001700 // First, if this window is at the current index, then all
1701 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001702 if (wallpaper == foundW) {
1703 foundI--;
1704 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001705 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001706 continue;
1707 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001709 // The window didn't match... the current wallpaper window,
1710 // wherever it is, is in the wrong place, so make sure it is
1711 // not in the list.
1712 int oldIndex = localmWindows.indexOf(wallpaper);
1713 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001714 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001715 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001716 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001717 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001718 if (oldIndex < foundI) {
1719 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001720 }
1721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001723 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001724 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1725 Slog.v(TAG, "Moving wallpaper " + wallpaper
1726 + " from " + oldIndex + " to " + foundI);
1727 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001728
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001729 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001730 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001731 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001732 }
1733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001734
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001735 return changed;
1736 }
1737
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001738 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001739 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001740 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001741 mWallpaperAnimLayerAdjustment = adj;
1742 int curTokenIndex = mWallpaperTokens.size();
1743 while (curTokenIndex > 0) {
1744 curTokenIndex--;
1745 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1746 int curWallpaperIndex = token.windows.size();
1747 while (curWallpaperIndex > 0) {
1748 curWallpaperIndex--;
1749 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1750 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001751 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001752 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001753 }
1754 }
1755 }
1756
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001757 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1758 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001759 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001760 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001761 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001762 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001763 int availw = wallpaperWin.mScaledFrame.right-wallpaperWin.mScaledFrame.left-dw;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001764 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1765 changed = wallpaperWin.mXOffset != offset;
1766 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001767 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001768 + wallpaperWin + " x: " + offset);
1769 wallpaperWin.mXOffset = offset;
1770 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001771 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001772 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001773 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001774 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001775 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001776
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001777 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001778 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001779 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1780 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1781 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001782 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001783 + wallpaperWin + " y: " + offset);
1784 changed = true;
1785 wallpaperWin.mYOffset = offset;
1786 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001787 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001788 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001789 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001790 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001791 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001792
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001793 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001794 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001796 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1797 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001798 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001799 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001800 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001801 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001802 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1803 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001804 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001805 if (mWaitingOnWallpaper != null) {
1806 long start = SystemClock.uptimeMillis();
1807 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1808 < start) {
1809 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001810 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001811 "Waiting for offset complete...");
1812 mWindowMap.wait(WALLPAPER_TIMEOUT);
1813 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001814 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001816 if ((start+WALLPAPER_TIMEOUT)
1817 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001818 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001819 + wallpaperWin);
1820 mLastWallpaperTimeoutTime = start;
1821 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001822 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001823 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001824 }
1825 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001826 } catch (RemoteException e) {
1827 }
1828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001830 return changed;
1831 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001832
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001833 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001834 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001835 if (mWaitingOnWallpaper != null &&
1836 mWaitingOnWallpaper.mClient.asBinder() == window) {
1837 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001838 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001839 }
1840 }
1841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001842
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001843 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001844 final int dw = mCurDisplayWidth;
1845 final int dh = mCurDisplayHeight;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001846
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001847 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001848
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001849 WindowState target = mWallpaperTarget;
1850 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001851 if (target.mWallpaperX >= 0) {
1852 mLastWallpaperX = target.mWallpaperX;
1853 } else if (changingTarget.mWallpaperX >= 0) {
1854 mLastWallpaperX = changingTarget.mWallpaperX;
1855 }
1856 if (target.mWallpaperY >= 0) {
1857 mLastWallpaperY = target.mWallpaperY;
1858 } else if (changingTarget.mWallpaperY >= 0) {
1859 mLastWallpaperY = changingTarget.mWallpaperY;
1860 }
1861 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001862
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001863 int curTokenIndex = mWallpaperTokens.size();
1864 while (curTokenIndex > 0) {
1865 curTokenIndex--;
1866 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1867 int curWallpaperIndex = token.windows.size();
1868 while (curWallpaperIndex > 0) {
1869 curWallpaperIndex--;
1870 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1871 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1872 wallpaper.computeShownFrameLocked();
1873 changed = true;
1874 // We only want to be synchronous with one wallpaper.
1875 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001876 }
1877 }
1878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001880 return changed;
1881 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001882
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001883 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001884 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001885 final int dw = mCurDisplayWidth;
1886 final int dh = mCurDisplayHeight;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001887
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001888 int curTokenIndex = mWallpaperTokens.size();
1889 while (curTokenIndex > 0) {
1890 curTokenIndex--;
1891 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001892 if (token.hidden == visible) {
1893 token.hidden = !visible;
1894 // Need to do a layout to ensure the wallpaper now has the
1895 // correct size.
1896 mLayoutNeeded = true;
1897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001898
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001899 int curWallpaperIndex = token.windows.size();
1900 while (curWallpaperIndex > 0) {
1901 curWallpaperIndex--;
1902 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1903 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001904 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001905 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001906
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001907 if (wallpaper.mWallpaperVisible != visible) {
1908 wallpaper.mWallpaperVisible = visible;
1909 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001910 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001911 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001912 + ": " + visible);
1913 wallpaper.mClient.dispatchAppVisibility(visible);
1914 } catch (RemoteException e) {
1915 }
1916 }
1917 }
1918 }
1919 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 public int addWindow(Session session, IWindow client,
1922 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001923 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 int res = mPolicy.checkAddPermission(attrs);
1925 if (res != WindowManagerImpl.ADD_OKAY) {
1926 return res;
1927 }
Romain Guy06882f82009-06-10 13:36:04 -07001928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 boolean reportNewConfig = false;
1930 WindowState attachedWindow = null;
1931 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001932 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001936 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 }
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001940 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1942 }
1943
1944 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001945 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001947 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 + attrs.token + ". Aborting.");
1949 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1950 }
1951 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1952 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001953 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 + attrs.token + ". Aborting.");
1955 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1956 }
1957 }
1958
1959 boolean addToken = false;
1960 WindowToken token = mTokenMap.get(attrs.token);
1961 if (token == null) {
1962 if (attrs.type >= FIRST_APPLICATION_WINDOW
1963 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001964 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 + attrs.token + ". Aborting.");
1966 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1967 }
1968 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001969 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 + attrs.token + ". Aborting.");
1971 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1972 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001973 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001974 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001975 + attrs.token + ". Aborting.");
1976 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1977 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001978 token = new WindowToken(this, attrs.token, -1, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 addToken = true;
1980 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1981 && attrs.type <= LAST_APPLICATION_WINDOW) {
1982 AppWindowToken atoken = token.appWindowToken;
1983 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001984 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 + token + ". Aborting.");
1986 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1987 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001988 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 + token + ". Aborting.");
1990 return WindowManagerImpl.ADD_APP_EXITING;
1991 }
1992 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1993 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001994 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1996 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1997 }
1998 } else if (attrs.type == TYPE_INPUT_METHOD) {
1999 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002000 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 + attrs.token + ". Aborting.");
2002 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2003 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002004 } else if (attrs.type == TYPE_WALLPAPER) {
2005 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002006 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002007 + attrs.token + ". Aborting.");
2008 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 }
2011
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002012 win = new WindowState(this, session, client, token,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 attachedWindow, attrs, viewVisibility);
2014 if (win.mDeathRecipient == null) {
2015 // Client has apparently died, so there is no reason to
2016 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002017 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 + " that is dead, aborting.");
2019 return WindowManagerImpl.ADD_APP_EXITING;
2020 }
2021
2022 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 res = mPolicy.prepareAddWindowLw(win, attrs);
2025 if (res != WindowManagerImpl.ADD_OKAY) {
2026 return res;
2027 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002028
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002029 if (outInputChannel != null) {
2030 String name = win.makeInputChannelName();
2031 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2032 win.mInputChannel = inputChannels[0];
2033 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2034
Jeff Brown928e0542011-01-10 11:17:36 -08002035 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037
2038 // From now on, no exceptions or errors allowed!
2039
2040 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002041
Dianne Hackborn5132b372010-07-29 12:51:35 -07002042 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 if (addToken) {
2045 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 }
2047 win.attach();
2048 mWindowMap.put(client.asBinder(), win);
2049
2050 if (attrs.type == TYPE_APPLICATION_STARTING &&
2051 token.appWindowToken != null) {
2052 token.appWindowToken.startingWindow = win;
2053 }
2054
2055 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 if (attrs.type == TYPE_INPUT_METHOD) {
2058 mInputMethodWindow = win;
2059 addInputMethodWindowToListLocked(win);
2060 imMayMove = false;
2061 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2062 mInputMethodDialogs.add(win);
2063 addWindowToListInOrderLocked(win, true);
2064 adjustInputMethodDialogsLocked();
2065 imMayMove = false;
2066 } else {
2067 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002068 if (attrs.type == TYPE_WALLPAPER) {
2069 mLastWallpaperTimeoutTime = 0;
2070 adjustWallpaperWindowsLocked();
2071 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002072 adjustWallpaperWindowsLocked();
2073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 }
Romain Guy06882f82009-06-10 13:36:04 -07002075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 if (mInTouchMode) {
2081 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2082 }
2083 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2084 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2085 }
Romain Guy06882f82009-06-10 13:36:04 -07002086
Jeff Brown2e44b072011-01-24 15:21:56 -08002087 mInputMonitor.setUpdateInputWindowsNeededLw();
2088
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002089 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002091 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2092 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002093 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 imMayMove = false;
2095 }
2096 }
Romain Guy06882f82009-06-10 13:36:04 -07002097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002099 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 }
Romain Guy06882f82009-06-10 13:36:04 -07002101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 assignLayersLocked();
2103 // Don't do layout here, the window must call
2104 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 //dump();
2107
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002108 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002109 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002110 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002111 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002112
Joe Onorato8a9b2202010-02-26 18:56:32 -08002113 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002114 TAG, "New client " + client.asBinder()
2115 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002116
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002117 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002118 reportNewConfig = true;
2119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 }
2121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 if (reportNewConfig) {
2123 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002124 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 return res;
2129 }
Romain Guy06882f82009-06-10 13:36:04 -07002130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 public void removeWindow(Session session, IWindow client) {
2132 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002133 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002134 if (win == null) {
2135 return;
2136 }
2137 removeWindowLocked(session, win);
2138 }
2139 }
Romain Guy06882f82009-06-10 13:36:04 -07002140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 public void removeWindowLocked(Session session, WindowState win) {
2142
Joe Onorato8a9b2202010-02-26 18:56:32 -08002143 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 TAG, "Remove " + win + " client="
2145 + Integer.toHexString(System.identityHashCode(
2146 win.mClient.asBinder()))
2147 + ", surface=" + win.mSurface);
2148
2149 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002150
2151 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002152
Joe Onorato8a9b2202010-02-26 18:56:32 -08002153 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2155 + " mExiting=" + win.mExiting
2156 + " isAnimating=" + win.isAnimating()
2157 + " app-animation="
2158 + (win.mAppToken != null ? win.mAppToken.animation : null)
2159 + " inPendingTransaction="
2160 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2161 + " mDisplayFrozen=" + mDisplayFrozen);
2162 // Visibility of the removed window. Will be used later to update orientation later on.
2163 boolean wasVisible = false;
2164 // First, see if we need to run an animation. If we do, we have
2165 // to hold off on removing the window until the animation is done.
2166 // If the display is frozen, just remove immediately, since the
2167 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002168 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 // If we are not currently running the exit animation, we
2170 // need to see about starting one.
2171 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2174 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2175 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2176 }
2177 // Try starting an animation.
2178 if (applyAnimationLocked(win, transit, false)) {
2179 win.mExiting = true;
2180 }
2181 }
2182 if (win.mExiting || win.isAnimating()) {
2183 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 win.mExiting = true;
2186 win.mRemoveOnExit = true;
2187 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002188 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2189 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002191 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 if (win.mAppToken != null) {
2193 win.mAppToken.updateReportedVisibilityLocked();
2194 }
2195 //dump();
2196 Binder.restoreCallingIdentity(origId);
2197 return;
2198 }
2199 }
2200
2201 removeWindowInnerLocked(session, win);
2202 // Removing a visible window will effect the computed orientation
2203 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002204 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002205 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002206 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002207 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002209 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 Binder.restoreCallingIdentity(origId);
2211 }
Romain Guy06882f82009-06-10 13:36:04 -07002212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002214 if (win.mRemoved) {
2215 // Nothing to do.
2216 return;
2217 }
2218
2219 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2220 WindowState cwin = win.mChildWindows.get(i);
2221 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2222 + win);
2223 removeWindowInnerLocked(cwin.mSession, cwin);
2224 }
2225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 if (mInputMethodTarget == win) {
2229 moveInputMethodWindowsIfNeededLocked(false);
2230 }
Romain Guy06882f82009-06-10 13:36:04 -07002231
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002232 if (false) {
2233 RuntimeException e = new RuntimeException("here");
2234 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002235 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 mPolicy.removeWindowLw(win);
2239 win.removeLocked();
2240
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002241 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 mWindowMap.remove(win.mClient.asBinder());
2243 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002244 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002245 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002246 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247
2248 if (mInputMethodWindow == win) {
2249 mInputMethodWindow = null;
2250 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2251 mInputMethodDialogs.remove(win);
2252 }
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 final WindowToken token = win.mToken;
2255 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002256 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 token.windows.remove(win);
2258 if (atoken != null) {
2259 atoken.allAppWindows.remove(win);
2260 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002261 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 TAG, "**** Removing window " + win + ": count="
2263 + token.windows.size());
2264 if (token.windows.size() == 0) {
2265 if (!token.explicit) {
2266 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 } else if (atoken != null) {
2268 atoken.firstWindowDrawn = false;
2269 }
2270 }
2271
2272 if (atoken != null) {
2273 if (atoken.startingWindow == win) {
2274 atoken.startingWindow = null;
2275 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2276 // If this is the last window and we had requested a starting
2277 // transition window, well there is no point now.
2278 atoken.startingData = null;
2279 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2280 // If this is the last window except for a starting transition
2281 // window, we need to get rid of the starting transition.
2282 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002283 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 + ": no more real windows");
2285 }
2286 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2287 mH.sendMessage(m);
2288 }
2289 }
Romain Guy06882f82009-06-10 13:36:04 -07002290
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002291 if (win.mAttrs.type == TYPE_WALLPAPER) {
2292 mLastWallpaperTimeoutTime = 0;
2293 adjustWallpaperWindowsLocked();
2294 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002295 adjustWallpaperWindowsLocked();
2296 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 if (!mInLayout) {
2299 assignLayersLocked();
2300 mLayoutNeeded = true;
2301 performLayoutAndPlaceSurfacesLocked();
2302 if (win.mAppToken != null) {
2303 win.mAppToken.updateReportedVisibilityLocked();
2304 }
2305 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002306
Jeff Brown2e44b072011-01-24 15:21:56 -08002307 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 }
2309
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002310 static void logSurface(WindowState w, String msg, RuntimeException where) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002311 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2312 + ": " + msg + " / " + w.mAttrs.getTitle();
2313 if (where != null) {
2314 Slog.i(TAG, str, where);
2315 } else {
2316 Slog.i(TAG, str);
2317 }
2318 }
2319
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002320 void setTransparentRegionWindow(Session session, IWindow client, Region region) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 long origId = Binder.clearCallingIdentity();
2322 try {
2323 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002324 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002326 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2327 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 Surface.openTransaction();
2329 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002330 if (SHOW_TRANSACTIONS) logSurface(w,
2331 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 w.mSurface.setTransparentRegionHint(region);
2333 } finally {
2334 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002335 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2336 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 }
2338 }
2339 }
2340 } finally {
2341 Binder.restoreCallingIdentity(origId);
2342 }
2343 }
2344
2345 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002346 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002347 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 long origId = Binder.clearCallingIdentity();
2349 try {
2350 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002351 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 if (w != null) {
2353 w.mGivenInsetsPending = false;
2354 w.mGivenContentInsets.set(contentInsets);
2355 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002356 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 w.mTouchableInsets = touchableInsets;
2358 mLayoutNeeded = true;
2359 performLayoutAndPlaceSurfacesLocked();
2360 }
2361 }
2362 } finally {
2363 Binder.restoreCallingIdentity(origId);
2364 }
2365 }
Romain Guy06882f82009-06-10 13:36:04 -07002366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 public void getWindowDisplayFrame(Session session, IWindow client,
2368 Rect outDisplayFrame) {
2369 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002370 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 if (win == null) {
2372 outDisplayFrame.setEmpty();
2373 return;
2374 }
2375 outDisplayFrame.set(win.mDisplayFrame);
2376 }
2377 }
2378
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002379 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2380 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002381 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2382 window.mWallpaperX = x;
2383 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002384 window.mWallpaperXStep = xStep;
2385 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002386 if (updateWallpaperOffsetLocked(window, true)) {
2387 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002388 }
2389 }
2390 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002391
Dianne Hackborn75804932009-10-20 20:15:20 -07002392 void wallpaperCommandComplete(IBinder window, Bundle result) {
2393 synchronized (mWindowMap) {
2394 if (mWaitingOnWallpaper != null &&
2395 mWaitingOnWallpaper.mClient.asBinder() == window) {
2396 mWaitingOnWallpaper = null;
2397 mWindowMap.notifyAll();
2398 }
2399 }
2400 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002401
Dianne Hackborn75804932009-10-20 20:15:20 -07002402 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2403 String action, int x, int y, int z, Bundle extras, boolean sync) {
2404 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2405 || window == mUpperWallpaperTarget) {
2406 boolean doWait = sync;
2407 int curTokenIndex = mWallpaperTokens.size();
2408 while (curTokenIndex > 0) {
2409 curTokenIndex--;
2410 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2411 int curWallpaperIndex = token.windows.size();
2412 while (curWallpaperIndex > 0) {
2413 curWallpaperIndex--;
2414 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2415 try {
2416 wallpaper.mClient.dispatchWallpaperCommand(action,
2417 x, y, z, extras, sync);
2418 // We only want to be synchronous with one wallpaper.
2419 sync = false;
2420 } catch (RemoteException e) {
2421 }
2422 }
2423 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002424
Dianne Hackborn75804932009-10-20 20:15:20 -07002425 if (doWait) {
2426 // XXX Need to wait for result.
2427 }
2428 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002429
Dianne Hackborn75804932009-10-20 20:15:20 -07002430 return null;
2431 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 public int relayoutWindow(Session session, IWindow client,
2434 WindowManager.LayoutParams attrs, int requestedWidth,
2435 int requestedHeight, int viewVisibility, boolean insetsPending,
2436 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002437 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 boolean displayed = false;
2439 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002440 boolean configChanged;
Joe Onoratoac0ee892011-01-30 15:38:30 -08002441
2442 // if they don't have this permission, mask out the status bar bits
2443 if (attrs != null) {
2444 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
2445 != PackageManager.PERMISSION_GRANTED) {
2446 attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2447 attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2448 }
2449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002453 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002454 if (win == null) {
2455 return 0;
2456 }
2457 win.mRequestedWidth = requestedWidth;
2458 win.mRequestedHeight = requestedHeight;
2459
2460 if (attrs != null) {
2461 mPolicy.adjustWindowParamsLw(attrs);
2462 }
Romain Guy06882f82009-06-10 13:36:04 -07002463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 int attrChanges = 0;
2465 int flagChanges = 0;
2466 if (attrs != null) {
2467 flagChanges = win.mAttrs.flags ^= attrs.flags;
2468 attrChanges = win.mAttrs.copyFrom(attrs);
2469 }
2470
Joe Onorato8a9b2202010-02-26 18:56:32 -08002471 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472
2473 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2474 win.mAlpha = attrs.alpha;
2475 }
2476
2477 final boolean scaledWindow =
2478 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2479
2480 if (scaledWindow) {
2481 // requested{Width|Height} Surface's physical size
2482 // attrs.{width|height} Size on screen
2483 win.mHScale = (attrs.width != requestedWidth) ?
2484 (attrs.width / (float)requestedWidth) : 1.0f;
2485 win.mVScale = (attrs.height != requestedHeight) ?
2486 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002487 } else {
2488 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 }
2490
2491 boolean imMayMove = (flagChanges&(
2492 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2493 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 boolean focusMayChange = win.mViewVisibility != viewVisibility
2496 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2497 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002498
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002499 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2500 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 win.mRelayoutCalled = true;
2503 final int oldVisibility = win.mViewVisibility;
2504 win.mViewVisibility = viewVisibility;
2505 if (viewVisibility == View.VISIBLE &&
2506 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2507 displayed = !win.isVisibleLw();
2508 if (win.mExiting) {
2509 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002510 if (win.mAnimation != null) {
2511 win.mAnimation.cancel();
2512 win.mAnimation = null;
2513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 }
2515 if (win.mDestroying) {
2516 win.mDestroying = false;
2517 mDestroySurface.remove(win);
2518 }
2519 if (oldVisibility == View.GONE) {
2520 win.mEnterAnimationPending = true;
2521 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002522 if (displayed) {
2523 if (win.mSurface != null && !win.mDrawPending
2524 && !win.mCommitDrawPending && !mDisplayFrozen
2525 && mPolicy.isScreenOn()) {
2526 applyEnterAnimationLocked(win);
2527 }
2528 if ((win.mAttrs.flags
2529 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2530 if (DEBUG_VISIBILITY) Slog.v(TAG,
2531 "Relayout window turning screen on: " + win);
2532 win.mTurnOnScreen = true;
2533 }
2534 int diff = 0;
2535 if (win.mConfiguration != mCurConfiguration
2536 && (win.mConfiguration == null
2537 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2538 win.mConfiguration = mCurConfiguration;
2539 if (DEBUG_CONFIGURATION) {
2540 Slog.i(TAG, "Window " + win + " visible with new config: "
2541 + win.mConfiguration + " / 0x"
2542 + Integer.toHexString(diff));
2543 }
2544 outConfig.setTo(mCurConfiguration);
2545 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2548 // To change the format, we need to re-build the surface.
2549 win.destroySurfaceLocked();
2550 displayed = true;
2551 }
2552 try {
2553 Surface surface = win.createSurfaceLocked();
2554 if (surface != null) {
2555 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002556 win.mReportDestroySurface = false;
2557 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002558 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002559 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002561 // For some reason there isn't a surface. Clear the
2562 // caller's object so they see the same state.
2563 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 }
2565 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002566 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002567
Joe Onorato8a9b2202010-02-26 18:56:32 -08002568 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002569 + client + " (" + win.mAttrs.getTitle() + ")",
2570 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 Binder.restoreCallingIdentity(origId);
2572 return 0;
2573 }
2574 if (displayed) {
2575 focusMayChange = true;
2576 }
2577 if (win.mAttrs.type == TYPE_INPUT_METHOD
2578 && mInputMethodWindow == null) {
2579 mInputMethodWindow = win;
2580 imMayMove = true;
2581 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002582 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2583 && win.mAppToken != null
2584 && win.mAppToken.startingWindow != null) {
2585 // Special handling of starting window over the base
2586 // window of the app: propagate lock screen flags to it,
2587 // to provide the correct semantics while starting.
2588 final int mask =
2589 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002590 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2591 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002592 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2593 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 } else {
2596 win.mEnterAnimationPending = false;
2597 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002598 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002599 + ": mExiting=" + win.mExiting
2600 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 // If we are not currently running the exit animation, we
2602 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002603 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 // Try starting an animation; if there isn't one, we
2605 // can destroy the surface right away.
2606 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2607 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2608 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2609 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002610 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002612 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 } else if (win.isAnimating()) {
2615 // Currently in a hide animation... turn this into
2616 // an exit.
2617 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002618 } else if (win == mWallpaperTarget) {
2619 // If the wallpaper is currently behind this
2620 // window, we need to change both of them inside
2621 // of a transaction to avoid artifacts.
2622 win.mExiting = true;
2623 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 } else {
2625 if (mInputMethodWindow == win) {
2626 mInputMethodWindow = null;
2627 }
2628 win.destroySurfaceLocked();
2629 }
2630 }
2631 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002632
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002633 if (win.mSurface == null || (win.getAttrs().flags
2634 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2635 || win.mSurfacePendingDestroy) {
2636 // We are being called from a local process, which
2637 // means outSurface holds its current surface. Ensure the
2638 // surface object is cleared, but we don't want it actually
2639 // destroyed at this point.
2640 win.mSurfacePendingDestroy = false;
2641 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002642 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002643 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002644 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002645 "Keeping surface, will report destroy: " + win);
2646 win.mReportDestroySurface = true;
2647 outSurface.copyFrom(win.mSurface);
2648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 }
2650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 if (focusMayChange) {
2652 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002653 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2654 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 imMayMove = false;
2656 }
2657 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2658 }
Romain Guy06882f82009-06-10 13:36:04 -07002659
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002660 // updateFocusedWindowLocked() already assigned layers so we only need to
2661 // reassign them at this point if the IM window state gets shuffled
2662 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002665 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2666 // Little hack here -- we -should- be able to rely on the
2667 // function to return true if the IME has moved and needs
2668 // its layer recomputed. However, if the IME was hidden
2669 // and isn't actually moved in the list, its layer may be
2670 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 assignLayers = true;
2672 }
2673 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002674 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002675 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002676 assignLayers = true;
2677 }
2678 }
Romain Guy06882f82009-06-10 13:36:04 -07002679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002680 mLayoutNeeded = true;
2681 win.mGivenInsetsPending = insetsPending;
2682 if (assignLayers) {
2683 assignLayersLocked();
2684 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002685 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002687 if (displayed && win.mIsWallpaper) {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07002688 updateWallpaperOffsetLocked(win, mCurDisplayWidth, mCurDisplayHeight, false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 if (win.mAppToken != null) {
2691 win.mAppToken.updateReportedVisibilityLocked();
2692 }
2693 outFrame.set(win.mFrame);
2694 outContentInsets.set(win.mContentInsets);
2695 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002696 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002698 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 + ", requestedHeight=" + requestedHeight
2700 + ", viewVisibility=" + viewVisibility
2701 + "\nRelayout returning frame=" + outFrame
2702 + ", surface=" + outSurface);
2703
Joe Onorato8a9b2202010-02-26 18:56:32 -08002704 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2706
2707 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002708
Jeff Brown2e44b072011-01-24 15:21:56 -08002709 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 }
2711
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002712 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 sendNewConfiguration();
2714 }
Romain Guy06882f82009-06-10 13:36:04 -07002715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2719 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2720 }
2721
Dianne Hackborn64825172011-03-02 21:32:58 -08002722 public boolean outOfMemoryWindow(Session session, IWindow client) {
2723 long origId = Binder.clearCallingIdentity();
2724
2725 try {
2726 synchronized(mWindowMap) {
2727 WindowState win = windowForClientLocked(session, client, false);
2728 if (win == null) {
2729 return false;
2730 }
2731 return reclaimSomeSurfaceMemoryLocked(win, "from-client", false);
2732 }
2733 } finally {
2734 Binder.restoreCallingIdentity(origId);
2735 }
2736 }
2737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 public void finishDrawingWindow(Session session, IWindow client) {
2739 final long origId = Binder.clearCallingIdentity();
2740 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002741 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002743 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2744 adjustWallpaperWindowsLocked();
2745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746 mLayoutNeeded = true;
2747 performLayoutAndPlaceSurfacesLocked();
2748 }
2749 }
2750 Binder.restoreCallingIdentity(origId);
2751 }
2752
2753 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08002754 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 + (lp != null ? lp.packageName : null)
2756 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2757 if (lp != null && lp.windowAnimations != 0) {
2758 // If this is a system resource, don't try to load it from the
2759 // application resources. It is nice to avoid loading application
2760 // resources if we can.
2761 String packageName = lp.packageName != null ? lp.packageName : "android";
2762 int resId = lp.windowAnimations;
2763 if ((resId&0xFF000000) == 0x01000000) {
2764 packageName = "android";
2765 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002766 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002767 + packageName);
2768 return AttributeCache.instance().get(packageName, resId,
2769 com.android.internal.R.styleable.WindowAnimation);
2770 }
2771 return null;
2772 }
Romain Guy06882f82009-06-10 13:36:04 -07002773
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002774 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08002775 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002776 + packageName + " resId=0x" + Integer.toHexString(resId));
2777 if (packageName != null) {
2778 if ((resId&0xFF000000) == 0x01000000) {
2779 packageName = "android";
2780 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002781 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002782 + packageName);
2783 return AttributeCache.instance().get(packageName, resId,
2784 com.android.internal.R.styleable.WindowAnimation);
2785 }
2786 return null;
2787 }
2788
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002789 void applyEnterAnimationLocked(WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2791 if (win.mEnterAnimationPending) {
2792 win.mEnterAnimationPending = false;
2793 transit = WindowManagerPolicy.TRANSIT_ENTER;
2794 }
2795
2796 applyAnimationLocked(win, transit, true);
2797 }
2798
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002799 boolean applyAnimationLocked(WindowState win,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 int transit, boolean isEntrance) {
2801 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2802 // If we are trying to apply an animation, but already running
2803 // an animation of the same type, then just leave that one alone.
2804 return true;
2805 }
Romain Guy06882f82009-06-10 13:36:04 -07002806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 // Only apply an animation if the display isn't frozen. If it is
2808 // frozen, there is no reason to animate and it can cause strange
2809 // artifacts when we unfreeze the display if some different animation
2810 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002811 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 int anim = mPolicy.selectAnimationLw(win, transit);
2813 int attr = -1;
2814 Animation a = null;
2815 if (anim != 0) {
2816 a = AnimationUtils.loadAnimation(mContext, anim);
2817 } else {
2818 switch (transit) {
2819 case WindowManagerPolicy.TRANSIT_ENTER:
2820 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2821 break;
2822 case WindowManagerPolicy.TRANSIT_EXIT:
2823 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2824 break;
2825 case WindowManagerPolicy.TRANSIT_SHOW:
2826 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2827 break;
2828 case WindowManagerPolicy.TRANSIT_HIDE:
2829 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2830 break;
2831 }
2832 if (attr >= 0) {
2833 a = loadAnimation(win.mAttrs, attr);
2834 }
2835 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002836 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2838 + " mAnimation=" + win.mAnimation
2839 + " isEntrance=" + isEntrance);
2840 if (a != null) {
2841 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002842 RuntimeException e = null;
2843 if (!HIDE_STACK_CRAWLS) {
2844 e = new RuntimeException();
2845 e.fillInStackTrace();
2846 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002847 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 }
2849 win.setAnimation(a);
2850 win.mAnimationIsEntrance = isEntrance;
2851 }
2852 } else {
2853 win.clearAnimation();
2854 }
2855
2856 return win.mAnimation != null;
2857 }
2858
2859 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2860 int anim = 0;
2861 Context context = mContext;
2862 if (animAttr >= 0) {
2863 AttributeCache.Entry ent = getCachedAnimations(lp);
2864 if (ent != null) {
2865 context = ent.context;
2866 anim = ent.array.getResourceId(animAttr, 0);
2867 }
2868 }
2869 if (anim != 0) {
2870 return AnimationUtils.loadAnimation(context, anim);
2871 }
2872 return null;
2873 }
Romain Guy06882f82009-06-10 13:36:04 -07002874
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002875 private Animation loadAnimation(String packageName, int resId) {
2876 int anim = 0;
2877 Context context = mContext;
2878 if (resId >= 0) {
2879 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2880 if (ent != null) {
2881 context = ent.context;
2882 anim = resId;
2883 }
2884 }
2885 if (anim != 0) {
2886 return AnimationUtils.loadAnimation(context, anim);
2887 }
2888 return null;
2889 }
2890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 private boolean applyAnimationLocked(AppWindowToken wtoken,
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002892 WindowManager.LayoutParams lp, int transit, boolean enter, boolean bgFiller) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 // Only apply an animation if the display isn't frozen. If it is
2894 // frozen, there is no reason to animate and it can cause strange
2895 // artifacts when we unfreeze the display if some different animation
2896 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002897 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002898 Animation a;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002899 if (bgFiller) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002900 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002901 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002902 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002903 } else if (mNextAppTransitionPackage != null) {
2904 a = loadAnimation(mNextAppTransitionPackage, enter ?
2905 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002906 } else {
2907 int animAttr = 0;
2908 switch (transit) {
2909 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2910 animAttr = enter
2911 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2912 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2913 break;
2914 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2915 animAttr = enter
2916 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2917 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2918 break;
2919 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2920 animAttr = enter
2921 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2922 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2923 break;
2924 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2925 animAttr = enter
2926 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2927 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2928 break;
2929 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2930 animAttr = enter
2931 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2932 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2933 break;
2934 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2935 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002936 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002937 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2938 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002939 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002940 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002941 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2942 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002943 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002944 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002945 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002946 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2947 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2948 break;
2949 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2950 animAttr = enter
2951 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2952 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2953 break;
2954 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2955 animAttr = enter
2956 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2957 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002958 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002959 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002960 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002961 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002962 + " anim=" + a
2963 + " animAttr=0x" + Integer.toHexString(animAttr)
2964 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 if (a != null) {
2967 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002968 RuntimeException e = null;
2969 if (!HIDE_STACK_CRAWLS) {
2970 e = new RuntimeException();
2971 e.fillInStackTrace();
2972 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002973 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 }
2975 wtoken.setAnimation(a);
2976 }
2977 } else {
2978 wtoken.clearAnimation();
2979 }
2980
2981 return wtoken.animation != null;
2982 }
2983
2984 // -------------------------------------------------------------
2985 // Application Window Tokens
2986 // -------------------------------------------------------------
2987
2988 public void validateAppTokens(List tokens) {
2989 int v = tokens.size()-1;
2990 int m = mAppTokens.size()-1;
2991 while (v >= 0 && m >= 0) {
2992 AppWindowToken wtoken = mAppTokens.get(m);
2993 if (wtoken.removed) {
2994 m--;
2995 continue;
2996 }
2997 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002998 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3000 }
3001 v--;
3002 m--;
3003 }
3004 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003005 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 v--;
3007 }
3008 while (m >= 0) {
3009 AppWindowToken wtoken = mAppTokens.get(m);
3010 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003011 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 }
3013 m--;
3014 }
3015 }
3016
3017 boolean checkCallingPermission(String permission, String func) {
3018 // Quick check: if the calling permission is me, it's all okay.
3019 if (Binder.getCallingPid() == Process.myPid()) {
3020 return true;
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 if (mContext.checkCallingPermission(permission)
3024 == PackageManager.PERMISSION_GRANTED) {
3025 return true;
3026 }
3027 String msg = "Permission Denial: " + func + " from pid="
3028 + Binder.getCallingPid()
3029 + ", uid=" + Binder.getCallingUid()
3030 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003031 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 return false;
3033 }
Romain Guy06882f82009-06-10 13:36:04 -07003034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 AppWindowToken findAppWindowToken(IBinder token) {
3036 WindowToken wtoken = mTokenMap.get(token);
3037 if (wtoken == null) {
3038 return null;
3039 }
3040 return wtoken.appWindowToken;
3041 }
Romain Guy06882f82009-06-10 13:36:04 -07003042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 public void addWindowToken(IBinder token, int type) {
3044 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3045 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003046 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 }
Romain Guy06882f82009-06-10 13:36:04 -07003048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003049 synchronized(mWindowMap) {
3050 WindowToken wtoken = mTokenMap.get(token);
3051 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003052 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003053 return;
3054 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003055 wtoken = new WindowToken(this, token, type, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003057 if (type == TYPE_WALLPAPER) {
3058 mWallpaperTokens.add(wtoken);
3059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
3061 }
Romain Guy06882f82009-06-10 13:36:04 -07003062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 public void removeWindowToken(IBinder token) {
3064 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3065 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003066 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067 }
3068
3069 final long origId = Binder.clearCallingIdentity();
3070 synchronized(mWindowMap) {
3071 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 if (wtoken != null) {
3073 boolean delayed = false;
3074 if (!wtoken.hidden) {
3075 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 final int N = wtoken.windows.size();
3078 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 for (int i=0; i<N; i++) {
3081 WindowState win = wtoken.windows.get(i);
3082
3083 if (win.isAnimating()) {
3084 delayed = true;
3085 }
Romain Guy06882f82009-06-10 13:36:04 -07003086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 if (win.isVisibleNow()) {
3088 applyAnimationLocked(win,
3089 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 changed = true;
3091 }
3092 }
3093
3094 if (changed) {
3095 mLayoutNeeded = true;
3096 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003097 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3098 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 }
Romain Guy06882f82009-06-10 13:36:04 -07003100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 if (delayed) {
3102 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003103 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3104 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 }
3106 }
Romain Guy06882f82009-06-10 13:36:04 -07003107
Jeff Brown2e44b072011-01-24 15:21:56 -08003108 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003110 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 }
3112 }
3113 Binder.restoreCallingIdentity(origId);
3114 }
3115
3116 public void addAppToken(int addPos, IApplicationToken token,
3117 int groupId, int requestedOrientation, boolean fullscreen) {
3118 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3119 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003120 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003121 }
Jeff Brown349703e2010-06-22 01:27:15 -07003122
3123 // Get the dispatching timeout here while we are not holding any locks so that it
3124 // can be cached by the AppWindowToken. The timeout value is used later by the
3125 // input dispatcher in code that does hold locks. If we did not cache the value
3126 // here we would run the chance of introducing a deadlock between the window manager
3127 // (which holds locks while updating the input dispatcher state) and the activity manager
3128 // (which holds locks while querying the application token).
3129 long inputDispatchingTimeoutNanos;
3130 try {
3131 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3132 } catch (RemoteException ex) {
3133 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3134 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3135 }
Romain Guy06882f82009-06-10 13:36:04 -07003136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003137 synchronized(mWindowMap) {
3138 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3139 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003140 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 return;
3142 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003143 wtoken = new AppWindowToken(this, token);
Jeff Brown349703e2010-06-22 01:27:15 -07003144 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 wtoken.groupId = groupId;
3146 wtoken.appFullscreen = fullscreen;
3147 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003148 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 // Application tokens start out hidden.
3153 wtoken.hidden = true;
3154 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 //dump();
3157 }
3158 }
Romain Guy06882f82009-06-10 13:36:04 -07003159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 public void setAppGroupId(IBinder token, int groupId) {
3161 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3162 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003163 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 }
3165
3166 synchronized(mWindowMap) {
3167 AppWindowToken wtoken = findAppWindowToken(token);
3168 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003169 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 return;
3171 }
3172 wtoken.groupId = groupId;
3173 }
3174 }
Romain Guy06882f82009-06-10 13:36:04 -07003175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 public int getOrientationFromWindowsLocked() {
3177 int pos = mWindows.size() - 1;
3178 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003179 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 pos--;
3181 if (wtoken.mAppToken != null) {
3182 // We hit an application window. so the orientation will be determined by the
3183 // app window. No point in continuing further.
3184 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3185 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003186 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 continue;
3188 }
3189 int req = wtoken.mAttrs.screenOrientation;
3190 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3191 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3192 continue;
3193 } else {
3194 return req;
3195 }
3196 }
3197 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3198 }
Romain Guy06882f82009-06-10 13:36:04 -07003199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003201 int pos = mAppTokens.size() - 1;
3202 int curGroup = 0;
3203 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3204 boolean findingBehind = false;
3205 boolean haveGroup = false;
3206 boolean lastFullscreen = false;
3207 while (pos >= 0) {
3208 AppWindowToken wtoken = mAppTokens.get(pos);
3209 pos--;
3210 // if we're about to tear down this window and not seek for
3211 // the behind activity, don't use it for orientation
3212 if (!findingBehind
3213 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3214 continue;
3215 }
3216
3217 if (!haveGroup) {
3218 // We ignore any hidden applications on the top.
3219 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003220 continue;
3221 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003222 haveGroup = true;
3223 curGroup = wtoken.groupId;
3224 lastOrientation = wtoken.requestedOrientation;
3225 } else if (curGroup != wtoken.groupId) {
3226 // If we have hit a new application group, and the bottom
3227 // of the previous group didn't explicitly say to use
3228 // the orientation behind it, and the last app was
3229 // full screen, then we'll stick with the
3230 // user's orientation.
3231 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3232 && lastFullscreen) {
3233 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003236 int or = wtoken.requestedOrientation;
3237 // If this application is fullscreen, and didn't explicitly say
3238 // to use the orientation behind it, then just take whatever
3239 // orientation it has and ignores whatever is under it.
3240 lastFullscreen = wtoken.appFullscreen;
3241 if (lastFullscreen
3242 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3243 return or;
3244 }
3245 // If this application has requested an explicit orientation,
3246 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003247 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3248 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003249 return or;
3250 }
3251 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3252 }
3253 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 }
Romain Guy06882f82009-06-10 13:36:04 -07003255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003257 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003258 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3259 "updateOrientationFromAppTokens()")) {
3260 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3261 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003262
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003263 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003265
3266 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003267 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003268 if (freezeThisOneIfNeeded != null) {
3269 AppWindowToken wtoken = findAppWindowToken(
3270 freezeThisOneIfNeeded);
3271 if (wtoken != null) {
3272 startAppFreezingScreenLocked(wtoken,
3273 ActivityInfo.CONFIG_ORIENTATION);
3274 }
3275 }
3276 config = computeNewConfigurationLocked();
3277
3278 } else if (currentConfig != null) {
3279 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003280 // state mismatches the activity manager's, update it,
3281 // disregarding font scale, which should remain set to
3282 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003283 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003284 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003285 if (computeNewConfigurationLocked(mTempConfiguration)) {
3286 if (currentConfig.diff(mTempConfiguration) != 0) {
3287 mWaitingForConfig = true;
3288 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003289 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003290 config = new Configuration(mTempConfiguration);
3291 }
3292 }
3293 }
3294 }
3295
Dianne Hackborncfaef692009-06-15 14:24:44 -07003296 Binder.restoreCallingIdentity(ident);
3297 return config;
3298 }
3299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003301 * Determine the new desired orientation of the display, returning
3302 * a non-null new Configuration if it has changed from the current
3303 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3304 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3305 * SCREEN. This will typically be done for you if you call
3306 * sendNewConfiguration().
3307 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 * The orientation is computed from non-application windows first. If none of
3309 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003310 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3312 * android.os.IBinder)
3313 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003314 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3315 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003316 // If the display is frozen, some activities may be in the middle
3317 // of restarting, and thus have removed their old window. If the
3318 // window has the flag to hide the lock screen, then the lock screen
3319 // can re-appear and inflict its own orientation on us. Keep the
3320 // orientation stable until this all settles down.
3321 return false;
3322 }
3323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 long ident = Binder.clearCallingIdentity();
3326 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003327 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 mForcedAppOrientation = req;
3331 //send a message to Policy indicating orientation change to take
3332 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003333 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003334 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003335 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3336 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003337 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 }
3339 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003340
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003341 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 } finally {
3343 Binder.restoreCallingIdentity(ident);
3344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 }
Romain Guy06882f82009-06-10 13:36:04 -07003346
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003347 int computeForcedAppOrientationLocked() {
3348 int req = getOrientationFromWindowsLocked();
3349 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3350 req = getOrientationFromAppTokensLocked();
3351 }
3352 return req;
3353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003355 public void setNewConfiguration(Configuration config) {
3356 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3357 "setNewConfiguration()")) {
3358 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3359 }
3360
3361 synchronized(mWindowMap) {
3362 mCurConfiguration = new Configuration(config);
3363 mWaitingForConfig = false;
3364 performLayoutAndPlaceSurfacesLocked();
3365 }
3366 }
3367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3369 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3370 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003371 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 }
Romain Guy06882f82009-06-10 13:36:04 -07003373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 synchronized(mWindowMap) {
3375 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3376 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003377 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 return;
3379 }
Romain Guy06882f82009-06-10 13:36:04 -07003380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 wtoken.requestedOrientation = requestedOrientation;
3382 }
3383 }
Romain Guy06882f82009-06-10 13:36:04 -07003384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 public int getAppOrientation(IApplicationToken token) {
3386 synchronized(mWindowMap) {
3387 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3388 if (wtoken == null) {
3389 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3390 }
Romain Guy06882f82009-06-10 13:36:04 -07003391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 return wtoken.requestedOrientation;
3393 }
3394 }
Romain Guy06882f82009-06-10 13:36:04 -07003395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003396 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3397 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3398 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003399 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 }
3401
3402 synchronized(mWindowMap) {
3403 boolean changed = false;
3404 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003405 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 changed = mFocusedApp != null;
3407 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003408 if (changed) {
3409 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 } else {
3412 AppWindowToken newFocus = findAppWindowToken(token);
3413 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003414 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 return;
3416 }
3417 changed = mFocusedApp != newFocus;
3418 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003419 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003420 if (changed) {
3421 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 }
3424
3425 if (moveFocusNow && changed) {
3426 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003427 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 Binder.restoreCallingIdentity(origId);
3429 }
3430 }
3431 }
3432
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003433 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3435 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003436 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 }
Romain Guy06882f82009-06-10 13:36:04 -07003438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003440 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 TAG, "Prepare app transition: transit=" + transit
3442 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003443 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003444 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3445 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003447 } else if (!alwaysKeepCurrent) {
3448 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3449 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3450 // Opening a new task always supersedes a close for the anim.
3451 mNextAppTransition = transit;
3452 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3453 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3454 // Opening a new activity always supersedes a close for the anim.
3455 mNextAppTransition = transit;
3456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 }
3458 mAppTransitionReady = false;
3459 mAppTransitionTimeout = false;
3460 mStartingIconInTransition = false;
3461 mSkipAppTransitionAnimation = false;
3462 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3463 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3464 5000);
3465 }
3466 }
3467 }
3468
3469 public int getPendingAppTransition() {
3470 return mNextAppTransition;
3471 }
Romain Guy06882f82009-06-10 13:36:04 -07003472
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003473 public void overridePendingAppTransition(String packageName,
3474 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003475 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003476 mNextAppTransitionPackage = packageName;
3477 mNextAppTransitionEnter = enterAnim;
3478 mNextAppTransitionExit = exitAnim;
3479 }
3480 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 public void executeAppTransition() {
3483 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3484 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003485 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 }
Romain Guy06882f82009-06-10 13:36:04 -07003487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003489 if (DEBUG_APP_TRANSITIONS) {
3490 RuntimeException e = new RuntimeException("here");
3491 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003492 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003493 + mNextAppTransition, e);
3494 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003495 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 mAppTransitionReady = true;
3497 final long origId = Binder.clearCallingIdentity();
3498 performLayoutAndPlaceSurfacesLocked();
3499 Binder.restoreCallingIdentity(origId);
3500 }
3501 }
3502 }
3503
3504 public void setAppStartingWindow(IBinder token, String pkg,
3505 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003506 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3508 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003509 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 }
3511
3512 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003513 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3515 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 AppWindowToken wtoken = findAppWindowToken(token);
3518 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003519 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 return;
3521 }
3522
3523 // If the display is frozen, we won't do anything until the
3524 // actual window is displayed so there is no reason to put in
3525 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003526 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 return;
3528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 if (wtoken.startingData != null) {
3531 return;
3532 }
Romain Guy06882f82009-06-10 13:36:04 -07003533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 if (transferFrom != null) {
3535 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3536 if (ttoken != null) {
3537 WindowState startingWindow = ttoken.startingWindow;
3538 if (startingWindow != null) {
3539 if (mStartingIconInTransition) {
3540 // In this case, the starting icon has already
3541 // been displayed, so start letting windows get
3542 // shown immediately without any more transitions.
3543 mSkipAppTransitionAnimation = true;
3544 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003545 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 "Moving existing starting from " + ttoken
3547 + " to " + wtoken);
3548 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 // Transfer the starting window over to the new
3551 // token.
3552 wtoken.startingData = ttoken.startingData;
3553 wtoken.startingView = ttoken.startingView;
3554 wtoken.startingWindow = startingWindow;
3555 ttoken.startingData = null;
3556 ttoken.startingView = null;
3557 ttoken.startingWindow = null;
3558 ttoken.startingMoved = true;
3559 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003560 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003562 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003563 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003565 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003566 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3567 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 ttoken.windows.remove(startingWindow);
3569 ttoken.allAppWindows.remove(startingWindow);
3570 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 // Propagate other interesting state between the
3573 // tokens. If the old token is displayed, we should
3574 // immediately force the new one to be displayed. If
3575 // it is animating, we need to move that animation to
3576 // the new one.
3577 if (ttoken.allDrawn) {
3578 wtoken.allDrawn = true;
3579 }
3580 if (ttoken.firstWindowDrawn) {
3581 wtoken.firstWindowDrawn = true;
3582 }
3583 if (!ttoken.hidden) {
3584 wtoken.hidden = false;
3585 wtoken.hiddenRequested = false;
3586 wtoken.willBeHidden = false;
3587 }
3588 if (wtoken.clientHidden != ttoken.clientHidden) {
3589 wtoken.clientHidden = ttoken.clientHidden;
3590 wtoken.sendAppVisibilityToClients();
3591 }
3592 if (ttoken.animation != null) {
3593 wtoken.animation = ttoken.animation;
3594 wtoken.animating = ttoken.animating;
3595 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3596 ttoken.animation = null;
3597 ttoken.animLayerAdjustment = 0;
3598 wtoken.updateLayers();
3599 ttoken.updateLayers();
3600 }
Romain Guy06882f82009-06-10 13:36:04 -07003601
Jeff Brown3a22cd92011-01-21 13:59:04 -08003602 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3603 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 mLayoutNeeded = true;
3605 performLayoutAndPlaceSurfacesLocked();
3606 Binder.restoreCallingIdentity(origId);
3607 return;
3608 } else if (ttoken.startingData != null) {
3609 // The previous app was getting ready to show a
3610 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003611 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 "Moving pending starting from " + ttoken
3613 + " to " + wtoken);
3614 wtoken.startingData = ttoken.startingData;
3615 ttoken.startingData = null;
3616 ttoken.startingMoved = true;
3617 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3618 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3619 // want to process the message ASAP, before any other queued
3620 // messages.
3621 mH.sendMessageAtFrontOfQueue(m);
3622 return;
3623 }
3624 }
3625 }
3626
3627 // There is no existing starting window, and the caller doesn't
3628 // want us to create one, so that's it!
3629 if (!createIfNeeded) {
3630 return;
3631 }
Romain Guy06882f82009-06-10 13:36:04 -07003632
Dianne Hackborn284ac932009-08-28 10:34:25 -07003633 // If this is a translucent or wallpaper window, then don't
3634 // show a starting window -- the current effect (a full-screen
3635 // opaque starting window that fades away to the real contents
3636 // when it is ready) does not work for this.
3637 if (theme != 0) {
3638 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3639 com.android.internal.R.styleable.Window);
3640 if (ent.array.getBoolean(
3641 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3642 return;
3643 }
3644 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003645 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3646 return;
3647 }
3648 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003649 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3650 return;
3651 }
3652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 mStartingIconInTransition = true;
3655 wtoken.startingData = new StartingData(
3656 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003657 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3659 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3660 // want to process the message ASAP, before any other queued
3661 // messages.
3662 mH.sendMessageAtFrontOfQueue(m);
3663 }
3664 }
3665
3666 public void setAppWillBeHidden(IBinder token) {
3667 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3668 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003669 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 }
3671
3672 AppWindowToken wtoken;
3673
3674 synchronized(mWindowMap) {
3675 wtoken = findAppWindowToken(token);
3676 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003677 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 -08003678 return;
3679 }
3680 wtoken.willBeHidden = true;
3681 }
3682 }
Romain Guy06882f82009-06-10 13:36:04 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003685 boolean visible, int transit, boolean performLayout, boolean bgFiller) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 boolean delayed = false;
3687
3688 if (wtoken.clientHidden == visible) {
3689 wtoken.clientHidden = !visible;
3690 wtoken.sendAppVisibilityToClients();
3691 }
Romain Guy06882f82009-06-10 13:36:04 -07003692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 wtoken.willBeHidden = false;
3694 if (wtoken.hidden == visible) {
3695 final int N = wtoken.allAppWindows.size();
3696 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003697 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3699 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003702
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003703 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 if (wtoken.animation == sDummyAnimation) {
3705 wtoken.animation = null;
3706 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003707 applyAnimationLocked(wtoken, lp, transit, visible, bgFiller);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 changed = true;
3709 if (wtoken.animation != null) {
3710 delayed = runningAppAnimation = true;
3711 }
3712 }
Romain Guy06882f82009-06-10 13:36:04 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 for (int i=0; i<N; i++) {
3715 WindowState win = wtoken.allAppWindows.get(i);
3716 if (win == wtoken.startingWindow) {
3717 continue;
3718 }
3719
3720 if (win.isAnimating()) {
3721 delayed = true;
3722 }
Romain Guy06882f82009-06-10 13:36:04 -07003723
Joe Onorato8a9b2202010-02-26 18:56:32 -08003724 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 //win.dump(" ");
3726 if (visible) {
3727 if (!win.isVisibleNow()) {
3728 if (!runningAppAnimation) {
3729 applyAnimationLocked(win,
3730 WindowManagerPolicy.TRANSIT_ENTER, true);
3731 }
3732 changed = true;
3733 }
3734 } else if (win.isVisibleNow()) {
3735 if (!runningAppAnimation) {
3736 applyAnimationLocked(win,
3737 WindowManagerPolicy.TRANSIT_EXIT, false);
3738 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 changed = true;
3740 }
3741 }
3742
3743 wtoken.hidden = wtoken.hiddenRequested = !visible;
3744 if (!visible) {
3745 unsetAppFreezingScreenLocked(wtoken, true, true);
3746 } else {
3747 // If we are being set visible, and the starting window is
3748 // not yet displayed, then make sure it doesn't get displayed.
3749 WindowState swin = wtoken.startingWindow;
3750 if (swin != null && (swin.mDrawPending
3751 || swin.mCommitDrawPending)) {
3752 swin.mPolicyVisibility = false;
3753 swin.mPolicyVisibilityAfterAnim = false;
3754 }
3755 }
Romain Guy06882f82009-06-10 13:36:04 -07003756
Joe Onorato8a9b2202010-02-26 18:56:32 -08003757 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3759 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003760
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003761 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08003763 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003764 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08003765 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3766 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003767 performLayoutAndPlaceSurfacesLocked();
3768 }
Jeff Brown2e44b072011-01-24 15:21:56 -08003769 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 }
3771 }
3772
3773 if (wtoken.animation != null) {
3774 delayed = true;
3775 }
Romain Guy06882f82009-06-10 13:36:04 -07003776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 return delayed;
3778 }
3779
3780 public void setAppVisibility(IBinder token, boolean visible) {
3781 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3782 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003783 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 }
3785
3786 AppWindowToken wtoken;
3787
3788 synchronized(mWindowMap) {
3789 wtoken = findAppWindowToken(token);
3790 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003791 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 return;
3793 }
3794
3795 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003796 RuntimeException e = null;
3797 if (!HIDE_STACK_CRAWLS) {
3798 e = new RuntimeException();
3799 e.fillInStackTrace();
3800 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003801 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 + "): mNextAppTransition=" + mNextAppTransition
3803 + " hidden=" + wtoken.hidden
3804 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3805 }
Romain Guy06882f82009-06-10 13:36:04 -07003806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 // If we are preparing an app transition, then delay changing
3808 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003809 if (!mDisplayFrozen && mPolicy.isScreenOn()
3810 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 // Already in requested state, don't do anything more.
3812 if (wtoken.hiddenRequested != visible) {
3813 return;
3814 }
3815 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003816
Joe Onorato8a9b2202010-02-26 18:56:32 -08003817 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 TAG, "Setting dummy animation on: " + wtoken);
3819 wtoken.setDummyAnimation();
3820 mOpeningApps.remove(wtoken);
3821 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003822 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 wtoken.inPendingTransaction = true;
3824 if (visible) {
3825 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 wtoken.startingDisplayed = false;
3827 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003828
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003829 // If the token is currently hidden (should be the
3830 // common case), then we need to set up to wait for
3831 // its windows to be ready.
3832 if (wtoken.hidden) {
3833 wtoken.allDrawn = false;
3834 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003835
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003836 if (wtoken.clientHidden) {
3837 // In the case where we are making an app visible
3838 // but holding off for a transition, we still need
3839 // to tell the client to make its windows visible so
3840 // they get drawn. Otherwise, we will wait on
3841 // performing the transition until all windows have
3842 // been drawn, they never will be, and we are sad.
3843 wtoken.clientHidden = false;
3844 wtoken.sendAppVisibilityToClients();
3845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
3847 } else {
3848 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003849
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003850 // If the token is currently visible (should be the
3851 // common case), then set up to wait for it to be hidden.
3852 if (!wtoken.hidden) {
3853 wtoken.waitingToHide = true;
3854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 }
3856 return;
3857 }
Romain Guy06882f82009-06-10 13:36:04 -07003858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 final long origId = Binder.clearCallingIdentity();
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003860 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET,
3861 true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 wtoken.updateReportedVisibilityLocked();
3863 Binder.restoreCallingIdentity(origId);
3864 }
3865 }
3866
3867 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3868 boolean unfreezeSurfaceNow, boolean force) {
3869 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003870 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003871 + " force=" + force);
3872 final int N = wtoken.allAppWindows.size();
3873 boolean unfrozeWindows = false;
3874 for (int i=0; i<N; i++) {
3875 WindowState w = wtoken.allAppWindows.get(i);
3876 if (w.mAppFreezing) {
3877 w.mAppFreezing = false;
3878 if (w.mSurface != null && !w.mOrientationChanging) {
3879 w.mOrientationChanging = true;
3880 }
3881 unfrozeWindows = true;
3882 }
3883 }
3884 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003885 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 wtoken.freezingScreen = false;
3887 mAppsFreezingScreen--;
3888 }
3889 if (unfreezeSurfaceNow) {
3890 if (unfrozeWindows) {
3891 mLayoutNeeded = true;
3892 performLayoutAndPlaceSurfacesLocked();
3893 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003894 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003895 }
3896 }
3897 }
Romain Guy06882f82009-06-10 13:36:04 -07003898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3900 int configChanges) {
3901 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003902 RuntimeException e = null;
3903 if (!HIDE_STACK_CRAWLS) {
3904 e = new RuntimeException();
3905 e.fillInStackTrace();
3906 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003908 + ": hidden=" + wtoken.hidden + " freezing="
3909 + wtoken.freezingScreen, e);
3910 }
3911 if (!wtoken.hiddenRequested) {
3912 if (!wtoken.freezingScreen) {
3913 wtoken.freezingScreen = true;
3914 mAppsFreezingScreen++;
3915 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003916 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3918 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3919 5000);
3920 }
3921 }
3922 final int N = wtoken.allAppWindows.size();
3923 for (int i=0; i<N; i++) {
3924 WindowState w = wtoken.allAppWindows.get(i);
3925 w.mAppFreezing = true;
3926 }
3927 }
3928 }
Romain Guy06882f82009-06-10 13:36:04 -07003929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 public void startAppFreezingScreen(IBinder token, int configChanges) {
3931 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3932 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003933 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 }
3935
3936 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003937 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003938 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 return;
3940 }
Romain Guy06882f82009-06-10 13:36:04 -07003941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003942 AppWindowToken wtoken = findAppWindowToken(token);
3943 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003944 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003945 return;
3946 }
3947 final long origId = Binder.clearCallingIdentity();
3948 startAppFreezingScreenLocked(wtoken, configChanges);
3949 Binder.restoreCallingIdentity(origId);
3950 }
3951 }
Romain Guy06882f82009-06-10 13:36:04 -07003952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953 public void stopAppFreezingScreen(IBinder token, boolean force) {
3954 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3955 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003956 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 }
3958
3959 synchronized(mWindowMap) {
3960 AppWindowToken wtoken = findAppWindowToken(token);
3961 if (wtoken == null || wtoken.appToken == null) {
3962 return;
3963 }
3964 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003965 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3967 unsetAppFreezingScreenLocked(wtoken, true, force);
3968 Binder.restoreCallingIdentity(origId);
3969 }
3970 }
Romain Guy06882f82009-06-10 13:36:04 -07003971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 public void removeAppToken(IBinder token) {
3973 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3974 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003975 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 }
3977
3978 AppWindowToken wtoken = null;
3979 AppWindowToken startingToken = null;
3980 boolean delayed = false;
3981
3982 final long origId = Binder.clearCallingIdentity();
3983 synchronized(mWindowMap) {
3984 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003986 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003987 delayed = setTokenVisibilityLocked(wtoken, null, false,
3988 WindowManagerPolicy.TRANSIT_UNSET, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 wtoken.inPendingTransaction = false;
3990 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003991 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 if (mClosingApps.contains(wtoken)) {
3993 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003994 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003996 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 delayed = true;
3998 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003999 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 TAG, "Removing app " + wtoken + " delayed=" + delayed
4001 + " animation=" + wtoken.animation
4002 + " animating=" + wtoken.animating);
4003 if (delayed) {
4004 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004005 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4006 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004008 } else {
4009 // Make sure there is no animation running on this token,
4010 // so any windows associated with it will be removed as
4011 // soon as their animations are complete
4012 wtoken.animation = null;
4013 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004015 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4016 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004017 mAppTokens.remove(wtoken);
4018 wtoken.removed = true;
4019 if (wtoken.startingData != null) {
4020 startingToken = wtoken;
4021 }
4022 unsetAppFreezingScreenLocked(wtoken, true, true);
4023 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004024 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004025 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004026 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004027 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004028 }
4029 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004030 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 }
Romain Guy06882f82009-06-10 13:36:04 -07004032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 if (!delayed && wtoken != null) {
4034 wtoken.updateReportedVisibilityLocked();
4035 }
4036 }
4037 Binder.restoreCallingIdentity(origId);
4038
4039 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004040 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004041 + startingToken + ": app token removed");
4042 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4043 mH.sendMessage(m);
4044 }
4045 }
4046
4047 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4048 final int NW = token.windows.size();
4049 for (int i=0; i<NW; i++) {
4050 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004051 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004053 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 int j = win.mChildWindows.size();
4055 while (j > 0) {
4056 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004057 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004058 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004059 "Tmp removing child window " + cwin);
4060 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004061 }
4062 }
4063 return NW > 0;
4064 }
4065
4066 void dumpAppTokensLocked() {
4067 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004068 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004069 }
4070 }
Romain Guy06882f82009-06-10 13:36:04 -07004071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004072 void dumpWindowsLocked() {
4073 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004074 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 }
4076 }
Romain Guy06882f82009-06-10 13:36:04 -07004077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 private int findWindowOffsetLocked(int tokenPos) {
4079 final int NW = mWindows.size();
4080
4081 if (tokenPos >= mAppTokens.size()) {
4082 int i = NW;
4083 while (i > 0) {
4084 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004085 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 if (win.getAppToken() != null) {
4087 return i+1;
4088 }
4089 }
4090 }
4091
4092 while (tokenPos > 0) {
4093 // Find the first app token below the new position that has
4094 // a window displayed.
4095 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004096 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004098 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004099 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004100 "Skipping token -- currently sending to bottom");
4101 tokenPos--;
4102 continue;
4103 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004104 int i = wtoken.windows.size();
4105 while (i > 0) {
4106 i--;
4107 WindowState win = wtoken.windows.get(i);
4108 int j = win.mChildWindows.size();
4109 while (j > 0) {
4110 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004111 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004112 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 for (int pos=NW-1; pos>=0; pos--) {
4114 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004115 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 "Found child win @" + (pos+1));
4117 return pos+1;
4118 }
4119 }
4120 }
4121 }
4122 for (int pos=NW-1; pos>=0; pos--) {
4123 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004124 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 return pos+1;
4126 }
4127 }
4128 }
4129 tokenPos--;
4130 }
4131
4132 return 0;
4133 }
4134
4135 private final int reAddWindowLocked(int index, WindowState win) {
4136 final int NCW = win.mChildWindows.size();
4137 boolean added = false;
4138 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004139 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004141 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004142 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004143 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004144 mWindows.add(index, win);
4145 index++;
4146 added = true;
4147 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004148 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004149 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004150 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 mWindows.add(index, cwin);
4152 index++;
4153 }
4154 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004155 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004156 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004157 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 mWindows.add(index, win);
4159 index++;
4160 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004161 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 return index;
4163 }
Romain Guy06882f82009-06-10 13:36:04 -07004164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4166 final int NW = token.windows.size();
4167 for (int i=0; i<NW; i++) {
4168 index = reAddWindowLocked(index, token.windows.get(i));
4169 }
4170 return index;
4171 }
4172
4173 public void moveAppToken(int index, IBinder token) {
4174 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4175 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004176 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 }
4178
4179 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004180 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 if (DEBUG_REORDER) dumpAppTokensLocked();
4182 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004183 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4184 "Start moving token " + wtoken + " initially at "
4185 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004187 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 + token + " (" + wtoken + ")");
4189 return;
4190 }
4191 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004192 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004193 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004196 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004197 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004198 if (DEBUG_REORDER) dumpWindowsLocked();
4199 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004200 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 if (DEBUG_REORDER) dumpWindowsLocked();
4202 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004203 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004205 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4206 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004208 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004210 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 }
4212 Binder.restoreCallingIdentity(origId);
4213 }
4214 }
4215
4216 private void removeAppTokensLocked(List<IBinder> tokens) {
4217 // XXX This should be done more efficiently!
4218 // (take advantage of the fact that both lists should be
4219 // ordered in the same way.)
4220 int N = tokens.size();
4221 for (int i=0; i<N; i++) {
4222 IBinder token = tokens.get(i);
4223 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004224 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4225 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004227 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004228 + token + " (" + wtoken + ")");
4229 i--;
4230 N--;
4231 }
4232 }
4233 }
4234
Dianne Hackborna8f60182009-09-01 19:01:50 -07004235 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4236 boolean updateFocusAndLayout) {
4237 // First remove all of the windows from the list.
4238 tmpRemoveAppWindowsLocked(wtoken);
4239
4240 // Where to start adding?
4241 int pos = findWindowOffsetLocked(tokenPos);
4242
4243 // And now add them back at the correct place.
4244 pos = reAddAppWindowsLocked(pos, wtoken);
4245
4246 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004247 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004248 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4249 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004250 assignLayersLocked();
4251 }
4252 mLayoutNeeded = true;
4253 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004254 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004255 }
4256 }
4257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4259 // First remove all of the windows from the list.
4260 final int N = tokens.size();
4261 int i;
4262 for (i=0; i<N; i++) {
4263 WindowToken token = mTokenMap.get(tokens.get(i));
4264 if (token != null) {
4265 tmpRemoveAppWindowsLocked(token);
4266 }
4267 }
4268
4269 // Where to start adding?
4270 int pos = findWindowOffsetLocked(tokenPos);
4271
4272 // And now add them back at the correct place.
4273 for (i=0; i<N; i++) {
4274 WindowToken token = mTokenMap.get(tokens.get(i));
4275 if (token != null) {
4276 pos = reAddAppWindowsLocked(pos, token);
4277 }
4278 }
4279
Jeff Brown2e44b072011-01-24 15:21:56 -08004280 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004281 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4282 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004283 assignLayersLocked();
4284 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 mLayoutNeeded = true;
4286 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004287 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288
4289 //dump();
4290 }
4291
4292 public void moveAppTokensToTop(List<IBinder> tokens) {
4293 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4294 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004295 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 }
4297
4298 final long origId = Binder.clearCallingIdentity();
4299 synchronized(mWindowMap) {
4300 removeAppTokensLocked(tokens);
4301 final int N = tokens.size();
4302 for (int i=0; i<N; i++) {
4303 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4304 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004305 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4306 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004308 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004309 mToTopApps.remove(wt);
4310 mToBottomApps.remove(wt);
4311 mToTopApps.add(wt);
4312 wt.sendingToBottom = false;
4313 wt.sendingToTop = true;
4314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 }
4316 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004317
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004318 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004319 moveAppWindowsLocked(tokens, mAppTokens.size());
4320 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 }
4322 Binder.restoreCallingIdentity(origId);
4323 }
4324
4325 public void moveAppTokensToBottom(List<IBinder> tokens) {
4326 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4327 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004328 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 }
4330
4331 final long origId = Binder.clearCallingIdentity();
4332 synchronized(mWindowMap) {
4333 removeAppTokensLocked(tokens);
4334 final int N = tokens.size();
4335 int pos = 0;
4336 for (int i=0; i<N; i++) {
4337 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4338 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004339 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4340 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004341 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004342 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004343 mToTopApps.remove(wt);
4344 mToBottomApps.remove(wt);
4345 mToBottomApps.add(i, wt);
4346 wt.sendingToTop = false;
4347 wt.sendingToBottom = true;
4348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 pos++;
4350 }
4351 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004352
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004353 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004354 moveAppWindowsLocked(tokens, 0);
4355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 }
4357 Binder.restoreCallingIdentity(origId);
4358 }
4359
4360 // -------------------------------------------------------------
4361 // Misc IWindowSession methods
4362 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004363
Jim Miller284b62e2010-06-08 14:27:42 -07004364 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004365 {
Jim Miller284b62e2010-06-08 14:27:42 -07004366 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4367 // called before DevicePolicyManagerService has started.
4368 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4369 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4370 Context.DEVICE_POLICY_SERVICE);
4371 if (dpm != null) {
4372 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4373 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4374 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4375 }
Jim Millerd6b57052010-06-07 17:52:42 -07004376 }
Jim Miller284b62e2010-06-08 14:27:42 -07004377 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004378 }
4379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004381 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 != PackageManager.PERMISSION_GRANTED) {
4383 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4384 }
Jim Millerd6b57052010-06-07 17:52:42 -07004385
Jim Miller284b62e2010-06-08 14:27:42 -07004386 synchronized (mKeyguardTokenWatcher) {
4387 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 }
4390
4391 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004392 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004393 != PackageManager.PERMISSION_GRANTED) {
4394 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396
Jim Miller284b62e2010-06-08 14:27:42 -07004397 synchronized (mKeyguardTokenWatcher) {
4398 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004399
Jim Miller284b62e2010-06-08 14:27:42 -07004400 if (!mKeyguardTokenWatcher.isAcquired()) {
4401 // If we are the last one to reenable the keyguard wait until
4402 // we have actually finished reenabling until returning.
4403 // It is possible that reenableKeyguard() can be called before
4404 // the previous disableKeyguard() is handled, in which case
4405 // neither mKeyguardTokenWatcher.acquired() or released() would
4406 // be called. In that case mKeyguardDisabled will be false here
4407 // and we have nothing to wait for.
4408 while (mKeyguardDisabled) {
4409 try {
4410 mKeyguardTokenWatcher.wait();
4411 } catch (InterruptedException e) {
4412 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 }
4414 }
4415 }
4416 }
4417 }
4418
4419 /**
4420 * @see android.app.KeyguardManager#exitKeyguardSecurely
4421 */
4422 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004423 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 != PackageManager.PERMISSION_GRANTED) {
4425 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4426 }
4427 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4428 public void onKeyguardExitResult(boolean success) {
4429 try {
4430 callback.onKeyguardExitResult(success);
4431 } catch (RemoteException e) {
4432 // Client has died, we don't care.
4433 }
4434 }
4435 });
4436 }
4437
4438 public boolean inKeyguardRestrictedInputMode() {
4439 return mPolicy.inKeyguardRestrictedKeyInputMode();
4440 }
Romain Guy06882f82009-06-10 13:36:04 -07004441
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004442 public boolean isKeyguardLocked() {
4443 return mPolicy.isKeyguardLocked();
4444 }
4445
4446 public boolean isKeyguardSecure() {
4447 return mPolicy.isKeyguardSecure();
4448 }
4449
Dianne Hackbornffa42482009-09-23 22:20:11 -07004450 public void closeSystemDialogs(String reason) {
4451 synchronized(mWindowMap) {
4452 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004453 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004454 if (w.mSurface != null) {
4455 try {
4456 w.mClient.closeSystemDialogs(reason);
4457 } catch (RemoteException e) {
4458 }
4459 }
4460 }
4461 }
4462 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 static float fixScale(float scale) {
4465 if (scale < 0) scale = 0;
4466 else if (scale > 20) scale = 20;
4467 return Math.abs(scale);
4468 }
Romain Guy06882f82009-06-10 13:36:04 -07004469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 public void setAnimationScale(int which, float scale) {
4471 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4472 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004473 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 }
4475
4476 if (scale < 0) scale = 0;
4477 else if (scale > 20) scale = 20;
4478 scale = Math.abs(scale);
4479 switch (which) {
4480 case 0: mWindowAnimationScale = fixScale(scale); break;
4481 case 1: mTransitionAnimationScale = fixScale(scale); break;
4482 }
Romain Guy06882f82009-06-10 13:36:04 -07004483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 // Persist setting
4485 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4486 }
Romain Guy06882f82009-06-10 13:36:04 -07004487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 public void setAnimationScales(float[] scales) {
4489 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4490 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004491 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 }
4493
4494 if (scales != null) {
4495 if (scales.length >= 1) {
4496 mWindowAnimationScale = fixScale(scales[0]);
4497 }
4498 if (scales.length >= 2) {
4499 mTransitionAnimationScale = fixScale(scales[1]);
4500 }
4501 }
Romain Guy06882f82009-06-10 13:36:04 -07004502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503 // Persist setting
4504 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4505 }
Romain Guy06882f82009-06-10 13:36:04 -07004506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 public float getAnimationScale(int which) {
4508 switch (which) {
4509 case 0: return mWindowAnimationScale;
4510 case 1: return mTransitionAnimationScale;
4511 }
4512 return 0;
4513 }
Romain Guy06882f82009-06-10 13:36:04 -07004514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 public float[] getAnimationScales() {
4516 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4517 }
Romain Guy06882f82009-06-10 13:36:04 -07004518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 public int getSwitchState(int sw) {
4520 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4521 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004522 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004524 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 }
Romain Guy06882f82009-06-10 13:36:04 -07004526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 public int getSwitchStateForDevice(int devid, int sw) {
4528 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4529 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004530 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004532 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533 }
Romain Guy06882f82009-06-10 13:36:04 -07004534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 public int getScancodeState(int sw) {
4536 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4537 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004538 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004539 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004540 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004541 }
Romain Guy06882f82009-06-10 13:36:04 -07004542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 public int getScancodeStateForDevice(int devid, int sw) {
4544 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4545 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004546 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004548 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004549 }
Romain Guy06882f82009-06-10 13:36:04 -07004550
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004551 public int getTrackballScancodeState(int sw) {
4552 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4553 "getTrackballScancodeState()")) {
4554 throw new SecurityException("Requires READ_INPUT_STATE permission");
4555 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004556 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004557 }
4558
4559 public int getDPadScancodeState(int sw) {
4560 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4561 "getDPadScancodeState()")) {
4562 throw new SecurityException("Requires READ_INPUT_STATE permission");
4563 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004564 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004565 }
4566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004567 public int getKeycodeState(int sw) {
4568 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4569 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004570 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004572 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 }
Romain Guy06882f82009-06-10 13:36:04 -07004574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 public int getKeycodeStateForDevice(int devid, int sw) {
4576 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4577 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004578 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004580 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 }
Romain Guy06882f82009-06-10 13:36:04 -07004582
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004583 public int getTrackballKeycodeState(int sw) {
4584 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4585 "getTrackballKeycodeState()")) {
4586 throw new SecurityException("Requires READ_INPUT_STATE permission");
4587 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004588 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004589 }
4590
4591 public int getDPadKeycodeState(int sw) {
4592 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4593 "getDPadKeycodeState()")) {
4594 throw new SecurityException("Requires READ_INPUT_STATE permission");
4595 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004596 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004597 }
Jeff Browna41ca772010-08-11 14:46:32 -07004598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004599 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004600 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004601 }
Romain Guy06882f82009-06-10 13:36:04 -07004602
Jeff Browna41ca772010-08-11 14:46:32 -07004603 public InputChannel monitorInput(String inputChannelName) {
4604 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4605 "monitorInput()")) {
4606 throw new SecurityException("Requires READ_INPUT_STATE permission");
4607 }
4608 return mInputManager.monitorInput(inputChannelName);
4609 }
4610
Jeff Brown0029c662011-03-30 02:25:18 -07004611 public void setInputFilter(InputFilter filter) {
4612 mInputManager.setInputFilter(filter);
4613 }
4614
Jeff Brown8d608662010-08-30 03:02:23 -07004615 public InputDevice getInputDevice(int deviceId) {
4616 return mInputManager.getInputDevice(deviceId);
4617 }
4618
4619 public int[] getInputDeviceIds() {
4620 return mInputManager.getInputDeviceIds();
4621 }
4622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 public void enableScreenAfterBoot() {
4624 synchronized(mWindowMap) {
4625 if (mSystemBooted) {
4626 return;
4627 }
4628 mSystemBooted = true;
4629 }
Romain Guy06882f82009-06-10 13:36:04 -07004630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 performEnableScreen();
4632 }
Romain Guy06882f82009-06-10 13:36:04 -07004633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004634 public void enableScreenIfNeededLocked() {
4635 if (mDisplayEnabled) {
4636 return;
4637 }
4638 if (!mSystemBooted) {
4639 return;
4640 }
4641 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4642 }
Romain Guy06882f82009-06-10 13:36:04 -07004643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004644 public void performEnableScreen() {
4645 synchronized(mWindowMap) {
4646 if (mDisplayEnabled) {
4647 return;
4648 }
4649 if (!mSystemBooted) {
4650 return;
4651 }
Romain Guy06882f82009-06-10 13:36:04 -07004652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 // Don't enable the screen until all existing windows
4654 // have been drawn.
4655 final int N = mWindows.size();
4656 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004657 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004658 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 return;
4660 }
4661 }
Romain Guy06882f82009-06-10 13:36:04 -07004662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004663 mDisplayEnabled = true;
4664 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004665 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 StringWriter sw = new StringWriter();
4667 PrintWriter pw = new PrintWriter(sw);
4668 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004669 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 }
4671 try {
4672 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4673 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004674 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004675 Parcel data = Parcel.obtain();
4676 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4677 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4678 data, null, 0);
4679 data.recycle();
4680 }
4681 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004682 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
4684 }
Romain Guy06882f82009-06-10 13:36:04 -07004685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004689 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4690 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004691 }
Romain Guy06882f82009-06-10 13:36:04 -07004692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 public void setInTouchMode(boolean mode) {
4694 synchronized(mWindowMap) {
4695 mInTouchMode = mode;
4696 }
4697 }
4698
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004699 // TODO: more accounting of which pid(s) turned it on, keep count,
4700 // only allow disables from pids which have count on, etc.
4701 public void showStrictModeViolation(boolean on) {
4702 int pid = Binder.getCallingPid();
4703 synchronized(mWindowMap) {
4704 // Ignoring requests to enable the red border from clients
4705 // which aren't on screen. (e.g. Broadcast Receivers in
4706 // the background..)
4707 if (on) {
4708 boolean isVisible = false;
4709 for (WindowState ws : mWindows) {
4710 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4711 isVisible = true;
4712 break;
4713 }
4714 }
4715 if (!isVisible) {
4716 return;
4717 }
4718 }
4719
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004720 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004721 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004722 try {
4723 if (mStrictModeFlash == null) {
4724 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4725 }
4726 mStrictModeFlash.setVisibility(on);
4727 } finally {
4728 Surface.closeTransaction();
4729 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004730 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004731 }
4732 }
4733
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004734 public void setStrictModeVisualIndicatorPreference(String value) {
4735 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4736 }
4737
Jim Millere70d5062011-03-08 21:38:39 -08004738 /**
4739 * Takes a snapshot of the screen. In landscape mode this grabs the whole screen.
4740 * In portrait mode, it grabs the upper region of the screen based on the vertical dimension
4741 * of the target image.
4742 *
4743 * @param width the width of the target bitmap
4744 * @param height the height of the target bitmap
4745 */
4746 public Bitmap screenshotApplications(IBinder appToken, int width, int height) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004747 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4748 "screenshotApplications()")) {
4749 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4750 }
4751
4752 Bitmap rawss;
4753
Dianne Hackbornd2835932010-12-13 16:28:46 -08004754 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004755 final Rect frame = new Rect();
4756
4757 float scale;
Jim Millere70d5062011-03-08 21:38:39 -08004758 int dw, dh;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004759 int rot;
4760
4761 synchronized(mWindowMap) {
4762 long ident = Binder.clearCallingIdentity();
4763
Dianne Hackbornaa9d84c2011-05-09 19:00:59 -07004764 dw = mPolicy.getNonDecorDisplayWidth(mCurDisplayWidth);
4765 dh = mPolicy.getNonDecorDisplayHeight(mCurDisplayHeight);
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004766
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004767 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
4768 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
4769 + TYPE_LAYER_OFFSET;
4770 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
4771
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004772 boolean isImeTarget = mInputMethodTarget != null
4773 && mInputMethodTarget.mAppToken != null
4774 && mInputMethodTarget.mAppToken.appToken != null
4775 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
4776
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004777 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004778 boolean including = false;
4779 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004780 WindowState ws = mWindows.get(i);
4781 if (ws.mSurface == null) {
4782 continue;
4783 }
4784 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08004785 continue;
4786 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004787 // When we will skip windows: when we are not including
4788 // ones behind a window we didn't skip, and we are actually
4789 // taking a screenshot of a specific app.
4790 if (!including && appToken != null) {
4791 // Also, we can possibly skip this window if it is not
4792 // an IME target or the application for the screenshot
4793 // is not the current IME target.
4794 if (!ws.mIsImWindow || !isImeTarget) {
4795 // And finally, this window is of no interest if it
4796 // is not associated with the screenshot app.
4797 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
4798 continue;
4799 }
4800 }
4801 }
4802
4803 // We keep on including windows until we go past a full-screen
4804 // window.
4805 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
4806
Dianne Hackbornd2835932010-12-13 16:28:46 -08004807 if (maxLayer < ws.mAnimLayer) {
4808 maxLayer = ws.mAnimLayer;
4809 }
Jim Miller2aded182011-03-08 15:32:42 -08004810
4811 // Don't include wallpaper in bounds calculation
4812 if (!ws.mIsWallpaper) {
Dianne Hackborne2515ee2011-04-27 18:52:56 -04004813 final Rect wf = ws.mScaledFrame;
Jim Miller2aded182011-03-08 15:32:42 -08004814 final Rect cr = ws.mContentInsets;
4815 int left = wf.left + cr.left;
4816 int top = wf.top + cr.top;
4817 int right = wf.right - cr.right;
4818 int bottom = wf.bottom - cr.bottom;
4819 frame.union(left, top, right, bottom);
4820 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004821 }
4822 Binder.restoreCallingIdentity(ident);
4823
Dianne Hackborndd962ee2011-02-02 11:11:50 -08004824 // Constrain frame to the screen size.
4825 frame.intersect(0, 0, dw, dh);
Jim Millere70d5062011-03-08 21:38:39 -08004826
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004827 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004828 return null;
4829 }
4830
4831 // The screenshot API does not apply the current screen rotation.
4832 rot = mDisplay.getRotation();
4833 int fw = frame.width();
4834 int fh = frame.height();
4835
4836 // First try reducing to fit in x dimension.
Jim Millere70d5062011-03-08 21:38:39 -08004837 scale = width/(float)fw;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004838
4839 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004840 dw = (int)(dw*scale);
4841 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004842 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
4843 int tmp = dw;
4844 dw = dh;
4845 dh = tmp;
4846 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
4847 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08004848 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004849 }
4850
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004851 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08004852 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
4853 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004854 return null;
4855 }
Jim Millere70d5062011-03-08 21:38:39 -08004856
4857 Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig());
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004858 Matrix matrix = new Matrix();
4859 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
4860 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
4861 Canvas canvas = new Canvas(bm);
4862 canvas.drawBitmap(rawss, matrix, null);
4863
4864 rawss.recycle();
4865 return bm;
4866 }
4867
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004868 public void freezeRotation() {
4869 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004870 "freezeRotation()")) {
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004871 throw new SecurityException("Requires SET_ORIENTATION permission");
4872 }
4873
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004874 if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation);
4875
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004876 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4877 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4878 }
4879
4880 public void thawRotation() {
4881 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004882 "thawRotation()")) {
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004883 throw new SecurityException("Requires SET_ORIENTATION permission");
4884 }
4885
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004886 if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation);
4887
4888 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 777); // rot not used
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004889 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4890 }
4891
Romain Guy06882f82009-06-10 13:36:04 -07004892 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004893 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004894 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004895 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004896 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 }
4898
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004899 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 }
Romain Guy06882f82009-06-10 13:36:04 -07004901
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004902 public void setRotationUnchecked(int rotation,
4903 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004904 if(DEBUG_ORIENTATION) Slog.v(TAG,
David 'Digit' Turner910a0682011-02-05 00:34:46 +01004905 "setRotationUnchecked(rotation=" + rotation +
4906 " alwaysSendConfiguration=" + alwaysSendConfiguration +
4907 " animFlags=" + animFlags);
Romain Guy06882f82009-06-10 13:36:04 -07004908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004909 long origId = Binder.clearCallingIdentity();
4910 boolean changed;
4911 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004912 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 }
Romain Guy06882f82009-06-10 13:36:04 -07004914
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004915 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 sendNewConfiguration();
4917 }
Romain Guy06882f82009-06-10 13:36:04 -07004918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 Binder.restoreCallingIdentity(origId);
4920 }
Romain Guy06882f82009-06-10 13:36:04 -07004921
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004922 /**
4923 * Apply a new rotation to the screen, respecting the requests of
4924 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4925 * re-evaluate the desired rotation.
4926 *
4927 * Returns null if the rotation has been changed. In this case YOU
4928 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4929 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004930 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004931 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08004932 // Potential rotation during a drag. Don't do the rotation now, but make
4933 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004934 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
4935 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
4936 mDeferredRotation = rotation;
4937 mDeferredRotationAnimFlags = animFlags;
4938 }
Christopher Tateccd24de2011-01-12 15:02:55 -08004939 return false;
4940 }
4941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 boolean changed;
4943 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004944 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
4945 rotation = mDeferredRotation;
4946 mRequestedRotation = rotation;
4947 mLastRotationFlags = mDeferredRotationAnimFlags;
4948 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 rotation = mRequestedRotation;
4950 } else {
4951 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004952 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004954 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08004955 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004956 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004957 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004958 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004959
4960 int desiredRotation = rotation;
4961 int lockedRotation = mPolicy.getLockedRotationLw();
4962 if (lockedRotation >= 0 && rotation != lockedRotation) {
4963 // We are locked in a rotation but something is requesting
4964 // a different rotation... we will either keep the locked
4965 // rotation if it results in the same orientation, or have to
4966 // switch into an emulated orientation mode.
4967
4968 // First, we know that our rotation is actually going to be
4969 // the locked rotation.
4970 rotation = lockedRotation;
4971
4972 // Now the difference between the desired and lockedRotation
4973 // may mean that the orientation is different... if that is
4974 // not the case, we can just make the desired rotation be the
4975 // same as the new locked rotation.
4976 switch (lockedRotation) {
4977 case Surface.ROTATION_0:
4978 if (rotation == Surface.ROTATION_180) {
4979 desiredRotation = lockedRotation;
4980 }
4981 break;
4982 case Surface.ROTATION_90:
4983 if (rotation == Surface.ROTATION_270) {
4984 desiredRotation = lockedRotation;
4985 }
4986 break;
4987 case Surface.ROTATION_180:
4988 if (rotation == Surface.ROTATION_0) {
4989 desiredRotation = lockedRotation;
4990 }
4991 break;
4992 case Surface.ROTATION_270:
4993 if (rotation == Surface.ROTATION_90) {
4994 desiredRotation = lockedRotation;
4995 }
4996 break;
4997 }
4998 }
4999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005000 changed = mDisplayEnabled && mRotation != rotation;
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005001 if (mAltOrientation != (rotation != desiredRotation)) {
5002 changed = true;
5003 mAltOrientation = rotation != desiredRotation;
5004 }
Romain Guy06882f82009-06-10 13:36:04 -07005005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005006 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005007 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005008 "Rotation changed to " + rotation
5009 + " from " + mRotation
5010 + " (forceApp=" + mForcedAppOrientation
5011 + ", req=" + mRequestedRotation + ")");
5012 mRotation = rotation;
5013 mWindowsFreezingScreen = true;
5014 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5015 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5016 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005017 mWaitingForConfig = true;
5018 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005019 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005020 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005021 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005022 if (mDisplayEnabled) {
David 'Digit' Turner910a0682011-02-05 00:34:46 +01005023 // NOTE: We disable the rotation in the emulator because
5024 // it doesn't support hardware OpenGL emulation yet.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08005025 if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
5026 && mScreenRotationAnimation.hasScreenshot()) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005027 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005028 if (!inTransaction) {
5029 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5030 ">>> OPEN TRANSACTION setRotationUnchecked");
5031 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005032 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005033 try {
5034 if (mScreenRotationAnimation != null) {
5035 mScreenRotationAnimation.setRotation(rotation);
5036 }
5037 } finally {
5038 if (!inTransaction) {
5039 Surface.closeTransaction();
5040 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5041 "<<< CLOSE TRANSACTION setRotationUnchecked");
5042 }
5043 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005044 Surface.setOrientation(0, rotation, animFlags);
5045 Surface.unfreezeDisplay(0);
5046 } else {
5047 Surface.setOrientation(0, rotation, animFlags);
5048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005049 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005051 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005052 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005053 if (w.mSurface != null) {
5054 w.mOrientationChanging = true;
5055 }
5056 }
5057 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5058 try {
5059 mRotationWatchers.get(i).onRotationChanged(rotation);
5060 } catch (RemoteException e) {
5061 }
5062 }
5063 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 return changed;
5066 }
Romain Guy06882f82009-06-10 13:36:04 -07005067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005068 public int getRotation() {
5069 return mRotation;
5070 }
5071
5072 public int watchRotation(IRotationWatcher watcher) {
5073 final IBinder watcherBinder = watcher.asBinder();
5074 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5075 public void binderDied() {
5076 synchronized (mWindowMap) {
5077 for (int i=0; i<mRotationWatchers.size(); i++) {
5078 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005079 IRotationWatcher removed = mRotationWatchers.remove(i);
5080 if (removed != null) {
5081 removed.asBinder().unlinkToDeath(this, 0);
5082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005083 i--;
5084 }
5085 }
5086 }
5087 }
5088 };
Romain Guy06882f82009-06-10 13:36:04 -07005089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005090 synchronized (mWindowMap) {
5091 try {
5092 watcher.asBinder().linkToDeath(dr, 0);
5093 mRotationWatchers.add(watcher);
5094 } catch (RemoteException e) {
5095 // Client died, no cleanup needed.
5096 }
Romain Guy06882f82009-06-10 13:36:04 -07005097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005098 return mRotation;
5099 }
5100 }
5101
5102 /**
5103 * Starts the view server on the specified port.
5104 *
5105 * @param port The port to listener to.
5106 *
5107 * @return True if the server was successfully started, false otherwise.
5108 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005109 * @see com.android.server.wm.ViewServer
5110 * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005111 */
5112 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005113 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005114 return false;
5115 }
5116
5117 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5118 return false;
5119 }
5120
5121 if (port < 1024) {
5122 return false;
5123 }
5124
5125 if (mViewServer != null) {
5126 if (!mViewServer.isRunning()) {
5127 try {
5128 return mViewServer.start();
5129 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005130 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005131 }
5132 }
5133 return false;
5134 }
5135
5136 try {
5137 mViewServer = new ViewServer(this, port);
5138 return mViewServer.start();
5139 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005140 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005141 }
5142 return false;
5143 }
5144
Romain Guy06882f82009-06-10 13:36:04 -07005145 private boolean isSystemSecure() {
5146 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5147 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5148 }
5149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005150 /**
5151 * Stops the view server if it exists.
5152 *
5153 * @return True if the server stopped, false if it wasn't started or
5154 * couldn't be stopped.
5155 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005156 * @see com.android.server.wm.ViewServer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005157 */
5158 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005159 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005160 return false;
5161 }
5162
5163 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5164 return false;
5165 }
5166
5167 if (mViewServer != null) {
5168 return mViewServer.stop();
5169 }
5170 return false;
5171 }
5172
5173 /**
5174 * Indicates whether the view server is running.
5175 *
5176 * @return True if the server is running, false otherwise.
5177 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005178 * @see com.android.server.wm.ViewServer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 */
5180 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005181 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005182 return false;
5183 }
5184
5185 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5186 return false;
5187 }
5188
5189 return mViewServer != null && mViewServer.isRunning();
5190 }
5191
5192 /**
5193 * Lists all availble windows in the system. The listing is written in the
5194 * specified Socket's output stream with the following syntax:
5195 * windowHashCodeInHexadecimal windowName
5196 * Each line of the ouput represents a different window.
5197 *
5198 * @param client The remote client to send the listing to.
5199 * @return False if an error occured, true otherwise.
5200 */
5201 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005202 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005203 return false;
5204 }
5205
5206 boolean result = true;
5207
Jeff Browne33348b2010-07-15 23:54:05 -07005208 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005209 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005211 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005212 }
5213
5214 BufferedWriter out = null;
5215
5216 // Any uncaught exception will crash the system process
5217 try {
5218 OutputStream clientStream = client.getOutputStream();
5219 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5220
5221 final int count = windows.length;
5222 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005223 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 out.write(Integer.toHexString(System.identityHashCode(w)));
5225 out.write(' ');
5226 out.append(w.mAttrs.getTitle());
5227 out.write('\n');
5228 }
5229
5230 out.write("DONE.\n");
5231 out.flush();
5232 } catch (Exception e) {
5233 result = false;
5234 } finally {
5235 if (out != null) {
5236 try {
5237 out.close();
5238 } catch (IOException e) {
5239 result = false;
5240 }
5241 }
5242 }
5243
5244 return result;
5245 }
5246
5247 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005248 * Returns the focused window in the following format:
5249 * windowHashCodeInHexadecimal windowName
5250 *
5251 * @param client The remote client to send the listing to.
5252 * @return False if an error occurred, true otherwise.
5253 */
5254 boolean viewServerGetFocusedWindow(Socket client) {
5255 if (isSystemSecure()) {
5256 return false;
5257 }
5258
5259 boolean result = true;
5260
5261 WindowState focusedWindow = getFocusedWindow();
5262
5263 BufferedWriter out = null;
5264
5265 // Any uncaught exception will crash the system process
5266 try {
5267 OutputStream clientStream = client.getOutputStream();
5268 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5269
5270 if(focusedWindow != null) {
5271 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5272 out.write(' ');
5273 out.append(focusedWindow.mAttrs.getTitle());
5274 }
5275 out.write('\n');
5276 out.flush();
5277 } catch (Exception e) {
5278 result = false;
5279 } finally {
5280 if (out != null) {
5281 try {
5282 out.close();
5283 } catch (IOException e) {
5284 result = false;
5285 }
5286 }
5287 }
5288
5289 return result;
5290 }
5291
5292 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005293 * Sends a command to a target window. The result of the command, if any, will be
5294 * written in the output stream of the specified socket.
5295 *
5296 * The parameters must follow this syntax:
5297 * windowHashcode extra
5298 *
5299 * Where XX is the length in characeters of the windowTitle.
5300 *
5301 * The first parameter is the target window. The window with the specified hashcode
5302 * will be the target. If no target can be found, nothing happens. The extra parameters
5303 * will be delivered to the target window and as parameters to the command itself.
5304 *
5305 * @param client The remote client to sent the result, if any, to.
5306 * @param command The command to execute.
5307 * @param parameters The command parameters.
5308 *
5309 * @return True if the command was successfully delivered, false otherwise. This does
5310 * not indicate whether the command itself was successful.
5311 */
5312 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005313 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005314 return false;
5315 }
5316
5317 boolean success = true;
5318 Parcel data = null;
5319 Parcel reply = null;
5320
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005321 BufferedWriter out = null;
5322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 // Any uncaught exception will crash the system process
5324 try {
5325 // Find the hashcode of the window
5326 int index = parameters.indexOf(' ');
5327 if (index == -1) {
5328 index = parameters.length();
5329 }
5330 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005331 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005332
5333 // Extract the command's parameter after the window description
5334 if (index < parameters.length()) {
5335 parameters = parameters.substring(index + 1);
5336 } else {
5337 parameters = "";
5338 }
5339
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005340 final WindowState window = findWindow(hashCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005341 if (window == null) {
5342 return false;
5343 }
5344
5345 data = Parcel.obtain();
5346 data.writeInterfaceToken("android.view.IWindow");
5347 data.writeString(command);
5348 data.writeString(parameters);
5349 data.writeInt(1);
5350 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5351
5352 reply = Parcel.obtain();
5353
5354 final IBinder binder = window.mClient.asBinder();
5355 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5356 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5357
5358 reply.readException();
5359
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005360 if (!client.isOutputShutdown()) {
5361 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5362 out.write("DONE\n");
5363 out.flush();
5364 }
5365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005366 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005367 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368 success = false;
5369 } finally {
5370 if (data != null) {
5371 data.recycle();
5372 }
5373 if (reply != null) {
5374 reply.recycle();
5375 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005376 if (out != null) {
5377 try {
5378 out.close();
5379 } catch (IOException e) {
5380
5381 }
5382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005383 }
5384
5385 return success;
5386 }
5387
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005388 public void addWindowChangeListener(WindowChangeListener listener) {
5389 synchronized(mWindowMap) {
5390 mWindowChangeListeners.add(listener);
5391 }
5392 }
5393
5394 public void removeWindowChangeListener(WindowChangeListener listener) {
5395 synchronized(mWindowMap) {
5396 mWindowChangeListeners.remove(listener);
5397 }
5398 }
5399
5400 private void notifyWindowsChanged() {
5401 WindowChangeListener[] windowChangeListeners;
5402 synchronized(mWindowMap) {
5403 if(mWindowChangeListeners.isEmpty()) {
5404 return;
5405 }
5406 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5407 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5408 }
5409 int N = windowChangeListeners.length;
5410 for(int i = 0; i < N; i++) {
5411 windowChangeListeners[i].windowsChanged();
5412 }
5413 }
5414
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005415 private void notifyFocusChanged() {
5416 WindowChangeListener[] windowChangeListeners;
5417 synchronized(mWindowMap) {
5418 if(mWindowChangeListeners.isEmpty()) {
5419 return;
5420 }
5421 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5422 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5423 }
5424 int N = windowChangeListeners.length;
5425 for(int i = 0; i < N; i++) {
5426 windowChangeListeners[i].focusChanged();
5427 }
5428 }
5429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 private WindowState findWindow(int hashCode) {
5431 if (hashCode == -1) {
5432 return getFocusedWindow();
5433 }
5434
5435 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005436 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005437 final int count = windows.size();
5438
5439 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005440 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005441 if (System.identityHashCode(w) == hashCode) {
5442 return w;
5443 }
5444 }
5445 }
5446
5447 return null;
5448 }
5449
5450 /*
5451 * Instruct the Activity Manager to fetch the current configuration and broadcast
5452 * that to config-changed listeners if appropriate.
5453 */
5454 void sendNewConfiguration() {
5455 try {
5456 mActivityManager.updateConfiguration(null);
5457 } catch (RemoteException e) {
5458 }
5459 }
Romain Guy06882f82009-06-10 13:36:04 -07005460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005461 public Configuration computeNewConfiguration() {
5462 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005463 Configuration config = computeNewConfigurationLocked();
5464 if (config == null && mWaitingForConfig) {
5465 // Nothing changed but we are waiting for something... stop that!
5466 mWaitingForConfig = false;
5467 performLayoutAndPlaceSurfacesLocked();
5468 }
5469 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005470 }
5471 }
Romain Guy06882f82009-06-10 13:36:04 -07005472
Dianne Hackbornc485a602009-03-24 22:39:49 -07005473 Configuration computeNewConfigurationLocked() {
5474 Configuration config = new Configuration();
5475 if (!computeNewConfigurationLocked(config)) {
5476 return null;
5477 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005478 return config;
5479 }
Romain Guy06882f82009-06-10 13:36:04 -07005480
Dianne Hackbornc485a602009-03-24 22:39:49 -07005481 boolean computeNewConfigurationLocked(Configuration config) {
5482 if (mDisplay == null) {
5483 return false;
5484 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005485
5486 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005487
5488 // Use the effective "visual" dimensions based on current rotation
5489 final boolean rotated = (mRotation == Surface.ROTATION_90
5490 || mRotation == Surface.ROTATION_270);
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005491 final int realdw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5492 final int realdh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5493
5494 if (mAltOrientation) {
5495 mCurDisplayWidth = realdw;
5496 mCurDisplayHeight = realdh;
5497 if (realdw > realdh) {
5498 // Turn landscape into portrait.
5499 int maxw = (int)(realdh/1.3f);
5500 if (maxw < realdw) {
5501 mCurDisplayWidth = maxw;
5502 }
5503 } else {
5504 // Turn portrait into landscape.
5505 int maxh = (int)(realdw/1.3f);
5506 if (maxh < realdh) {
5507 mCurDisplayHeight = maxh;
5508 }
5509 }
5510 } else {
5511 mCurDisplayWidth = realdw;
5512 mCurDisplayHeight = realdh;
5513 }
5514
5515 final int dw = mCurDisplayWidth;
5516 final int dh = mCurDisplayHeight;
Christopher Tateb696aee2010-04-02 19:08:30 -07005517
Dianne Hackbornc485a602009-03-24 22:39:49 -07005518 int orientation = Configuration.ORIENTATION_SQUARE;
5519 if (dw < dh) {
5520 orientation = Configuration.ORIENTATION_PORTRAIT;
5521 } else if (dw > dh) {
5522 orientation = Configuration.ORIENTATION_LANDSCAPE;
5523 }
5524 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005525
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005526 DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005527 mDisplay.getRealMetrics(dm);
5528
5529 // Override display width and height with what we are computing,
5530 // to be sure they remain consistent.
Dianne Hackbornaa9d84c2011-05-09 19:00:59 -07005531 dm.widthPixels = mPolicy.getNonDecorDisplayWidth(dw);
5532 dm.heightPixels = mPolicy.getNonDecorDisplayHeight(dh);
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005533
Dianne Hackborne2515ee2011-04-27 18:52:56 -04005534 mCompatibleScreenScale = CompatibilityInfo.updateCompatibleScreenFrame(
5535 dm, mCompatibleScreenFrame, null);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005536
Dianne Hackborn3fc982f2011-03-30 16:20:26 -07005537 config.screenWidthDp = (int)(dm.widthPixels / dm.density);
5538 config.screenHeightDp = (int)(dm.heightPixels / dm.density);
5539
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005540 // Compute the screen layout size class.
5541 int screenLayout;
5542 int longSize = dw;
5543 int shortSize = dh;
5544 if (longSize < shortSize) {
5545 int tmp = longSize;
5546 longSize = shortSize;
5547 shortSize = tmp;
5548 }
5549 longSize = (int)(longSize/dm.density);
5550 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005551
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005552 // These semi-magic numbers define our compatibility modes for
5553 // applications with different screens. These are guarantees to
5554 // app developers about the space they can expect for a particular
5555 // configuration. DO NOT CHANGE!
5556 if (longSize < 470) {
5557 // This is shorter than an HVGA normal density screen (which
5558 // is 480 pixels on its long side).
5559 screenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5560 | Configuration.SCREENLAYOUT_LONG_NO;
5561 } else {
5562 // What size is this screen screen?
5563 if (longSize >= 960 && shortSize >= 720) {
5564 // 1.5xVGA or larger screens at medium density are the point
5565 // at which we consider it to be an extra large screen.
5566 screenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5567 } else if (longSize >= 640 && shortSize >= 480) {
5568 // VGA or larger screens at medium density are the point
5569 // at which we consider it to be a large screen.
5570 screenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005571 } else {
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005572 screenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
5573 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005574
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005575 // If this screen is wider than normal HVGA, or taller
5576 // than FWVGA, then for old apps we want to run in size
5577 // compatibility mode.
5578 if (shortSize > 321 || longSize > 570) {
5579 screenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5580 }
5581
5582 // Is this a long screen?
5583 if (((longSize*3)/5) >= (shortSize-1)) {
5584 // Anything wider than WVGA (5:3) is considering to be long.
5585 screenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5586 } else {
5587 screenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005588 }
5589 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005590 config.screenLayout = screenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005591
Jeff Brown597eec82011-01-31 17:12:25 -08005592 // Determine whether a hard keyboard is available and enabled.
Jeff Brown2992ea72011-01-28 22:04:14 -08005593 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5594 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5595 mHardKeyboardAvailable = hardKeyboardAvailable;
5596 mHardKeyboardEnabled = hardKeyboardAvailable;
5597
5598 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5599 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5600 }
5601 if (!mHardKeyboardEnabled) {
5602 config.keyboard = Configuration.KEYBOARD_NOKEYS;
Jeff Brown2992ea72011-01-28 22:04:14 -08005603 }
Jeff Brown597eec82011-01-31 17:12:25 -08005604
5605 // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
5606 // based on whether a hard or soft keyboard is present, whether navigation keys
5607 // are present and the lid switch state.
5608 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5609 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5610 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
5611 mPolicy.adjustConfigurationLw(config);
Dianne Hackbornc485a602009-03-24 22:39:49 -07005612 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005613 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005614
Jeff Brown2992ea72011-01-28 22:04:14 -08005615 public boolean isHardKeyboardAvailable() {
5616 synchronized (mWindowMap) {
5617 return mHardKeyboardAvailable;
5618 }
5619 }
5620
5621 public boolean isHardKeyboardEnabled() {
5622 synchronized (mWindowMap) {
5623 return mHardKeyboardEnabled;
5624 }
5625 }
5626
5627 public void setHardKeyboardEnabled(boolean enabled) {
5628 synchronized (mWindowMap) {
5629 if (mHardKeyboardEnabled != enabled) {
5630 mHardKeyboardEnabled = enabled;
5631 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5632 }
5633 }
5634 }
5635
5636 public void setOnHardKeyboardStatusChangeListener(
5637 OnHardKeyboardStatusChangeListener listener) {
5638 synchronized (mWindowMap) {
5639 mHardKeyboardStatusChangeListener = listener;
5640 }
5641 }
5642
5643 void notifyHardKeyboardStatusChange() {
5644 final boolean available, enabled;
5645 final OnHardKeyboardStatusChangeListener listener;
5646 synchronized (mWindowMap) {
5647 listener = mHardKeyboardStatusChangeListener;
5648 available = mHardKeyboardAvailable;
5649 enabled = mHardKeyboardEnabled;
5650 }
5651 if (listener != null) {
5652 listener.onHardKeyboardStatusChange(available, enabled);
5653 }
5654 }
5655
Christopher Tatea53146c2010-09-07 11:57:52 -07005656 // -------------------------------------------------------------
5657 // Drag and drop
5658 // -------------------------------------------------------------
5659
5660 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005661 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005662 if (DEBUG_DRAG) {
5663 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005664 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005665 + " asbinder=" + window.asBinder());
5666 }
5667
5668 final int callerPid = Binder.getCallingPid();
5669 final long origId = Binder.clearCallingIdentity();
5670 IBinder token = null;
5671
5672 try {
5673 synchronized (mWindowMap) {
5674 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005675 if (mDragState == null) {
5676 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5677 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
Dianne Hackbornac1471a2011-02-03 13:46:06 -08005678 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG "
5679 + surface + ": CREATE");
Christopher Tatea53146c2010-09-07 11:57:52 -07005680 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005681 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005682 token = new Binder();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005683 mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005684 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005685 token = mDragState.mToken = new Binder();
5686
5687 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005688 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5689 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005690 mH.sendMessageDelayed(msg, 5000);
5691 } else {
5692 Slog.w(TAG, "Drag already in progress");
5693 }
5694 } catch (Surface.OutOfResourcesException e) {
5695 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5696 if (mDragState != null) {
5697 mDragState.reset();
5698 mDragState = null;
5699 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005700 }
5701 }
5702 } finally {
5703 Binder.restoreCallingIdentity(origId);
5704 }
5705
5706 return token;
5707 }
5708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005709 // -------------------------------------------------------------
5710 // Input Events and Focus Management
5711 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005712
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005713 final InputMonitor mInputMonitor = new InputMonitor(this);
Jeff Brown349703e2010-06-22 01:27:15 -07005714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005715 public void pauseKeyDispatching(IBinder _token) {
5716 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5717 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005718 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005719 }
5720
5721 synchronized (mWindowMap) {
5722 WindowToken token = mTokenMap.get(_token);
5723 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005724 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 }
5726 }
5727 }
5728
5729 public void resumeKeyDispatching(IBinder _token) {
5730 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5731 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005732 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 }
5734
5735 synchronized (mWindowMap) {
5736 WindowToken token = mTokenMap.get(_token);
5737 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005738 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005739 }
5740 }
5741 }
5742
5743 public void setEventDispatching(boolean enabled) {
5744 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5745 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005746 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005747 }
5748
5749 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005750 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005751 }
5752 }
Romain Guy06882f82009-06-10 13:36:04 -07005753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005754 /**
5755 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005756 * Even when sync is false, this method may block while waiting for current
5757 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005758 *
5759 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005760 * {@link SystemClock#uptimeMillis()} as the timebase.)
5761 * @param sync If true, wait for the event to be completed before returning to the caller.
5762 * @return Returns true if event was dispatched, false if it was dropped for any reason
5763 */
5764 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5765 long downTime = ev.getDownTime();
5766 long eventTime = ev.getEventTime();
5767
5768 int action = ev.getAction();
5769 int code = ev.getKeyCode();
5770 int repeatCount = ev.getRepeatCount();
5771 int metaState = ev.getMetaState();
5772 int deviceId = ev.getDeviceId();
5773 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005774 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00005775 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005776
5777 if (source == InputDevice.SOURCE_UNKNOWN) {
5778 source = InputDevice.SOURCE_KEYBOARD;
5779 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005780
5781 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5782 if (downTime == 0) downTime = eventTime;
5783
5784 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08005785 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005786
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005787 final int pid = Binder.getCallingPid();
5788 final int uid = Binder.getCallingUid();
5789 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005790
Jeff Brownbbda99d2010-07-28 15:48:59 -07005791 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5792 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5793 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5794 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005795
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005796 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005797 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005798 }
5799
5800 /**
5801 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005802 * Even when sync is false, this method may block while waiting for current
5803 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005804 *
5805 * @param ev A motion event describing the pointer (touch) action. (As noted in
5806 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005807 * {@link SystemClock#uptimeMillis()} as the timebase.)
5808 * @param sync If true, wait for the event to be completed before returning to the caller.
5809 * @return Returns true if event was dispatched, false if it was dropped for any reason
5810 */
5811 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005812 final int pid = Binder.getCallingPid();
5813 final int uid = Binder.getCallingUid();
5814 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005815
Jeff Brownc5ed5912010-07-14 18:48:53 -07005816 MotionEvent newEvent = MotionEvent.obtain(ev);
5817 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5818 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5819 }
5820
Jeff Brownbbda99d2010-07-28 15:48:59 -07005821 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5822 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5823 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5824 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005825
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005826 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005827 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005828 }
Romain Guy06882f82009-06-10 13:36:04 -07005829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 /**
5831 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005832 * Even when sync is false, this method may block while waiting for current
5833 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005834 *
5835 * @param ev A motion event describing the trackball action. (As noted in
5836 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 * {@link SystemClock#uptimeMillis()} as the timebase.)
5838 * @param sync If true, wait for the event to be completed before returning to the caller.
5839 * @return Returns true if event was dispatched, false if it was dropped for any reason
5840 */
5841 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005842 final int pid = Binder.getCallingPid();
5843 final int uid = Binder.getCallingUid();
5844 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005845
Jeff Brownc5ed5912010-07-14 18:48:53 -07005846 MotionEvent newEvent = MotionEvent.obtain(ev);
5847 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5848 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5849 }
5850
Jeff Brownbbda99d2010-07-28 15:48:59 -07005851 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5852 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5853 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5854 INJECTION_TIMEOUT_MILLIS);
5855
5856 Binder.restoreCallingIdentity(ident);
5857 return reportInjectionResult(result);
5858 }
5859
5860 /**
5861 * Inject an input event into the UI without waiting for dispatch to commence.
5862 * This variant is useful for fire-and-forget input event injection. It does not
5863 * block any longer than it takes to enqueue the input event.
5864 *
5865 * @param ev An input event. (Be sure to set the input source correctly.)
5866 * @return Returns true if event was dispatched, false if it was dropped for any reason
5867 */
5868 public boolean injectInputEventNoWait(InputEvent ev) {
5869 final int pid = Binder.getCallingPid();
5870 final int uid = Binder.getCallingUid();
5871 final long ident = Binder.clearCallingIdentity();
5872
5873 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5874 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5875 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005876
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005877 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005878 return reportInjectionResult(result);
5879 }
5880
5881 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005882 switch (result) {
5883 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5884 Slog.w(TAG, "Input event injection permission denied.");
5885 throw new SecurityException(
5886 "Injecting to another application requires INJECT_EVENTS permission");
5887 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005888 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005889 return true;
5890 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5891 Slog.w(TAG, "Input event injection timed out.");
5892 return false;
5893 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5894 default:
5895 Slog.w(TAG, "Input event injection failed.");
5896 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005898 }
Romain Guy06882f82009-06-10 13:36:04 -07005899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 private WindowState getFocusedWindow() {
5901 synchronized (mWindowMap) {
5902 return getFocusedWindowLocked();
5903 }
5904 }
5905
5906 private WindowState getFocusedWindowLocked() {
5907 return mCurrentFocus;
5908 }
Romain Guy06882f82009-06-10 13:36:04 -07005909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005910 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08005911 if (!mInputMonitor.waitForInputDevicesReady(
5912 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
5913 Slog.w(TAG, "Devices still not ready after waiting "
5914 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
5915 + " milliseconds before attempting to detect safe mode.");
5916 }
5917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005918 mSafeMode = mPolicy.detectSafeMode();
5919 return mSafeMode;
5920 }
Romain Guy06882f82009-06-10 13:36:04 -07005921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005922 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005923 synchronized(mWindowMap) {
5924 if (mDisplay != null) {
5925 throw new IllegalStateException("Display already initialized");
5926 }
5927 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5928 mDisplay = wm.getDefaultDisplay();
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07005929 mInitialDisplayWidth = mCurDisplayWidth = mDisplay.getRealWidth();
5930 mInitialDisplayHeight = mCurDisplayHeight = mDisplay.getRealHeight();
5931 mInputManager.setDisplaySize(0, mDisplay.getRawWidth(), mDisplay.getRawHeight());
Dianne Hackborn9d132642011-04-21 17:26:39 -07005932 mPolicy.setInitialDisplaySize(mInitialDisplayWidth, mInitialDisplayHeight);
Dianne Hackborn5132b372010-07-29 12:51:35 -07005933 }
5934
5935 try {
5936 mActivityManager.updateConfiguration(null);
5937 } catch (RemoteException e) {
5938 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005939
5940 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005941 }
5942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005943 // This is an animation that does nothing: it just immediately finishes
5944 // itself every time it is called. It is used as a stub animation in cases
5945 // where we want to synchronize multiple things that may be animating.
5946 static final class DummyAnimation extends Animation {
5947 public boolean getTransformation(long currentTime, Transformation outTransformation) {
5948 return false;
5949 }
5950 }
5951 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07005952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005953 // -------------------------------------------------------------
5954 // Async Handler
5955 // -------------------------------------------------------------
5956
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005957 final class H extends Handler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005958 public static final int REPORT_FOCUS_CHANGE = 2;
5959 public static final int REPORT_LOSING_FOCUS = 3;
5960 public static final int ANIMATE = 4;
5961 public static final int ADD_STARTING = 5;
5962 public static final int REMOVE_STARTING = 6;
5963 public static final int FINISHED_STARTING = 7;
5964 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005965 public static final int WINDOW_FREEZE_TIMEOUT = 11;
5966 public static final int HOLD_SCREEN_CHANGED = 12;
5967 public static final int APP_TRANSITION_TIMEOUT = 13;
5968 public static final int PERSIST_ANIMATION_SCALE = 14;
5969 public static final int FORCE_GC = 15;
5970 public static final int ENABLE_SCREEN = 16;
5971 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005972 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005973 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07005974 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07005975 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08005976 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07005977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005978 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07005979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005980 public H() {
5981 }
Romain Guy06882f82009-06-10 13:36:04 -07005982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005983 @Override
5984 public void handleMessage(Message msg) {
5985 switch (msg.what) {
5986 case REPORT_FOCUS_CHANGE: {
5987 WindowState lastFocus;
5988 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005990 synchronized(mWindowMap) {
5991 lastFocus = mLastFocus;
5992 newFocus = mCurrentFocus;
5993 if (lastFocus == newFocus) {
5994 // Focus is not changing, so nothing to do.
5995 return;
5996 }
5997 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005998 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005999 // + " to " + newFocus);
6000 if (newFocus != null && lastFocus != null
6001 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006002 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006003 mLosingFocus.add(lastFocus);
6004 lastFocus = null;
6005 }
6006 }
6007
6008 if (lastFocus != newFocus) {
6009 //System.out.println("Changing focus from " + lastFocus
6010 // + " to " + newFocus);
6011 if (newFocus != null) {
6012 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006013 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006014 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
6015 } catch (RemoteException e) {
6016 // Ignore if process has died.
6017 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07006018 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006019 }
6020
6021 if (lastFocus != null) {
6022 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006023 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006024 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
6025 } catch (RemoteException e) {
6026 // Ignore if process has died.
6027 }
6028 }
Joe Onorato664644d2011-01-23 17:53:23 -08006029
6030 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006031 }
6032 } break;
6033
6034 case REPORT_LOSING_FOCUS: {
6035 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07006036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 synchronized(mWindowMap) {
6038 losers = mLosingFocus;
6039 mLosingFocus = new ArrayList<WindowState>();
6040 }
6041
6042 final int N = losers.size();
6043 for (int i=0; i<N; i++) {
6044 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006045 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006046 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
6047 } catch (RemoteException e) {
6048 // Ignore if process has died.
6049 }
6050 }
6051 } break;
6052
6053 case ANIMATE: {
6054 synchronized(mWindowMap) {
6055 mAnimationPending = false;
6056 performLayoutAndPlaceSurfacesLocked();
6057 }
6058 } break;
6059
6060 case ADD_STARTING: {
6061 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
6062 final StartingData sd = wtoken.startingData;
6063
6064 if (sd == null) {
6065 // Animation has been canceled... do nothing.
6066 return;
6067 }
Romain Guy06882f82009-06-10 13:36:04 -07006068
Joe Onorato8a9b2202010-02-26 18:56:32 -08006069 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006070 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07006071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 View view = null;
6073 try {
6074 view = mPolicy.addStartingWindow(
6075 wtoken.token, sd.pkg,
6076 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08006077 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006079 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006080 }
6081
6082 if (view != null) {
6083 boolean abort = false;
6084
6085 synchronized(mWindowMap) {
6086 if (wtoken.removed || wtoken.startingData == null) {
6087 // If the window was successfully added, then
6088 // we need to remove it.
6089 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006090 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006091 "Aborted starting " + wtoken
6092 + ": removed=" + wtoken.removed
6093 + " startingData=" + wtoken.startingData);
6094 wtoken.startingWindow = null;
6095 wtoken.startingData = null;
6096 abort = true;
6097 }
6098 } else {
6099 wtoken.startingView = view;
6100 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006101 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006102 "Added starting " + wtoken
6103 + ": startingWindow="
6104 + wtoken.startingWindow + " startingView="
6105 + wtoken.startingView);
6106 }
6107
6108 if (abort) {
6109 try {
6110 mPolicy.removeStartingWindow(wtoken.token, view);
6111 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006112 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 }
6114 }
6115 }
6116 } break;
6117
6118 case REMOVE_STARTING: {
6119 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
6120 IBinder token = null;
6121 View view = null;
6122 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006123 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006124 + wtoken + ": startingWindow="
6125 + wtoken.startingWindow + " startingView="
6126 + wtoken.startingView);
6127 if (wtoken.startingWindow != null) {
6128 view = wtoken.startingView;
6129 token = wtoken.token;
6130 wtoken.startingData = null;
6131 wtoken.startingView = null;
6132 wtoken.startingWindow = null;
6133 }
6134 }
6135 if (view != null) {
6136 try {
6137 mPolicy.removeStartingWindow(token, view);
6138 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006139 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006140 }
6141 }
6142 } break;
6143
6144 case FINISHED_STARTING: {
6145 IBinder token = null;
6146 View view = null;
6147 while (true) {
6148 synchronized (mWindowMap) {
6149 final int N = mFinishedStarting.size();
6150 if (N <= 0) {
6151 break;
6152 }
6153 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
6154
Joe Onorato8a9b2202010-02-26 18:56:32 -08006155 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006156 "Finished starting " + wtoken
6157 + ": startingWindow=" + wtoken.startingWindow
6158 + " startingView=" + wtoken.startingView);
6159
6160 if (wtoken.startingWindow == null) {
6161 continue;
6162 }
6163
6164 view = wtoken.startingView;
6165 token = wtoken.token;
6166 wtoken.startingData = null;
6167 wtoken.startingView = null;
6168 wtoken.startingWindow = null;
6169 }
6170
6171 try {
6172 mPolicy.removeStartingWindow(token, view);
6173 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006174 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006175 }
6176 }
6177 } break;
6178
6179 case REPORT_APPLICATION_TOKEN_WINDOWS: {
6180 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
6181
6182 boolean nowVisible = msg.arg1 != 0;
6183 boolean nowGone = msg.arg2 != 0;
6184
6185 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006186 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 TAG, "Reporting visible in " + wtoken
6188 + " visible=" + nowVisible
6189 + " gone=" + nowGone);
6190 if (nowVisible) {
6191 wtoken.appToken.windowsVisible();
6192 } else {
6193 wtoken.appToken.windowsGone();
6194 }
6195 } catch (RemoteException ex) {
6196 }
6197 } break;
Romain Guy06882f82009-06-10 13:36:04 -07006198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006199 case WINDOW_FREEZE_TIMEOUT: {
6200 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006201 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006202 int i = mWindows.size();
6203 while (i > 0) {
6204 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006205 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 if (w.mOrientationChanging) {
6207 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006208 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 }
6210 }
6211 performLayoutAndPlaceSurfacesLocked();
6212 }
6213 break;
6214 }
Romain Guy06882f82009-06-10 13:36:04 -07006215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 case HOLD_SCREEN_CHANGED: {
6217 Session oldHold;
6218 Session newHold;
6219 synchronized (mWindowMap) {
6220 oldHold = mLastReportedHold;
6221 newHold = (Session)msg.obj;
6222 mLastReportedHold = newHold;
6223 }
Romain Guy06882f82009-06-10 13:36:04 -07006224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006225 if (oldHold != newHold) {
6226 try {
6227 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07006228 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 "window",
6230 BatteryStats.WAKE_TYPE_WINDOW);
6231 }
6232 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07006233 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006234 "window",
6235 BatteryStats.WAKE_TYPE_WINDOW);
6236 }
6237 } catch (RemoteException e) {
6238 }
6239 }
6240 break;
6241 }
Romain Guy06882f82009-06-10 13:36:04 -07006242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006243 case APP_TRANSITION_TIMEOUT: {
6244 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006245 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006246 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006247 "*** APP TRANSITION TIMEOUT");
6248 mAppTransitionReady = true;
6249 mAppTransitionTimeout = true;
6250 performLayoutAndPlaceSurfacesLocked();
6251 }
6252 }
6253 break;
6254 }
Romain Guy06882f82009-06-10 13:36:04 -07006255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 case PERSIST_ANIMATION_SCALE: {
6257 Settings.System.putFloat(mContext.getContentResolver(),
6258 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
6259 Settings.System.putFloat(mContext.getContentResolver(),
6260 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
6261 break;
6262 }
Romain Guy06882f82009-06-10 13:36:04 -07006263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 case FORCE_GC: {
6265 synchronized(mWindowMap) {
6266 if (mAnimationPending) {
6267 // If we are animating, don't do the gc now but
6268 // delay a bit so we don't interrupt the animation.
6269 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
6270 2000);
6271 return;
6272 }
6273 // If we are currently rotating the display, it will
6274 // schedule a new message when done.
6275 if (mDisplayFrozen) {
6276 return;
6277 }
6278 mFreezeGcPending = 0;
6279 }
6280 Runtime.getRuntime().gc();
6281 break;
6282 }
Romain Guy06882f82009-06-10 13:36:04 -07006283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006284 case ENABLE_SCREEN: {
6285 performEnableScreen();
6286 break;
6287 }
Romain Guy06882f82009-06-10 13:36:04 -07006288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 case APP_FREEZE_TIMEOUT: {
6290 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006291 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 int i = mAppTokens.size();
6293 while (i > 0) {
6294 i--;
6295 AppWindowToken tok = mAppTokens.get(i);
6296 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006297 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006298 unsetAppFreezingScreenLocked(tok, true, true);
6299 }
6300 }
6301 }
6302 break;
6303 }
Romain Guy06882f82009-06-10 13:36:04 -07006304
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006305 case SEND_NEW_CONFIGURATION: {
6306 removeMessages(SEND_NEW_CONFIGURATION);
6307 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006308 break;
6309 }
Romain Guy06882f82009-06-10 13:36:04 -07006310
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07006311 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006312 if (mWindowsChanged) {
6313 synchronized (mWindowMap) {
6314 mWindowsChanged = false;
6315 }
6316 notifyWindowsChanged();
6317 }
6318 break;
6319 }
6320
Christopher Tatea53146c2010-09-07 11:57:52 -07006321 case DRAG_START_TIMEOUT: {
6322 IBinder win = (IBinder)msg.obj;
6323 if (DEBUG_DRAG) {
6324 Slog.w(TAG, "Timeout starting drag by win " + win);
6325 }
6326 synchronized (mWindowMap) {
6327 // !!! TODO: ANR the app that has failed to start the drag in time
6328 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07006329 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08006330 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07006331 mDragState.reset();
6332 mDragState = null;
6333 }
6334 }
Chris Tated4533f12010-10-19 15:15:08 -07006335 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07006336 }
6337
Chris Tated4533f12010-10-19 15:15:08 -07006338 case DRAG_END_TIMEOUT: {
6339 IBinder win = (IBinder)msg.obj;
6340 if (DEBUG_DRAG) {
6341 Slog.w(TAG, "Timeout ending drag to win " + win);
6342 }
6343 synchronized (mWindowMap) {
6344 // !!! TODO: ANR the drag-receiving app
6345 mDragState.mDragResult = false;
6346 mDragState.endDragLw();
6347 }
6348 break;
6349 }
Jeff Brown2992ea72011-01-28 22:04:14 -08006350
6351 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
6352 notifyHardKeyboardStatusChange();
6353 break;
6354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006355 }
6356 }
6357 }
6358
6359 // -------------------------------------------------------------
6360 // IWindowManager API
6361 // -------------------------------------------------------------
6362
6363 public IWindowSession openSession(IInputMethodClient client,
6364 IInputContext inputContext) {
6365 if (client == null) throw new IllegalArgumentException("null client");
6366 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08006367 Session session = new Session(this, client, inputContext);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006368 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 }
6370
6371 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
6372 synchronized (mWindowMap) {
6373 // The focus for the client is the window immediately below
6374 // where we would place the input method window.
6375 int idx = findDesiredInputMethodWindowIndexLocked(false);
6376 WindowState imFocus;
6377 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07006378 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08006379 //Log.i(TAG, "Desired input method target: " + imFocus);
6380 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
6381 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08006383 // This may be a starting window, in which case we still want
6384 // to count it as okay.
6385 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
6386 && imFocus.mAppToken != null) {
6387 // The client has definitely started, so it really should
6388 // have a window in this app token. Let's look for it.
6389 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
6390 WindowState w = imFocus.mAppToken.windows.get(i);
6391 if (w != imFocus) {
6392 //Log.i(TAG, "Switching to real app window: " + w);
6393 imFocus = w;
6394 break;
6395 }
6396 }
6397 }
6398 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
6399 //if (imFocus.mSession.mClient != null) {
6400 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
6401 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
6402 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006403 if (imFocus.mSession.mClient != null &&
6404 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
6405 return true;
6406 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08006407
6408 // Okay, how about this... what is the current focus?
6409 // It seems in some cases we may not have moved the IM
6410 // target window, such as when it was in a pop-up window,
6411 // so let's also look at the current focus. (An example:
6412 // go to Gmail, start searching so the keyboard goes up,
6413 // press home. Sometimes the IME won't go down.)
6414 // Would be nice to fix this more correctly, but it's
6415 // way at the end of a release, and this should be good enough.
6416 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
6417 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
6418 return true;
6419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 }
6421 }
6422 }
6423 return false;
6424 }
Romain Guy06882f82009-06-10 13:36:04 -07006425
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07006426 public void getDisplaySize(Point size) {
6427 synchronized(mWindowMap) {
6428 size.x = mCurDisplayWidth;
6429 size.y = mCurDisplayHeight;
6430 }
6431 }
6432
6433 public int getMaximumSizeDimension() {
6434 synchronized(mWindowMap) {
6435 // Do this based on the raw screen size, until we are smarter.
6436 return mInitialDisplayWidth > mInitialDisplayHeight
6437 ? mInitialDisplayWidth : mInitialDisplayHeight;
6438 }
6439 }
6440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 // -------------------------------------------------------------
6442 // Internals
6443 // -------------------------------------------------------------
6444
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006445 final WindowState windowForClientLocked(Session session, IWindow client,
6446 boolean throwOnError) {
6447 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 }
Romain Guy06882f82009-06-10 13:36:04 -07006449
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006450 final WindowState windowForClientLocked(Session session, IBinder client,
6451 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006453 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 TAG, "Looking up client " + client + ": " + win);
6455 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006456 RuntimeException ex = new IllegalArgumentException(
6457 "Requested window " + client + " does not exist");
6458 if (throwOnError) {
6459 throw ex;
6460 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006461 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 return null;
6463 }
6464 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006465 RuntimeException ex = new IllegalArgumentException(
6466 "Requested window " + client + " is in session " +
6467 win.mSession + ", not " + session);
6468 if (throwOnError) {
6469 throw ex;
6470 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006471 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 return null;
6473 }
6474
6475 return win;
6476 }
6477
Dianne Hackborna8f60182009-09-01 19:01:50 -07006478 final void rebuildAppWindowListLocked() {
6479 int NW = mWindows.size();
6480 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006481 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006482 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006483
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006484 if (mRebuildTmp.length < NW) {
6485 mRebuildTmp = new WindowState[NW+10];
6486 }
6487
Dianne Hackborna8f60182009-09-01 19:01:50 -07006488 // First remove all existing app windows.
6489 i=0;
6490 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07006491 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006492 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07006493 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006494 win.mRebuilding = true;
6495 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006496 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006497 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006498 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07006499 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006500 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07006501 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006502 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
6503 && lastWallpaper == i-1) {
6504 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07006505 }
6506 i++;
6507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006508
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006509 // The wallpaper window(s) typically live at the bottom of the stack,
6510 // so skip them before adding app tokens.
6511 lastWallpaper++;
6512 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006513
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006514 // First add all of the exiting app tokens... these are no longer
6515 // in the main app list, but still have windows shown. We put them
6516 // in the back because now that the animation is over we no longer
6517 // will care about them.
6518 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07006519 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006520 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
6521 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006522
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006523 // And add in the still active app tokens in Z order.
6524 NT = mAppTokens.size();
6525 for (int j=0; j<NT; j++) {
6526 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07006527 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006528
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006529 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006530 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006531 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006532 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006533 for (i=0; i<numRemoved; i++) {
6534 WindowState ws = mRebuildTmp[i];
6535 if (ws.mRebuilding) {
6536 StringWriter sw = new StringWriter();
6537 PrintWriter pw = new PrintWriter(sw);
6538 ws.dump(pw, "");
6539 pw.flush();
6540 Slog.w(TAG, "This window was lost: " + ws);
6541 Slog.w(TAG, sw.toString());
6542 }
6543 }
6544 Slog.w(TAG, "Current app token list:");
6545 dumpAppTokensLocked();
6546 Slog.w(TAG, "Final window list:");
6547 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006548 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07006549 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 private final void assignLayersLocked() {
6552 int N = mWindows.size();
6553 int curBaseLayer = 0;
6554 int curLayer = 0;
6555 int i;
Romain Guy06882f82009-06-10 13:36:04 -07006556
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006557 if (DEBUG_LAYERS) {
6558 RuntimeException here = new RuntimeException("here");
6559 here.fillInStackTrace();
6560 Log.v(TAG, "Assigning layers", here);
6561 }
6562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006564 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006565 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
6566 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 curLayer += WINDOW_LAYER_MULTIPLIER;
6568 w.mLayer = curLayer;
6569 } else {
6570 curBaseLayer = curLayer = w.mBaseLayer;
6571 w.mLayer = curLayer;
6572 }
6573 if (w.mTargetAppToken != null) {
6574 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
6575 } else if (w.mAppToken != null) {
6576 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
6577 } else {
6578 w.mAnimLayer = w.mLayer;
6579 }
6580 if (w.mIsImWindow) {
6581 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006582 } else if (w.mIsWallpaper) {
6583 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006584 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006585 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006586 + w.mAnimLayer);
6587 //System.out.println(
6588 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
6589 }
6590 }
6591
6592 private boolean mInLayout = false;
6593 private final void performLayoutAndPlaceSurfacesLocked() {
6594 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07006595 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006596 throw new RuntimeException("Recursive call!");
6597 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006598 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 return;
6600 }
6601
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006602 if (mWaitingForConfig) {
6603 // Our configuration has changed (most likely rotation), but we
6604 // don't yet have the complete configuration to report to
6605 // applications. Don't do any window layout until we have it.
6606 return;
6607 }
6608
Dianne Hackbornce2ef762010-09-20 11:39:14 -07006609 if (mDisplay == null) {
6610 // Not yet initialized, nothing to do.
6611 return;
6612 }
6613
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006614 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006616
6617 try {
6618 if (mForceRemoves != null) {
6619 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006620 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006621 for (int i=0; i<mForceRemoves.size(); i++) {
6622 WindowState ws = mForceRemoves.get(i);
6623 Slog.i(TAG, "Force removing: " + ws);
6624 removeWindowInnerLocked(ws.mSession, ws);
6625 }
6626 mForceRemoves = null;
6627 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
6628 Object tmp = new Object();
6629 synchronized (tmp) {
6630 try {
6631 tmp.wait(250);
6632 } catch (InterruptedException e) {
6633 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006634 }
6635 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006636 } catch (RuntimeException e) {
6637 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006638 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 try {
6641 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07006642
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006643 int N = mPendingRemove.size();
6644 if (N > 0) {
6645 if (mPendingRemoveTmp.length < N) {
6646 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006647 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006648 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006649 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006650 for (int i=0; i<N; i++) {
6651 WindowState w = mPendingRemoveTmp[i];
6652 removeWindowInnerLocked(w.mSession, w);
6653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654
6655 mInLayout = false;
6656 assignLayersLocked();
6657 mLayoutNeeded = true;
6658 performLayoutAndPlaceSurfacesLocked();
6659
6660 } else {
6661 mInLayout = false;
6662 if (mLayoutNeeded) {
6663 requestAnimationLocked(0);
6664 }
6665 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006666 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07006667 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
6668 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006670 } catch (RuntimeException e) {
6671 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006672 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006673 }
6674 }
6675
Jeff Brown3a22cd92011-01-21 13:59:04 -08006676 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006677 if (!mLayoutNeeded) {
6678 return 0;
6679 }
6680
6681 mLayoutNeeded = false;
6682
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07006683 final int dw = mCurDisplayWidth;
6684 final int dh = mCurDisplayHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006686 final int innerDw = mPolicy.getNonDecorDisplayWidth(dw);
6687 final int innerDh = mPolicy.getNonDecorDisplayHeight(dh);
6688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006689 final int N = mWindows.size();
6690 int i;
6691
Joe Onorato8a9b2202010-02-26 18:56:32 -08006692 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08006693 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
6694
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006695 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07006696
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006697 int seq = mLayoutSeq+1;
6698 if (seq < 0) seq = 0;
6699 mLayoutSeq = seq;
6700
6701 // First perform layout of any root windows (not attached
6702 // to another window).
6703 int topAttached = -1;
6704 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006705 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006707 // Don't do layout of a window if it is not visible, or
6708 // soon won't be visible, to avoid wasting time and funky
6709 // changes while a window is animating away.
6710 final AppWindowToken atoken = win.mAppToken;
6711 final boolean gone = win.mViewVisibility == View.GONE
6712 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08006713 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006714 || (atoken != null && atoken.hiddenRequested)
6715 || win.mAttachedHidden
6716 || win.mExiting || win.mDestroying;
6717
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006718 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
6719 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006720 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
6721 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006722 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006723 + win.mViewVisibility + " mRelayoutCalled="
6724 + win.mRelayoutCalled + " hidden="
6725 + win.mRootToken.hidden + " hiddenRequested="
6726 + (atoken != null && atoken.hiddenRequested)
6727 + " mAttachedHidden=" + win.mAttachedHidden);
6728 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006729
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006730 // If this view is GONE, then skip it -- keep the current
6731 // frame, and let the caller know so they can ignore it
6732 // if they want. (We do the normal layout for INVISIBLE
6733 // windows, since that means "perform layout as normal,
6734 // just don't display").
6735 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006736 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006737 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006738 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006739 win.mContentChanged = false;
6740 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006741 win.prelayout();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006742 mPolicy.layoutWindowLw(win, win.mAttrs, null);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006743 win.evalNeedsBackgroundFiller(innerDw, innerDh);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006744 win.mLayoutSeq = seq;
6745 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
6746 + win.mFrame + " mContainingFrame="
6747 + win.mContainingFrame + " mDisplayFrame="
6748 + win.mDisplayFrame);
6749 } else {
6750 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006751 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07006752 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006754
6755 // Now perform layout of attached windows, which usually
6756 // depend on the position of the window they are attached to.
6757 // XXX does not deal with windows that are attached to windows
6758 // that are themselves attached.
6759 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006760 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006761
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006762 if (win.mLayoutAttached) {
6763 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
6764 + " mHaveFrame=" + win.mHaveFrame
6765 + " mViewVisibility=" + win.mViewVisibility
6766 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006767 // If this view is GONE, then skip it -- keep the current
6768 // frame, and let the caller know so they can ignore it
6769 // if they want. (We do the normal layout for INVISIBLE
6770 // windows, since that means "perform layout as normal,
6771 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006772 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
6773 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006774 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006775 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006776 win.mContentChanged = false;
6777 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006778 win.prelayout();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006779 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006780 win.evalNeedsBackgroundFiller(innerDw, innerDh);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006781 win.mLayoutSeq = seq;
6782 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
6783 + win.mFrame + " mContainingFrame="
6784 + win.mContainingFrame + " mDisplayFrame="
6785 + win.mDisplayFrame);
6786 }
6787 }
6788 }
Jeff Brown349703e2010-06-22 01:27:15 -07006789
6790 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08006791 mInputMonitor.setUpdateInputWindowsNeededLw();
6792 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006793 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006794 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006795
6796 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 }
Romain Guy06882f82009-06-10 13:36:04 -07006798
Brad Fitzpatrick68044332010-11-22 18:19:48 -08006799 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 private final void performLayoutAndPlaceSurfacesLockedInner(
6801 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04006802 if (mDisplay == null) {
6803 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
6804 return;
6805 }
6806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 final long currentTime = SystemClock.uptimeMillis();
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006808 final int dw = mCurDisplayWidth;
6809 final int dh = mCurDisplayHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006811 final int innerDw = mPolicy.getNonDecorDisplayWidth(dw);
6812 final int innerDh = mPolicy.getNonDecorDisplayHeight(dh);
6813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 int i;
6815
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006816 if (mFocusMayChange) {
6817 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006818 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
6819 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006820 }
6821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 // Initialize state of exiting tokens.
6823 for (i=mExitingTokens.size()-1; i>=0; i--) {
6824 mExitingTokens.get(i).hasVisible = false;
6825 }
6826
6827 // Initialize state of exiting applications.
6828 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
6829 mExitingAppTokens.get(i).hasVisible = false;
6830 }
6831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006832 boolean orientationChangeComplete = true;
6833 Session holdScreen = null;
6834 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05006835 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 boolean focusDisplayed = false;
6837 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006838 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08006839 boolean updateRotation = false;
Dianne Hackborn50660e22011-02-02 17:12:25 -08006840 boolean screenRotationFinished = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006841
6842 if (mFxSession == null) {
6843 mFxSession = new SurfaceSession();
6844 createWatermark = true;
6845 }
6846
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006847 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848
6849 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006850
6851 if (createWatermark) {
6852 createWatermark();
6853 }
6854 if (mWatermark != null) {
6855 mWatermark.positionSurface(dw, dh);
6856 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08006857 if (mStrictModeFlash != null) {
6858 mStrictModeFlash.positionSurface(dw, dh);
6859 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006861 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006862 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006863 int repeats = 0;
6864 int changes = 0;
6865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006867 repeats++;
6868 if (repeats > 6) {
6869 Slog.w(TAG, "Animation repeat aborted after too many iterations");
6870 mLayoutNeeded = false;
6871 break;
6872 }
6873
6874 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
6875 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
6876 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
6877 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
6878 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
6879 assignLayersLocked();
6880 mLayoutNeeded = true;
6881 }
6882 }
6883 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
6884 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006885 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006886 mLayoutNeeded = true;
6887 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
6888 }
6889 }
6890 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
6891 mLayoutNeeded = true;
6892 }
6893 }
6894
6895 // FIRST LOOP: Perform a layout, if needed.
6896 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006897 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006898 if (changes != 0) {
6899 continue;
6900 }
6901 } else {
6902 Slog.w(TAG, "Layout repeat skipped after too many iterations");
6903 changes = 0;
6904 }
6905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006906 final int transactionSequence = ++mTransactionSequence;
6907
6908 // Update animations of all applications, including those
6909 // associated with exiting/removed apps
6910 boolean tokensAnimating = false;
6911 final int NAT = mAppTokens.size();
6912 for (i=0; i<NAT; i++) {
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006913 if (mAppTokens.get(i).stepAnimationLocked(currentTime,
6914 innerDw, innerDh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006915 tokensAnimating = true;
6916 }
6917 }
6918 final int NEAT = mExitingAppTokens.size();
6919 for (i=0; i<NEAT; i++) {
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006920 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime,
6921 innerDw, innerDh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 tokensAnimating = true;
6923 }
6924 }
6925
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006926 // SECOND LOOP: Execute animations and update visibility of windows.
6927
Joe Onorato8a9b2202010-02-26 18:56:32 -08006928 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006929 + transactionSequence + " tokensAnimating="
6930 + tokensAnimating);
6931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006933
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08006934 if (mScreenRotationAnimation != null) {
6935 if (mScreenRotationAnimation.isAnimating()) {
6936 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
6937 animating = true;
6938 } else {
Dianne Hackborn50660e22011-02-02 17:12:25 -08006939 screenRotationFinished = true;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08006940 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08006941 }
6942 }
6943 }
6944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006946 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006947 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006948 WindowState windowDetachedWallpaper = null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -08006949 WindowState windowAnimationBackground = null;
6950 int windowAnimationBackgroundColor = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951
6952 mPolicy.beginAnimationLw(dw, dh);
6953
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006954 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006957 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958
6959 final WindowManager.LayoutParams attrs = w.mAttrs;
6960
6961 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006962 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006963 if (w.commitFinishDrawingLocked(currentTime)) {
6964 if ((w.mAttrs.flags
6965 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006966 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006967 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006968 wallpaperMayChange = true;
6969 }
6970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006971
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006972 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006973
Dianne Hackborne2515ee2011-04-27 18:52:56 -04006974 int animDw = innerDw;
6975 int animDh = innerDh;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006976
6977 // If the window has moved due to its containing
6978 // content frame changing, then we'd like to animate
6979 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08006980 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006981 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006982 // Frame has moved, containing content frame
6983 // has also moved, and we're not currently animating...
6984 // let's do something.
6985 Animation a = AnimationUtils.loadAnimation(mContext,
6986 com.android.internal.R.anim.window_move_from_decor);
6987 w.setAnimation(a);
6988 animDw = w.mLastFrame.left - w.mFrame.left;
6989 animDh = w.mLastFrame.top - w.mFrame.top;
6990 }
6991
6992 // Execute animation.
6993 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
6994 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006995
6996 // If this window is animating, make a note that we have
6997 // an animating window and take care of a request to run
6998 // a detached wallpaper animation.
6999 if (nowAnimating) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007000 if (w.mAnimation != null) {
7001 if (w.mAnimation.getDetachWallpaper()) {
7002 windowDetachedWallpaper = w;
7003 }
7004 if (w.mAnimation.getBackgroundColor() != 0) {
7005 windowAnimationBackground = w;
7006 windowAnimationBackgroundColor =
7007 w.mAnimation.getBackgroundColor();
7008 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007010 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007011 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007012
7013 // If this window's app token is running a detached wallpaper
7014 // animation, make a note so we can ensure the wallpaper is
7015 // displayed behind it.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007016 if (w.mAppToken != null && w.mAppToken.animation != null) {
7017 if (w.mAppToken.animation.getDetachWallpaper()) {
7018 windowDetachedWallpaper = w;
7019 }
7020 if (w.mAppToken.animation.getBackgroundColor() != 0) {
7021 windowAnimationBackground = w;
7022 windowAnimationBackgroundColor =
7023 w.mAppToken.animation.getBackgroundColor();
7024 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007025 }
7026
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007027 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
7028 wallpaperMayChange = true;
7029 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007030
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007031 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007032 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08007033 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007034 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08007035 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007036 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007037 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007038 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
7039 forceHiding = true;
7040 }
7041 } else if (mPolicy.canBeForceHidden(w, attrs)) {
7042 boolean changed;
7043 if (forceHiding) {
7044 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08007045 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
7046 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007047 } else {
7048 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08007049 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
7050 "Now policy shown: " + w);
7051 if (changed) {
7052 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007053 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08007054 // Assume we will need to animate. If
7055 // we don't (because the wallpaper will
7056 // stay with the lock screen), then we will
7057 // clean up later.
7058 Animation a = mPolicy.createForceHideEnterAnimation();
7059 if (a != null) {
7060 w.setAnimation(a);
7061 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007062 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08007063 if (mCurrentFocus == null ||
7064 mCurrentFocus.mLayer < w.mLayer) {
7065 // We are showing on to of the current
7066 // focus, so re-evaluate focus to make
7067 // sure it is correct.
7068 mFocusMayChange = true;
7069 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007070 }
7071 }
7072 if (changed && (attrs.flags
7073 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
7074 wallpaperMayChange = true;
7075 }
7076 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007078 mPolicy.animatingWindowLw(w, attrs);
7079 }
7080
7081 final AppWindowToken atoken = w.mAppToken;
7082 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
7083 if (atoken.lastTransactionSequence != transactionSequence) {
7084 atoken.lastTransactionSequence = transactionSequence;
7085 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
7086 atoken.startingDisplayed = false;
7087 }
7088 if ((w.isOnScreen() || w.mAttrs.type
7089 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
7090 && !w.mExiting && !w.mDestroying) {
7091 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007092 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007093 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007095 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007096 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 + " pv=" + w.mPolicyVisibility
7098 + " dp=" + w.mDrawPending
7099 + " cdp=" + w.mCommitDrawPending
7100 + " ah=" + w.mAttachedHidden
7101 + " th=" + atoken.hiddenRequested
7102 + " a=" + w.mAnimating);
7103 }
7104 }
7105 if (w != atoken.startingWindow) {
7106 if (!atoken.freezingScreen || !w.mAppFreezing) {
7107 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007108 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007109 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007110 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 "tokenMayBeDrawn: " + atoken
7112 + " freezingScreen=" + atoken.freezingScreen
7113 + " mAppFreezing=" + w.mAppFreezing);
7114 tokenMayBeDrawn = true;
7115 }
7116 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007117 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007118 atoken.startingDisplayed = true;
7119 }
7120 }
7121 } else if (w.mReadyToShow) {
7122 w.performShowLocked();
7123 }
7124 }
7125
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007126 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007127
7128 if (tokenMayBeDrawn) {
7129 // See if any windows have been drawn, so they (and others
7130 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007131 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007132 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007133 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007134 if (wtoken.freezingScreen) {
7135 int numInteresting = wtoken.numInterestingWindows;
7136 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007137 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007138 "allDrawn: " + wtoken
7139 + " interesting=" + numInteresting
7140 + " drawn=" + wtoken.numDrawnWindows);
7141 wtoken.showAllWindowsLocked();
7142 unsetAppFreezingScreenLocked(wtoken, false, true);
7143 orientationChangeComplete = true;
7144 }
7145 } else if (!wtoken.allDrawn) {
7146 int numInteresting = wtoken.numInterestingWindows;
7147 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007148 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 "allDrawn: " + wtoken
7150 + " interesting=" + numInteresting
7151 + " drawn=" + wtoken.numDrawnWindows);
7152 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007153 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154
7155 // We can now show all of the drawn windows!
7156 if (!mOpeningApps.contains(wtoken)) {
7157 wtoken.showAllWindowsLocked();
7158 }
7159 }
7160 }
7161 }
7162 }
7163
7164 // If we are ready to perform an app transition, check through
7165 // all of the app tokens to be shown and see if they are ready
7166 // to go.
7167 if (mAppTransitionReady) {
7168 int NN = mOpeningApps.size();
7169 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007170 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 "Checking " + NN + " opening apps (frozen="
7172 + mDisplayFrozen + " timeout="
7173 + mAppTransitionTimeout + ")...");
7174 if (!mDisplayFrozen && !mAppTransitionTimeout) {
7175 // If the display isn't frozen, wait to do anything until
7176 // all of the apps are ready. Otherwise just go because
7177 // we'll unfreeze the display when everyone is ready.
7178 for (i=0; i<NN && goodToGo; i++) {
7179 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007180 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181 "Check opening app" + wtoken + ": allDrawn="
7182 + wtoken.allDrawn + " startingDisplayed="
7183 + wtoken.startingDisplayed);
7184 if (!wtoken.allDrawn && !wtoken.startingDisplayed
7185 && !wtoken.startingMoved) {
7186 goodToGo = false;
7187 }
7188 }
7189 }
7190 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007191 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 int transit = mNextAppTransition;
7193 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007194 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007196 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007197 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007198 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 mAppTransitionTimeout = false;
7200 mStartingIconInTransition = false;
7201 mSkipAppTransitionAnimation = false;
7202
7203 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
7204
Dianne Hackborna8f60182009-09-01 19:01:50 -07007205 // If there are applications waiting to come to the
7206 // top of the stack, now is the time to move their windows.
7207 // (Note that we don't do apps going to the bottom
7208 // here -- we want to keep their windows in the old
7209 // Z-order until the animation completes.)
7210 if (mToTopApps.size() > 0) {
7211 NN = mAppTokens.size();
7212 for (i=0; i<NN; i++) {
7213 AppWindowToken wtoken = mAppTokens.get(i);
7214 if (wtoken.sendingToTop) {
7215 wtoken.sendingToTop = false;
7216 moveAppWindowsLocked(wtoken, NN, false);
7217 }
7218 }
7219 mToTopApps.clear();
7220 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007221
Dianne Hackborn25994b42009-09-04 14:21:19 -07007222 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007223
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007224 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007225 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007226
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007227 // The top-most window will supply the layout params,
7228 // and we will determine it below.
7229 LayoutParams animLp = null;
7230 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007231 boolean fullscreenAnim = false;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04007232 boolean needBgFiller = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007233
Joe Onorato8a9b2202010-02-26 18:56:32 -08007234 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007235 "New wallpaper target=" + mWallpaperTarget
7236 + ", lower target=" + mLowerWallpaperTarget
7237 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07007238 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007239 // Do a first pass through the tokens for two
7240 // things:
7241 // (1) Determine if both the closing and opening
7242 // app token sets are wallpaper targets, in which
7243 // case special animations are needed
7244 // (since the wallpaper needs to stay static
7245 // behind them).
7246 // (2) Find the layout params of the top-most
7247 // application window in the tokens, which is
7248 // what will control the animation theme.
7249 final int NC = mClosingApps.size();
7250 NN = NC + mOpeningApps.size();
7251 for (i=0; i<NN; i++) {
7252 AppWindowToken wtoken;
7253 int mode;
7254 if (i < NC) {
7255 wtoken = mClosingApps.get(i);
7256 mode = 1;
7257 } else {
7258 wtoken = mOpeningApps.get(i-NC);
7259 mode = 2;
7260 }
7261 if (mLowerWallpaperTarget != null) {
7262 if (mLowerWallpaperTarget.mAppToken == wtoken
7263 || mUpperWallpaperTarget.mAppToken == wtoken) {
7264 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007265 }
7266 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007267 if (wtoken.appFullscreen) {
7268 WindowState ws = wtoken.findMainWindow();
7269 if (ws != null) {
7270 // If this is a compatibility mode
7271 // window, we will always use its anim.
Dianne Hackborne2515ee2011-04-27 18:52:56 -04007272 if (ws.mNeedsBackgroundFiller) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007273 animLp = ws.mAttrs;
7274 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04007275 needBgFiller = true;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007276 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007277 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007278 bestAnimLayer = ws.mLayer;
7279 }
7280 fullscreenAnim = true;
7281 }
7282 } else if (!fullscreenAnim) {
7283 WindowState ws = wtoken.findMainWindow();
7284 if (ws != null) {
7285 if (ws.mLayer > bestAnimLayer) {
7286 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007287 bestAnimLayer = ws.mLayer;
7288 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07007289 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007290 }
7291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007292
Dianne Hackborn25994b42009-09-04 14:21:19 -07007293 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007294 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007295 "Wallpaper animation!");
7296 switch (transit) {
7297 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
7298 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
7299 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
7300 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
7301 break;
7302 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
7303 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
7304 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
7305 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
7306 break;
7307 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007308 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007309 "New transit: " + transit);
7310 } else if (oldWallpaper != null) {
7311 // We are transitioning from an activity with
7312 // a wallpaper to one without.
7313 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007314 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007315 "New transit away from wallpaper: " + transit);
7316 } else if (mWallpaperTarget != null) {
7317 // We are transitioning from an activity without
7318 // a wallpaper to now showing the wallpaper
7319 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007320 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007321 "New transit into wallpaper: " + transit);
7322 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007323
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007324 // If all closing windows are obscured, then there is
7325 // no need to do an animation. This is the case, for
7326 // example, when this transition is being done behind
7327 // the lock screen.
7328 if (!mPolicy.allowAppAnimationsLw()) {
7329 animLp = null;
7330 }
7331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 NN = mOpeningApps.size();
7333 for (i=0; i<NN; i++) {
7334 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007335 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 "Now opening app" + wtoken);
7337 wtoken.reportedVisible = false;
7338 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07007339 wtoken.animation = null;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04007340 setTokenVisibilityLocked(wtoken, animLp, true,
7341 transit, false, needBgFiller);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07007343 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 wtoken.showAllWindowsLocked();
7345 }
7346 NN = mClosingApps.size();
7347 for (i=0; i<NN; i++) {
7348 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007349 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 "Now closing app" + wtoken);
7351 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07007352 wtoken.animation = null;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04007353 setTokenVisibilityLocked(wtoken, animLp, false,
7354 transit, false, needBgFiller);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07007356 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007357 // Force the allDrawn flag, because we want to start
7358 // this guy's animations regardless of whether it's
7359 // gotten drawn.
7360 wtoken.allDrawn = true;
7361 }
7362
Dianne Hackborn8b571a82009-09-25 16:09:43 -07007363 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 mOpeningApps.clear();
7366 mClosingApps.clear();
7367
7368 // This has changed the visibility of windows, so perform
7369 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007370 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
7371 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07007373 if (!moveInputMethodWindowsIfNeededLocked(true)) {
7374 assignLayersLocked();
7375 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08007376 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
7377 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007378 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007379 }
7380 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007381
Dianne Hackborn16064f92010-03-25 00:47:24 -07007382 int adjResult = 0;
7383
Dianne Hackborna8f60182009-09-01 19:01:50 -07007384 if (!animating && mAppTransitionRunning) {
7385 // We have finished the animation of an app transition. To do
7386 // this, we have delayed a lot of operations like showing and
7387 // hiding apps, moving apps in Z-order, etc. The app token list
7388 // reflects the correct Z-order, but the window list may now
7389 // be out of sync with it. So here we will just rebuild the
7390 // entire app window list. Fun!
7391 mAppTransitionRunning = false;
7392 // Clear information about apps that were moving.
7393 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007394
Dianne Hackborna8f60182009-09-01 19:01:50 -07007395 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007396 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007397 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007398 moveInputMethodWindowsIfNeededLocked(false);
7399 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08007400 // Since the window list has been rebuilt, focus might
7401 // have to be recomputed since the actual order of windows
7402 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007403 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007404 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007405
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007406 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007407 // At this point, there was a window with a wallpaper that
7408 // was force hiding other windows behind it, but now it
7409 // is going away. This may be simple -- just animate
7410 // away the wallpaper and its window -- or it may be
7411 // hard -- the wallpaper now needs to be shown behind
7412 // something that was hidden.
7413 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007414 if (mLowerWallpaperTarget != null
7415 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007416 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007417 "wallpaperForceHiding changed with lower="
7418 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007419 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007420 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
7421 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
7422 if (mLowerWallpaperTarget.mAppToken.hidden) {
7423 // The lower target has become hidden before we
7424 // actually started the animation... let's completely
7425 // re-evaluate everything.
7426 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007427 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007428 }
7429 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07007430 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007431 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007432 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007433 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007434 + " NEW: " + mWallpaperTarget
7435 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007436 if (mLowerWallpaperTarget == null) {
7437 // Whoops, we don't need a special wallpaper animation.
7438 // Clear them out.
7439 forceHiding = false;
7440 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07007441 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007442 if (w.mSurface != null) {
7443 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07007444 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007445 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007446 forceHiding = true;
7447 } else if (mPolicy.canBeForceHidden(w, attrs)) {
7448 if (!w.mAnimating) {
7449 // We set the animation above so it
7450 // is not yet running.
7451 w.clearAnimation();
7452 }
7453 }
7454 }
7455 }
7456 }
7457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007458
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007459 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
7460 if (DEBUG_WALLPAPER) Slog.v(TAG,
7461 "Detached wallpaper changed from " + mWindowDetachedWallpaper
7462 + windowDetachedWallpaper);
7463 mWindowDetachedWallpaper = windowDetachedWallpaper;
7464 wallpaperMayChange = true;
7465 }
7466
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007467 if (windowAnimationBackgroundColor != 0) {
7468 if (mWindowAnimationBackgroundSurface == null) {
7469 mWindowAnimationBackgroundSurface = new DimSurface(mFxSession);
7470 }
7471 mWindowAnimationBackgroundSurface.show(dw, dh,
7472 windowAnimationBackground.mAnimLayer - LAYER_OFFSET_DIM,
7473 windowAnimationBackgroundColor);
7474 } else if (mWindowAnimationBackgroundSurface != null) {
7475 mWindowAnimationBackgroundSurface.hide();
7476 }
7477
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007478 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007479 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007480 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07007481 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007482 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007483
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007484 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007485 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007486 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007487 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007488 assignLayersLocked();
7489 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007490 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007491 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007492 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007493 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007494
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007495 if (mFocusMayChange) {
7496 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08007497 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
7498 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007499 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007500 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007501 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007502 }
7503
7504 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007505 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007506 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007507
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007508 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
7509 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007510 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511
7512 // THIRD LOOP: Update the surfaces of all windows.
7513
7514 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
7515
7516 boolean obscured = false;
7517 boolean blurring = false;
7518 boolean dimming = false;
7519 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007520 boolean syswin = false;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007521 boolean backgroundFillerWasShown = mBackgroundFillerTarget != null;
7522 mBackgroundFillerTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07007524 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07007527 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528
7529 boolean displayed = false;
7530 final WindowManager.LayoutParams attrs = w.mAttrs;
7531 final int attrFlags = attrs.flags;
7532
7533 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007534 // XXX NOTE: The logic here could be improved. We have
7535 // the decision about whether to resize a window separated
7536 // from whether to hide the surface. This can cause us to
7537 // resize a surface even if we are going to hide it. You
7538 // can see this by (1) holding device in landscape mode on
7539 // home screen; (2) tapping browser icon (device will rotate
7540 // to landscape; (3) tap home. The wallpaper will be resized
7541 // in step 2 but then immediately hidden, causing us to
7542 // have to resize and then redraw it again in step 3. It
7543 // would be nice to figure out how to avoid this, but it is
7544 // difficult because we do need to resize surfaces in some
7545 // cases while they are hidden such as when first showing a
7546 // window.
7547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08007549 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 TAG, "Placing surface #" + i + " " + w.mSurface
7551 + ": new=" + w.mShownFrame + ", old="
7552 + w.mLastShownFrame);
7553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 int width, height;
7555 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007556 // for a scaled surface, we just want to use
7557 // the requested size.
7558 width = w.mRequestedWidth;
7559 height = w.mRequestedHeight;
7560 w.mLastRequestedWidth = width;
7561 w.mLastRequestedHeight = height;
7562 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007564 width = w.mShownFrame.width();
7565 height = w.mShownFrame.height();
7566 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 }
7568
Jeff Brownfbae7222011-01-23 13:07:25 -08007569 if (w.mSurface != null) {
7570 if (w.mSurfaceX != w.mShownFrame.left
7571 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007573 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -08007574 "POS " + w.mShownFrame.left
7575 + ", " + w.mShownFrame.top, null);
7576 w.mSurfaceX = w.mShownFrame.left;
7577 w.mSurfaceY = w.mShownFrame.top;
7578 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
7579 } catch (RuntimeException e) {
7580 Slog.w(TAG, "Error positioning surface of " + w
7581 + " pos=(" + w.mShownFrame.left
7582 + "," + w.mShownFrame.top + ")", e);
7583 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007584 reclaimSomeSurfaceMemoryLocked(w, "position", true);
Jeff Brownfbae7222011-01-23 13:07:25 -08007585 }
7586 }
7587 }
7588
7589 if (width < 1) {
7590 width = 1;
7591 }
7592 if (height < 1) {
7593 height = 1;
7594 }
7595
7596 if (w.mSurfaceW != width || w.mSurfaceH != height) {
7597 try {
7598 if (SHOW_TRANSACTIONS) logSurface(w,
7599 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007600 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007601 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007602 w.mSurfaceW = width;
7603 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007604 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 } catch (RuntimeException e) {
7606 // If something goes wrong with the surface (such
7607 // as running out of memory), don't take down the
7608 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -08007609 Slog.e(TAG, "Error resizing surface of " + w
7610 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007612 reclaimSomeSurfaceMemoryLocked(w, "size", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 }
7614 }
7615 }
7616 }
Jeff Brownfbae7222011-01-23 13:07:25 -08007617
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007618 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007619 w.mContentInsetsChanged =
7620 !w.mLastContentInsets.equals(w.mContentInsets);
7621 w.mVisibleInsetsChanged =
7622 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007623 boolean configChanged =
7624 w.mConfiguration != mCurConfiguration
7625 && (w.mConfiguration == null
7626 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007627 if (DEBUG_CONFIGURATION && configChanged) {
7628 Slog.v(TAG, "Win " + w + " config changed: "
7629 + mCurConfiguration);
7630 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007631 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007632 + ": configChanged=" + configChanged
7633 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -08007634 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
7635 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007636 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007637 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007638 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007639 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -08007640 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
7641 Slog.v(TAG, "Resize reasons: "
7642 + "frameChanged=" + frameChanged
7643 + " contentInsetsChanged=" + w.mContentInsetsChanged
7644 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
7645 + " surfaceResized=" + w.mSurfaceResized
7646 + " configChanged=" + configChanged);
7647 }
7648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007649 w.mLastFrame.set(w.mFrame);
7650 w.mLastContentInsets.set(w.mContentInsets);
7651 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007652 // If the screen is currently frozen, then keep
7653 // it frozen until this window draws at its new
7654 // orientation.
7655 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007656 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007657 "Resizing while display frozen: " + w);
7658 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007659 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007660 mWindowsFreezingScreen = true;
7661 // XXX should probably keep timeout from
7662 // when we first froze the display.
7663 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
7664 mH.sendMessageDelayed(mH.obtainMessage(
7665 H.WINDOW_FREEZE_TIMEOUT), 2000);
7666 }
7667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007668 // If the orientation is changing, then we need to
7669 // hold off on unfreezing the display until this
7670 // window has been redrawn; to do that, we need
7671 // to go through the process of getting informed
7672 // by the application when it has finished drawing.
7673 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007674 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007675 "Orientation start waiting for draw in "
7676 + w + ", surface " + w.mSurface);
7677 w.mDrawPending = true;
7678 w.mCommitDrawPending = false;
7679 w.mReadyToShow = false;
7680 if (w.mAppToken != null) {
7681 w.mAppToken.allDrawn = false;
7682 }
7683 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007684 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 "Resizing window " + w + " to " + w.mFrame);
7686 mResizingWindows.add(w);
7687 } else if (w.mOrientationChanging) {
7688 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007689 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 "Orientation not waiting for draw in "
7691 + w + ", surface " + w.mSurface);
7692 w.mOrientationChanging = false;
7693 }
7694 }
7695 }
7696
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007697 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 if (!w.mLastHidden) {
7699 //dump();
7700 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007701 if (SHOW_TRANSACTIONS) logSurface(w,
7702 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007703 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007704 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007705 try {
7706 w.mSurface.hide();
7707 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007708 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 }
7710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007711 }
7712 // If we are waiting for this window to handle an
7713 // orientation change, well, it is hidden, so
7714 // doesn't really matter. Note that this does
7715 // introduce a potential glitch if the window
7716 // becomes unhidden before it has drawn for the
7717 // new orientation.
7718 if (w.mOrientationChanging) {
7719 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007720 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007721 "Orientation change skips hidden " + w);
7722 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 } else if (w.mLastLayer != w.mAnimLayer
7724 || w.mLastAlpha != w.mShownAlpha
7725 || w.mLastDsDx != w.mDsDx
7726 || w.mLastDtDx != w.mDtDx
7727 || w.mLastDsDy != w.mDsDy
7728 || w.mLastDtDy != w.mDtDy
7729 || w.mLastHScale != w.mHScale
7730 || w.mLastVScale != w.mVScale
7731 || w.mLastHidden) {
7732 displayed = true;
7733 w.mLastAlpha = w.mShownAlpha;
7734 w.mLastLayer = w.mAnimLayer;
7735 w.mLastDsDx = w.mDsDx;
7736 w.mLastDtDx = w.mDtDx;
7737 w.mLastDsDy = w.mDsDy;
7738 w.mLastDtDy = w.mDtDy;
7739 w.mLastHScale = w.mHScale;
7740 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007741 if (SHOW_TRANSACTIONS) logSurface(w,
7742 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007743 + " matrix=[" + (w.mDsDx*w.mHScale)
7744 + "," + (w.mDtDx*w.mVScale)
7745 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007746 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007747 if (w.mSurface != null) {
7748 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007749 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007751 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007752 w.mSurface.setLayer(w.mAnimLayer);
7753 w.mSurface.setMatrix(
7754 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
7755 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
7756 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007757 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007759 reclaimSomeSurfaceMemoryLocked(w, "update", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007760 }
7761 }
7762 }
7763
7764 if (w.mLastHidden && !w.mDrawPending
7765 && !w.mCommitDrawPending
7766 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007767 if (SHOW_TRANSACTIONS) logSurface(w,
7768 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007769 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 + " during relayout");
7771 if (showSurfaceRobustlyLocked(w)) {
7772 w.mHasDrawn = true;
7773 w.mLastHidden = false;
7774 } else {
7775 w.mOrientationChanging = false;
7776 }
7777 }
7778 if (w.mSurface != null) {
7779 w.mToken.hasVisible = true;
7780 }
7781 } else {
7782 displayed = true;
7783 }
7784
7785 if (displayed) {
7786 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08007787 if (attrs.width == LayoutParams.MATCH_PARENT
7788 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007789 covered = true;
7790 }
7791 }
7792 if (w.mOrientationChanging) {
7793 if (w.mDrawPending || w.mCommitDrawPending) {
7794 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007795 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 "Orientation continue waiting for draw in " + w);
7797 } else {
7798 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007799 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007800 "Orientation change complete in " + w);
7801 }
7802 }
7803 w.mToken.hasVisible = true;
7804 }
7805 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007806 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 "Orientation change skips hidden " + w);
7808 w.mOrientationChanging = false;
7809 }
7810
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007811 if (w.mContentChanged) {
7812 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
7813 w.mContentChanged = false;
7814 }
7815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007816 final boolean canBeSeen = w.isDisplayedLw();
7817
7818 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
7819 focusDisplayed = true;
7820 }
7821
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007822 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007823
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007824 if (mBackgroundFillerTarget != null) {
7825 if (w.isAnimating()) {
7826 // Background filler is below all other windows that
7827 // are animating.
7828 mBackgroundFillerTarget = w;
7829 } else if (w.mIsWallpaper) {
7830 mBackgroundFillerTarget = w;
7831 }
7832 }
7833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007834 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007835 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007836 if (w.mSurface != null) {
7837 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
7838 holdScreen = w.mSession;
7839 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007840 if (!syswin && w.mAttrs.screenBrightness >= 0
7841 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 screenBrightness = w.mAttrs.screenBrightness;
7843 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05007844 if (!syswin && w.mAttrs.buttonBrightness >= 0
7845 && buttonBrightness < 0) {
7846 buttonBrightness = w.mAttrs.buttonBrightness;
7847 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05007848 if (canBeSeen
7849 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
7850 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
7851 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007852 syswin = true;
7853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007854 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007855
Dianne Hackborn25994b42009-09-04 14:21:19 -07007856 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
Dianne Hackborne2515ee2011-04-27 18:52:56 -04007857 if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007858 // This window completely covers everything behind it,
7859 // so we want to leave all of them as unblurred (for
7860 // performance reasons).
7861 obscured = true;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04007862 } else if (w.mNeedsBackgroundFiller && w.mHasDrawn
7863 && w.mViewVisibility == View.VISIBLE
7864 && (canBeSeen || w.isAnimating())) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007865 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007866 obscured = true;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007867 mBackgroundFillerTarget = w;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007868 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007869 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007870 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 + ": blurring=" + blurring
7872 + " obscured=" + obscured
7873 + " displayed=" + displayed);
7874 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
7875 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007876 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007877 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007878 if (mDimAnimator == null) {
7879 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007881 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007882 mDimAnimator.updateParameters(mContext.getResources(),
7883 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007884 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 }
7886 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
7887 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007888 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007889 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007890 if (mBlurSurface == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 try {
Romain Guy06882f82009-06-10 13:36:04 -07007892 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007893 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 -1, 16, 16,
7895 PixelFormat.OPAQUE,
7896 Surface.FX_SURFACE_BLUR);
7897 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007898 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 }
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007900 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7901 + mBlurSurface + ": CREATE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007903 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007904 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7905 + mBlurSurface + ": pos=(0,0) (" +
7906 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 mBlurSurface.setPosition(0, 0);
7908 mBlurSurface.setSize(dw, dh);
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007909 mBlurSurface.setLayer(w.mAnimLayer-LAYER_OFFSET_BLUR);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007910 if (!mBlurShown) {
7911 try {
7912 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7913 + mBlurSurface + ": SHOW");
7914 mBlurSurface.show();
7915 } catch (RuntimeException e) {
7916 Slog.w(TAG, "Failure showing blur surface", e);
7917 }
7918 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 }
7920 }
7921 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007922 }
7923 }
7924 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007925
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007926 if (obscuredChanged && mWallpaperTarget == w) {
7927 // This is the wallpaper target and its obscured state
7928 // changed... make sure the current wallaper's visibility
7929 // has been updated accordingly.
7930 updateWallpaperVisibilityLocked();
7931 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007933
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007934 if (mBackgroundFillerTarget != null) {
7935 if (mBackgroundFillerSurface == null) {
7936 try {
7937 mBackgroundFillerSurface = new Surface(mFxSession, 0,
7938 "BackGroundFiller",
7939 0, dw, dh,
7940 PixelFormat.OPAQUE,
7941 Surface.FX_SURFACE_NORMAL);
7942 } catch (Exception e) {
7943 Slog.e(TAG, "Exception creating filler surface", e);
7944 }
7945 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7946 + mBackgroundFillerSurface + ": CREATE");
7947 }
7948 try {
7949 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7950 + mBackgroundFillerSurface + " SHOW: pos=(0,0) ("
7951 + dw + "x" + dh + ") layer="
7952 + (mBackgroundFillerTarget.mLayer - 1));
7953 mBackgroundFillerSurface.setPosition(0, 0);
7954 mBackgroundFillerSurface.setSize(dw, dh);
7955 // Using the same layer as Dim because they will never be shown at the
7956 // same time. NOTE: we do NOT use mAnimLayer, because we don't
7957 // want this surface dragged up in front of stuff that is animating.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007958 mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer
7959 - LAYER_OFFSET_DIM);
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007960 mBackgroundFillerSurface.show();
7961 } catch (RuntimeException e) {
7962 Slog.e(TAG, "Exception showing filler surface");
7963 }
7964 } else if (backgroundFillerWasShown) {
7965 mBackgroundFillerTarget = null;
7966 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7967 + mBackgroundFillerSurface + " HIDE");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007968 try {
7969 mBackgroundFillerSurface.hide();
7970 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007971 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007972 }
7973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007974
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007975 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007976 animating |= mDimAnimator.updateSurface(dimming, currentTime,
7977 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007978 }
Romain Guy06882f82009-06-10 13:36:04 -07007979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007981 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007982 + ": HIDE");
7983 try {
7984 mBlurSurface.hide();
7985 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007986 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007987 }
7988 mBlurShown = false;
7989 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007990 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007991 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007992 }
7993
7994 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07007995
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007996 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
7997
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07007998 if (mWatermark != null) {
7999 mWatermark.drawIfNeeded();
8000 }
8001
Joe Onorato8a9b2202010-02-26 18:56:32 -08008002 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 "With display frozen, orientationChangeComplete="
8004 + orientationChangeComplete);
8005 if (orientationChangeComplete) {
8006 if (mWindowsFreezingScreen) {
8007 mWindowsFreezingScreen = false;
8008 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
8009 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008010 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011 }
Romain Guy06882f82009-06-10 13:36:04 -07008012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008013 i = mResizingWindows.size();
8014 if (i > 0) {
8015 do {
8016 i--;
8017 WindowState win = mResizingWindows.get(i);
8018 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08008019 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
8020 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07008021 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008022 boolean configChanged =
8023 win.mConfiguration != mCurConfiguration
8024 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07008025 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
8026 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
8027 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008028 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008029 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07008030 + " / " + mCurConfiguration + " / 0x"
8031 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008032 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07008033 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 win.mClient.resized(win.mFrame.width(),
8035 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008036 win.mLastVisibleInsets, win.mDrawPending,
8037 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 win.mContentInsetsChanged = false;
8039 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08008040 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008041 } catch (RemoteException e) {
8042 win.mOrientationChanging = false;
8043 }
8044 } while (i > 0);
8045 mResizingWindows.clear();
8046 }
Romain Guy06882f82009-06-10 13:36:04 -07008047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008049 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 i = mDestroySurface.size();
8051 if (i > 0) {
8052 do {
8053 i--;
8054 WindowState win = mDestroySurface.get(i);
8055 win.mDestroying = false;
8056 if (mInputMethodWindow == win) {
8057 mInputMethodWindow = null;
8058 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008059 if (win == mWallpaperTarget) {
8060 wallpaperDestroyed = true;
8061 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 win.destroySurfaceLocked();
8063 } while (i > 0);
8064 mDestroySurface.clear();
8065 }
8066
8067 // Time to remove any exiting tokens?
8068 for (i=mExitingTokens.size()-1; i>=0; i--) {
8069 WindowToken token = mExitingTokens.get(i);
8070 if (!token.hasVisible) {
8071 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008072 if (token.windowType == TYPE_WALLPAPER) {
8073 mWallpaperTokens.remove(token);
8074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008075 }
8076 }
8077
8078 // Time to remove any exiting applications?
8079 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8080 AppWindowToken token = mExitingAppTokens.get(i);
8081 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008082 // Make sure there is no animation running on this token,
8083 // so any windows associated with it will be removed as
8084 // soon as their animations are complete
8085 token.animation = null;
8086 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008087 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
8088 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 mAppTokens.remove(token);
8090 mExitingAppTokens.remove(i);
8091 }
8092 }
8093
Dianne Hackborna8f60182009-09-01 19:01:50 -07008094 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008095
Dianne Hackborna8f60182009-09-01 19:01:50 -07008096 if (!animating && mAppTransitionRunning) {
8097 // We have finished the animation of an app transition. To do
8098 // this, we have delayed a lot of operations like showing and
8099 // hiding apps, moving apps in Z-order, etc. The app token list
8100 // reflects the correct Z-order, but the window list may now
8101 // be out of sync with it. So here we will just rebuild the
8102 // entire app window list. Fun!
8103 mAppTransitionRunning = false;
8104 needRelayout = true;
8105 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008106 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008107 // Clear information about apps that were moving.
8108 mToBottomApps.clear();
8109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 if (focusDisplayed) {
8112 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
8113 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008114 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008115 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008116 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008117 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008118 requestAnimationLocked(0);
8119 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
8121 }
Jeff Browneb857f12010-07-16 10:06:33 -07008122
Jeff Brown3a22cd92011-01-21 13:59:04 -08008123 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -08008124 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -07008125
Jeff Brown8e03b752010-06-13 19:16:55 -07008126 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -08008127 if (!mDisplayFrozen) {
8128 if (screenBrightness < 0 || screenBrightness > 1.0f) {
8129 mPowerManager.setScreenBrightnessOverride(-1);
8130 } else {
8131 mPowerManager.setScreenBrightnessOverride((int)
8132 (screenBrightness * Power.BRIGHTNESS_ON));
8133 }
8134 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
8135 mPowerManager.setButtonBrightnessOverride(-1);
8136 } else {
8137 mPowerManager.setButtonBrightnessOverride((int)
8138 (buttonBrightness * Power.BRIGHTNESS_ON));
8139 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008141 if (holdScreen != mHoldingScreenOn) {
8142 mHoldingScreenOn = holdScreen;
8143 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
8144 mH.sendMessage(m);
8145 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008146
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008147 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008148 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008149 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
8150 LocalPowerManager.BUTTON_EVENT, true);
8151 mTurnOnScreen = false;
8152 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008153
Dianne Hackborn50660e22011-02-02 17:12:25 -08008154 if (screenRotationFinished && mScreenRotationAnimation != null) {
8155 mScreenRotationAnimation.kill();
8156 mScreenRotationAnimation = null;
8157 }
8158
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008159 if (updateRotation) {
8160 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
8161 boolean changed = setRotationUncheckedLocked(
8162 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
8163 if (changed) {
Dianne Hackborn3e4f9d02011-02-04 14:05:55 -08008164 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008165 }
8166 }
8167
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008168 // Check to see if we are now in a state where the screen should
8169 // be enabled, because the window obscured flags have changed.
8170 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008171 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07008172
8173 /**
8174 * Must be called with the main window manager lock held.
8175 */
8176 void setHoldScreenLocked(boolean holding) {
8177 boolean state = mHoldingScreenWakeLock.isHeld();
8178 if (holding != state) {
8179 if (holding) {
8180 mHoldingScreenWakeLock.acquire();
8181 } else {
8182 mPolicy.screenOnStoppedLw();
8183 mHoldingScreenWakeLock.release();
8184 }
8185 }
8186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008187
8188 void requestAnimationLocked(long delay) {
8189 if (!mAnimationPending) {
8190 mAnimationPending = true;
8191 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
8192 }
8193 }
Romain Guy06882f82009-06-10 13:36:04 -07008194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008195 /**
8196 * Have the surface flinger show a surface, robustly dealing with
8197 * error conditions. In particular, if there is not enough memory
8198 * to show the surface, then we will try to get rid of other surfaces
8199 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07008200 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008201 * @return Returns true if the surface was successfully shown.
8202 */
8203 boolean showSurfaceRobustlyLocked(WindowState win) {
8204 try {
8205 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07008206 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008207 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008208 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008209 if (DEBUG_VISIBILITY) Slog.v(TAG,
8210 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008211 win.mTurnOnScreen = false;
8212 mTurnOnScreen = true;
8213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008214 }
8215 return true;
8216 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008217 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008218 }
Romain Guy06882f82009-06-10 13:36:04 -07008219
Dianne Hackborn64825172011-03-02 21:32:58 -08008220 reclaimSomeSurfaceMemoryLocked(win, "show", true);
Romain Guy06882f82009-06-10 13:36:04 -07008221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008222 return false;
8223 }
Romain Guy06882f82009-06-10 13:36:04 -07008224
Dianne Hackborn64825172011-03-02 21:32:58 -08008225 boolean reclaimSomeSurfaceMemoryLocked(WindowState win, String operation, boolean secure) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008226 final Surface surface = win.mSurface;
Dianne Hackborn64825172011-03-02 21:32:58 -08008227 boolean leakedSurface = false;
8228 boolean killedApps = false;
Romain Guy06882f82009-06-10 13:36:04 -07008229
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008230 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008231 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07008232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008233 if (mForceRemoves == null) {
8234 mForceRemoves = new ArrayList<WindowState>();
8235 }
Romain Guy06882f82009-06-10 13:36:04 -07008236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008237 long callingIdentity = Binder.clearCallingIdentity();
8238 try {
8239 // There was some problem... first, do a sanity check of the
8240 // window list to make sure we haven't left any dangling surfaces
8241 // around.
8242 int N = mWindows.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08008243 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008244 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008245 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008246 if (ws.mSurface != null) {
8247 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008248 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008249 + ws + " surface=" + ws.mSurface
8250 + " token=" + win.mToken
8251 + " pid=" + ws.mSession.mPid
8252 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008253 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008254 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008255 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008256 ws.mSurface = null;
8257 mForceRemoves.add(ws);
8258 i--;
8259 N--;
8260 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008261 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008262 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008263 + ws + " surface=" + ws.mSurface
8264 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008265 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008266 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008267 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 ws.mSurface = null;
8269 leakedSurface = true;
8270 }
8271 }
8272 }
Romain Guy06882f82009-06-10 13:36:04 -07008273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008274 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008275 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008276 SparseIntArray pidCandidates = new SparseIntArray();
8277 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008278 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 if (ws.mSurface != null) {
8280 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
8281 }
8282 }
8283 if (pidCandidates.size() > 0) {
8284 int[] pids = new int[pidCandidates.size()];
8285 for (int i=0; i<pids.length; i++) {
8286 pids[i] = pidCandidates.keyAt(i);
8287 }
8288 try {
Dianne Hackborn64825172011-03-02 21:32:58 -08008289 if (mActivityManager.killPids(pids, "Free memory", secure)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008290 killedApps = true;
8291 }
8292 } catch (RemoteException e) {
8293 }
8294 }
8295 }
Romain Guy06882f82009-06-10 13:36:04 -07008296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008297 if (leakedSurface || killedApps) {
8298 // We managed to reclaim some memory, so get rid of the trouble
8299 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08008300 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008301 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008302 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008303 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008304 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008305 win.mSurface = null;
8306 }
Romain Guy06882f82009-06-10 13:36:04 -07008307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008308 try {
8309 win.mClient.dispatchGetNewSurface();
8310 } catch (RemoteException e) {
8311 }
8312 }
8313 } finally {
8314 Binder.restoreCallingIdentity(callingIdentity);
8315 }
Dianne Hackborn64825172011-03-02 21:32:58 -08008316
8317 return leakedSurface || killedApps;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008318 }
Romain Guy06882f82009-06-10 13:36:04 -07008319
Jeff Brown3a22cd92011-01-21 13:59:04 -08008320 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 WindowState newFocus = computeFocusedWindowLocked();
8322 if (mCurrentFocus != newFocus) {
8323 // This check makes sure that we don't already have the focus
8324 // change message pending.
8325 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
8326 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008327 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
8329 final WindowState oldFocus = mCurrentFocus;
8330 mCurrentFocus = newFocus;
8331 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07008332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008333 final WindowState imWindow = mInputMethodWindow;
8334 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008335 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008337 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
8338 mLayoutNeeded = true;
8339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08008341 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008342 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
8343 // Client will do the layout, but we need to assign layers
8344 // for handleNewWindowLocked() below.
8345 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346 }
8347 }
Jeff Brown349703e2010-06-22 01:27:15 -07008348
8349 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
8350 // If we defer assigning layers, then the caller is responsible for
8351 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -08008352 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 return true;
8355 }
8356 return false;
8357 }
Jeff Brown349703e2010-06-22 01:27:15 -07008358
Jeff Brown3a22cd92011-01-21 13:59:04 -08008359 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
8360 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -07008361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008362
8363 private WindowState computeFocusedWindowLocked() {
8364 WindowState result = null;
8365 WindowState win;
8366
8367 int i = mWindows.size() - 1;
8368 int nextAppIndex = mAppTokens.size()-1;
8369 WindowToken nextApp = nextAppIndex >= 0
8370 ? mAppTokens.get(nextAppIndex) : null;
8371
8372 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008373 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008374
Joe Onorato8a9b2202010-02-26 18:56:32 -08008375 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008376 TAG, "Looking for focus: " + i
8377 + " = " + win
8378 + ", flags=" + win.mAttrs.flags
8379 + ", canReceive=" + win.canReceiveKeys());
8380
8381 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07008382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008383 // If this window's application has been removed, just skip it.
8384 if (thisApp != null && thisApp.removed) {
8385 i--;
8386 continue;
8387 }
Romain Guy06882f82009-06-10 13:36:04 -07008388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008389 // If there is a focused app, don't allow focus to go to any
8390 // windows below it. If this is an application window, step
8391 // through the app tokens until we find its app.
8392 if (thisApp != null && nextApp != null && thisApp != nextApp
8393 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
8394 int origAppIndex = nextAppIndex;
8395 while (nextAppIndex > 0) {
8396 if (nextApp == mFocusedApp) {
8397 // Whoops, we are below the focused app... no focus
8398 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08008399 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008400 TAG, "Reached focused app: " + mFocusedApp);
8401 return null;
8402 }
8403 nextAppIndex--;
8404 nextApp = mAppTokens.get(nextAppIndex);
8405 if (nextApp == thisApp) {
8406 break;
8407 }
8408 }
8409 if (thisApp != nextApp) {
8410 // Uh oh, the app token doesn't exist! This shouldn't
8411 // happen, but if it does we can get totally hosed...
8412 // so restart at the original app.
8413 nextAppIndex = origAppIndex;
8414 nextApp = mAppTokens.get(nextAppIndex);
8415 }
8416 }
8417
8418 // Dispatch to this window if it is wants key events.
8419 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008420 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008421 TAG, "Found focus @ " + i + " = " + win);
8422 result = win;
8423 break;
8424 }
8425
8426 i--;
8427 }
8428
8429 return result;
8430 }
8431
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008432 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 if (mDisplayFrozen) {
8434 return;
8435 }
Romain Guy06882f82009-06-10 13:36:04 -07008436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07008438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008439 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08008440 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 if (mFreezeGcPending != 0) {
8442 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008443 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008444 mH.removeMessages(H.FORCE_GC);
8445 Runtime.getRuntime().gc();
8446 mFreezeGcPending = now;
8447 }
8448 } else {
8449 mFreezeGcPending = now;
8450 }
Romain Guy06882f82009-06-10 13:36:04 -07008451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07008453
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008454 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07008455
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008456 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
8457 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008458 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008459 mAppTransitionReady = true;
8460 }
Romain Guy06882f82009-06-10 13:36:04 -07008461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 if (PROFILE_ORIENTATION) {
8463 File file = new File("/data/system/frozen");
8464 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
8465 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008466
8467 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08008468 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
8469 mScreenRotationAnimation.kill();
8470 mScreenRotationAnimation = null;
8471 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008472 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08008473 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008474 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -08008475 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008476 if (!mScreenRotationAnimation.hasScreenshot()) {
8477 Surface.freezeDisplay(0);
8478 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008479 } else {
8480 Surface.freezeDisplay(0);
8481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 }
Romain Guy06882f82009-06-10 13:36:04 -07008483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008484 private void stopFreezingDisplayLocked() {
8485 if (!mDisplayFrozen) {
8486 return;
8487 }
Romain Guy06882f82009-06-10 13:36:04 -07008488
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008489 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
8490 return;
8491 }
8492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 mDisplayFrozen = false;
8494 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
8495 if (PROFILE_ORIENTATION) {
8496 Debug.stopMethodTracing();
8497 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008498
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008499 boolean updateRotation = false;
8500
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008501 if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
8502 && mScreenRotationAnimation.hasScreenshot()) {
8503 if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION,
8504 mTransitionAnimationScale)) {
8505 requestAnimationLocked(0);
8506 } else {
8507 mScreenRotationAnimation = null;
8508 updateRotation = true;
Dianne Hackborna1111872010-11-23 20:55:11 -08008509 }
8510 } else {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008511 if (mScreenRotationAnimation != null) {
8512 mScreenRotationAnimation.kill();
8513 mScreenRotationAnimation = null;
8514 }
8515 updateRotation = true;
Dianne Hackborna1111872010-11-23 20:55:11 -08008516 Surface.unfreezeDisplay(0);
8517 }
Romain Guy06882f82009-06-10 13:36:04 -07008518
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008519 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520
Dianne Hackborn420829e2011-01-28 11:30:35 -08008521 boolean configChanged;
8522
Christopher Tateb696aee2010-04-02 19:08:30 -07008523 // While the display is frozen we don't re-compute the orientation
8524 // to avoid inconsistent states. However, something interesting
8525 // could have actually changed during that time so re-evaluate it
8526 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -08008527 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -07008528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 // A little kludge: a lot could have happened while the
8530 // display was frozen, so now that we are coming back we
8531 // do a gc so that any remote references the system
8532 // processes holds on others can be released if they are
8533 // no longer needed.
8534 mH.removeMessages(H.FORCE_GC);
8535 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8536 2000);
Romain Guy06882f82009-06-10 13:36:04 -07008537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008539
8540 if (updateRotation) {
8541 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -08008542 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008543 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -08008544 }
8545
8546 if (configChanged) {
8547 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 }
Romain Guy06882f82009-06-10 13:36:04 -07008550
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008551 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
8552 DisplayMetrics dm) {
8553 if (index < tokens.length) {
8554 String str = tokens[index];
8555 if (str != null && str.length() > 0) {
8556 try {
8557 int val = Integer.parseInt(str);
8558 return val;
8559 } catch (Exception e) {
8560 }
8561 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008562 }
8563 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
8564 return defDps;
8565 }
8566 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
8567 return val;
8568 }
8569
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008570 void createWatermark() {
8571 if (mWatermark != null) {
8572 return;
8573 }
8574
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008575 File file = new File("/system/etc/setup.conf");
8576 FileInputStream in = null;
8577 try {
8578 in = new FileInputStream(file);
8579 DataInputStream ind = new DataInputStream(in);
8580 String line = ind.readLine();
8581 if (line != null) {
8582 String[] toks = line.split("%");
8583 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -07008584 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008585 }
8586 }
8587 } catch (FileNotFoundException e) {
8588 } catch (IOException e) {
8589 } finally {
8590 if (in != null) {
8591 try {
8592 in.close();
8593 } catch (IOException e) {
8594 }
8595 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008596 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008597 }
8598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 @Override
Joe Onorato664644d2011-01-23 17:53:23 -08008600 public void statusBarVisibilityChanged(int visibility) {
Jeff Brown05dc66a2011-03-02 14:41:58 -08008601 mInputManager.setSystemUiVisibility(visibility);
Joe Onorato664644d2011-01-23 17:53:23 -08008602 synchronized (mWindowMap) {
8603 final int N = mWindows.size();
8604 for (int i = 0; i < N; i++) {
8605 WindowState ws = mWindows.get(i);
8606 try {
8607 if (ws.getAttrs().hasSystemUiListeners) {
8608 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
8609 }
8610 } catch (RemoteException e) {
8611 // so sorry
8612 }
8613 }
8614 }
8615 }
8616
8617 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
8619 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
8620 != PackageManager.PERMISSION_GRANTED) {
8621 pw.println("Permission Denial: can't dump WindowManager from from pid="
8622 + Binder.getCallingPid()
8623 + ", uid=" + Binder.getCallingUid());
8624 return;
8625 }
Romain Guy06882f82009-06-10 13:36:04 -07008626
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008627 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08008628 pw.println(" ");
8629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 synchronized(mWindowMap) {
8631 pw.println("Current Window Manager state:");
8632 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008633 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008634 pw.print(" Window #"); pw.print(i); pw.print(' ');
8635 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008636 w.dump(pw, " ");
8637 }
8638 if (mInputMethodDialogs.size() > 0) {
8639 pw.println(" ");
8640 pw.println(" Input method dialogs:");
8641 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
8642 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008643 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 }
8645 }
8646 if (mPendingRemove.size() > 0) {
8647 pw.println(" ");
8648 pw.println(" Remove pending for:");
8649 for (int i=mPendingRemove.size()-1; i>=0; i--) {
8650 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008651 pw.print(" Remove #"); pw.print(i); pw.print(' ');
8652 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 w.dump(pw, " ");
8654 }
8655 }
8656 if (mForceRemoves != null && mForceRemoves.size() > 0) {
8657 pw.println(" ");
8658 pw.println(" Windows force removing:");
8659 for (int i=mForceRemoves.size()-1; i>=0; i--) {
8660 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008661 pw.print(" Removing #"); pw.print(i); pw.print(' ');
8662 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 w.dump(pw, " ");
8664 }
8665 }
8666 if (mDestroySurface.size() > 0) {
8667 pw.println(" ");
8668 pw.println(" Windows waiting to destroy their surface:");
8669 for (int i=mDestroySurface.size()-1; i>=0; i--) {
8670 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008671 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
8672 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 w.dump(pw, " ");
8674 }
8675 }
8676 if (mLosingFocus.size() > 0) {
8677 pw.println(" ");
8678 pw.println(" Windows losing focus:");
8679 for (int i=mLosingFocus.size()-1; i>=0; i--) {
8680 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008681 pw.print(" Losing #"); pw.print(i); pw.print(' ');
8682 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 w.dump(pw, " ");
8684 }
8685 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008686 if (mResizingWindows.size() > 0) {
8687 pw.println(" ");
8688 pw.println(" Windows waiting to resize:");
8689 for (int i=mResizingWindows.size()-1; i>=0; i--) {
8690 WindowState w = mResizingWindows.get(i);
8691 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
8692 pw.print(w); pw.println(":");
8693 w.dump(pw, " ");
8694 }
8695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 if (mSessions.size() > 0) {
8697 pw.println(" ");
8698 pw.println(" All active sessions:");
8699 Iterator<Session> it = mSessions.iterator();
8700 while (it.hasNext()) {
8701 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008702 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008703 s.dump(pw, " ");
8704 }
8705 }
8706 if (mTokenMap.size() > 0) {
8707 pw.println(" ");
8708 pw.println(" All tokens:");
8709 Iterator<WindowToken> it = mTokenMap.values().iterator();
8710 while (it.hasNext()) {
8711 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008712 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713 token.dump(pw, " ");
8714 }
8715 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008716 if (mWallpaperTokens.size() > 0) {
8717 pw.println(" ");
8718 pw.println(" Wallpaper tokens:");
8719 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
8720 WindowToken token = mWallpaperTokens.get(i);
8721 pw.print(" Wallpaper #"); pw.print(i);
8722 pw.print(' '); pw.print(token); pw.println(':');
8723 token.dump(pw, " ");
8724 }
8725 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008726 if (mAppTokens.size() > 0) {
8727 pw.println(" ");
8728 pw.println(" Application tokens in Z order:");
8729 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008730 pw.print(" App #"); pw.print(i); pw.print(": ");
8731 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008732 }
8733 }
8734 if (mFinishedStarting.size() > 0) {
8735 pw.println(" ");
8736 pw.println(" Finishing start of application tokens:");
8737 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
8738 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008739 pw.print(" Finished Starting #"); pw.print(i);
8740 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008741 token.dump(pw, " ");
8742 }
8743 }
8744 if (mExitingTokens.size() > 0) {
8745 pw.println(" ");
8746 pw.println(" Exiting tokens:");
8747 for (int i=mExitingTokens.size()-1; i>=0; i--) {
8748 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008749 pw.print(" Exiting #"); pw.print(i);
8750 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008751 token.dump(pw, " ");
8752 }
8753 }
8754 if (mExitingAppTokens.size() > 0) {
8755 pw.println(" ");
8756 pw.println(" Exiting application tokens:");
8757 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
8758 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008759 pw.print(" Exiting App #"); pw.print(i);
8760 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 token.dump(pw, " ");
8762 }
8763 }
8764 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008765 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
8766 pw.print(" mLastFocus="); pw.println(mLastFocus);
8767 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
8768 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
8769 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -07008770 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -07008771 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
8772 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
8773 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
8774 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08008775 if (mWindowDetachedWallpaper != null) {
8776 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
8777 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008778 if (mWindowAnimationBackgroundSurface != null) {
8779 pw.println(" mWindowAnimationBackgroundSurface:");
8780 mWindowAnimationBackgroundSurface.printTo(" ", pw);
8781 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008782 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
8783 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
8784 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008785 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
8786 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
8787 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
8788 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008789 if (mDimAnimator != null) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008790 pw.println(" mDimAnimator:");
8791 mDimAnimator.printTo(" ", pw);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008792 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -08008793 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008794 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008795 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008796 pw.print(mInputMethodAnimLayerAdjustment);
8797 pw.print(" mWallpaperAnimLayerAdjustment=");
8798 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -07008799 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
8800 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008801 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
8802 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008803 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
8804 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008805 pw.print(" mRotation="); pw.print(mRotation);
Dianne Hackborndacea8c2011-04-21 17:26:39 -07008806 pw.print(" mForcedAppOrientation="); pw.print(mForcedAppOrientation);
8807 pw.print(" mRequestedRotation="); pw.print(mRequestedRotation);
8808 pw.print(" mAltOrientation="); pw.println(mAltOrientation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008809 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
Dianne Hackborn9d132642011-04-21 17:26:39 -07008810 pw.print(", mDeferredRotationAnimFlags="); pw.println(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008811 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
8812 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
8813 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
8814 pw.print(" mNextAppTransition=0x");
8815 pw.print(Integer.toHexString(mNextAppTransition));
Dianne Hackborn9d132642011-04-21 17:26:39 -07008816 pw.print(" mAppTransitionReady="); pw.println(mAppTransitionReady);
8817 pw.print(" mAppTransitionRunning="); pw.print(mAppTransitionRunning);
8818 pw.print(" mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008819 if (mNextAppTransitionPackage != null) {
8820 pw.print(" mNextAppTransitionPackage=");
8821 pw.print(mNextAppTransitionPackage);
Dianne Hackborn9d132642011-04-21 17:26:39 -07008822 pw.print(" mNextAppTransitionEnter=0x");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008823 pw.print(Integer.toHexString(mNextAppTransitionEnter));
Dianne Hackborn9d132642011-04-21 17:26:39 -07008824 pw.print(" mNextAppTransitionExit=0x");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008825 pw.print(Integer.toHexString(mNextAppTransitionExit));
8826 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008827 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
8828 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
8829 if (mOpeningApps.size() > 0) {
8830 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
8831 }
8832 if (mClosingApps.size() > 0) {
8833 pw.print(" mClosingApps="); pw.println(mClosingApps);
8834 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008835 if (mToTopApps.size() > 0) {
8836 pw.print(" mToTopApps="); pw.println(mToTopApps);
8837 }
8838 if (mToBottomApps.size() > 0) {
8839 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
8840 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -08008841 if (mDisplay != null) {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07008842 pw.print(" Display: init="); pw.print(mInitialDisplayWidth); pw.print("x");
8843 pw.print(mInitialDisplayHeight); pw.print(" cur=");
8844 pw.print(mCurDisplayWidth); pw.print("x"); pw.print(mCurDisplayHeight);
8845 pw.print(" real="); pw.print(mDisplay.getRealWidth());
8846 pw.print("x"); pw.print(mDisplay.getRealHeight());
8847 pw.print(" raw="); pw.print(mDisplay.getRawWidth());
8848 pw.print("x"); pw.println(mDisplay.getRawHeight());
Dianne Hackborn87fc3082010-12-03 13:09:12 -08008849 } else {
8850 pw.println(" NO DISPLAY");
8851 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008852 pw.println(" Policy:");
8853 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008854 }
8855 }
8856
Jeff Brown349703e2010-06-22 01:27:15 -07008857 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008858 public void monitor() {
8859 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -05008860 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07008861 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008862
Jeff Brown2992ea72011-01-28 22:04:14 -08008863 public interface OnHardKeyboardStatusChangeListener {
8864 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
8865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866}