blob: 5728226baa9ce89b5a2598c82a06d00cd75fc29c [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
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;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
32import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070035import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37import com.android.internal.app.IBatteryStats;
38import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080039import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070040import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import com.android.internal.view.IInputContext;
42import com.android.internal.view.IInputMethodClient;
43import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080044import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import com.android.server.am.BatteryStatsService;
46
47import android.Manifest;
48import android.app.ActivityManagerNative;
49import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070050import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070051import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070052import android.content.ClipData;
53import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080061import android.content.res.Resources;
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;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070067import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070088import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
90import android.os.SystemProperties;
91import android.os.TokenWatcher;
92import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070093import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070095import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080096import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070098import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700100import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101import android.view.Gravity;
102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800152 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800162 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700164 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean DEBUG_APP_TRANSITIONS = false;
166 static final boolean DEBUG_STARTING_WINDOW = false;
167 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700168 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800169 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700171 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 static final boolean PROFILE_ORIENTATION = false;
174 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700175 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to multiply the policy's type layer, to reserve room
178 * for multiple windows of the same type and Z-ordering adjustment
179 * with TYPE_LAYER_OFFSET. */
180 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
183 * or below others in the same layer. */
184 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** How much to increment the layer for each window, to reserve room
187 * for effect surfaces between them.
188 */
189 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** The maximum length we will accept for a loaded animation duration:
192 * this is 10 seconds.
193 */
194 static final int MAX_ANIMATION_DURATION = 10*1000;
195
196 /** Amount of time (in milliseconds) to animate the dim surface from one
197 * value to another, when no window animation is driving it.
198 */
199 static final int DEFAULT_DIM_DURATION = 200;
200
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700201 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
202 * compatible windows.
203 */
204 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
205
Dianne Hackborna1111872010-11-23 20:55:11 -0800206 /**
207 * If true, the window manager will do its own custom freezing and general
208 * management of the screen during rotation.
209 */
210 static final boolean CUSTOM_SCREEN_ROTATION = true;
211
Jeff Brown7fbdc842010-06-17 20:52:56 -0700212 // Maximum number of milliseconds to wait for input event injection.
213 // FIXME is this value reasonable?
214 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700215
216 // Default input dispatching timeout in nanoseconds.
217 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 static final int UPDATE_FOCUS_NORMAL = 0;
220 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
221 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
222 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700225 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226
227 /**
228 * Condition waited on by {@link #reenableKeyguard} to know the call to
229 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 * This is set to true only if mKeyguardTokenWatcher.acquired() has
231 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500233 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234
Jim Miller284b62e2010-06-08 14:27:42 -0700235 private static final int ALLOW_DISABLE_YES = 1;
236 private static final int ALLOW_DISABLE_NO = 0;
237 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
238 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
239
Mike Lockwood983ee092009-11-22 01:42:24 -0500240 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
241 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700243 if (shouldAllowDisableKeyguard()) {
244 mPolicy.enableKeyguard(false);
245 mKeyguardDisabled = true;
246 } else {
247 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 }
250 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700251 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500252 synchronized (mKeyguardTokenWatcher) {
253 mKeyguardDisabled = false;
254 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 }
256 }
257 };
258
Jim Miller284b62e2010-06-08 14:27:42 -0700259 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
260 @Override
261 public void onReceive(Context context, Intent intent) {
262 mPolicy.enableKeyguard(true);
263 synchronized(mKeyguardTokenWatcher) {
264 // lazily evaluate this next time we're asked to disable keyguard
265 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
266 mKeyguardDisabled = false;
267 }
268 }
269 };
270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 final Context mContext;
272
273 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
278
279 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 /**
284 * All currently active sessions with clients.
285 */
286 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 /**
289 * Mapping from an IWindow IBinder to the server's Window object.
290 * This is also used as the lock for all of our state.
291 */
292 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
293
294 /**
295 * Mapping from a token IBinder to a WindowToken object.
296 */
297 final HashMap<IBinder, WindowToken> mTokenMap =
298 new HashMap<IBinder, WindowToken>();
299
300 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 * Window tokens that are in the process of exiting, but still
302 * on screen for animations.
303 */
304 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
305
306 /**
307 * Z-ordered (bottom-most first) list of all application tokens, for
308 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800309 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 */
311 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
312
313 /**
314 * Application tokens that are in the process of exiting, but still
315 * on screen for animations.
316 */
317 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
318
319 /**
320 * List of window tokens that have finished starting their application,
321 * and now need to have the policy remove their windows.
322 */
323 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
324
325 /**
326 * Z-ordered (bottom-most first) list of all Window objects.
327 */
Jeff Browne33348b2010-07-15 23:54:05 -0700328 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
330 /**
331 * Windows that are being resized. Used so we can tell the client about
332 * the resize after closing the transaction in which we resized the
333 * underlying surface.
334 */
335 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
336
337 /**
338 * Windows whose animations have ended and now must be removed.
339 */
340 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
341
342 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800343 * Used when processing mPendingRemove to avoid working on the original array.
344 */
345 WindowState[] mPendingRemoveTmp = new WindowState[20];
346
347 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 * Windows whose surface should be destroyed.
349 */
350 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
351
352 /**
353 * Windows that have lost input focus and are waiting for the new
354 * focus window to be displayed before they are told about this.
355 */
356 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
357
358 /**
359 * This is set when we have run out of memory, and will either be an empty
360 * list or contain windows that need to be force removed.
361 */
362 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700363
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800364 /**
365 * Used when rebuilding window list to keep track of windows that have
366 * been removed.
367 */
368 WindowState[] mRebuildTmp = new WindowState[20];
369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700373 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 Surface mBlurSurface;
375 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700376 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800377 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800378 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 final float[] mTmpFloats = new float[9];
383
384 boolean mSafeMode;
385 boolean mDisplayEnabled = false;
386 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700387 int mInitialDisplayWidth = 0;
388 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 int mRotation = 0;
390 int mRequestedRotation = 0;
391 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700392 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 ArrayList<IRotationWatcher> mRotationWatchers
394 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 boolean mLayoutNeeded = true;
397 boolean mAnimationPending = false;
398 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800399 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mWindowsFreezingScreen = false;
401 long mFreezeGcPending = 0;
402 int mAppsFreezingScreen = 0;
403
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800404 int mLayoutSeq = 0;
405
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800406 // State while inside of layoutAndPlaceSurfacesLocked().
407 boolean mFocusMayChange;
408
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800409 Configuration mCurConfiguration = new Configuration();
410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // This is held as long as we have the screen frozen, to give us time to
412 // perform a rotation animation when turning off shows the lock screen which
413 // changes the orientation.
414 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 // State management of app transitions. When we are preparing for a
417 // transition, mNextAppTransition will be the kind of transition to
418 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
419 // mOpeningApps and mClosingApps are the lists of tokens that will be
420 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700421 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700422 String mNextAppTransitionPackage;
423 int mNextAppTransitionEnter;
424 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700426 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionTimeout = false;
428 boolean mStartingIconInTransition = false;
429 boolean mSkipAppTransitionAnimation = false;
430 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
431 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 H mH = new H();
438
439 WindowState mCurrentFocus = null;
440 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 // This just indicates the window the input method is on top of, not
443 // necessarily the window its input is going to.
444 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 boolean mInputMethodTargetWaitingAnim;
446 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 WindowState mInputMethodWindow = null;
449 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
450
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700451 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800452
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700453 // If non-null, this is the currently visible window that is associated
454 // with the wallpaper.
455 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700456 // If non-null, we are in the middle of animating from one wallpaper target
457 // to another, and this is the lower one in Z-order.
458 WindowState mLowerWallpaperTarget = null;
459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the higher one in Z-order.
461 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800462 // Window currently running an animation that has requested it be detached
463 // from the wallpaper. This means we need to ensure the wallpaper is
464 // visible behind it in case it animates in a way that would allow it to be
465 // seen.
466 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700467 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700468 float mLastWallpaperX = -1;
469 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800470 float mLastWallpaperXStep = -1;
471 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700472 // This is set when we are waiting for a wallpaper to tell us it is done
473 // changing its scroll position.
474 WindowState mWaitingOnWallpaper;
475 // The last time we had a timeout when waiting for a wallpaper.
476 long mLastWallpaperTimeoutTime;
477 // We give a wallpaper up to 150ms to finish scrolling.
478 static final long WALLPAPER_TIMEOUT = 150;
479 // Time we wait after a timeout before trying to wait again.
480 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 AppWindowToken mFocusedApp = null;
483
484 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 float mWindowAnimationScale = 1.0f;
487 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700488
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700489 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
491 // Who is holding the screen on.
492 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700493 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700495 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700498 * Drag/drop state
499 */
500 class DragState {
501 IBinder mToken;
502 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800503 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700504 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700505 ClipData mData;
506 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700507 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700508 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 float mThumbOffsetX, mThumbOffsetY;
510 InputChannel mServerChannel, mClientChannel;
511 WindowState mTargetWindow;
512 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700513 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700514
515 private final Rect tmpRect = new Rect();
516
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800517 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700518 mToken = token;
519 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800520 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700521 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700522 mNotifiedWindows = new ArrayList<WindowState>();
523 }
524
525 void reset() {
526 if (mSurface != null) {
527 mSurface.destroy();
528 }
529 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800530 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700531 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700532 mToken = null;
533 mData = null;
534 mThumbOffsetX = mThumbOffsetY = 0;
535 mNotifiedWindows = null;
536 }
537
538 void register() {
539 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
540 if (mClientChannel != null) {
541 Slog.e(TAG, "Duplicate register of drag input channel");
542 } else {
543 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
544 mServerChannel = channels[0];
545 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800546 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700547 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
548 mH.getLooper().getQueue());
549 }
550 }
551
552 void unregister() {
553 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
554 if (mClientChannel == null) {
555 Slog.e(TAG, "Unregister of nonexistent drag input channel");
556 } else {
557 mInputManager.unregisterInputChannel(mServerChannel);
558 InputQueue.unregisterInputChannel(mClientChannel);
559 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700560 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700561 mClientChannel = null;
562 mServerChannel = null;
563 }
564 }
565
Chris Tatea32dcf72010-10-14 12:13:50 -0700566 int getDragLayerLw() {
567 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
568 * TYPE_LAYER_MULTIPLIER
569 + TYPE_LAYER_OFFSET;
570 }
571
Christopher Tatea53146c2010-09-07 11:57:52 -0700572 /* call out to each visible window/session informing it about the drag
573 */
Chris Tateb8203e92010-10-12 14:23:21 -0700574 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700575 // Cache a base-class instance of the clip metadata so that parceling
576 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700577 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700579 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700580
581 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700582 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 }
584
Christopher Tate2c095f32010-10-04 14:13:40 -0700585 final int N = mWindows.size();
586 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700587 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
590
591 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
592 * designated window is potentially a drop recipient. There are race situations
593 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
594 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700595 *
596 * This method clones the 'event' parameter if it's being delivered to the same
597 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 */
Chris Tateb478f462010-10-15 16:02:26 -0700599 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
600 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700601 // Don't actually send the event if the drag is supposed to be pinned
602 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800603 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700604 final IBinder winBinder = newWin.mClient.asBinder();
605 if (winBinder != mLocalWin) {
606 if (DEBUG_DRAG) {
607 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
608 }
609 return;
610 }
611 }
612
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700613 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700614 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
615 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800616 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700617 try {
618 newWin.mClient.dispatchDragEvent(event);
619 // track each window that we've notified that the drag is starting
620 mNotifiedWindows.add(newWin);
621 } catch (RemoteException e) {
622 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700623 } finally {
624 // if the callee was local, the dispatch has already recycled the event
625 if (Process.myPid() != newWin.mSession.mPid) {
626 event.recycle();
627 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700628 }
629 }
630 }
631
632 /* helper - construct and send a DRAG_STARTED event only if the window has not
633 * previously been notified, i.e. it became visible after the drag operation
634 * was begun. This is a rare case.
635 */
636 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700637 if (mDragInProgress) {
638 // If we have sent the drag-started, we needn't do so again
639 for (WindowState ws : mNotifiedWindows) {
640 if (ws == newWin) {
641 return;
642 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700643 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700644 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700645 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700646 }
Chris Tateb478f462010-10-15 16:02:26 -0700647 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700648 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
650
Chris Tated4533f142010-10-19 15:15:08 -0700651 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700652 if (DEBUG_DRAG) {
653 Slog.d(TAG, "broadcasting DRAG_ENDED");
654 }
Chris Tated4533f142010-10-19 15:15:08 -0700655 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800656 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700657 for (WindowState ws: mNotifiedWindows) {
658 try {
659 ws.mClient.dispatchDragEvent(evt);
660 } catch (RemoteException e) {
661 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700662 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 }
Chris Tated4533f142010-10-19 15:15:08 -0700664 mNotifiedWindows.clear();
665 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700666 evt.recycle();
667 }
668
Chris Tated4533f142010-10-19 15:15:08 -0700669 void endDragLw() {
670 mDragState.broadcastDragEndedLw();
671
672 // stop intercepting input
673 mDragState.unregister();
674 mInputMonitor.updateInputWindowsLw();
675
676 // free our resources and drop all the object references
677 mDragState.reset();
678 mDragState = null;
679 }
680
Christopher Tatea53146c2010-09-07 11:57:52 -0700681 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700682 final int myPid = Process.myPid();
683
684 // Move the surface to the given touch
685 mSurface.openTransaction();
686 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
687 mSurface.closeTransaction();
688
689 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700690 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800691 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700692 final IBinder touchedBinder = touchedWin.mClient.asBinder();
693 if (touchedBinder != mLocalWin) {
694 // This drag is pinned only to the originating window, but the drag
695 // point is outside that window. Pretend it's over empty space.
696 touchedWin = null;
697 }
698 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700699 try {
700 // have we dragged over a new window?
701 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
702 if (DEBUG_DRAG) {
703 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
704 }
705 // force DRAG_EXITED_EVENT if appropriate
706 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700707 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800708 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700709 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700710 if (myPid != mTargetWindow.mSession.mPid) {
711 evt.recycle();
712 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700713 }
714 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700715 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700716 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
717 }
718 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700719 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800720 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700721 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700722 if (myPid != touchedWin.mSession.mPid) {
723 evt.recycle();
724 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700725 }
726 } catch (RemoteException e) {
727 Slog.w(TAG, "can't send drag notification to windows");
728 }
729 mTargetWindow = touchedWin;
730 }
731
Chris Tated4533f142010-10-19 15:15:08 -0700732 // Tell the drop target about the data. Returns 'true' if we can immediately
733 // dispatch the global drag-ended message, 'false' if we need to wait for a
734 // result from the recipient.
735 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700736 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700737 if (touchedWin == null) {
738 // "drop" outside a valid window -- no recipient to apply a
739 // timeout to, and we can send the drag-ended message immediately.
740 mDragResult = false;
741 return true;
742 }
743
744 if (DEBUG_DRAG) {
745 Slog.d(TAG, "sending DROP to " + touchedWin);
746 }
747 final int myPid = Process.myPid();
748 final IBinder token = touchedWin.mClient.asBinder();
749 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
750 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800751 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700752 try {
753 touchedWin.mClient.dispatchDragEvent(evt);
754
755 // 5 second timeout for this window to respond to the drop
756 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
757 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
758 mH.sendMessageDelayed(msg, 5000);
759 } catch (RemoteException e) {
760 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
761 return true;
762 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700763 if (myPid != touchedWin.mSession.mPid) {
764 evt.recycle();
765 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700766 }
Chris Tated4533f142010-10-19 15:15:08 -0700767 mToken = token;
768 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700769 }
770
771 // Find the visible, touch-deliverable window under the given point
772 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
773 WindowState touchedWin = null;
774 final int x = (int) xf;
775 final int y = (int) yf;
776 final ArrayList<WindowState> windows = mWindows;
777 final int N = windows.size();
778 for (int i = N - 1; i >= 0; i--) {
779 WindowState child = windows.get(i);
780 final int flags = child.mAttrs.flags;
781 if (!child.isVisibleLw()) {
782 // not visible == don't tell about drags
783 continue;
784 }
785 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
786 // not touchable == don't tell about drags
787 continue;
788 }
789 // account for the window's decor etc
790 tmpRect.set(child.mFrame);
791 if (child.mTouchableInsets == ViewTreeObserver
792 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
793 // The point is inside of the window if it is
794 // inside the frame, AND the content part of that
795 // frame that was given by the application.
796 tmpRect.left += child.mGivenContentInsets.left;
797 tmpRect.top += child.mGivenContentInsets.top;
798 tmpRect.right -= child.mGivenContentInsets.right;
799 tmpRect.bottom -= child.mGivenContentInsets.bottom;
800 } else if (child.mTouchableInsets == ViewTreeObserver
801 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
802 // The point is inside of the window if it is
803 // inside the frame, AND the visible part of that
804 // frame that was given by the application.
805 tmpRect.left += child.mGivenVisibleInsets.left;
806 tmpRect.top += child.mGivenVisibleInsets.top;
807 tmpRect.right -= child.mGivenVisibleInsets.right;
808 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
809 }
810 final int touchFlags = flags &
811 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
812 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
813 if (tmpRect.contains(x, y) || touchFlags == 0) {
814 // Found it
815 touchedWin = child;
816 break;
817 }
818 }
819
820 return touchedWin;
821 }
822 }
823
824 DragState mDragState = null;
825 private final InputHandler mDragInputHandler = new BaseInputHandler() {
826 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700827 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
828 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700829 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700830 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
831 && mDragState != null) {
832 boolean endDrag = false;
833 final float newX = event.getRawX();
834 final float newY = event.getRawY();
835
Christopher Tatea53146c2010-09-07 11:57:52 -0700836 switch (event.getAction()) {
837 case MotionEvent.ACTION_DOWN: {
838 if (DEBUG_DRAG) {
839 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
840 }
841 } break;
842
843 case MotionEvent.ACTION_MOVE: {
844 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700845 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700846 mDragState.notifyMoveLw(newX, newY);
847 }
848 } break;
849
850 case MotionEvent.ACTION_UP: {
851 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
852 + newX + "," + newY);
853 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700854 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700855 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700856 } break;
857
858 case MotionEvent.ACTION_CANCEL: {
859 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
860 endDrag = true;
861 } break;
862 }
863
864 if (endDrag) {
865 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
866 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700867 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700868 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700869 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700870 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700871
872 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700873 }
874 } catch (Exception e) {
875 Slog.e(TAG, "Exception caught by drag handleMotion", e);
876 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700877 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700878 }
879 }
880 };
881
882 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 * Whether the UI is currently running in touch mode (not showing
884 * navigational focus because the user is directly pressing the screen).
885 */
886 boolean mInTouchMode = false;
887
888 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700889 private ArrayList<WindowChangeListener> mWindowChangeListeners =
890 new ArrayList<WindowChangeListener>();
891 private boolean mWindowsChanged = false;
892
893 public interface WindowChangeListener {
894 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700895 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897
Dianne Hackbornc485a602009-03-24 22:39:49 -0700898 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700899 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700900
901 // The frame use to limit the size of the app running in compatibility mode.
902 Rect mCompatibleScreenFrame = new Rect();
903 // The surface used to fill the outer rim of the app running in compatibility mode.
904 Surface mBackgroundFillerSurface = null;
905 boolean mBackgroundFillerShown = false;
906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 public static WindowManagerService main(Context context,
908 PowerManagerService pm, boolean haveInputMethods) {
909 WMThread thr = new WMThread(context, pm, haveInputMethods);
910 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 synchronized (thr) {
913 while (thr.mService == null) {
914 try {
915 thr.wait();
916 } catch (InterruptedException e) {
917 }
918 }
919 }
Romain Guy06882f82009-06-10 13:36:04 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 return thr.mService;
922 }
Romain Guy06882f82009-06-10 13:36:04 -0700923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 static class WMThread extends Thread {
925 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 private final Context mContext;
928 private final PowerManagerService mPM;
929 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 public WMThread(Context context, PowerManagerService pm,
932 boolean haveInputMethods) {
933 super("WindowManager");
934 mContext = context;
935 mPM = pm;
936 mHaveInputMethods = haveInputMethods;
937 }
Romain Guy06882f82009-06-10 13:36:04 -0700938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 public void run() {
940 Looper.prepare();
941 WindowManagerService s = new WindowManagerService(mContext, mPM,
942 mHaveInputMethods);
943 android.os.Process.setThreadPriority(
944 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700945 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 synchronized (this) {
948 mService = s;
949 notifyAll();
950 }
Romain Guy06882f82009-06-10 13:36:04 -0700951
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700952 // For debug builds, log event loop stalls to dropbox for analysis.
953 if (StrictMode.conditionallyEnableDebugLogging()) {
954 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
955 }
956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 Looper.loop();
958 }
959 }
960
961 static class PolicyThread extends Thread {
962 private final WindowManagerPolicy mPolicy;
963 private final WindowManagerService mService;
964 private final Context mContext;
965 private final PowerManagerService mPM;
966 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 public PolicyThread(WindowManagerPolicy policy,
969 WindowManagerService service, Context context,
970 PowerManagerService pm) {
971 super("WindowManagerPolicy");
972 mPolicy = policy;
973 mService = service;
974 mContext = context;
975 mPM = pm;
976 }
Romain Guy06882f82009-06-10 13:36:04 -0700977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 public void run() {
979 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800980 WindowManagerPolicyThread.set(this, Looper.myLooper());
981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800983 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 android.os.Process.setThreadPriority(
985 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700986 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 synchronized (this) {
990 mRunning = true;
991 notifyAll();
992 }
Romain Guy06882f82009-06-10 13:36:04 -0700993
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700994 // For debug builds, log event loop stalls to dropbox for analysis.
995 if (StrictMode.conditionallyEnableDebugLogging()) {
996 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
997 }
998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 Looper.loop();
1000 }
1001 }
1002
1003 private WindowManagerService(Context context, PowerManagerService pm,
1004 boolean haveInputMethods) {
1005 mContext = context;
1006 mHaveInputMethods = haveInputMethods;
1007 mLimitedAlphaCompositing = context.getResources().getBoolean(
1008 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 mPowerManager = pm;
1011 mPowerManager.setPolicy(mPolicy);
1012 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1013 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1014 "SCREEN_FROZEN");
1015 mScreenFrozenLock.setReferenceCounted(false);
1016
1017 mActivityManager = ActivityManagerNative.getDefault();
1018 mBatteryStats = BatteryStatsService.getService();
1019
1020 // Get persisted window scale setting
1021 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1022 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1023 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1024 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001025
Jim Miller284b62e2010-06-08 14:27:42 -07001026 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1027 IntentFilter filter = new IntentFilter();
1028 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1029 mContext.registerReceiver(mBroadcastReceiver, filter);
1030
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001031 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1032 "KEEP_SCREEN_ON_FLAG");
1033 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034
Jeff Browne33348b2010-07-15 23:54:05 -07001035 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1038 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 synchronized (thr) {
1041 while (!thr.mRunning) {
1042 try {
1043 thr.wait();
1044 } catch (InterruptedException e) {
1045 }
1046 }
1047 }
Romain Guy06882f82009-06-10 13:36:04 -07001048
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001049 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 // Add ourself to the Watchdog monitors.
1052 Watchdog.getInstance().addMonitor(this);
1053 }
1054
1055 @Override
1056 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1057 throws RemoteException {
1058 try {
1059 return super.onTransact(code, data, reply, flags);
1060 } catch (RuntimeException e) {
1061 // The window manager only throws security exceptions, so let's
1062 // log all others.
1063 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001064 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 }
1066 throw e;
1067 }
1068 }
1069
Jeff Browne33348b2010-07-15 23:54:05 -07001070 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001072 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 TAG, "Adding window " + window + " at "
1074 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1075 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001076 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 }
1078
Jeff Browne33348b2010-07-15 23:54:05 -07001079 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001081 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 TAG, "Adding window " + window + " at "
1083 + i + " of " + mWindows.size() + " (before " + pos + ")");
1084 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001085 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
1087
1088 //This method finds out the index of a window that has the same app token as
1089 //win. used for z ordering the windows in mWindows
1090 private int findIdxBasedOnAppTokens(WindowState win) {
1091 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001092 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 int jmax = localmWindows.size();
1094 if(jmax == 0) {
1095 return -1;
1096 }
1097 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001098 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 if(wentry.mAppToken == win.mAppToken) {
1100 return j;
1101 }
1102 }
1103 return -1;
1104 }
Romain Guy06882f82009-06-10 13:36:04 -07001105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1107 final IWindow client = win.mClient;
1108 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001109 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 final int N = localmWindows.size();
1112 final WindowState attached = win.mAttachedWindow;
1113 int i;
1114 if (attached == null) {
1115 int tokenWindowsPos = token.windows.size();
1116 if (token.appWindowToken != null) {
1117 int index = tokenWindowsPos-1;
1118 if (index >= 0) {
1119 // If this application has existing windows, we
1120 // simply place the new window on top of them... but
1121 // keep the starting window on top.
1122 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1123 // Base windows go behind everything else.
1124 placeWindowBefore(token.windows.get(0), win);
1125 tokenWindowsPos = 0;
1126 } else {
1127 AppWindowToken atoken = win.mAppToken;
1128 if (atoken != null &&
1129 token.windows.get(index) == atoken.startingWindow) {
1130 placeWindowBefore(token.windows.get(index), win);
1131 tokenWindowsPos--;
1132 } else {
1133 int newIdx = findIdxBasedOnAppTokens(win);
1134 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001135 //there is a window above this one associated with the same
1136 //apptoken note that the window could be a floating window
1137 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001139 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1140 Slog.v(TAG, "Adding window " + win + " at "
1141 + (newIdx+1) + " of " + N);
1142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001144 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 }
1147 }
1148 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001149 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 TAG, "Figuring out where to add app window "
1151 + client.asBinder() + " (token=" + token + ")");
1152 // Figure out where the window should go, based on the
1153 // order of applications.
1154 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001155 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 for (i=NA-1; i>=0; i--) {
1157 AppWindowToken t = mAppTokens.get(i);
1158 if (t == token) {
1159 i--;
1160 break;
1161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001162
Dianne Hackborna8f60182009-09-01 19:01:50 -07001163 // We haven't reached the token yet; if this token
1164 // is not going to the bottom and has windows, we can
1165 // use it as an anchor for when we do reach the token.
1166 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 pos = t.windows.get(0);
1168 }
1169 }
1170 // We now know the index into the apps. If we found
1171 // an app window above, that gives us the position; else
1172 // we need to look some more.
1173 if (pos != null) {
1174 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001175 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 if (atoken != null) {
1177 final int NC = atoken.windows.size();
1178 if (NC > 0) {
1179 WindowState bottom = atoken.windows.get(0);
1180 if (bottom.mSubLayer < 0) {
1181 pos = bottom;
1182 }
1183 }
1184 }
1185 placeWindowBefore(pos, win);
1186 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001187 // Continue looking down until we find the first
1188 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 while (i >= 0) {
1190 AppWindowToken t = mAppTokens.get(i);
1191 final int NW = t.windows.size();
1192 if (NW > 0) {
1193 pos = t.windows.get(NW-1);
1194 break;
1195 }
1196 i--;
1197 }
1198 if (pos != null) {
1199 // Move in front of any windows attached to this
1200 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001201 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 if (atoken != null) {
1203 final int NC = atoken.windows.size();
1204 if (NC > 0) {
1205 WindowState top = atoken.windows.get(NC-1);
1206 if (top.mSubLayer >= 0) {
1207 pos = top;
1208 }
1209 }
1210 }
1211 placeWindowAfter(pos, win);
1212 } else {
1213 // Just search for the start of this layer.
1214 final int myLayer = win.mBaseLayer;
1215 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001216 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 if (w.mBaseLayer > myLayer) {
1218 break;
1219 }
1220 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001221 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1222 Slog.v(TAG, "Adding window " + win + " at "
1223 + i + " of " + N);
1224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001226 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 }
1228 }
1229 }
1230 } else {
1231 // Figure out where window should go, based on layer.
1232 final int myLayer = win.mBaseLayer;
1233 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001234 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 i++;
1236 break;
1237 }
1238 }
1239 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001240 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001241 TAG, "Adding window " + win + " at "
1242 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001244 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 }
1246 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001247 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 token.windows.add(tokenWindowsPos, win);
1249 }
1250
1251 } else {
1252 // Figure out this window's ordering relative to the window
1253 // it is attached to.
1254 final int NA = token.windows.size();
1255 final int sublayer = win.mSubLayer;
1256 int largestSublayer = Integer.MIN_VALUE;
1257 WindowState windowWithLargestSublayer = null;
1258 for (i=0; i<NA; i++) {
1259 WindowState w = token.windows.get(i);
1260 final int wSublayer = w.mSubLayer;
1261 if (wSublayer >= largestSublayer) {
1262 largestSublayer = wSublayer;
1263 windowWithLargestSublayer = w;
1264 }
1265 if (sublayer < 0) {
1266 // For negative sublayers, we go below all windows
1267 // in the same sublayer.
1268 if (wSublayer >= sublayer) {
1269 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001270 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 token.windows.add(i, win);
1272 }
1273 placeWindowBefore(
1274 wSublayer >= 0 ? attached : w, win);
1275 break;
1276 }
1277 } else {
1278 // For positive sublayers, we go above all windows
1279 // in the same sublayer.
1280 if (wSublayer > sublayer) {
1281 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001282 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 token.windows.add(i, win);
1284 }
1285 placeWindowBefore(w, win);
1286 break;
1287 }
1288 }
1289 }
1290 if (i >= NA) {
1291 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001292 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 token.windows.add(win);
1294 }
1295 if (sublayer < 0) {
1296 placeWindowBefore(attached, win);
1297 } else {
1298 placeWindowAfter(largestSublayer >= 0
1299 ? windowWithLargestSublayer
1300 : attached,
1301 win);
1302 }
1303 }
1304 }
Romain Guy06882f82009-06-10 13:36:04 -07001305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 if (win.mAppToken != null && addToToken) {
1307 win.mAppToken.allAppWindows.add(win);
1308 }
1309 }
Romain Guy06882f82009-06-10 13:36:04 -07001310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 static boolean canBeImeTarget(WindowState w) {
1312 final int fl = w.mAttrs.flags
1313 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1314 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1315 return w.isVisibleOrAdding();
1316 }
1317 return false;
1318 }
Romain Guy06882f82009-06-10 13:36:04 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001321 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 final int N = localmWindows.size();
1323 WindowState w = null;
1324 int i = N;
1325 while (i > 0) {
1326 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001327 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001328
Joe Onorato8a9b2202010-02-26 18:56:32 -08001329 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 // + Integer.toHexString(w.mAttrs.flags));
1331 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001332 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 // Yet more tricksyness! If this window is a "starting"
1335 // window, we do actually want to be on top of it, but
1336 // it is not -really- where input will go. So if the caller
1337 // is not actually looking to move the IME, look down below
1338 // for a real window to target...
1339 if (!willMove
1340 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1341 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001342 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1344 i--;
1345 w = wb;
1346 }
1347 }
1348 break;
1349 }
1350 }
Romain Guy06882f82009-06-10 13:36:04 -07001351
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001352 // Now, a special case -- if the last target's window is in the
1353 // process of exiting, and is above the new target, keep on the
1354 // last target to avoid flicker. Consider for example a Dialog with
1355 // the IME shown: when the Dialog is dismissed, we want to keep
1356 // the IME above it until it is completely gone so it doesn't drop
1357 // behind the dialog or its full-screen scrim.
1358 if (mInputMethodTarget != null && w != null
1359 && mInputMethodTarget.isDisplayedLw()
1360 && mInputMethodTarget.mExiting) {
1361 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1362 w = mInputMethodTarget;
1363 i = localmWindows.indexOf(w);
1364 }
1365 }
Romain Guy06882f82009-06-10 13:36:04 -07001366
Joe Onorato8a9b2202010-02-26 18:56:32 -08001367 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 if (willMove && w != null) {
1371 final WindowState curTarget = mInputMethodTarget;
1372 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 // Now some fun for dealing with window animations that
1375 // modify the Z order. We need to look at all windows below
1376 // the current target that are in this app, finding the highest
1377 // visible one in layering.
1378 AppWindowToken token = curTarget.mAppToken;
1379 WindowState highestTarget = null;
1380 int highestPos = 0;
1381 if (token.animating || token.animation != null) {
1382 int pos = 0;
1383 pos = localmWindows.indexOf(curTarget);
1384 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001385 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 if (win.mAppToken != token) {
1387 break;
1388 }
1389 if (!win.mRemoved) {
1390 if (highestTarget == null || win.mAnimLayer >
1391 highestTarget.mAnimLayer) {
1392 highestTarget = win;
1393 highestPos = pos;
1394 }
1395 }
1396 pos--;
1397 }
1398 }
Romain Guy06882f82009-06-10 13:36:04 -07001399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001401 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 + mNextAppTransition + " " + highestTarget
1403 + " animating=" + highestTarget.isAnimating()
1404 + " layer=" + highestTarget.mAnimLayer
1405 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001406
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001407 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 // If we are currently setting up for an animation,
1409 // hold everything until we can find out what will happen.
1410 mInputMethodTargetWaitingAnim = true;
1411 mInputMethodTarget = highestTarget;
1412 return highestPos + 1;
1413 } else if (highestTarget.isAnimating() &&
1414 highestTarget.mAnimLayer > w.mAnimLayer) {
1415 // If the window we are currently targeting is involved
1416 // with an animation, and it is on top of the next target
1417 // we will be over, then hold off on moving until
1418 // that is done.
1419 mInputMethodTarget = highestTarget;
1420 return highestPos + 1;
1421 }
1422 }
1423 }
1424 }
Romain Guy06882f82009-06-10 13:36:04 -07001425
Joe Onorato8a9b2202010-02-26 18:56:32 -08001426 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 if (w != null) {
1428 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001429 if (DEBUG_INPUT_METHOD) {
1430 RuntimeException e = null;
1431 if (!HIDE_STACK_CRAWLS) {
1432 e = new RuntimeException();
1433 e.fillInStackTrace();
1434 }
1435 Slog.w(TAG, "Moving IM target from "
1436 + mInputMethodTarget + " to " + w, e);
1437 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 mInputMethodTarget = w;
1439 if (w.mAppToken != null) {
1440 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1441 } else {
1442 setInputMethodAnimLayerAdjustment(0);
1443 }
1444 }
1445 return i+1;
1446 }
1447 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001448 if (DEBUG_INPUT_METHOD) {
1449 RuntimeException e = null;
1450 if (!HIDE_STACK_CRAWLS) {
1451 e = new RuntimeException();
1452 e.fillInStackTrace();
1453 }
1454 Slog.w(TAG, "Moving IM target from "
1455 + mInputMethodTarget + " to null", e);
1456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 mInputMethodTarget = null;
1458 setInputMethodAnimLayerAdjustment(0);
1459 }
1460 return -1;
1461 }
Romain Guy06882f82009-06-10 13:36:04 -07001462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 void addInputMethodWindowToListLocked(WindowState win) {
1464 int pos = findDesiredInputMethodWindowIndexLocked(true);
1465 if (pos >= 0) {
1466 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001467 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001468 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001470 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 moveInputMethodDialogsLocked(pos+1);
1472 return;
1473 }
1474 win.mTargetAppToken = null;
1475 addWindowToListInOrderLocked(win, true);
1476 moveInputMethodDialogsLocked(pos);
1477 }
Romain Guy06882f82009-06-10 13:36:04 -07001478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001480 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 mInputMethodAnimLayerAdjustment = adj;
1482 WindowState imw = mInputMethodWindow;
1483 if (imw != null) {
1484 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001485 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 + " anim layer: " + imw.mAnimLayer);
1487 int wi = imw.mChildWindows.size();
1488 while (wi > 0) {
1489 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001490 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001492 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 + " anim layer: " + cw.mAnimLayer);
1494 }
1495 }
1496 int di = mInputMethodDialogs.size();
1497 while (di > 0) {
1498 di --;
1499 imw = mInputMethodDialogs.get(di);
1500 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001501 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 + " anim layer: " + imw.mAnimLayer);
1503 }
1504 }
Romain Guy06882f82009-06-10 13:36:04 -07001505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1507 int wpos = mWindows.indexOf(win);
1508 if (wpos >= 0) {
1509 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001510 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001512 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 int NC = win.mChildWindows.size();
1514 while (NC > 0) {
1515 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001516 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 int cpos = mWindows.indexOf(cw);
1518 if (cpos >= 0) {
1519 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001520 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001521 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 mWindows.remove(cpos);
1523 }
1524 }
1525 }
1526 return interestingPos;
1527 }
Romain Guy06882f82009-06-10 13:36:04 -07001528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 private void reAddWindowToListInOrderLocked(WindowState win) {
1530 addWindowToListInOrderLocked(win, false);
1531 // This is a hack to get all of the child windows added as well
1532 // at the right position. Child windows should be rare and
1533 // this case should be rare, so it shouldn't be that big a deal.
1534 int wpos = mWindows.indexOf(win);
1535 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001536 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001537 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001539 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 reAddWindowLocked(wpos, win);
1541 }
1542 }
Romain Guy06882f82009-06-10 13:36:04 -07001543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 void logWindowList(String prefix) {
1545 int N = mWindows.size();
1546 while (N > 0) {
1547 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 }
1550 }
Romain Guy06882f82009-06-10 13:36:04 -07001551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 void moveInputMethodDialogsLocked(int pos) {
1553 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001556 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 for (int i=0; i<N; i++) {
1558 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1559 }
1560 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 logWindowList(" ");
1563 }
Romain Guy06882f82009-06-10 13:36:04 -07001564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 if (pos >= 0) {
1566 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1567 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001568 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 if (wp == mInputMethodWindow) {
1570 pos++;
1571 }
1572 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001573 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 for (int i=0; i<N; i++) {
1575 WindowState win = dialogs.get(i);
1576 win.mTargetAppToken = targetAppToken;
1577 pos = reAddWindowLocked(pos, win);
1578 }
1579 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001580 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 logWindowList(" ");
1582 }
1583 return;
1584 }
1585 for (int i=0; i<N; i++) {
1586 WindowState win = dialogs.get(i);
1587 win.mTargetAppToken = null;
1588 reAddWindowToListInOrderLocked(win);
1589 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001590 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 logWindowList(" ");
1592 }
1593 }
1594 }
Romain Guy06882f82009-06-10 13:36:04 -07001595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1597 final WindowState imWin = mInputMethodWindow;
1598 final int DN = mInputMethodDialogs.size();
1599 if (imWin == null && DN == 0) {
1600 return false;
1601 }
Romain Guy06882f82009-06-10 13:36:04 -07001602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1604 if (imPos >= 0) {
1605 // In this case, the input method windows are to be placed
1606 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 // First check to see if the input method windows are already
1609 // located here, and contiguous.
1610 final int N = mWindows.size();
1611 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001612 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 // Figure out the actual input method window that should be
1615 // at the bottom of their stack.
1616 WindowState baseImWin = imWin != null
1617 ? imWin : mInputMethodDialogs.get(0);
1618 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001619 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001620 if (cw.mSubLayer < 0) baseImWin = cw;
1621 }
Romain Guy06882f82009-06-10 13:36:04 -07001622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 if (firstImWin == baseImWin) {
1624 // The windows haven't moved... but are they still contiguous?
1625 // First find the top IM window.
1626 int pos = imPos+1;
1627 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001628 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 break;
1630 }
1631 pos++;
1632 }
1633 pos++;
1634 // Now there should be no more input method windows above.
1635 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001636 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 break;
1638 }
1639 pos++;
1640 }
1641 if (pos >= N) {
1642 // All is good!
1643 return false;
1644 }
1645 }
Romain Guy06882f82009-06-10 13:36:04 -07001646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 if (imWin != null) {
1648 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001649 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 logWindowList(" ");
1651 }
1652 imPos = tmpRemoveWindowLocked(imPos, imWin);
1653 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001654 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 logWindowList(" ");
1656 }
1657 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1658 reAddWindowLocked(imPos, imWin);
1659 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001660 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 logWindowList(" ");
1662 }
1663 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1664 } else {
1665 moveInputMethodDialogsLocked(imPos);
1666 }
Romain Guy06882f82009-06-10 13:36:04 -07001667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 } else {
1669 // In this case, the input method windows go in a fixed layer,
1670 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001673 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 tmpRemoveWindowLocked(0, imWin);
1675 imWin.mTargetAppToken = null;
1676 reAddWindowToListInOrderLocked(imWin);
1677 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 logWindowList(" ");
1680 }
1681 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1682 } else {
1683 moveInputMethodDialogsLocked(-1);;
1684 }
Romain Guy06882f82009-06-10 13:36:04 -07001685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 }
Romain Guy06882f82009-06-10 13:36:04 -07001687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 if (needAssignLayers) {
1689 assignLayersLocked();
1690 }
Romain Guy06882f82009-06-10 13:36:04 -07001691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 return true;
1693 }
Romain Guy06882f82009-06-10 13:36:04 -07001694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 void adjustInputMethodDialogsLocked() {
1696 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1697 }
Romain Guy06882f82009-06-10 13:36:04 -07001698
Dianne Hackborn25994b42009-09-04 14:21:19 -07001699 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001701 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1702 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1703 ? wallpaperTarget.mAppToken.animation : null)
1704 + " upper=" + mUpperWallpaperTarget
1705 + " lower=" + mLowerWallpaperTarget);
1706 return (wallpaperTarget != null
1707 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1708 && wallpaperTarget.mAppToken.animation != null)))
1709 || mUpperWallpaperTarget != null
1710 || mLowerWallpaperTarget != null;
1711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001712
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001713 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1714 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001715
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001716 int adjustWallpaperWindowsLocked() {
1717 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001718
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001719 final int dw = mDisplay.getWidth();
1720 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001721
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001722 // First find top-most window that has asked to be on top of the
1723 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001724 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001725 int N = localmWindows.size();
1726 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001727 WindowState foundW = null;
1728 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001729 WindowState topCurW = null;
1730 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001731 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001732 int i = N;
1733 while (i > 0) {
1734 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001735 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001736 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1737 if (topCurW == null) {
1738 topCurW = w;
1739 topCurI = i;
1740 }
1741 continue;
1742 }
1743 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001744 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001745 // If this window's app token is hidden and not animating,
1746 // it is of no interest to us.
1747 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001748 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001749 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001750 continue;
1751 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001752 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001753 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001754 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1755 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001756 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001757 && (mWallpaperTarget == w
1758 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001759 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001760 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001761 foundW = w;
1762 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001763 if (w == mWallpaperTarget && ((w.mAppToken != null
1764 && w.mAppToken.animation != null)
1765 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001766 // The current wallpaper target is animating, so we'll
1767 // look behind it for another possible target and figure
1768 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001771 continue;
1772 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001773 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001774 } else if (w == mWindowDetachedWallpaper) {
1775 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001776 }
1777 }
1778
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001779 if (foundW == null && windowDetachedI >= 0) {
1780 if (DEBUG_WALLPAPER) Slog.v(TAG,
1781 "Found animating detached wallpaper activity: #" + i + "=" + w);
1782 foundW = w;
1783 foundI = windowDetachedI;
1784 }
1785
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001786 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001787 // If we are currently waiting for an app transition, and either
1788 // the current target or the next target are involved with it,
1789 // then hold off on doing anything with the wallpaper.
1790 // Note that we are checking here for just whether the target
1791 // is part of an app token... which is potentially overly aggressive
1792 // (the app token may not be involved in the transition), but good
1793 // enough (we'll just wait until whatever transition is pending
1794 // executes).
1795 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001798 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001799 }
1800 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001801 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001802 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001803 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001804 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001806
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001807 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001808 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001810 + " oldTarget: " + mWallpaperTarget);
1811 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001812
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001813 mLowerWallpaperTarget = null;
1814 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001815
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 WindowState oldW = mWallpaperTarget;
1817 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001818
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001819 // Now what is happening... if the current and new targets are
1820 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001821 if (foundW != null && oldW != null) {
1822 boolean oldAnim = oldW.mAnimation != null
1823 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1824 boolean foundAnim = foundW.mAnimation != null
1825 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001826 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001827 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001828 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001830 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001831 int oldI = localmWindows.indexOf(oldW);
1832 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 }
1835 if (oldI >= 0) {
1836 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001837 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 + "=" + oldW + "; new#" + foundI
1839 + "=" + foundW);
1840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001842 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001843 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001844 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 }
1847 mWallpaperTarget = oldW;
1848 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001849
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001850 // Now set the upper and lower wallpaper targets
1851 // correctly, and make sure that we are positioning
1852 // the wallpaper below the lower.
1853 if (foundI > oldI) {
1854 // The new target is on top of the old one.
1855 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001856 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001857 }
1858 mUpperWallpaperTarget = foundW;
1859 mLowerWallpaperTarget = oldW;
1860 foundW = oldW;
1861 foundI = oldI;
1862 } else {
1863 // The new target is below the old one.
1864 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001865 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001866 }
1867 mUpperWallpaperTarget = oldW;
1868 mLowerWallpaperTarget = foundW;
1869 }
1870 }
1871 }
1872 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001873
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001874 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001875 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001876 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1877 || (mLowerWallpaperTarget.mAppToken != null
1878 && mLowerWallpaperTarget.mAppToken.animation != null);
1879 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1880 || (mUpperWallpaperTarget.mAppToken != null
1881 && mUpperWallpaperTarget.mAppToken.animation != null);
1882 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001883 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001884 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001885 }
1886 mLowerWallpaperTarget = null;
1887 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001888 }
1889 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001890
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001891 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001892 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001893 // The window is visible to the compositor... but is it visible
1894 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001895 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001896 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001897
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001898 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001899 // its layer adjustment. Only do this if we are not transfering
1900 // between two wallpaper targets.
1901 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001902 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001903 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001904
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001905 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1906 * TYPE_LAYER_MULTIPLIER
1907 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001908
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001909 // Now w is the window we are supposed to be behind... but we
1910 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001911 // AND any starting window associated with it, AND below the
1912 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001913 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001914 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001915 if (wb.mBaseLayer < maxLayer &&
1916 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001917 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001918 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001919 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001920 // This window is not related to the previous one in any
1921 // interesting way, so stop here.
1922 break;
1923 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001924 foundW = wb;
1925 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001926 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001927 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001928 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001929 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001930
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001931 if (foundW == null && topCurW != null) {
1932 // There is no wallpaper target, so it goes at the bottom.
1933 // We will assume it is the same place as last time, if known.
1934 foundW = topCurW;
1935 foundI = topCurI+1;
1936 } else {
1937 // Okay i is the position immediately above the wallpaper. Look at
1938 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001939 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001940 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001941
Dianne Hackborn284ac932009-08-28 10:34:25 -07001942 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001943 if (mWallpaperTarget.mWallpaperX >= 0) {
1944 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001945 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001946 }
1947 if (mWallpaperTarget.mWallpaperY >= 0) {
1948 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001949 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001950 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001951 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001952
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001953 // Start stepping backwards from here, ensuring that our wallpaper windows
1954 // are correctly placed.
1955 int curTokenIndex = mWallpaperTokens.size();
1956 while (curTokenIndex > 0) {
1957 curTokenIndex--;
1958 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001959 if (token.hidden == visible) {
1960 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1961 token.hidden = !visible;
1962 // Need to do a layout to ensure the wallpaper now has the
1963 // correct size.
1964 mLayoutNeeded = true;
1965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001966
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001967 int curWallpaperIndex = token.windows.size();
1968 while (curWallpaperIndex > 0) {
1969 curWallpaperIndex--;
1970 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001971
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001972 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001973 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001974 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001975
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001976 // First, make sure the client has the current visibility
1977 // state.
1978 if (wallpaper.mWallpaperVisible != visible) {
1979 wallpaper.mWallpaperVisible = visible;
1980 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001981 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001982 "Setting visibility of wallpaper " + wallpaper
1983 + ": " + visible);
1984 wallpaper.mClient.dispatchAppVisibility(visible);
1985 } catch (RemoteException e) {
1986 }
1987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001989 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001990 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001991 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001992
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001993 // First, if this window is at the current index, then all
1994 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001995 if (wallpaper == foundW) {
1996 foundI--;
1997 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001998 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001999 continue;
2000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002001
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002002 // The window didn't match... the current wallpaper window,
2003 // wherever it is, is in the wrong place, so make sure it is
2004 // not in the list.
2005 int oldIndex = localmWindows.indexOf(wallpaper);
2006 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002007 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002008 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002009 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002010 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002011 if (oldIndex < foundI) {
2012 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002013 }
2014 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002015
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002016 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002017 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2018 Slog.v(TAG, "Moving wallpaper " + wallpaper
2019 + " from " + oldIndex + " to " + foundI);
2020 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002021
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002022 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002023 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002024 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002025 }
2026 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002027
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002028 return changed;
2029 }
2030
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002031 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002032 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002033 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002034 mWallpaperAnimLayerAdjustment = adj;
2035 int curTokenIndex = mWallpaperTokens.size();
2036 while (curTokenIndex > 0) {
2037 curTokenIndex--;
2038 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2039 int curWallpaperIndex = token.windows.size();
2040 while (curWallpaperIndex > 0) {
2041 curWallpaperIndex--;
2042 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2043 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002044 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002045 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002046 }
2047 }
2048 }
2049
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002050 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2051 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002052 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002053 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002054 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002055 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002056 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2057 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2058 changed = wallpaperWin.mXOffset != offset;
2059 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002060 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002061 + wallpaperWin + " x: " + offset);
2062 wallpaperWin.mXOffset = offset;
2063 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002064 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002065 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002066 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002067 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002068 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002069
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002070 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002071 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002072 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2073 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2074 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002075 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002076 + wallpaperWin + " y: " + offset);
2077 changed = true;
2078 wallpaperWin.mYOffset = offset;
2079 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002080 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002081 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002082 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002083 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002084 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002085
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002086 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002087 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002088 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002089 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2090 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002091 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002092 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002093 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002094 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002095 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2096 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002097 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002098 if (mWaitingOnWallpaper != null) {
2099 long start = SystemClock.uptimeMillis();
2100 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2101 < start) {
2102 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002103 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002104 "Waiting for offset complete...");
2105 mWindowMap.wait(WALLPAPER_TIMEOUT);
2106 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002107 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002108 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002109 if ((start+WALLPAPER_TIMEOUT)
2110 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002111 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002112 + wallpaperWin);
2113 mLastWallpaperTimeoutTime = start;
2114 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002115 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002116 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002117 }
2118 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002119 } catch (RemoteException e) {
2120 }
2121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002122
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002123 return changed;
2124 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002125
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002126 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002127 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002128 if (mWaitingOnWallpaper != null &&
2129 mWaitingOnWallpaper.mClient.asBinder() == window) {
2130 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002131 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002132 }
2133 }
2134 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002135
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002136 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002137 final int dw = mDisplay.getWidth();
2138 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002139
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002140 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002141
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002142 WindowState target = mWallpaperTarget;
2143 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002144 if (target.mWallpaperX >= 0) {
2145 mLastWallpaperX = target.mWallpaperX;
2146 } else if (changingTarget.mWallpaperX >= 0) {
2147 mLastWallpaperX = changingTarget.mWallpaperX;
2148 }
2149 if (target.mWallpaperY >= 0) {
2150 mLastWallpaperY = target.mWallpaperY;
2151 } else if (changingTarget.mWallpaperY >= 0) {
2152 mLastWallpaperY = changingTarget.mWallpaperY;
2153 }
2154 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002155
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002156 int curTokenIndex = mWallpaperTokens.size();
2157 while (curTokenIndex > 0) {
2158 curTokenIndex--;
2159 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2160 int curWallpaperIndex = token.windows.size();
2161 while (curWallpaperIndex > 0) {
2162 curWallpaperIndex--;
2163 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2164 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2165 wallpaper.computeShownFrameLocked();
2166 changed = true;
2167 // We only want to be synchronous with one wallpaper.
2168 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002169 }
2170 }
2171 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002172
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002173 return changed;
2174 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002175
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002176 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002177 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002178 final int dw = mDisplay.getWidth();
2179 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002180
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002181 int curTokenIndex = mWallpaperTokens.size();
2182 while (curTokenIndex > 0) {
2183 curTokenIndex--;
2184 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002185 if (token.hidden == visible) {
2186 token.hidden = !visible;
2187 // Need to do a layout to ensure the wallpaper now has the
2188 // correct size.
2189 mLayoutNeeded = true;
2190 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002191
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002192 int curWallpaperIndex = token.windows.size();
2193 while (curWallpaperIndex > 0) {
2194 curWallpaperIndex--;
2195 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2196 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002197 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002198 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002199
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002200 if (wallpaper.mWallpaperVisible != visible) {
2201 wallpaper.mWallpaperVisible = visible;
2202 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002203 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002204 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002205 + ": " + visible);
2206 wallpaper.mClient.dispatchAppVisibility(visible);
2207 } catch (RemoteException e) {
2208 }
2209 }
2210 }
2211 }
2212 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 public int addWindow(Session session, IWindow client,
2215 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002216 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 int res = mPolicy.checkAddPermission(attrs);
2218 if (res != WindowManagerImpl.ADD_OKAY) {
2219 return res;
2220 }
Romain Guy06882f82009-06-10 13:36:04 -07002221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 boolean reportNewConfig = false;
2223 WindowState attachedWindow = null;
2224 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002225 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002229 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 }
Romain Guy06882f82009-06-10 13:36:04 -07002231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002233 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2235 }
2236
2237 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002238 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002240 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 + attrs.token + ". Aborting.");
2242 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2243 }
2244 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2245 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002246 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 + attrs.token + ". Aborting.");
2248 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2249 }
2250 }
2251
2252 boolean addToken = false;
2253 WindowToken token = mTokenMap.get(attrs.token);
2254 if (token == null) {
2255 if (attrs.type >= FIRST_APPLICATION_WINDOW
2256 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002257 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 + attrs.token + ". Aborting.");
2259 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2260 }
2261 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002262 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 + attrs.token + ". Aborting.");
2264 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2265 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002266 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002267 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002268 + attrs.token + ". Aborting.");
2269 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2270 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 token = new WindowToken(attrs.token, -1, false);
2272 addToken = true;
2273 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2274 && attrs.type <= LAST_APPLICATION_WINDOW) {
2275 AppWindowToken atoken = token.appWindowToken;
2276 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002277 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 + token + ". Aborting.");
2279 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2280 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002281 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 + token + ". Aborting.");
2283 return WindowManagerImpl.ADD_APP_EXITING;
2284 }
2285 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2286 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002287 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2289 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2290 }
2291 } else if (attrs.type == TYPE_INPUT_METHOD) {
2292 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002293 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 + attrs.token + ". Aborting.");
2295 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2296 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002297 } else if (attrs.type == TYPE_WALLPAPER) {
2298 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002299 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002300 + attrs.token + ". Aborting.");
2301 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 }
2304
2305 win = new WindowState(session, client, token,
2306 attachedWindow, attrs, viewVisibility);
2307 if (win.mDeathRecipient == null) {
2308 // Client has apparently died, so there is no reason to
2309 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002310 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 + " that is dead, aborting.");
2312 return WindowManagerImpl.ADD_APP_EXITING;
2313 }
2314
2315 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 res = mPolicy.prepareAddWindowLw(win, attrs);
2318 if (res != WindowManagerImpl.ADD_OKAY) {
2319 return res;
2320 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002321
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002322 if (outInputChannel != null) {
2323 String name = win.makeInputChannelName();
2324 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2325 win.mInputChannel = inputChannels[0];
2326 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2327
Jeff Brown928e0542011-01-10 11:17:36 -08002328 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330
2331 // From now on, no exceptions or errors allowed!
2332
2333 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002334
Dianne Hackborn5132b372010-07-29 12:51:35 -07002335 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 if (addToken) {
2338 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 }
2340 win.attach();
2341 mWindowMap.put(client.asBinder(), win);
2342
2343 if (attrs.type == TYPE_APPLICATION_STARTING &&
2344 token.appWindowToken != null) {
2345 token.appWindowToken.startingWindow = win;
2346 }
2347
2348 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 if (attrs.type == TYPE_INPUT_METHOD) {
2351 mInputMethodWindow = win;
2352 addInputMethodWindowToListLocked(win);
2353 imMayMove = false;
2354 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2355 mInputMethodDialogs.add(win);
2356 addWindowToListInOrderLocked(win, true);
2357 adjustInputMethodDialogsLocked();
2358 imMayMove = false;
2359 } else {
2360 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002361 if (attrs.type == TYPE_WALLPAPER) {
2362 mLastWallpaperTimeoutTime = 0;
2363 adjustWallpaperWindowsLocked();
2364 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002365 adjustWallpaperWindowsLocked();
2366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 }
Romain Guy06882f82009-06-10 13:36:04 -07002368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 if (mInTouchMode) {
2374 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2375 }
2376 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2377 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2378 }
Romain Guy06882f82009-06-10 13:36:04 -07002379
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002380 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002382 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2383 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 imMayMove = false;
2385 }
2386 }
Romain Guy06882f82009-06-10 13:36:04 -07002387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002389 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 }
Romain Guy06882f82009-06-10 13:36:04 -07002391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 assignLayersLocked();
2393 // Don't do layout here, the window must call
2394 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 //dump();
2397
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002398 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002399 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002400 }
Jeff Brown349703e2010-06-22 01:27:15 -07002401
Joe Onorato8a9b2202010-02-26 18:56:32 -08002402 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 TAG, "New client " + client.asBinder()
2404 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002405
2406 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2407 reportNewConfig = true;
2408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 }
2410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 if (reportNewConfig) {
2412 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 return res;
2418 }
Romain Guy06882f82009-06-10 13:36:04 -07002419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 public void removeWindow(Session session, IWindow client) {
2421 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002422 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 if (win == null) {
2424 return;
2425 }
2426 removeWindowLocked(session, win);
2427 }
2428 }
Romain Guy06882f82009-06-10 13:36:04 -07002429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 public void removeWindowLocked(Session session, WindowState win) {
2431
Joe Onorato8a9b2202010-02-26 18:56:32 -08002432 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 TAG, "Remove " + win + " client="
2434 + Integer.toHexString(System.identityHashCode(
2435 win.mClient.asBinder()))
2436 + ", surface=" + win.mSurface);
2437
2438 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002439
2440 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002441
Joe Onorato8a9b2202010-02-26 18:56:32 -08002442 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2444 + " mExiting=" + win.mExiting
2445 + " isAnimating=" + win.isAnimating()
2446 + " app-animation="
2447 + (win.mAppToken != null ? win.mAppToken.animation : null)
2448 + " inPendingTransaction="
2449 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2450 + " mDisplayFrozen=" + mDisplayFrozen);
2451 // Visibility of the removed window. Will be used later to update orientation later on.
2452 boolean wasVisible = false;
2453 // First, see if we need to run an animation. If we do, we have
2454 // to hold off on removing the window until the animation is done.
2455 // If the display is frozen, just remove immediately, since the
2456 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002457 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 // If we are not currently running the exit animation, we
2459 // need to see about starting one.
2460 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2463 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2464 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2465 }
2466 // Try starting an animation.
2467 if (applyAnimationLocked(win, transit, false)) {
2468 win.mExiting = true;
2469 }
2470 }
2471 if (win.mExiting || win.isAnimating()) {
2472 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002473 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 win.mExiting = true;
2475 win.mRemoveOnExit = true;
2476 mLayoutNeeded = true;
2477 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2478 performLayoutAndPlaceSurfacesLocked();
2479 if (win.mAppToken != null) {
2480 win.mAppToken.updateReportedVisibilityLocked();
2481 }
2482 //dump();
2483 Binder.restoreCallingIdentity(origId);
2484 return;
2485 }
2486 }
2487
2488 removeWindowInnerLocked(session, win);
2489 // Removing a visible window will effect the computed orientation
2490 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002491 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002492 != mForcedAppOrientation
2493 && updateOrientationFromAppTokensLocked()) {
2494 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 }
2496 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2497 Binder.restoreCallingIdentity(origId);
2498 }
Romain Guy06882f82009-06-10 13:36:04 -07002499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002501 if (win.mRemoved) {
2502 // Nothing to do.
2503 return;
2504 }
2505
2506 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2507 WindowState cwin = win.mChildWindows.get(i);
2508 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2509 + win);
2510 removeWindowInnerLocked(cwin.mSession, cwin);
2511 }
2512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 if (mInputMethodTarget == win) {
2516 moveInputMethodWindowsIfNeededLocked(false);
2517 }
Romain Guy06882f82009-06-10 13:36:04 -07002518
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002519 if (false) {
2520 RuntimeException e = new RuntimeException("here");
2521 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002522 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002523 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 mPolicy.removeWindowLw(win);
2526 win.removeLocked();
2527
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002528 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 mWindowMap.remove(win.mClient.asBinder());
2530 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002531 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002532 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002533 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534
2535 if (mInputMethodWindow == win) {
2536 mInputMethodWindow = null;
2537 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2538 mInputMethodDialogs.remove(win);
2539 }
Romain Guy06882f82009-06-10 13:36:04 -07002540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 final WindowToken token = win.mToken;
2542 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002543 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 token.windows.remove(win);
2545 if (atoken != null) {
2546 atoken.allAppWindows.remove(win);
2547 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002548 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 TAG, "**** Removing window " + win + ": count="
2550 + token.windows.size());
2551 if (token.windows.size() == 0) {
2552 if (!token.explicit) {
2553 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 } else if (atoken != null) {
2555 atoken.firstWindowDrawn = false;
2556 }
2557 }
2558
2559 if (atoken != null) {
2560 if (atoken.startingWindow == win) {
2561 atoken.startingWindow = null;
2562 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2563 // If this is the last window and we had requested a starting
2564 // transition window, well there is no point now.
2565 atoken.startingData = null;
2566 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2567 // If this is the last window except for a starting transition
2568 // window, we need to get rid of the starting transition.
2569 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002570 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 + ": no more real windows");
2572 }
2573 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2574 mH.sendMessage(m);
2575 }
2576 }
Romain Guy06882f82009-06-10 13:36:04 -07002577
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002578 if (win.mAttrs.type == TYPE_WALLPAPER) {
2579 mLastWallpaperTimeoutTime = 0;
2580 adjustWallpaperWindowsLocked();
2581 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002582 adjustWallpaperWindowsLocked();
2583 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 if (!mInLayout) {
2586 assignLayersLocked();
2587 mLayoutNeeded = true;
2588 performLayoutAndPlaceSurfacesLocked();
2589 if (win.mAppToken != null) {
2590 win.mAppToken.updateReportedVisibilityLocked();
2591 }
2592 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002593
2594 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 }
2596
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002597 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2598 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2599 + ": " + msg + " / " + w.mAttrs.getTitle();
2600 if (where != null) {
2601 Slog.i(TAG, str, where);
2602 } else {
2603 Slog.i(TAG, str);
2604 }
2605 }
2606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2608 long origId = Binder.clearCallingIdentity();
2609 try {
2610 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002611 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002613 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 Surface.openTransaction();
2615 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002616 if (SHOW_TRANSACTIONS) logSurface(w,
2617 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 w.mSurface.setTransparentRegionHint(region);
2619 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002620 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 Surface.closeTransaction();
2622 }
2623 }
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(origId);
2627 }
2628 }
2629
2630 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002631 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 Rect visibleInsets) {
2633 long origId = Binder.clearCallingIdentity();
2634 try {
2635 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002636 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637 if (w != null) {
2638 w.mGivenInsetsPending = false;
2639 w.mGivenContentInsets.set(contentInsets);
2640 w.mGivenVisibleInsets.set(visibleInsets);
2641 w.mTouchableInsets = touchableInsets;
2642 mLayoutNeeded = true;
2643 performLayoutAndPlaceSurfacesLocked();
2644 }
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(origId);
2648 }
2649 }
Romain Guy06882f82009-06-10 13:36:04 -07002650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 public void getWindowDisplayFrame(Session session, IWindow client,
2652 Rect outDisplayFrame) {
2653 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002654 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 if (win == null) {
2656 outDisplayFrame.setEmpty();
2657 return;
2658 }
2659 outDisplayFrame.set(win.mDisplayFrame);
2660 }
2661 }
2662
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002663 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2664 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002665 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2666 window.mWallpaperX = x;
2667 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002668 window.mWallpaperXStep = xStep;
2669 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002670 if (updateWallpaperOffsetLocked(window, true)) {
2671 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002672 }
2673 }
2674 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002675
Dianne Hackborn75804932009-10-20 20:15:20 -07002676 void wallpaperCommandComplete(IBinder window, Bundle result) {
2677 synchronized (mWindowMap) {
2678 if (mWaitingOnWallpaper != null &&
2679 mWaitingOnWallpaper.mClient.asBinder() == window) {
2680 mWaitingOnWallpaper = null;
2681 mWindowMap.notifyAll();
2682 }
2683 }
2684 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002685
Dianne Hackborn75804932009-10-20 20:15:20 -07002686 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2687 String action, int x, int y, int z, Bundle extras, boolean sync) {
2688 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2689 || window == mUpperWallpaperTarget) {
2690 boolean doWait = sync;
2691 int curTokenIndex = mWallpaperTokens.size();
2692 while (curTokenIndex > 0) {
2693 curTokenIndex--;
2694 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2695 int curWallpaperIndex = token.windows.size();
2696 while (curWallpaperIndex > 0) {
2697 curWallpaperIndex--;
2698 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2699 try {
2700 wallpaper.mClient.dispatchWallpaperCommand(action,
2701 x, y, z, extras, sync);
2702 // We only want to be synchronous with one wallpaper.
2703 sync = false;
2704 } catch (RemoteException e) {
2705 }
2706 }
2707 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002708
Dianne Hackborn75804932009-10-20 20:15:20 -07002709 if (doWait) {
2710 // XXX Need to wait for result.
2711 }
2712 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002713
Dianne Hackborn75804932009-10-20 20:15:20 -07002714 return null;
2715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 public int relayoutWindow(Session session, IWindow client,
2718 WindowManager.LayoutParams attrs, int requestedWidth,
2719 int requestedHeight, int viewVisibility, boolean insetsPending,
2720 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002721 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 boolean displayed = false;
2723 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002724 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002725 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002728 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002729 if (win == null) {
2730 return 0;
2731 }
2732 win.mRequestedWidth = requestedWidth;
2733 win.mRequestedHeight = requestedHeight;
2734
2735 if (attrs != null) {
2736 mPolicy.adjustWindowParamsLw(attrs);
2737 }
Romain Guy06882f82009-06-10 13:36:04 -07002738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002739 int attrChanges = 0;
2740 int flagChanges = 0;
2741 if (attrs != null) {
2742 flagChanges = win.mAttrs.flags ^= attrs.flags;
2743 attrChanges = win.mAttrs.copyFrom(attrs);
2744 }
2745
Joe Onorato8a9b2202010-02-26 18:56:32 -08002746 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747
2748 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2749 win.mAlpha = attrs.alpha;
2750 }
2751
2752 final boolean scaledWindow =
2753 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2754
2755 if (scaledWindow) {
2756 // requested{Width|Height} Surface's physical size
2757 // attrs.{width|height} Size on screen
2758 win.mHScale = (attrs.width != requestedWidth) ?
2759 (attrs.width / (float)requestedWidth) : 1.0f;
2760 win.mVScale = (attrs.height != requestedHeight) ?
2761 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002762 } else {
2763 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002764 }
2765
2766 boolean imMayMove = (flagChanges&(
2767 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2768 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 boolean focusMayChange = win.mViewVisibility != viewVisibility
2771 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2772 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002773
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002774 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2775 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 win.mRelayoutCalled = true;
2778 final int oldVisibility = win.mViewVisibility;
2779 win.mViewVisibility = viewVisibility;
2780 if (viewVisibility == View.VISIBLE &&
2781 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2782 displayed = !win.isVisibleLw();
2783 if (win.mExiting) {
2784 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002785 if (win.mAnimation != null) {
2786 win.mAnimation.cancel();
2787 win.mAnimation = null;
2788 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 }
2790 if (win.mDestroying) {
2791 win.mDestroying = false;
2792 mDestroySurface.remove(win);
2793 }
2794 if (oldVisibility == View.GONE) {
2795 win.mEnterAnimationPending = true;
2796 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002797 if (displayed) {
2798 if (win.mSurface != null && !win.mDrawPending
2799 && !win.mCommitDrawPending && !mDisplayFrozen
2800 && mPolicy.isScreenOn()) {
2801 applyEnterAnimationLocked(win);
2802 }
2803 if ((win.mAttrs.flags
2804 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2805 if (DEBUG_VISIBILITY) Slog.v(TAG,
2806 "Relayout window turning screen on: " + win);
2807 win.mTurnOnScreen = true;
2808 }
2809 int diff = 0;
2810 if (win.mConfiguration != mCurConfiguration
2811 && (win.mConfiguration == null
2812 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2813 win.mConfiguration = mCurConfiguration;
2814 if (DEBUG_CONFIGURATION) {
2815 Slog.i(TAG, "Window " + win + " visible with new config: "
2816 + win.mConfiguration + " / 0x"
2817 + Integer.toHexString(diff));
2818 }
2819 outConfig.setTo(mCurConfiguration);
2820 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002821 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2823 // To change the format, we need to re-build the surface.
2824 win.destroySurfaceLocked();
2825 displayed = true;
2826 }
2827 try {
2828 Surface surface = win.createSurfaceLocked();
2829 if (surface != null) {
2830 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002831 win.mReportDestroySurface = false;
2832 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002833 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002834 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002836 // For some reason there isn't a surface. Clear the
2837 // caller's object so they see the same state.
2838 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 }
2840 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002841 mInputMonitor.updateInputWindowsLw();
2842
Joe Onorato8a9b2202010-02-26 18:56:32 -08002843 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002844 + client + " (" + win.mAttrs.getTitle() + ")",
2845 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 Binder.restoreCallingIdentity(origId);
2847 return 0;
2848 }
2849 if (displayed) {
2850 focusMayChange = true;
2851 }
2852 if (win.mAttrs.type == TYPE_INPUT_METHOD
2853 && mInputMethodWindow == null) {
2854 mInputMethodWindow = win;
2855 imMayMove = true;
2856 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002857 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2858 && win.mAppToken != null
2859 && win.mAppToken.startingWindow != null) {
2860 // Special handling of starting window over the base
2861 // window of the app: propagate lock screen flags to it,
2862 // to provide the correct semantics while starting.
2863 final int mask =
2864 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002865 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2866 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002867 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2868 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 } else {
2871 win.mEnterAnimationPending = false;
2872 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002873 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002874 + ": mExiting=" + win.mExiting
2875 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 // If we are not currently running the exit animation, we
2877 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002878 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 // Try starting an animation; if there isn't one, we
2880 // can destroy the surface right away.
2881 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2882 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2883 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2884 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002885 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002887 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 } else if (win.isAnimating()) {
2890 // Currently in a hide animation... turn this into
2891 // an exit.
2892 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002893 } else if (win == mWallpaperTarget) {
2894 // If the wallpaper is currently behind this
2895 // window, we need to change both of them inside
2896 // of a transaction to avoid artifacts.
2897 win.mExiting = true;
2898 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 } else {
2900 if (mInputMethodWindow == win) {
2901 mInputMethodWindow = null;
2902 }
2903 win.destroySurfaceLocked();
2904 }
2905 }
2906 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002907
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002908 if (win.mSurface == null || (win.getAttrs().flags
2909 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2910 || win.mSurfacePendingDestroy) {
2911 // We are being called from a local process, which
2912 // means outSurface holds its current surface. Ensure the
2913 // surface object is cleared, but we don't want it actually
2914 // destroyed at this point.
2915 win.mSurfacePendingDestroy = false;
2916 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002917 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002918 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002919 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002920 "Keeping surface, will report destroy: " + win);
2921 win.mReportDestroySurface = true;
2922 outSurface.copyFrom(win.mSurface);
2923 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 }
2925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 if (focusMayChange) {
2927 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2928 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 imMayMove = false;
2930 }
2931 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2932 }
Romain Guy06882f82009-06-10 13:36:04 -07002933
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002934 // updateFocusedWindowLocked() already assigned layers so we only need to
2935 // reassign them at this point if the IM window state gets shuffled
2936 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002939 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2940 // Little hack here -- we -should- be able to rely on the
2941 // function to return true if the IME has moved and needs
2942 // its layer recomputed. However, if the IME was hidden
2943 // and isn't actually moved in the list, its layer may be
2944 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 assignLayers = true;
2946 }
2947 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002948 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002949 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002950 assignLayers = true;
2951 }
2952 }
Romain Guy06882f82009-06-10 13:36:04 -07002953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 mLayoutNeeded = true;
2955 win.mGivenInsetsPending = insetsPending;
2956 if (assignLayers) {
2957 assignLayersLocked();
2958 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002959 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002961 if (displayed && win.mIsWallpaper) {
2962 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002963 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 if (win.mAppToken != null) {
2966 win.mAppToken.updateReportedVisibilityLocked();
2967 }
2968 outFrame.set(win.mFrame);
2969 outContentInsets.set(win.mContentInsets);
2970 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002973 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 + ", requestedHeight=" + requestedHeight
2975 + ", viewVisibility=" + viewVisibility
2976 + "\nRelayout returning frame=" + outFrame
2977 + ", surface=" + outSurface);
2978
Joe Onorato8a9b2202010-02-26 18:56:32 -08002979 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2981
2982 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002983
2984 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 }
2986
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002987 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 sendNewConfiguration();
2989 }
Romain Guy06882f82009-06-10 13:36:04 -07002990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2994 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2995 }
2996
2997 public void finishDrawingWindow(Session session, IWindow client) {
2998 final long origId = Binder.clearCallingIdentity();
2999 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003000 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003002 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3003 adjustWallpaperWindowsLocked();
3004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 mLayoutNeeded = true;
3006 performLayoutAndPlaceSurfacesLocked();
3007 }
3008 }
3009 Binder.restoreCallingIdentity(origId);
3010 }
3011
3012 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003013 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 + (lp != null ? lp.packageName : null)
3015 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3016 if (lp != null && lp.windowAnimations != 0) {
3017 // If this is a system resource, don't try to load it from the
3018 // application resources. It is nice to avoid loading application
3019 // resources if we can.
3020 String packageName = lp.packageName != null ? lp.packageName : "android";
3021 int resId = lp.windowAnimations;
3022 if ((resId&0xFF000000) == 0x01000000) {
3023 packageName = "android";
3024 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003025 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 + packageName);
3027 return AttributeCache.instance().get(packageName, resId,
3028 com.android.internal.R.styleable.WindowAnimation);
3029 }
3030 return null;
3031 }
Romain Guy06882f82009-06-10 13:36:04 -07003032
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003033 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003034 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003035 + packageName + " resId=0x" + Integer.toHexString(resId));
3036 if (packageName != null) {
3037 if ((resId&0xFF000000) == 0x01000000) {
3038 packageName = "android";
3039 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003040 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003041 + packageName);
3042 return AttributeCache.instance().get(packageName, resId,
3043 com.android.internal.R.styleable.WindowAnimation);
3044 }
3045 return null;
3046 }
3047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 private void applyEnterAnimationLocked(WindowState win) {
3049 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3050 if (win.mEnterAnimationPending) {
3051 win.mEnterAnimationPending = false;
3052 transit = WindowManagerPolicy.TRANSIT_ENTER;
3053 }
3054
3055 applyAnimationLocked(win, transit, true);
3056 }
3057
3058 private boolean applyAnimationLocked(WindowState win,
3059 int transit, boolean isEntrance) {
3060 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3061 // If we are trying to apply an animation, but already running
3062 // an animation of the same type, then just leave that one alone.
3063 return true;
3064 }
Romain Guy06882f82009-06-10 13:36:04 -07003065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 // Only apply an animation if the display isn't frozen. If it is
3067 // frozen, there is no reason to animate and it can cause strange
3068 // artifacts when we unfreeze the display if some different animation
3069 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003070 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003071 int anim = mPolicy.selectAnimationLw(win, transit);
3072 int attr = -1;
3073 Animation a = null;
3074 if (anim != 0) {
3075 a = AnimationUtils.loadAnimation(mContext, anim);
3076 } else {
3077 switch (transit) {
3078 case WindowManagerPolicy.TRANSIT_ENTER:
3079 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3080 break;
3081 case WindowManagerPolicy.TRANSIT_EXIT:
3082 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3083 break;
3084 case WindowManagerPolicy.TRANSIT_SHOW:
3085 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3086 break;
3087 case WindowManagerPolicy.TRANSIT_HIDE:
3088 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3089 break;
3090 }
3091 if (attr >= 0) {
3092 a = loadAnimation(win.mAttrs, attr);
3093 }
3094 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003095 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003096 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3097 + " mAnimation=" + win.mAnimation
3098 + " isEntrance=" + isEntrance);
3099 if (a != null) {
3100 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003101 RuntimeException e = null;
3102 if (!HIDE_STACK_CRAWLS) {
3103 e = new RuntimeException();
3104 e.fillInStackTrace();
3105 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003106 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107 }
3108 win.setAnimation(a);
3109 win.mAnimationIsEntrance = isEntrance;
3110 }
3111 } else {
3112 win.clearAnimation();
3113 }
3114
3115 return win.mAnimation != null;
3116 }
3117
3118 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3119 int anim = 0;
3120 Context context = mContext;
3121 if (animAttr >= 0) {
3122 AttributeCache.Entry ent = getCachedAnimations(lp);
3123 if (ent != null) {
3124 context = ent.context;
3125 anim = ent.array.getResourceId(animAttr, 0);
3126 }
3127 }
3128 if (anim != 0) {
3129 return AnimationUtils.loadAnimation(context, anim);
3130 }
3131 return null;
3132 }
Romain Guy06882f82009-06-10 13:36:04 -07003133
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003134 private Animation loadAnimation(String packageName, int resId) {
3135 int anim = 0;
3136 Context context = mContext;
3137 if (resId >= 0) {
3138 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3139 if (ent != null) {
3140 context = ent.context;
3141 anim = resId;
3142 }
3143 }
3144 if (anim != 0) {
3145 return AnimationUtils.loadAnimation(context, anim);
3146 }
3147 return null;
3148 }
3149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 private boolean applyAnimationLocked(AppWindowToken wtoken,
3151 WindowManager.LayoutParams lp, int transit, boolean enter) {
3152 // Only apply an animation if the display isn't frozen. If it is
3153 // frozen, there is no reason to animate and it can cause strange
3154 // artifacts when we unfreeze the display if some different animation
3155 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003156 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003157 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003158 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003159 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003160 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003161 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003162 } else if (mNextAppTransitionPackage != null) {
3163 a = loadAnimation(mNextAppTransitionPackage, enter ?
3164 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003165 } else {
3166 int animAttr = 0;
3167 switch (transit) {
3168 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3169 animAttr = enter
3170 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3171 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3172 break;
3173 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3174 animAttr = enter
3175 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3176 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3177 break;
3178 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3179 animAttr = enter
3180 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3181 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3182 break;
3183 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3184 animAttr = enter
3185 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3186 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3187 break;
3188 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3189 animAttr = enter
3190 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3191 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3192 break;
3193 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3194 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003195 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003196 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3197 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003198 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003199 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003200 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3201 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003202 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003203 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003204 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003205 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3206 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3207 break;
3208 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3209 animAttr = enter
3210 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3211 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3212 break;
3213 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3214 animAttr = enter
3215 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3216 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003217 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003218 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003219 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003220 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003221 + " anim=" + a
3222 + " animAttr=0x" + Integer.toHexString(animAttr)
3223 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 if (a != null) {
3226 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003227 RuntimeException e = null;
3228 if (!HIDE_STACK_CRAWLS) {
3229 e = new RuntimeException();
3230 e.fillInStackTrace();
3231 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003232 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 }
3234 wtoken.setAnimation(a);
3235 }
3236 } else {
3237 wtoken.clearAnimation();
3238 }
3239
3240 return wtoken.animation != null;
3241 }
3242
3243 // -------------------------------------------------------------
3244 // Application Window Tokens
3245 // -------------------------------------------------------------
3246
3247 public void validateAppTokens(List tokens) {
3248 int v = tokens.size()-1;
3249 int m = mAppTokens.size()-1;
3250 while (v >= 0 && m >= 0) {
3251 AppWindowToken wtoken = mAppTokens.get(m);
3252 if (wtoken.removed) {
3253 m--;
3254 continue;
3255 }
3256 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003257 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3259 }
3260 v--;
3261 m--;
3262 }
3263 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003264 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 v--;
3266 }
3267 while (m >= 0) {
3268 AppWindowToken wtoken = mAppTokens.get(m);
3269 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003270 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003271 }
3272 m--;
3273 }
3274 }
3275
3276 boolean checkCallingPermission(String permission, String func) {
3277 // Quick check: if the calling permission is me, it's all okay.
3278 if (Binder.getCallingPid() == Process.myPid()) {
3279 return true;
3280 }
Romain Guy06882f82009-06-10 13:36:04 -07003281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003282 if (mContext.checkCallingPermission(permission)
3283 == PackageManager.PERMISSION_GRANTED) {
3284 return true;
3285 }
3286 String msg = "Permission Denial: " + func + " from pid="
3287 + Binder.getCallingPid()
3288 + ", uid=" + Binder.getCallingUid()
3289 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003290 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 return false;
3292 }
Romain Guy06882f82009-06-10 13:36:04 -07003293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 AppWindowToken findAppWindowToken(IBinder token) {
3295 WindowToken wtoken = mTokenMap.get(token);
3296 if (wtoken == null) {
3297 return null;
3298 }
3299 return wtoken.appWindowToken;
3300 }
Romain Guy06882f82009-06-10 13:36:04 -07003301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 public void addWindowToken(IBinder token, int type) {
3303 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3304 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003305 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 synchronized(mWindowMap) {
3309 WindowToken wtoken = mTokenMap.get(token);
3310 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 return;
3313 }
3314 wtoken = new WindowToken(token, type, true);
3315 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003316 if (type == TYPE_WALLPAPER) {
3317 mWallpaperTokens.add(wtoken);
3318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 }
3320 }
Romain Guy06882f82009-06-10 13:36:04 -07003321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 public void removeWindowToken(IBinder token) {
3323 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3324 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003325 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 }
3327
3328 final long origId = Binder.clearCallingIdentity();
3329 synchronized(mWindowMap) {
3330 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 if (wtoken != null) {
3332 boolean delayed = false;
3333 if (!wtoken.hidden) {
3334 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 final int N = wtoken.windows.size();
3337 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 for (int i=0; i<N; i++) {
3340 WindowState win = wtoken.windows.get(i);
3341
3342 if (win.isAnimating()) {
3343 delayed = true;
3344 }
Romain Guy06882f82009-06-10 13:36:04 -07003345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 if (win.isVisibleNow()) {
3347 applyAnimationLocked(win,
3348 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 changed = true;
3350 }
3351 }
3352
3353 if (changed) {
3354 mLayoutNeeded = true;
3355 performLayoutAndPlaceSurfacesLocked();
3356 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3357 }
Romain Guy06882f82009-06-10 13:36:04 -07003358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 if (delayed) {
3360 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003361 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3362 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 }
3364 }
Romain Guy06882f82009-06-10 13:36:04 -07003365
Jeff Brownc5ed5912010-07-14 18:48:53 -07003366 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003368 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 }
3370 }
3371 Binder.restoreCallingIdentity(origId);
3372 }
3373
3374 public void addAppToken(int addPos, IApplicationToken token,
3375 int groupId, int requestedOrientation, boolean fullscreen) {
3376 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3377 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003378 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 }
Jeff Brown349703e2010-06-22 01:27:15 -07003380
3381 // Get the dispatching timeout here while we are not holding any locks so that it
3382 // can be cached by the AppWindowToken. The timeout value is used later by the
3383 // input dispatcher in code that does hold locks. If we did not cache the value
3384 // here we would run the chance of introducing a deadlock between the window manager
3385 // (which holds locks while updating the input dispatcher state) and the activity manager
3386 // (which holds locks while querying the application token).
3387 long inputDispatchingTimeoutNanos;
3388 try {
3389 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3390 } catch (RemoteException ex) {
3391 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3392 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3393 }
Romain Guy06882f82009-06-10 13:36:04 -07003394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 synchronized(mWindowMap) {
3396 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3397 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003398 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 return;
3400 }
3401 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003402 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 wtoken.groupId = groupId;
3404 wtoken.appFullscreen = fullscreen;
3405 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003406 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003408 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 // Application tokens start out hidden.
3411 wtoken.hidden = true;
3412 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 //dump();
3415 }
3416 }
Romain Guy06882f82009-06-10 13:36:04 -07003417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418 public void setAppGroupId(IBinder token, int groupId) {
3419 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3420 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003421 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 }
3423
3424 synchronized(mWindowMap) {
3425 AppWindowToken wtoken = findAppWindowToken(token);
3426 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003427 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 return;
3429 }
3430 wtoken.groupId = groupId;
3431 }
3432 }
Romain Guy06882f82009-06-10 13:36:04 -07003433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 public int getOrientationFromWindowsLocked() {
3435 int pos = mWindows.size() - 1;
3436 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003437 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 pos--;
3439 if (wtoken.mAppToken != null) {
3440 // We hit an application window. so the orientation will be determined by the
3441 // app window. No point in continuing further.
3442 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3443 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003444 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003445 continue;
3446 }
3447 int req = wtoken.mAttrs.screenOrientation;
3448 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3449 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3450 continue;
3451 } else {
3452 return req;
3453 }
3454 }
3455 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3456 }
Romain Guy06882f82009-06-10 13:36:04 -07003457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003459 int pos = mAppTokens.size() - 1;
3460 int curGroup = 0;
3461 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3462 boolean findingBehind = false;
3463 boolean haveGroup = false;
3464 boolean lastFullscreen = false;
3465 while (pos >= 0) {
3466 AppWindowToken wtoken = mAppTokens.get(pos);
3467 pos--;
3468 // if we're about to tear down this window and not seek for
3469 // the behind activity, don't use it for orientation
3470 if (!findingBehind
3471 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3472 continue;
3473 }
3474
3475 if (!haveGroup) {
3476 // We ignore any hidden applications on the top.
3477 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003478 continue;
3479 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003480 haveGroup = true;
3481 curGroup = wtoken.groupId;
3482 lastOrientation = wtoken.requestedOrientation;
3483 } else if (curGroup != wtoken.groupId) {
3484 // If we have hit a new application group, and the bottom
3485 // of the previous group didn't explicitly say to use
3486 // the orientation behind it, and the last app was
3487 // full screen, then we'll stick with the
3488 // user's orientation.
3489 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3490 && lastFullscreen) {
3491 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003494 int or = wtoken.requestedOrientation;
3495 // If this application is fullscreen, and didn't explicitly say
3496 // to use the orientation behind it, then just take whatever
3497 // orientation it has and ignores whatever is under it.
3498 lastFullscreen = wtoken.appFullscreen;
3499 if (lastFullscreen
3500 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3501 return or;
3502 }
3503 // If this application has requested an explicit orientation,
3504 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003505 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3506 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003507 return or;
3508 }
3509 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3510 }
3511 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 }
Romain Guy06882f82009-06-10 13:36:04 -07003513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003515 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003516 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3517 "updateOrientationFromAppTokens()")) {
3518 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003520
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003521 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003523
3524 synchronized(mWindowMap) {
3525 if (updateOrientationFromAppTokensLocked()) {
3526 if (freezeThisOneIfNeeded != null) {
3527 AppWindowToken wtoken = findAppWindowToken(
3528 freezeThisOneIfNeeded);
3529 if (wtoken != null) {
3530 startAppFreezingScreenLocked(wtoken,
3531 ActivityInfo.CONFIG_ORIENTATION);
3532 }
3533 }
3534 config = computeNewConfigurationLocked();
3535
3536 } else if (currentConfig != null) {
3537 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003538 // state mismatches the activity manager's, update it,
3539 // disregarding font scale, which should remain set to
3540 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003541 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003542 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003543 if (computeNewConfigurationLocked(mTempConfiguration)) {
3544 if (currentConfig.diff(mTempConfiguration) != 0) {
3545 mWaitingForConfig = true;
3546 mLayoutNeeded = true;
3547 startFreezingDisplayLocked();
3548 config = new Configuration(mTempConfiguration);
3549 }
3550 }
3551 }
3552 }
3553
Dianne Hackborncfaef692009-06-15 14:24:44 -07003554 Binder.restoreCallingIdentity(ident);
3555 return config;
3556 }
3557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559 * Determine the new desired orientation of the display, returning
3560 * a non-null new Configuration if it has changed from the current
3561 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3562 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3563 * SCREEN. This will typically be done for you if you call
3564 * sendNewConfiguration().
3565 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 * The orientation is computed from non-application windows first. If none of
3567 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003568 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003569 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3570 * android.os.IBinder)
3571 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003572 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003573 if (mDisplayFrozen) {
3574 // If the display is frozen, some activities may be in the middle
3575 // of restarting, and thus have removed their old window. If the
3576 // window has the flag to hide the lock screen, then the lock screen
3577 // can re-appear and inflict its own orientation on us. Keep the
3578 // orientation stable until this all settles down.
3579 return false;
3580 }
3581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 long ident = Binder.clearCallingIdentity();
3584 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003585 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 mForcedAppOrientation = req;
3589 //send a message to Policy indicating orientation change to take
3590 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003591 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003592 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3593 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3594 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 }
3596 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003597
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003598 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 } finally {
3600 Binder.restoreCallingIdentity(ident);
3601 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 }
Romain Guy06882f82009-06-10 13:36:04 -07003603
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003604 int computeForcedAppOrientationLocked() {
3605 int req = getOrientationFromWindowsLocked();
3606 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3607 req = getOrientationFromAppTokensLocked();
3608 }
3609 return req;
3610 }
Romain Guy06882f82009-06-10 13:36:04 -07003611
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003612 public void setNewConfiguration(Configuration config) {
3613 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3614 "setNewConfiguration()")) {
3615 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3616 }
3617
3618 synchronized(mWindowMap) {
3619 mCurConfiguration = new Configuration(config);
3620 mWaitingForConfig = false;
3621 performLayoutAndPlaceSurfacesLocked();
3622 }
3623 }
3624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3626 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3627 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003628 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 }
Romain Guy06882f82009-06-10 13:36:04 -07003630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 synchronized(mWindowMap) {
3632 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3633 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003634 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 return;
3636 }
Romain Guy06882f82009-06-10 13:36:04 -07003637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 wtoken.requestedOrientation = requestedOrientation;
3639 }
3640 }
Romain Guy06882f82009-06-10 13:36:04 -07003641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 public int getAppOrientation(IApplicationToken token) {
3643 synchronized(mWindowMap) {
3644 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3645 if (wtoken == null) {
3646 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3647 }
Romain Guy06882f82009-06-10 13:36:04 -07003648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 return wtoken.requestedOrientation;
3650 }
3651 }
Romain Guy06882f82009-06-10 13:36:04 -07003652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3654 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3655 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003656 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 }
3658
3659 synchronized(mWindowMap) {
3660 boolean changed = false;
3661 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003662 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 changed = mFocusedApp != null;
3664 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003665 if (changed) {
3666 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 } else {
3669 AppWindowToken newFocus = findAppWindowToken(token);
3670 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003671 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 return;
3673 }
3674 changed = mFocusedApp != newFocus;
3675 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003676 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003677 if (changed) {
3678 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003679 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 }
3681
3682 if (moveFocusNow && changed) {
3683 final long origId = Binder.clearCallingIdentity();
3684 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3685 Binder.restoreCallingIdentity(origId);
3686 }
3687 }
3688 }
3689
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003690 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3692 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003693 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 }
Romain Guy06882f82009-06-10 13:36:04 -07003695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 synchronized(mWindowMap) {
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, "Prepare app transition: transit=" + transit
3699 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003700 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003701 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3702 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003704 } else if (!alwaysKeepCurrent) {
3705 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3706 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3707 // Opening a new task always supersedes a close for the anim.
3708 mNextAppTransition = transit;
3709 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3710 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3711 // Opening a new activity always supersedes a close for the anim.
3712 mNextAppTransition = transit;
3713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 }
3715 mAppTransitionReady = false;
3716 mAppTransitionTimeout = false;
3717 mStartingIconInTransition = false;
3718 mSkipAppTransitionAnimation = false;
3719 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3720 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3721 5000);
3722 }
3723 }
3724 }
3725
3726 public int getPendingAppTransition() {
3727 return mNextAppTransition;
3728 }
Romain Guy06882f82009-06-10 13:36:04 -07003729
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003730 public void overridePendingAppTransition(String packageName,
3731 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003732 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003733 mNextAppTransitionPackage = packageName;
3734 mNextAppTransitionEnter = enterAnim;
3735 mNextAppTransitionExit = exitAnim;
3736 }
3737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 public void executeAppTransition() {
3740 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3741 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003742 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 }
Romain Guy06882f82009-06-10 13:36:04 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003746 if (DEBUG_APP_TRANSITIONS) {
3747 RuntimeException e = new RuntimeException("here");
3748 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003749 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003750 + mNextAppTransition, e);
3751 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003752 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 mAppTransitionReady = true;
3754 final long origId = Binder.clearCallingIdentity();
3755 performLayoutAndPlaceSurfacesLocked();
3756 Binder.restoreCallingIdentity(origId);
3757 }
3758 }
3759 }
3760
3761 public void setAppStartingWindow(IBinder token, String pkg,
3762 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003763 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3765 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003766 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 }
3768
3769 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003770 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3772 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 AppWindowToken wtoken = findAppWindowToken(token);
3775 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003776 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 return;
3778 }
3779
3780 // If the display is frozen, we won't do anything until the
3781 // actual window is displayed so there is no reason to put in
3782 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003783 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 return;
3785 }
Romain Guy06882f82009-06-10 13:36:04 -07003786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 if (wtoken.startingData != null) {
3788 return;
3789 }
Romain Guy06882f82009-06-10 13:36:04 -07003790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 if (transferFrom != null) {
3792 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3793 if (ttoken != null) {
3794 WindowState startingWindow = ttoken.startingWindow;
3795 if (startingWindow != null) {
3796 if (mStartingIconInTransition) {
3797 // In this case, the starting icon has already
3798 // been displayed, so start letting windows get
3799 // shown immediately without any more transitions.
3800 mSkipAppTransitionAnimation = true;
3801 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003802 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 "Moving existing starting from " + ttoken
3804 + " to " + wtoken);
3805 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 // Transfer the starting window over to the new
3808 // token.
3809 wtoken.startingData = ttoken.startingData;
3810 wtoken.startingView = ttoken.startingView;
3811 wtoken.startingWindow = startingWindow;
3812 ttoken.startingData = null;
3813 ttoken.startingView = null;
3814 ttoken.startingWindow = null;
3815 ttoken.startingMoved = true;
3816 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003817 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003819 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003820 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003822 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003823 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3824 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 ttoken.windows.remove(startingWindow);
3826 ttoken.allAppWindows.remove(startingWindow);
3827 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 // Propagate other interesting state between the
3830 // tokens. If the old token is displayed, we should
3831 // immediately force the new one to be displayed. If
3832 // it is animating, we need to move that animation to
3833 // the new one.
3834 if (ttoken.allDrawn) {
3835 wtoken.allDrawn = true;
3836 }
3837 if (ttoken.firstWindowDrawn) {
3838 wtoken.firstWindowDrawn = true;
3839 }
3840 if (!ttoken.hidden) {
3841 wtoken.hidden = false;
3842 wtoken.hiddenRequested = false;
3843 wtoken.willBeHidden = false;
3844 }
3845 if (wtoken.clientHidden != ttoken.clientHidden) {
3846 wtoken.clientHidden = ttoken.clientHidden;
3847 wtoken.sendAppVisibilityToClients();
3848 }
3849 if (ttoken.animation != null) {
3850 wtoken.animation = ttoken.animation;
3851 wtoken.animating = ttoken.animating;
3852 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3853 ttoken.animation = null;
3854 ttoken.animLayerAdjustment = 0;
3855 wtoken.updateLayers();
3856 ttoken.updateLayers();
3857 }
Romain Guy06882f82009-06-10 13:36:04 -07003858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 mLayoutNeeded = true;
3861 performLayoutAndPlaceSurfacesLocked();
3862 Binder.restoreCallingIdentity(origId);
3863 return;
3864 } else if (ttoken.startingData != null) {
3865 // The previous app was getting ready to show a
3866 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003867 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 "Moving pending starting from " + ttoken
3869 + " to " + wtoken);
3870 wtoken.startingData = ttoken.startingData;
3871 ttoken.startingData = null;
3872 ttoken.startingMoved = true;
3873 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3874 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3875 // want to process the message ASAP, before any other queued
3876 // messages.
3877 mH.sendMessageAtFrontOfQueue(m);
3878 return;
3879 }
3880 }
3881 }
3882
3883 // There is no existing starting window, and the caller doesn't
3884 // want us to create one, so that's it!
3885 if (!createIfNeeded) {
3886 return;
3887 }
Romain Guy06882f82009-06-10 13:36:04 -07003888
Dianne Hackborn284ac932009-08-28 10:34:25 -07003889 // If this is a translucent or wallpaper window, then don't
3890 // show a starting window -- the current effect (a full-screen
3891 // opaque starting window that fades away to the real contents
3892 // when it is ready) does not work for this.
3893 if (theme != 0) {
3894 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3895 com.android.internal.R.styleable.Window);
3896 if (ent.array.getBoolean(
3897 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3898 return;
3899 }
3900 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003901 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3902 return;
3903 }
3904 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003905 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3906 return;
3907 }
3908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 mStartingIconInTransition = true;
3911 wtoken.startingData = new StartingData(
3912 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003913 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3915 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3916 // want to process the message ASAP, before any other queued
3917 // messages.
3918 mH.sendMessageAtFrontOfQueue(m);
3919 }
3920 }
3921
3922 public void setAppWillBeHidden(IBinder token) {
3923 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3924 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003925 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003926 }
3927
3928 AppWindowToken wtoken;
3929
3930 synchronized(mWindowMap) {
3931 wtoken = findAppWindowToken(token);
3932 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003933 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 -08003934 return;
3935 }
3936 wtoken.willBeHidden = true;
3937 }
3938 }
Romain Guy06882f82009-06-10 13:36:04 -07003939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3941 boolean visible, int transit, boolean performLayout) {
3942 boolean delayed = false;
3943
3944 if (wtoken.clientHidden == visible) {
3945 wtoken.clientHidden = !visible;
3946 wtoken.sendAppVisibilityToClients();
3947 }
Romain Guy06882f82009-06-10 13:36:04 -07003948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 wtoken.willBeHidden = false;
3950 if (wtoken.hidden == visible) {
3951 final int N = wtoken.allAppWindows.size();
3952 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003953 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3955 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003958
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003959 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 if (wtoken.animation == sDummyAnimation) {
3961 wtoken.animation = null;
3962 }
3963 applyAnimationLocked(wtoken, lp, transit, visible);
3964 changed = true;
3965 if (wtoken.animation != null) {
3966 delayed = runningAppAnimation = true;
3967 }
3968 }
Romain Guy06882f82009-06-10 13:36:04 -07003969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 for (int i=0; i<N; i++) {
3971 WindowState win = wtoken.allAppWindows.get(i);
3972 if (win == wtoken.startingWindow) {
3973 continue;
3974 }
3975
3976 if (win.isAnimating()) {
3977 delayed = true;
3978 }
Romain Guy06882f82009-06-10 13:36:04 -07003979
Joe Onorato8a9b2202010-02-26 18:56:32 -08003980 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 //win.dump(" ");
3982 if (visible) {
3983 if (!win.isVisibleNow()) {
3984 if (!runningAppAnimation) {
3985 applyAnimationLocked(win,
3986 WindowManagerPolicy.TRANSIT_ENTER, true);
3987 }
3988 changed = true;
3989 }
3990 } else if (win.isVisibleNow()) {
3991 if (!runningAppAnimation) {
3992 applyAnimationLocked(win,
3993 WindowManagerPolicy.TRANSIT_EXIT, false);
3994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 changed = true;
3996 }
3997 }
3998
3999 wtoken.hidden = wtoken.hiddenRequested = !visible;
4000 if (!visible) {
4001 unsetAppFreezingScreenLocked(wtoken, true, true);
4002 } else {
4003 // If we are being set visible, and the starting window is
4004 // not yet displayed, then make sure it doesn't get displayed.
4005 WindowState swin = wtoken.startingWindow;
4006 if (swin != null && (swin.mDrawPending
4007 || swin.mCommitDrawPending)) {
4008 swin.mPolicyVisibility = false;
4009 swin.mPolicyVisibilityAfterAnim = false;
4010 }
4011 }
Romain Guy06882f82009-06-10 13:36:04 -07004012
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4015 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004016
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004017 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004018 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004019 if (performLayout) {
4020 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
4021 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07004022 } else {
4023 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004025 }
4026 }
4027
4028 if (wtoken.animation != null) {
4029 delayed = true;
4030 }
Romain Guy06882f82009-06-10 13:36:04 -07004031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004032 return delayed;
4033 }
4034
4035 public void setAppVisibility(IBinder token, boolean visible) {
4036 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4037 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004038 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039 }
4040
4041 AppWindowToken wtoken;
4042
4043 synchronized(mWindowMap) {
4044 wtoken = findAppWindowToken(token);
4045 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004046 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004047 return;
4048 }
4049
4050 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004051 RuntimeException e = null;
4052 if (!HIDE_STACK_CRAWLS) {
4053 e = new RuntimeException();
4054 e.fillInStackTrace();
4055 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004056 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 + "): mNextAppTransition=" + mNextAppTransition
4058 + " hidden=" + wtoken.hidden
4059 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4060 }
Romain Guy06882f82009-06-10 13:36:04 -07004061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004062 // If we are preparing an app transition, then delay changing
4063 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004064 if (!mDisplayFrozen && mPolicy.isScreenOn()
4065 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 // Already in requested state, don't do anything more.
4067 if (wtoken.hiddenRequested != visible) {
4068 return;
4069 }
4070 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004071
Joe Onorato8a9b2202010-02-26 18:56:32 -08004072 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004073 TAG, "Setting dummy animation on: " + wtoken);
4074 wtoken.setDummyAnimation();
4075 mOpeningApps.remove(wtoken);
4076 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004077 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 wtoken.inPendingTransaction = true;
4079 if (visible) {
4080 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 wtoken.startingDisplayed = false;
4082 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004083
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004084 // If the token is currently hidden (should be the
4085 // common case), then we need to set up to wait for
4086 // its windows to be ready.
4087 if (wtoken.hidden) {
4088 wtoken.allDrawn = false;
4089 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004090
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004091 if (wtoken.clientHidden) {
4092 // In the case where we are making an app visible
4093 // but holding off for a transition, we still need
4094 // to tell the client to make its windows visible so
4095 // they get drawn. Otherwise, we will wait on
4096 // performing the transition until all windows have
4097 // been drawn, they never will be, and we are sad.
4098 wtoken.clientHidden = false;
4099 wtoken.sendAppVisibilityToClients();
4100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 }
4102 } else {
4103 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004104
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004105 // If the token is currently visible (should be the
4106 // common case), then set up to wait for it to be hidden.
4107 if (!wtoken.hidden) {
4108 wtoken.waitingToHide = true;
4109 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 }
4111 return;
4112 }
Romain Guy06882f82009-06-10 13:36:04 -07004113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004115 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 wtoken.updateReportedVisibilityLocked();
4117 Binder.restoreCallingIdentity(origId);
4118 }
4119 }
4120
4121 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4122 boolean unfreezeSurfaceNow, boolean force) {
4123 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004124 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 + " force=" + force);
4126 final int N = wtoken.allAppWindows.size();
4127 boolean unfrozeWindows = false;
4128 for (int i=0; i<N; i++) {
4129 WindowState w = wtoken.allAppWindows.get(i);
4130 if (w.mAppFreezing) {
4131 w.mAppFreezing = false;
4132 if (w.mSurface != null && !w.mOrientationChanging) {
4133 w.mOrientationChanging = true;
4134 }
4135 unfrozeWindows = true;
4136 }
4137 }
4138 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004139 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 wtoken.freezingScreen = false;
4141 mAppsFreezingScreen--;
4142 }
4143 if (unfreezeSurfaceNow) {
4144 if (unfrozeWindows) {
4145 mLayoutNeeded = true;
4146 performLayoutAndPlaceSurfacesLocked();
4147 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004148 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 }
4150 }
4151 }
Romain Guy06882f82009-06-10 13:36:04 -07004152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4154 int configChanges) {
4155 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004156 RuntimeException e = null;
4157 if (!HIDE_STACK_CRAWLS) {
4158 e = new RuntimeException();
4159 e.fillInStackTrace();
4160 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004161 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 + ": hidden=" + wtoken.hidden + " freezing="
4163 + wtoken.freezingScreen, e);
4164 }
4165 if (!wtoken.hiddenRequested) {
4166 if (!wtoken.freezingScreen) {
4167 wtoken.freezingScreen = true;
4168 mAppsFreezingScreen++;
4169 if (mAppsFreezingScreen == 1) {
4170 startFreezingDisplayLocked();
4171 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4172 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4173 5000);
4174 }
4175 }
4176 final int N = wtoken.allAppWindows.size();
4177 for (int i=0; i<N; i++) {
4178 WindowState w = wtoken.allAppWindows.get(i);
4179 w.mAppFreezing = true;
4180 }
4181 }
4182 }
Romain Guy06882f82009-06-10 13:36:04 -07004183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 public void startAppFreezingScreen(IBinder token, int configChanges) {
4185 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4186 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004187 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 }
4189
4190 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004191 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004192 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 return;
4194 }
Romain Guy06882f82009-06-10 13:36:04 -07004195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004196 AppWindowToken wtoken = findAppWindowToken(token);
4197 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 return;
4200 }
4201 final long origId = Binder.clearCallingIdentity();
4202 startAppFreezingScreenLocked(wtoken, configChanges);
4203 Binder.restoreCallingIdentity(origId);
4204 }
4205 }
Romain Guy06882f82009-06-10 13:36:04 -07004206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 public void stopAppFreezingScreen(IBinder token, boolean force) {
4208 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4209 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004210 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 }
4212
4213 synchronized(mWindowMap) {
4214 AppWindowToken wtoken = findAppWindowToken(token);
4215 if (wtoken == null || wtoken.appToken == null) {
4216 return;
4217 }
4218 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004219 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4221 unsetAppFreezingScreenLocked(wtoken, true, force);
4222 Binder.restoreCallingIdentity(origId);
4223 }
4224 }
Romain Guy06882f82009-06-10 13:36:04 -07004225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 public void removeAppToken(IBinder token) {
4227 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4228 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004229 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004230 }
4231
4232 AppWindowToken wtoken = null;
4233 AppWindowToken startingToken = null;
4234 boolean delayed = false;
4235
4236 final long origId = Binder.clearCallingIdentity();
4237 synchronized(mWindowMap) {
4238 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004240 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004241 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004242 wtoken.inPendingTransaction = false;
4243 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004244 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 if (mClosingApps.contains(wtoken)) {
4246 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004247 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004249 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 delayed = true;
4251 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004252 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004253 TAG, "Removing app " + wtoken + " delayed=" + delayed
4254 + " animation=" + wtoken.animation
4255 + " animating=" + wtoken.animating);
4256 if (delayed) {
4257 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004258 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4259 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004261 } else {
4262 // Make sure there is no animation running on this token,
4263 // so any windows associated with it will be removed as
4264 // soon as their animations are complete
4265 wtoken.animation = null;
4266 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004268 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4269 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004270 mAppTokens.remove(wtoken);
4271 wtoken.removed = true;
4272 if (wtoken.startingData != null) {
4273 startingToken = wtoken;
4274 }
4275 unsetAppFreezingScreenLocked(wtoken, true, true);
4276 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004277 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 mFocusedApp = null;
4279 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004280 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 }
4282 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004283 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 }
Romain Guy06882f82009-06-10 13:36:04 -07004285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 if (!delayed && wtoken != null) {
4287 wtoken.updateReportedVisibilityLocked();
4288 }
4289 }
4290 Binder.restoreCallingIdentity(origId);
4291
4292 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004293 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 + startingToken + ": app token removed");
4295 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4296 mH.sendMessage(m);
4297 }
4298 }
4299
4300 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4301 final int NW = token.windows.size();
4302 for (int i=0; i<NW; i++) {
4303 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004304 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004306 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 int j = win.mChildWindows.size();
4308 while (j > 0) {
4309 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004310 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004311 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004312 "Tmp removing child window " + cwin);
4313 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 }
4315 }
4316 return NW > 0;
4317 }
4318
4319 void dumpAppTokensLocked() {
4320 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004321 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
4323 }
Romain Guy06882f82009-06-10 13:36:04 -07004324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 void dumpWindowsLocked() {
4326 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004327 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 }
4329 }
Romain Guy06882f82009-06-10 13:36:04 -07004330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 private int findWindowOffsetLocked(int tokenPos) {
4332 final int NW = mWindows.size();
4333
4334 if (tokenPos >= mAppTokens.size()) {
4335 int i = NW;
4336 while (i > 0) {
4337 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004338 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 if (win.getAppToken() != null) {
4340 return i+1;
4341 }
4342 }
4343 }
4344
4345 while (tokenPos > 0) {
4346 // Find the first app token below the new position that has
4347 // a window displayed.
4348 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004349 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004351 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004352 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004353 "Skipping token -- currently sending to bottom");
4354 tokenPos--;
4355 continue;
4356 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 int i = wtoken.windows.size();
4358 while (i > 0) {
4359 i--;
4360 WindowState win = wtoken.windows.get(i);
4361 int j = win.mChildWindows.size();
4362 while (j > 0) {
4363 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004364 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004365 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 for (int pos=NW-1; pos>=0; pos--) {
4367 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004368 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 "Found child win @" + (pos+1));
4370 return pos+1;
4371 }
4372 }
4373 }
4374 }
4375 for (int pos=NW-1; pos>=0; pos--) {
4376 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004377 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 return pos+1;
4379 }
4380 }
4381 }
4382 tokenPos--;
4383 }
4384
4385 return 0;
4386 }
4387
4388 private final int reAddWindowLocked(int index, WindowState win) {
4389 final int NCW = win.mChildWindows.size();
4390 boolean added = false;
4391 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004392 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004393 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004394 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004395 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004396 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004397 mWindows.add(index, win);
4398 index++;
4399 added = true;
4400 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004401 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004402 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004403 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 mWindows.add(index, cwin);
4405 index++;
4406 }
4407 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004408 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004409 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004410 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 mWindows.add(index, win);
4412 index++;
4413 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004414 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 return index;
4416 }
Romain Guy06882f82009-06-10 13:36:04 -07004417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4419 final int NW = token.windows.size();
4420 for (int i=0; i<NW; i++) {
4421 index = reAddWindowLocked(index, token.windows.get(i));
4422 }
4423 return index;
4424 }
4425
4426 public void moveAppToken(int index, IBinder token) {
4427 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4428 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004429 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004430 }
4431
4432 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004433 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004434 if (DEBUG_REORDER) dumpAppTokensLocked();
4435 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004436 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4437 "Start moving token " + wtoken + " initially at "
4438 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004440 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 + token + " (" + wtoken + ")");
4442 return;
4443 }
4444 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004446 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004450 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 if (DEBUG_REORDER) dumpWindowsLocked();
4452 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004453 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 if (DEBUG_REORDER) dumpWindowsLocked();
4455 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004456 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457 if (DEBUG_REORDER) dumpWindowsLocked();
4458 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 mLayoutNeeded = true;
4460 performLayoutAndPlaceSurfacesLocked();
4461 }
4462 Binder.restoreCallingIdentity(origId);
4463 }
4464 }
4465
4466 private void removeAppTokensLocked(List<IBinder> tokens) {
4467 // XXX This should be done more efficiently!
4468 // (take advantage of the fact that both lists should be
4469 // ordered in the same way.)
4470 int N = tokens.size();
4471 for (int i=0; i<N; i++) {
4472 IBinder token = tokens.get(i);
4473 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004474 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4475 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004477 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 + token + " (" + wtoken + ")");
4479 i--;
4480 N--;
4481 }
4482 }
4483 }
4484
Dianne Hackborna8f60182009-09-01 19:01:50 -07004485 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4486 boolean updateFocusAndLayout) {
4487 // First remove all of the windows from the list.
4488 tmpRemoveAppWindowsLocked(wtoken);
4489
4490 // Where to start adding?
4491 int pos = findWindowOffsetLocked(tokenPos);
4492
4493 // And now add them back at the correct place.
4494 pos = reAddAppWindowsLocked(pos, wtoken);
4495
4496 if (updateFocusAndLayout) {
4497 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4498 assignLayersLocked();
4499 }
4500 mLayoutNeeded = true;
4501 performLayoutAndPlaceSurfacesLocked();
4502 }
4503 }
4504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4506 // First remove all of the windows from the list.
4507 final int N = tokens.size();
4508 int i;
4509 for (i=0; i<N; i++) {
4510 WindowToken token = mTokenMap.get(tokens.get(i));
4511 if (token != null) {
4512 tmpRemoveAppWindowsLocked(token);
4513 }
4514 }
4515
4516 // Where to start adding?
4517 int pos = findWindowOffsetLocked(tokenPos);
4518
4519 // And now add them back at the correct place.
4520 for (i=0; i<N; i++) {
4521 WindowToken token = mTokenMap.get(tokens.get(i));
4522 if (token != null) {
4523 pos = reAddAppWindowsLocked(pos, token);
4524 }
4525 }
4526
Dianne Hackborna8f60182009-09-01 19:01:50 -07004527 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4528 assignLayersLocked();
4529 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 mLayoutNeeded = true;
4531 performLayoutAndPlaceSurfacesLocked();
4532
4533 //dump();
4534 }
4535
4536 public void moveAppTokensToTop(List<IBinder> tokens) {
4537 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4538 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004539 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 }
4541
4542 final long origId = Binder.clearCallingIdentity();
4543 synchronized(mWindowMap) {
4544 removeAppTokensLocked(tokens);
4545 final int N = tokens.size();
4546 for (int i=0; i<N; i++) {
4547 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4548 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004549 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4550 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004552 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004553 mToTopApps.remove(wt);
4554 mToBottomApps.remove(wt);
4555 mToTopApps.add(wt);
4556 wt.sendingToBottom = false;
4557 wt.sendingToTop = true;
4558 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004559 }
4560 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004561
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004562 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004563 moveAppWindowsLocked(tokens, mAppTokens.size());
4564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 }
4566 Binder.restoreCallingIdentity(origId);
4567 }
4568
4569 public void moveAppTokensToBottom(List<IBinder> tokens) {
4570 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4571 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004572 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 }
4574
4575 final long origId = Binder.clearCallingIdentity();
4576 synchronized(mWindowMap) {
4577 removeAppTokensLocked(tokens);
4578 final int N = tokens.size();
4579 int pos = 0;
4580 for (int i=0; i<N; i++) {
4581 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4582 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004583 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4584 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004585 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004586 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004587 mToTopApps.remove(wt);
4588 mToBottomApps.remove(wt);
4589 mToBottomApps.add(i, wt);
4590 wt.sendingToTop = false;
4591 wt.sendingToBottom = true;
4592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 pos++;
4594 }
4595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004596
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004597 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004598 moveAppWindowsLocked(tokens, 0);
4599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 }
4601 Binder.restoreCallingIdentity(origId);
4602 }
4603
4604 // -------------------------------------------------------------
4605 // Misc IWindowSession methods
4606 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004607
Jim Miller284b62e2010-06-08 14:27:42 -07004608 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004609 {
Jim Miller284b62e2010-06-08 14:27:42 -07004610 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4611 // called before DevicePolicyManagerService has started.
4612 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4613 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4614 Context.DEVICE_POLICY_SERVICE);
4615 if (dpm != null) {
4616 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4617 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4618 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4619 }
Jim Millerd6b57052010-06-07 17:52:42 -07004620 }
Jim Miller284b62e2010-06-08 14:27:42 -07004621 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004622 }
4623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004625 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004626 != PackageManager.PERMISSION_GRANTED) {
4627 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4628 }
Jim Millerd6b57052010-06-07 17:52:42 -07004629
Jim Miller284b62e2010-06-08 14:27:42 -07004630 synchronized (mKeyguardTokenWatcher) {
4631 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
4634
4635 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004636 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004637 != PackageManager.PERMISSION_GRANTED) {
4638 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640
Jim Miller284b62e2010-06-08 14:27:42 -07004641 synchronized (mKeyguardTokenWatcher) {
4642 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004643
Jim Miller284b62e2010-06-08 14:27:42 -07004644 if (!mKeyguardTokenWatcher.isAcquired()) {
4645 // If we are the last one to reenable the keyguard wait until
4646 // we have actually finished reenabling until returning.
4647 // It is possible that reenableKeyguard() can be called before
4648 // the previous disableKeyguard() is handled, in which case
4649 // neither mKeyguardTokenWatcher.acquired() or released() would
4650 // be called. In that case mKeyguardDisabled will be false here
4651 // and we have nothing to wait for.
4652 while (mKeyguardDisabled) {
4653 try {
4654 mKeyguardTokenWatcher.wait();
4655 } catch (InterruptedException e) {
4656 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 }
4658 }
4659 }
4660 }
4661 }
4662
4663 /**
4664 * @see android.app.KeyguardManager#exitKeyguardSecurely
4665 */
4666 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004667 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004668 != PackageManager.PERMISSION_GRANTED) {
4669 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4670 }
4671 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4672 public void onKeyguardExitResult(boolean success) {
4673 try {
4674 callback.onKeyguardExitResult(success);
4675 } catch (RemoteException e) {
4676 // Client has died, we don't care.
4677 }
4678 }
4679 });
4680 }
4681
4682 public boolean inKeyguardRestrictedInputMode() {
4683 return mPolicy.inKeyguardRestrictedKeyInputMode();
4684 }
Romain Guy06882f82009-06-10 13:36:04 -07004685
Dianne Hackbornffa42482009-09-23 22:20:11 -07004686 public void closeSystemDialogs(String reason) {
4687 synchronized(mWindowMap) {
4688 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004689 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004690 if (w.mSurface != null) {
4691 try {
4692 w.mClient.closeSystemDialogs(reason);
4693 } catch (RemoteException e) {
4694 }
4695 }
4696 }
4697 }
4698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700 static float fixScale(float scale) {
4701 if (scale < 0) scale = 0;
4702 else if (scale > 20) scale = 20;
4703 return Math.abs(scale);
4704 }
Romain Guy06882f82009-06-10 13:36:04 -07004705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 public void setAnimationScale(int which, float scale) {
4707 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4708 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004709 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 }
4711
4712 if (scale < 0) scale = 0;
4713 else if (scale > 20) scale = 20;
4714 scale = Math.abs(scale);
4715 switch (which) {
4716 case 0: mWindowAnimationScale = fixScale(scale); break;
4717 case 1: mTransitionAnimationScale = fixScale(scale); break;
4718 }
Romain Guy06882f82009-06-10 13:36:04 -07004719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 // Persist setting
4721 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4722 }
Romain Guy06882f82009-06-10 13:36:04 -07004723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 public void setAnimationScales(float[] scales) {
4725 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4726 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004727 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 }
4729
4730 if (scales != null) {
4731 if (scales.length >= 1) {
4732 mWindowAnimationScale = fixScale(scales[0]);
4733 }
4734 if (scales.length >= 2) {
4735 mTransitionAnimationScale = fixScale(scales[1]);
4736 }
4737 }
Romain Guy06882f82009-06-10 13:36:04 -07004738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004739 // Persist setting
4740 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4741 }
Romain Guy06882f82009-06-10 13:36:04 -07004742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004743 public float getAnimationScale(int which) {
4744 switch (which) {
4745 case 0: return mWindowAnimationScale;
4746 case 1: return mTransitionAnimationScale;
4747 }
4748 return 0;
4749 }
Romain Guy06882f82009-06-10 13:36:04 -07004750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004751 public float[] getAnimationScales() {
4752 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4753 }
Romain Guy06882f82009-06-10 13:36:04 -07004754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004755 public int getSwitchState(int sw) {
4756 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4757 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004758 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004759 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004760 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004761 }
Romain Guy06882f82009-06-10 13:36:04 -07004762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004763 public int getSwitchStateForDevice(int devid, int sw) {
4764 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4765 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004766 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004768 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 }
Romain Guy06882f82009-06-10 13:36:04 -07004770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004771 public int getScancodeState(int sw) {
4772 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4773 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004774 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004775 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004776 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004777 }
Romain Guy06882f82009-06-10 13:36:04 -07004778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004779 public int getScancodeStateForDevice(int devid, int sw) {
4780 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4781 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004782 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004784 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004785 }
Romain Guy06882f82009-06-10 13:36:04 -07004786
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004787 public int getTrackballScancodeState(int sw) {
4788 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4789 "getTrackballScancodeState()")) {
4790 throw new SecurityException("Requires READ_INPUT_STATE permission");
4791 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004792 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004793 }
4794
4795 public int getDPadScancodeState(int sw) {
4796 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4797 "getDPadScancodeState()")) {
4798 throw new SecurityException("Requires READ_INPUT_STATE permission");
4799 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004800 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004801 }
4802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 public int getKeycodeState(int sw) {
4804 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4805 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004806 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004808 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004809 }
Romain Guy06882f82009-06-10 13:36:04 -07004810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 public int getKeycodeStateForDevice(int devid, int sw) {
4812 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4813 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004814 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004816 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004817 }
Romain Guy06882f82009-06-10 13:36:04 -07004818
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004819 public int getTrackballKeycodeState(int sw) {
4820 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4821 "getTrackballKeycodeState()")) {
4822 throw new SecurityException("Requires READ_INPUT_STATE permission");
4823 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004824 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004825 }
4826
4827 public int getDPadKeycodeState(int sw) {
4828 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4829 "getDPadKeycodeState()")) {
4830 throw new SecurityException("Requires READ_INPUT_STATE permission");
4831 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004832 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004833 }
Jeff Browna41ca772010-08-11 14:46:32 -07004834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004836 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 }
Romain Guy06882f82009-06-10 13:36:04 -07004838
Jeff Browna41ca772010-08-11 14:46:32 -07004839 public InputChannel monitorInput(String inputChannelName) {
4840 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4841 "monitorInput()")) {
4842 throw new SecurityException("Requires READ_INPUT_STATE permission");
4843 }
4844 return mInputManager.monitorInput(inputChannelName);
4845 }
4846
Jeff Brown8d608662010-08-30 03:02:23 -07004847 public InputDevice getInputDevice(int deviceId) {
4848 return mInputManager.getInputDevice(deviceId);
4849 }
4850
4851 public int[] getInputDeviceIds() {
4852 return mInputManager.getInputDeviceIds();
4853 }
4854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 public void enableScreenAfterBoot() {
4856 synchronized(mWindowMap) {
4857 if (mSystemBooted) {
4858 return;
4859 }
4860 mSystemBooted = true;
4861 }
Romain Guy06882f82009-06-10 13:36:04 -07004862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 performEnableScreen();
4864 }
Romain Guy06882f82009-06-10 13:36:04 -07004865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 public void enableScreenIfNeededLocked() {
4867 if (mDisplayEnabled) {
4868 return;
4869 }
4870 if (!mSystemBooted) {
4871 return;
4872 }
4873 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4874 }
Romain Guy06882f82009-06-10 13:36:04 -07004875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 public void performEnableScreen() {
4877 synchronized(mWindowMap) {
4878 if (mDisplayEnabled) {
4879 return;
4880 }
4881 if (!mSystemBooted) {
4882 return;
4883 }
Romain Guy06882f82009-06-10 13:36:04 -07004884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004885 // Don't enable the screen until all existing windows
4886 // have been drawn.
4887 final int N = mWindows.size();
4888 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004889 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004890 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 return;
4892 }
4893 }
Romain Guy06882f82009-06-10 13:36:04 -07004894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 mDisplayEnabled = true;
4896 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004897 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 StringWriter sw = new StringWriter();
4899 PrintWriter pw = new PrintWriter(sw);
4900 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004901 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 }
4903 try {
4904 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4905 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004906 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004907 Parcel data = Parcel.obtain();
4908 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4909 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4910 data, null, 0);
4911 data.recycle();
4912 }
4913 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004914 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 }
4916 }
Romain Guy06882f82009-06-10 13:36:04 -07004917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004918 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004921 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4922 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004923 }
Romain Guy06882f82009-06-10 13:36:04 -07004924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 public void setInTouchMode(boolean mode) {
4926 synchronized(mWindowMap) {
4927 mInTouchMode = mode;
4928 }
4929 }
4930
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004931 // TODO: more accounting of which pid(s) turned it on, keep count,
4932 // only allow disables from pids which have count on, etc.
4933 public void showStrictModeViolation(boolean on) {
4934 int pid = Binder.getCallingPid();
4935 synchronized(mWindowMap) {
4936 // Ignoring requests to enable the red border from clients
4937 // which aren't on screen. (e.g. Broadcast Receivers in
4938 // the background..)
4939 if (on) {
4940 boolean isVisible = false;
4941 for (WindowState ws : mWindows) {
4942 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4943 isVisible = true;
4944 break;
4945 }
4946 }
4947 if (!isVisible) {
4948 return;
4949 }
4950 }
4951
4952 Surface.openTransaction();
4953 if (mStrictModeFlash == null) {
4954 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4955 }
4956 mStrictModeFlash.setVisibility(on);
4957 Surface.closeTransaction();
4958 }
4959 }
4960
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004961 public void setStrictModeVisualIndicatorPreference(String value) {
4962 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4963 }
4964
Dianne Hackbornd2835932010-12-13 16:28:46 -08004965 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004966 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4967 "screenshotApplications()")) {
4968 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4969 }
4970
4971 Bitmap rawss;
4972
Dianne Hackbornd2835932010-12-13 16:28:46 -08004973 int maxLayer = 0;
4974 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004975 final Rect frame = new Rect();
4976
4977 float scale;
4978 int sw, sh, dw, dh;
4979 int rot;
4980
4981 synchronized(mWindowMap) {
4982 long ident = Binder.clearCallingIdentity();
4983
4984 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
4985 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
4986 + TYPE_LAYER_OFFSET;
4987 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
4988
4989 // Figure out the part of the screen that is actually the app.
4990 for (int i=0; i<mWindows.size(); i++) {
4991 WindowState ws = mWindows.get(i);
4992 if (ws.mSurface == null) {
4993 continue;
4994 }
4995 if (ws.mLayer >= aboveAppLayer) {
4996 break;
4997 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08004998 if (appToken != null && (ws.mAppToken == null
4999 || ws.mAppToken.token != appToken)) {
5000 continue;
5001 }
5002 if (maxLayer < ws.mAnimLayer) {
5003 maxLayer = ws.mAnimLayer;
5004 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005005 final Rect wf = ws.mFrame;
5006 final Rect cr = ws.mContentInsets;
5007 int left = wf.left + cr.left;
5008 int top = wf.top + cr.top;
5009 int right = wf.right - cr.right;
5010 int bottom = wf.bottom - cr.bottom;
5011 frame.union(left, top, right, bottom);
5012 }
5013 Binder.restoreCallingIdentity(ident);
5014
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005015 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005016 return null;
5017 }
5018
5019 // The screenshot API does not apply the current screen rotation.
5020 rot = mDisplay.getRotation();
5021 int fw = frame.width();
5022 int fh = frame.height();
5023
5024 // First try reducing to fit in x dimension.
5025 scale = maxWidth/(float)fw;
5026 sw = maxWidth;
5027 sh = (int)(fh*scale);
5028 if (sh > maxHeight) {
5029 // y dimension became too long; constrain by that.
5030 scale = maxHeight/(float)fh;
5031 sw = (int)(fw*scale);
5032 sh = maxHeight;
5033 }
5034
5035 // The screen shot will contain the entire screen.
5036 dw = (int)(mDisplay.getWidth()*scale);
5037 dh = (int)(mDisplay.getHeight()*scale);
5038 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5039 int tmp = dw;
5040 dw = dh;
5041 dh = tmp;
5042 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5043 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005044 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005045 }
5046
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005047 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005048 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5049 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005050 return null;
5051 }
5052
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005053 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5054 Matrix matrix = new Matrix();
5055 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5056 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5057 Canvas canvas = new Canvas(bm);
5058 canvas.drawBitmap(rawss, matrix, null);
5059
5060 rawss.recycle();
5061 return bm;
5062 }
5063
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005064 public void freezeRotation() {
5065 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5066 "setRotation()")) {
5067 throw new SecurityException("Requires SET_ORIENTATION permission");
5068 }
5069
5070 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5071 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5072 }
5073
5074 public void thawRotation() {
5075 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5076 "setRotation()")) {
5077 throw new SecurityException("Requires SET_ORIENTATION permission");
5078 }
5079
5080 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5081 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5082 }
5083
Romain Guy06882f82009-06-10 13:36:04 -07005084 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005085 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005086 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005087 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005088 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005089 }
5090
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005091 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005092 }
Romain Guy06882f82009-06-10 13:36:04 -07005093
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005094 public void setRotationUnchecked(int rotation,
5095 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005096 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005097 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005099 long origId = Binder.clearCallingIdentity();
5100 boolean changed;
5101 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005102 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005103 }
Romain Guy06882f82009-06-10 13:36:04 -07005104
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005105 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 sendNewConfiguration();
5107 }
Romain Guy06882f82009-06-10 13:36:04 -07005108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005109 Binder.restoreCallingIdentity(origId);
5110 }
Romain Guy06882f82009-06-10 13:36:04 -07005111
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005112 /**
5113 * Apply a new rotation to the screen, respecting the requests of
5114 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5115 * re-evaluate the desired rotation.
5116 *
5117 * Returns null if the rotation has been changed. In this case YOU
5118 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5119 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005120 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005121 boolean changed;
5122 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5123 rotation = mRequestedRotation;
5124 } else {
5125 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005126 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005127 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005128 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005129 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005130 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005131 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005132 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005135 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 "Rotation changed to " + rotation
5137 + " from " + mRotation
5138 + " (forceApp=" + mForcedAppOrientation
5139 + ", req=" + mRequestedRotation + ")");
5140 mRotation = rotation;
5141 mWindowsFreezingScreen = true;
5142 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5143 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5144 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005145 mWaitingForConfig = true;
5146 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005147 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005148 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005149 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005150 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005151 if (CUSTOM_SCREEN_ROTATION) {
5152 Surface.freezeDisplay(0);
5153 Surface.openTransaction();
5154 if (mScreenRotationAnimation != null) {
5155 mScreenRotationAnimation.setRotation(rotation);
5156 }
5157 Surface.closeTransaction();
5158 Surface.setOrientation(0, rotation, animFlags);
5159 Surface.unfreezeDisplay(0);
5160 } else {
5161 Surface.setOrientation(0, rotation, animFlags);
5162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005163 }
5164 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005165 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005166 if (w.mSurface != null) {
5167 w.mOrientationChanging = true;
5168 }
5169 }
5170 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5171 try {
5172 mRotationWatchers.get(i).onRotationChanged(rotation);
5173 } catch (RemoteException e) {
5174 }
5175 }
5176 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 return changed;
5179 }
Romain Guy06882f82009-06-10 13:36:04 -07005180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005181 public int getRotation() {
5182 return mRotation;
5183 }
5184
5185 public int watchRotation(IRotationWatcher watcher) {
5186 final IBinder watcherBinder = watcher.asBinder();
5187 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5188 public void binderDied() {
5189 synchronized (mWindowMap) {
5190 for (int i=0; i<mRotationWatchers.size(); i++) {
5191 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005192 IRotationWatcher removed = mRotationWatchers.remove(i);
5193 if (removed != null) {
5194 removed.asBinder().unlinkToDeath(this, 0);
5195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 i--;
5197 }
5198 }
5199 }
5200 }
5201 };
Romain Guy06882f82009-06-10 13:36:04 -07005202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005203 synchronized (mWindowMap) {
5204 try {
5205 watcher.asBinder().linkToDeath(dr, 0);
5206 mRotationWatchers.add(watcher);
5207 } catch (RemoteException e) {
5208 // Client died, no cleanup needed.
5209 }
Romain Guy06882f82009-06-10 13:36:04 -07005210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005211 return mRotation;
5212 }
5213 }
5214
5215 /**
5216 * Starts the view server on the specified port.
5217 *
5218 * @param port The port to listener to.
5219 *
5220 * @return True if the server was successfully started, false otherwise.
5221 *
5222 * @see com.android.server.ViewServer
5223 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5224 */
5225 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005226 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005227 return false;
5228 }
5229
5230 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5231 return false;
5232 }
5233
5234 if (port < 1024) {
5235 return false;
5236 }
5237
5238 if (mViewServer != null) {
5239 if (!mViewServer.isRunning()) {
5240 try {
5241 return mViewServer.start();
5242 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005243 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005244 }
5245 }
5246 return false;
5247 }
5248
5249 try {
5250 mViewServer = new ViewServer(this, port);
5251 return mViewServer.start();
5252 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005253 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005254 }
5255 return false;
5256 }
5257
Romain Guy06882f82009-06-10 13:36:04 -07005258 private boolean isSystemSecure() {
5259 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5260 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5261 }
5262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263 /**
5264 * Stops the view server if it exists.
5265 *
5266 * @return True if the server stopped, false if it wasn't started or
5267 * couldn't be stopped.
5268 *
5269 * @see com.android.server.ViewServer
5270 */
5271 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005272 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273 return false;
5274 }
5275
5276 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5277 return false;
5278 }
5279
5280 if (mViewServer != null) {
5281 return mViewServer.stop();
5282 }
5283 return false;
5284 }
5285
5286 /**
5287 * Indicates whether the view server is running.
5288 *
5289 * @return True if the server is running, false otherwise.
5290 *
5291 * @see com.android.server.ViewServer
5292 */
5293 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005294 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005295 return false;
5296 }
5297
5298 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5299 return false;
5300 }
5301
5302 return mViewServer != null && mViewServer.isRunning();
5303 }
5304
5305 /**
5306 * Lists all availble windows in the system. The listing is written in the
5307 * specified Socket's output stream with the following syntax:
5308 * windowHashCodeInHexadecimal windowName
5309 * Each line of the ouput represents a different window.
5310 *
5311 * @param client The remote client to send the listing to.
5312 * @return False if an error occured, true otherwise.
5313 */
5314 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005315 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005316 return false;
5317 }
5318
5319 boolean result = true;
5320
Jeff Browne33348b2010-07-15 23:54:05 -07005321 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005322 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005324 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005325 }
5326
5327 BufferedWriter out = null;
5328
5329 // Any uncaught exception will crash the system process
5330 try {
5331 OutputStream clientStream = client.getOutputStream();
5332 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5333
5334 final int count = windows.length;
5335 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005336 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005337 out.write(Integer.toHexString(System.identityHashCode(w)));
5338 out.write(' ');
5339 out.append(w.mAttrs.getTitle());
5340 out.write('\n');
5341 }
5342
5343 out.write("DONE.\n");
5344 out.flush();
5345 } catch (Exception e) {
5346 result = false;
5347 } finally {
5348 if (out != null) {
5349 try {
5350 out.close();
5351 } catch (IOException e) {
5352 result = false;
5353 }
5354 }
5355 }
5356
5357 return result;
5358 }
5359
5360 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005361 * Returns the focused window in the following format:
5362 * windowHashCodeInHexadecimal windowName
5363 *
5364 * @param client The remote client to send the listing to.
5365 * @return False if an error occurred, true otherwise.
5366 */
5367 boolean viewServerGetFocusedWindow(Socket client) {
5368 if (isSystemSecure()) {
5369 return false;
5370 }
5371
5372 boolean result = true;
5373
5374 WindowState focusedWindow = getFocusedWindow();
5375
5376 BufferedWriter out = null;
5377
5378 // Any uncaught exception will crash the system process
5379 try {
5380 OutputStream clientStream = client.getOutputStream();
5381 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5382
5383 if(focusedWindow != null) {
5384 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5385 out.write(' ');
5386 out.append(focusedWindow.mAttrs.getTitle());
5387 }
5388 out.write('\n');
5389 out.flush();
5390 } catch (Exception e) {
5391 result = false;
5392 } finally {
5393 if (out != null) {
5394 try {
5395 out.close();
5396 } catch (IOException e) {
5397 result = false;
5398 }
5399 }
5400 }
5401
5402 return result;
5403 }
5404
5405 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005406 * Sends a command to a target window. The result of the command, if any, will be
5407 * written in the output stream of the specified socket.
5408 *
5409 * The parameters must follow this syntax:
5410 * windowHashcode extra
5411 *
5412 * Where XX is the length in characeters of the windowTitle.
5413 *
5414 * The first parameter is the target window. The window with the specified hashcode
5415 * will be the target. If no target can be found, nothing happens. The extra parameters
5416 * will be delivered to the target window and as parameters to the command itself.
5417 *
5418 * @param client The remote client to sent the result, if any, to.
5419 * @param command The command to execute.
5420 * @param parameters The command parameters.
5421 *
5422 * @return True if the command was successfully delivered, false otherwise. This does
5423 * not indicate whether the command itself was successful.
5424 */
5425 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005426 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 return false;
5428 }
5429
5430 boolean success = true;
5431 Parcel data = null;
5432 Parcel reply = null;
5433
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005434 BufferedWriter out = null;
5435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 // Any uncaught exception will crash the system process
5437 try {
5438 // Find the hashcode of the window
5439 int index = parameters.indexOf(' ');
5440 if (index == -1) {
5441 index = parameters.length();
5442 }
5443 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005444 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445
5446 // Extract the command's parameter after the window description
5447 if (index < parameters.length()) {
5448 parameters = parameters.substring(index + 1);
5449 } else {
5450 parameters = "";
5451 }
5452
5453 final WindowManagerService.WindowState window = findWindow(hashCode);
5454 if (window == null) {
5455 return false;
5456 }
5457
5458 data = Parcel.obtain();
5459 data.writeInterfaceToken("android.view.IWindow");
5460 data.writeString(command);
5461 data.writeString(parameters);
5462 data.writeInt(1);
5463 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5464
5465 reply = Parcel.obtain();
5466
5467 final IBinder binder = window.mClient.asBinder();
5468 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5469 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5470
5471 reply.readException();
5472
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005473 if (!client.isOutputShutdown()) {
5474 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5475 out.write("DONE\n");
5476 out.flush();
5477 }
5478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005479 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005480 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005481 success = false;
5482 } finally {
5483 if (data != null) {
5484 data.recycle();
5485 }
5486 if (reply != null) {
5487 reply.recycle();
5488 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005489 if (out != null) {
5490 try {
5491 out.close();
5492 } catch (IOException e) {
5493
5494 }
5495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 }
5497
5498 return success;
5499 }
5500
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005501 public void addWindowChangeListener(WindowChangeListener listener) {
5502 synchronized(mWindowMap) {
5503 mWindowChangeListeners.add(listener);
5504 }
5505 }
5506
5507 public void removeWindowChangeListener(WindowChangeListener listener) {
5508 synchronized(mWindowMap) {
5509 mWindowChangeListeners.remove(listener);
5510 }
5511 }
5512
5513 private void notifyWindowsChanged() {
5514 WindowChangeListener[] windowChangeListeners;
5515 synchronized(mWindowMap) {
5516 if(mWindowChangeListeners.isEmpty()) {
5517 return;
5518 }
5519 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5520 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5521 }
5522 int N = windowChangeListeners.length;
5523 for(int i = 0; i < N; i++) {
5524 windowChangeListeners[i].windowsChanged();
5525 }
5526 }
5527
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005528 private void notifyFocusChanged() {
5529 WindowChangeListener[] windowChangeListeners;
5530 synchronized(mWindowMap) {
5531 if(mWindowChangeListeners.isEmpty()) {
5532 return;
5533 }
5534 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5535 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5536 }
5537 int N = windowChangeListeners.length;
5538 for(int i = 0; i < N; i++) {
5539 windowChangeListeners[i].focusChanged();
5540 }
5541 }
5542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005543 private WindowState findWindow(int hashCode) {
5544 if (hashCode == -1) {
5545 return getFocusedWindow();
5546 }
5547
5548 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005549 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005550 final int count = windows.size();
5551
5552 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005553 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005554 if (System.identityHashCode(w) == hashCode) {
5555 return w;
5556 }
5557 }
5558 }
5559
5560 return null;
5561 }
5562
5563 /*
5564 * Instruct the Activity Manager to fetch the current configuration and broadcast
5565 * that to config-changed listeners if appropriate.
5566 */
5567 void sendNewConfiguration() {
5568 try {
5569 mActivityManager.updateConfiguration(null);
5570 } catch (RemoteException e) {
5571 }
5572 }
Romain Guy06882f82009-06-10 13:36:04 -07005573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 public Configuration computeNewConfiguration() {
5575 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005576 return computeNewConfigurationLocked();
5577 }
5578 }
Romain Guy06882f82009-06-10 13:36:04 -07005579
Dianne Hackbornc485a602009-03-24 22:39:49 -07005580 Configuration computeNewConfigurationLocked() {
5581 Configuration config = new Configuration();
5582 if (!computeNewConfigurationLocked(config)) {
5583 return null;
5584 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005585 return config;
5586 }
Romain Guy06882f82009-06-10 13:36:04 -07005587
Dianne Hackbornc485a602009-03-24 22:39:49 -07005588 boolean computeNewConfigurationLocked(Configuration config) {
5589 if (mDisplay == null) {
5590 return false;
5591 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005592
5593 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005594
5595 // Use the effective "visual" dimensions based on current rotation
5596 final boolean rotated = (mRotation == Surface.ROTATION_90
5597 || mRotation == Surface.ROTATION_270);
5598 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5599 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5600
Dianne Hackbornc485a602009-03-24 22:39:49 -07005601 int orientation = Configuration.ORIENTATION_SQUARE;
5602 if (dw < dh) {
5603 orientation = Configuration.ORIENTATION_PORTRAIT;
5604 } else if (dw > dh) {
5605 orientation = Configuration.ORIENTATION_LANDSCAPE;
5606 }
5607 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005608
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005609 DisplayMetrics dm = new DisplayMetrics();
5610 mDisplay.getMetrics(dm);
5611 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5612
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005613 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005614 // Note we only do this once because at this point we don't
5615 // expect the screen to change in this way at runtime, and want
5616 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005617 int longSize = dw;
5618 int shortSize = dh;
5619 if (longSize < shortSize) {
5620 int tmp = longSize;
5621 longSize = shortSize;
5622 shortSize = tmp;
5623 }
5624 longSize = (int)(longSize/dm.density);
5625 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005626
Dianne Hackborn723738c2009-06-25 19:48:04 -07005627 // These semi-magic numbers define our compatibility modes for
5628 // applications with different screens. Don't change unless you
5629 // make sure to test lots and lots of apps!
5630 if (longSize < 470) {
5631 // This is shorter than an HVGA normal density screen (which
5632 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005633 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5634 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005635 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005636 // What size is this screen screen?
5637 if (longSize >= 800 && shortSize >= 600) {
5638 // SVGA or larger screens at medium density are the point
5639 // at which we consider it to be an extra large screen.
5640 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005641 } else if (longSize >= 530 && shortSize >= 400) {
5642 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005643 // at which we consider it to be a large screen.
5644 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5645 } else {
5646 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005647
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005648 // If this screen is wider than normal HVGA, or taller
5649 // than FWVGA, then for old apps we want to run in size
5650 // compatibility mode.
5651 if (shortSize > 321 || longSize > 570) {
5652 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5653 }
5654 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005655
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005656 // Is this a long screen?
5657 if (((longSize*3)/5) >= (shortSize-1)) {
5658 // Anything wider than WVGA (5:3) is considering to be long.
5659 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5660 } else {
5661 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5662 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005663 }
5664 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005665 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005666
Dianne Hackbornc485a602009-03-24 22:39:49 -07005667 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5668 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5669 mPolicy.adjustConfigurationLw(config);
5670 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005672
5673 // -------------------------------------------------------------
5674 // Drag and drop
5675 // -------------------------------------------------------------
5676
5677 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005678 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005679 if (DEBUG_DRAG) {
5680 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005681 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005682 + " asbinder=" + window.asBinder());
5683 }
5684
5685 final int callerPid = Binder.getCallingPid();
5686 final long origId = Binder.clearCallingIdentity();
5687 IBinder token = null;
5688
5689 try {
5690 synchronized (mWindowMap) {
5691 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005692 if (mDragState == null) {
5693 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5694 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5695 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005696 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005697 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005698 // TODO: preserve flags param in DragState
5699 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005700 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005701 token = mDragState.mToken = new Binder();
5702
5703 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005704 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5705 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005706 mH.sendMessageDelayed(msg, 5000);
5707 } else {
5708 Slog.w(TAG, "Drag already in progress");
5709 }
5710 } catch (Surface.OutOfResourcesException e) {
5711 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5712 if (mDragState != null) {
5713 mDragState.reset();
5714 mDragState = null;
5715 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005716 }
5717 }
5718 } finally {
5719 Binder.restoreCallingIdentity(origId);
5720 }
5721
5722 return token;
5723 }
5724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 // -------------------------------------------------------------
5726 // Input Events and Focus Management
5727 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005728
Jeff Brown349703e2010-06-22 01:27:15 -07005729 InputMonitor mInputMonitor = new InputMonitor();
5730
5731 /* Tracks the progress of input dispatch and ensures that input dispatch state
5732 * is kept in sync with changes in window focus, visibility, registration, and
5733 * other relevant Window Manager state transitions. */
5734 final class InputMonitor {
5735 // Current window with input focus for keys and other non-touch events. May be null.
5736 private WindowState mInputFocus;
5737
5738 // When true, prevents input dispatch from proceeding until set to false again.
5739 private boolean mInputDispatchFrozen;
5740
5741 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5742 private boolean mInputDispatchEnabled = true;
5743
5744 // Temporary list of windows information to provide to the input dispatcher.
5745 private InputWindowList mTempInputWindows = new InputWindowList();
5746
5747 // Temporary input application object to provide to the input dispatcher.
5748 private InputApplication mTempInputApplication = new InputApplication();
5749
5750 /* Notifies the window manager about a broken input channel.
5751 *
5752 * Called by the InputManager.
5753 */
Jeff Brown928e0542011-01-10 11:17:36 -08005754 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5755 if (inputWindowHandle == null) {
5756 return;
5757 }
5758
Jeff Brown349703e2010-06-22 01:27:15 -07005759 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005760 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005761 Slog.i(TAG, "WINDOW DIED " + windowState);
5762 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005763 }
5764 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005765
Jeff Brown519e0242010-09-15 15:18:56 -07005766 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005767 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005768 *
5769 * Called by the InputManager.
5770 */
Jeff Brown928e0542011-01-10 11:17:36 -08005771 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5772 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005773 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005774 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005775 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005776 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005777 if (windowState != null) {
5778 Slog.i(TAG, "Input event dispatching timed out sending to "
5779 + windowState.mAttrs.getTitle());
5780 appWindowToken = windowState.mAppToken;
5781 }
Jeff Brown349703e2010-06-22 01:27:15 -07005782 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005783 }
5784
Jeff Brown928e0542011-01-10 11:17:36 -08005785 if (appWindowToken == null && inputApplicationHandle != null) {
5786 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005787 Slog.i(TAG, "Input event dispatching timed out sending to application "
5788 + appWindowToken.stringName);
5789 }
Jeff Brown349703e2010-06-22 01:27:15 -07005790
Jeff Brown519e0242010-09-15 15:18:56 -07005791 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005792 try {
5793 // Notify the activity manager about the timeout and let it decide whether
5794 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005795 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005796 if (! abort) {
5797 // The activity manager declined to abort dispatching.
5798 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005799 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005800 }
Jeff Brown349703e2010-06-22 01:27:15 -07005801 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005802 }
5803 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005804 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005805 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005806
Chris Tatea32dcf72010-10-14 12:13:50 -07005807 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005808 final InputWindow inputWindow = windowList.add();
5809 inputWindow.inputChannel = mDragState.mServerChannel;
5810 inputWindow.name = "drag";
5811 inputWindow.layoutParamsFlags = 0;
5812 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5813 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5814 inputWindow.visible = true;
5815 inputWindow.canReceiveKeys = false;
5816 inputWindow.hasFocus = true;
5817 inputWindow.hasWallpaper = false;
5818 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005819 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005820 inputWindow.ownerPid = Process.myPid();
5821 inputWindow.ownerUid = Process.myUid();
5822
5823 // The drag window covers the entire display
5824 inputWindow.frameLeft = 0;
5825 inputWindow.frameTop = 0;
5826 inputWindow.frameRight = mDisplay.getWidth();
5827 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005828
Christopher Tatea53146c2010-09-07 11:57:52 -07005829 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5830 inputWindow.visibleFrameTop = inputWindow.frameTop;
5831 inputWindow.visibleFrameRight = inputWindow.frameRight;
5832 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5833
5834 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5835 inputWindow.touchableAreaTop = inputWindow.frameTop;
5836 inputWindow.touchableAreaRight = inputWindow.frameRight;
5837 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5838 }
5839
Jeff Brown349703e2010-06-22 01:27:15 -07005840 /* Updates the cached window information provided to the input dispatcher. */
5841 public void updateInputWindowsLw() {
5842 // Populate the input window list with information about all of the windows that
5843 // could potentially receive input.
5844 // As an optimization, we could try to prune the list of windows but this turns
5845 // out to be difficult because only the native code knows for sure which window
5846 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005847 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005848
5849 // If there's a drag in flight, provide a pseudowindow to catch drag input
5850 final boolean inDrag = (mDragState != null);
5851 if (inDrag) {
5852 if (DEBUG_DRAG) {
5853 Log.d(TAG, "Inserting drag window");
5854 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005855 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005856 }
5857
Jeff Brown7fbdc842010-06-17 20:52:56 -07005858 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005859 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005860 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005861 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005862 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005863 continue;
5864 }
5865
Jeff Brown349703e2010-06-22 01:27:15 -07005866 final int flags = child.mAttrs.flags;
5867 final int type = child.mAttrs.type;
5868
5869 final boolean hasFocus = (child == mInputFocus);
5870 final boolean isVisible = child.isVisibleLw();
5871 final boolean hasWallpaper = (child == mWallpaperTarget)
5872 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005873
5874 // If there's a drag in progress and 'child' is a potential drop target,
5875 // make sure it's been told about the drag
5876 if (inDrag && isVisible) {
5877 mDragState.sendDragStartedIfNeededLw(child);
5878 }
5879
Jeff Brown349703e2010-06-22 01:27:15 -07005880 // Add a window to our list of input windows.
5881 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005882 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005883 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005884 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005885 inputWindow.layoutParamsFlags = flags;
5886 inputWindow.layoutParamsType = type;
5887 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5888 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005889 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005890 inputWindow.hasFocus = hasFocus;
5891 inputWindow.hasWallpaper = hasWallpaper;
5892 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005893 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005894 inputWindow.ownerPid = child.mSession.mPid;
5895 inputWindow.ownerUid = child.mSession.mUid;
5896
5897 final Rect frame = child.mFrame;
5898 inputWindow.frameLeft = frame.left;
5899 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005900 inputWindow.frameRight = frame.right;
5901 inputWindow.frameBottom = frame.bottom;
5902
5903 final Rect visibleFrame = child.mVisibleFrame;
5904 inputWindow.visibleFrameLeft = visibleFrame.left;
5905 inputWindow.visibleFrameTop = visibleFrame.top;
5906 inputWindow.visibleFrameRight = visibleFrame.right;
5907 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005908
5909 switch (child.mTouchableInsets) {
5910 default:
5911 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5912 inputWindow.touchableAreaLeft = frame.left;
5913 inputWindow.touchableAreaTop = frame.top;
5914 inputWindow.touchableAreaRight = frame.right;
5915 inputWindow.touchableAreaBottom = frame.bottom;
5916 break;
5917
5918 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5919 Rect inset = child.mGivenContentInsets;
5920 inputWindow.touchableAreaLeft = frame.left + inset.left;
5921 inputWindow.touchableAreaTop = frame.top + inset.top;
5922 inputWindow.touchableAreaRight = frame.right - inset.right;
5923 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5924 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005925 }
Jeff Brown349703e2010-06-22 01:27:15 -07005926
5927 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5928 Rect inset = child.mGivenVisibleInsets;
5929 inputWindow.touchableAreaLeft = frame.left + inset.left;
5930 inputWindow.touchableAreaTop = frame.top + inset.top;
5931 inputWindow.touchableAreaRight = frame.right - inset.right;
5932 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005933 break;
5934 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005935 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005936 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005937
Jeff Brown349703e2010-06-22 01:27:15 -07005938 // Send windows to native code.
5939 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005940
Jeff Brown349703e2010-06-22 01:27:15 -07005941 // Clear the list in preparation for the next round.
5942 // Also avoids keeping InputChannel objects referenced unnecessarily.
5943 mTempInputWindows.clear();
5944 }
5945
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005946 /* Notifies that the lid switch changed state. */
5947 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5948 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5949 }
5950
Jeff Brown349703e2010-06-22 01:27:15 -07005951 /* Provides an opportunity for the window manager policy to intercept early key
5952 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08005953 public int interceptKeyBeforeQueueing(
5954 KeyEvent event, int policyFlags, boolean isScreenOn) {
5955 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005956 }
5957
5958 /* Provides an opportunity for the window manager policy to process a key before
5959 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08005960 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08005961 InputWindowHandle focus, KeyEvent event, int policyFlags) {
5962 WindowState windowState = (WindowState) focus.windowState;
Jeff Brown1f245102010-11-18 20:53:46 -08005963 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005964 }
5965
Jeff Brown3915bb82010-11-05 15:02:16 -07005966 /* Provides an opportunity for the window manager policy to process a key that
5967 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08005968 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08005969 InputWindowHandle focus, KeyEvent event, int policyFlags) {
5970 WindowState windowState = (WindowState) focus.windowState;
Jeff Brown1f245102010-11-18 20:53:46 -08005971 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07005972 }
5973
Jeff Brown349703e2010-06-22 01:27:15 -07005974 /* Called when the current input focus changes.
5975 * Layer assignment is assumed to be complete by the time this is called.
5976 */
5977 public void setInputFocusLw(WindowState newWindow) {
5978 if (DEBUG_INPUT) {
5979 Slog.d(TAG, "Input focus has changed to " + newWindow);
5980 }
5981
5982 if (newWindow != mInputFocus) {
5983 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005984 // Displaying a window implicitly causes dispatching to be unpaused.
5985 // This is to protect against bugs if someone pauses dispatching but
5986 // forgets to resume.
5987 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005988 }
Jeff Brown349703e2010-06-22 01:27:15 -07005989
5990 mInputFocus = newWindow;
5991 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005992 }
5993 }
5994
Jeff Brown349703e2010-06-22 01:27:15 -07005995 public void setFocusedAppLw(AppWindowToken newApp) {
5996 // Focused app has changed.
5997 if (newApp == null) {
5998 mInputManager.setFocusedApplication(null);
5999 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006000 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006001 mTempInputApplication.name = newApp.toString();
6002 mTempInputApplication.dispatchingTimeoutNanos =
6003 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006004
Jeff Brown349703e2010-06-22 01:27:15 -07006005 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006006
6007 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006008 }
6009 }
6010
Jeff Brown349703e2010-06-22 01:27:15 -07006011 public void pauseDispatchingLw(WindowToken window) {
6012 if (! window.paused) {
6013 if (DEBUG_INPUT) {
6014 Slog.v(TAG, "Pausing WindowToken " + window);
6015 }
6016
6017 window.paused = true;
6018 updateInputWindowsLw();
6019 }
6020 }
6021
6022 public void resumeDispatchingLw(WindowToken window) {
6023 if (window.paused) {
6024 if (DEBUG_INPUT) {
6025 Slog.v(TAG, "Resuming WindowToken " + window);
6026 }
6027
6028 window.paused = false;
6029 updateInputWindowsLw();
6030 }
6031 }
6032
6033 public void freezeInputDispatchingLw() {
6034 if (! mInputDispatchFrozen) {
6035 if (DEBUG_INPUT) {
6036 Slog.v(TAG, "Freezing input dispatching");
6037 }
6038
6039 mInputDispatchFrozen = true;
6040 updateInputDispatchModeLw();
6041 }
6042 }
6043
6044 public void thawInputDispatchingLw() {
6045 if (mInputDispatchFrozen) {
6046 if (DEBUG_INPUT) {
6047 Slog.v(TAG, "Thawing input dispatching");
6048 }
6049
6050 mInputDispatchFrozen = false;
6051 updateInputDispatchModeLw();
6052 }
6053 }
6054
6055 public void setEventDispatchingLw(boolean enabled) {
6056 if (mInputDispatchEnabled != enabled) {
6057 if (DEBUG_INPUT) {
6058 Slog.v(TAG, "Setting event dispatching to " + enabled);
6059 }
6060
6061 mInputDispatchEnabled = enabled;
6062 updateInputDispatchModeLw();
6063 }
6064 }
6065
6066 private void updateInputDispatchModeLw() {
6067 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6068 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071 public void pauseKeyDispatching(IBinder _token) {
6072 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6073 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006074 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006075 }
6076
6077 synchronized (mWindowMap) {
6078 WindowToken token = mTokenMap.get(_token);
6079 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006080 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006081 }
6082 }
6083 }
6084
6085 public void resumeKeyDispatching(IBinder _token) {
6086 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6087 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006088 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006089 }
6090
6091 synchronized (mWindowMap) {
6092 WindowToken token = mTokenMap.get(_token);
6093 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006094 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095 }
6096 }
6097 }
6098
6099 public void setEventDispatching(boolean enabled) {
6100 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6101 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006102 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006103 }
6104
6105 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006106 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 }
6108 }
Romain Guy06882f82009-06-10 13:36:04 -07006109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110 /**
6111 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006112 * Even when sync is false, this method may block while waiting for current
6113 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006114 *
6115 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 * {@link SystemClock#uptimeMillis()} as the timebase.)
6117 * @param sync If true, wait for the event to be completed before returning to the caller.
6118 * @return Returns true if event was dispatched, false if it was dropped for any reason
6119 */
6120 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6121 long downTime = ev.getDownTime();
6122 long eventTime = ev.getEventTime();
6123
6124 int action = ev.getAction();
6125 int code = ev.getKeyCode();
6126 int repeatCount = ev.getRepeatCount();
6127 int metaState = ev.getMetaState();
6128 int deviceId = ev.getDeviceId();
6129 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006130 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006131 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006132
6133 if (source == InputDevice.SOURCE_UNKNOWN) {
6134 source = InputDevice.SOURCE_KEYBOARD;
6135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136
6137 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6138 if (downTime == 0) downTime = eventTime;
6139
6140 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006141 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006143 final int pid = Binder.getCallingPid();
6144 final int uid = Binder.getCallingUid();
6145 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006146
Jeff Brownbbda99d2010-07-28 15:48:59 -07006147 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6148 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6149 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6150 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006151
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006152 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006153 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 }
6155
6156 /**
6157 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006158 * Even when sync is false, this method may block while waiting for current
6159 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006160 *
6161 * @param ev A motion event describing the pointer (touch) action. (As noted in
6162 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006163 * {@link SystemClock#uptimeMillis()} as the timebase.)
6164 * @param sync If true, wait for the event to be completed before returning to the caller.
6165 * @return Returns true if event was dispatched, false if it was dropped for any reason
6166 */
6167 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006168 final int pid = Binder.getCallingPid();
6169 final int uid = Binder.getCallingUid();
6170 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006171
Jeff Brownc5ed5912010-07-14 18:48:53 -07006172 MotionEvent newEvent = MotionEvent.obtain(ev);
6173 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6174 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6175 }
6176
Jeff Brownbbda99d2010-07-28 15:48:59 -07006177 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6178 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6179 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6180 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006181
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006182 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006183 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006184 }
Romain Guy06882f82009-06-10 13:36:04 -07006185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 /**
6187 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006188 * Even when sync is false, this method may block while waiting for current
6189 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006190 *
6191 * @param ev A motion event describing the trackball action. (As noted in
6192 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 * {@link SystemClock#uptimeMillis()} as the timebase.)
6194 * @param sync If true, wait for the event to be completed before returning to the caller.
6195 * @return Returns true if event was dispatched, false if it was dropped for any reason
6196 */
6197 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006198 final int pid = Binder.getCallingPid();
6199 final int uid = Binder.getCallingUid();
6200 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006201
Jeff Brownc5ed5912010-07-14 18:48:53 -07006202 MotionEvent newEvent = MotionEvent.obtain(ev);
6203 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6204 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6205 }
6206
Jeff Brownbbda99d2010-07-28 15:48:59 -07006207 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6208 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6209 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6210 INJECTION_TIMEOUT_MILLIS);
6211
6212 Binder.restoreCallingIdentity(ident);
6213 return reportInjectionResult(result);
6214 }
6215
6216 /**
6217 * Inject an input event into the UI without waiting for dispatch to commence.
6218 * This variant is useful for fire-and-forget input event injection. It does not
6219 * block any longer than it takes to enqueue the input event.
6220 *
6221 * @param ev An input event. (Be sure to set the input source correctly.)
6222 * @return Returns true if event was dispatched, false if it was dropped for any reason
6223 */
6224 public boolean injectInputEventNoWait(InputEvent ev) {
6225 final int pid = Binder.getCallingPid();
6226 final int uid = Binder.getCallingUid();
6227 final long ident = Binder.clearCallingIdentity();
6228
6229 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6230 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6231 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006232
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006233 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006234 return reportInjectionResult(result);
6235 }
6236
6237 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006238 switch (result) {
6239 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6240 Slog.w(TAG, "Input event injection permission denied.");
6241 throw new SecurityException(
6242 "Injecting to another application requires INJECT_EVENTS permission");
6243 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006244 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006245 return true;
6246 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6247 Slog.w(TAG, "Input event injection timed out.");
6248 return false;
6249 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6250 default:
6251 Slog.w(TAG, "Input event injection failed.");
6252 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254 }
Romain Guy06882f82009-06-10 13:36:04 -07006255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 private WindowState getFocusedWindow() {
6257 synchronized (mWindowMap) {
6258 return getFocusedWindowLocked();
6259 }
6260 }
6261
6262 private WindowState getFocusedWindowLocked() {
6263 return mCurrentFocus;
6264 }
Romain Guy06882f82009-06-10 13:36:04 -07006265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 public boolean detectSafeMode() {
6267 mSafeMode = mPolicy.detectSafeMode();
6268 return mSafeMode;
6269 }
Romain Guy06882f82009-06-10 13:36:04 -07006270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006271 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006272 synchronized(mWindowMap) {
6273 if (mDisplay != null) {
6274 throw new IllegalStateException("Display already initialized");
6275 }
6276 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6277 mDisplay = wm.getDefaultDisplay();
6278 mInitialDisplayWidth = mDisplay.getWidth();
6279 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006280 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6281 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006282 }
6283
6284 try {
6285 mActivityManager.updateConfiguration(null);
6286 } catch (RemoteException e) {
6287 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006288
6289 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006290 }
6291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 // -------------------------------------------------------------
6293 // Client Session State
6294 // -------------------------------------------------------------
6295
6296 private final class Session extends IWindowSession.Stub
6297 implements IBinder.DeathRecipient {
6298 final IInputMethodClient mClient;
6299 final IInputContext mInputContext;
6300 final int mUid;
6301 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006302 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006303 SurfaceSession mSurfaceSession;
6304 int mNumWindow = 0;
6305 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 public Session(IInputMethodClient client, IInputContext inputContext) {
6308 mClient = client;
6309 mInputContext = inputContext;
6310 mUid = Binder.getCallingUid();
6311 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006312 StringBuilder sb = new StringBuilder();
6313 sb.append("Session{");
6314 sb.append(Integer.toHexString(System.identityHashCode(this)));
6315 sb.append(" uid ");
6316 sb.append(mUid);
6317 sb.append("}");
6318 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006320 synchronized (mWindowMap) {
6321 if (mInputMethodManager == null && mHaveInputMethods) {
6322 IBinder b = ServiceManager.getService(
6323 Context.INPUT_METHOD_SERVICE);
6324 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6325 }
6326 }
6327 long ident = Binder.clearCallingIdentity();
6328 try {
6329 // Note: it is safe to call in to the input method manager
6330 // here because we are not holding our lock.
6331 if (mInputMethodManager != null) {
6332 mInputMethodManager.addClient(client, inputContext,
6333 mUid, mPid);
6334 } else {
6335 client.setUsingInputMethod(false);
6336 }
6337 client.asBinder().linkToDeath(this, 0);
6338 } catch (RemoteException e) {
6339 // The caller has died, so we can just forget about this.
6340 try {
6341 if (mInputMethodManager != null) {
6342 mInputMethodManager.removeClient(client);
6343 }
6344 } catch (RemoteException ee) {
6345 }
6346 } finally {
6347 Binder.restoreCallingIdentity(ident);
6348 }
6349 }
Romain Guy06882f82009-06-10 13:36:04 -07006350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 @Override
6352 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6353 throws RemoteException {
6354 try {
6355 return super.onTransact(code, data, reply, flags);
6356 } catch (RuntimeException e) {
6357 // Log all 'real' exceptions thrown to the caller
6358 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006359 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 }
6361 throw e;
6362 }
6363 }
6364
6365 public void binderDied() {
6366 // Note: it is safe to call in to the input method manager
6367 // here because we are not holding our lock.
6368 try {
6369 if (mInputMethodManager != null) {
6370 mInputMethodManager.removeClient(mClient);
6371 }
6372 } catch (RemoteException e) {
6373 }
6374 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006375 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 mClientDead = true;
6377 killSessionLocked();
6378 }
6379 }
6380
6381 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006382 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6383 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6384 outInputChannel);
6385 }
6386
6387 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006388 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006389 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006390 }
Romain Guy06882f82009-06-10 13:36:04 -07006391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006392 public void remove(IWindow window) {
6393 removeWindow(this, window);
6394 }
Romain Guy06882f82009-06-10 13:36:04 -07006395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6397 int requestedWidth, int requestedHeight, int viewFlags,
6398 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006399 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006400 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6401 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006403 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006404 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6405 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406 }
Romain Guy06882f82009-06-10 13:36:04 -07006407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 public void setTransparentRegion(IWindow window, Region region) {
6409 setTransparentRegionWindow(this, window, region);
6410 }
Romain Guy06882f82009-06-10 13:36:04 -07006411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006412 public void setInsets(IWindow window, int touchableInsets,
6413 Rect contentInsets, Rect visibleInsets) {
6414 setInsetsWindow(this, window, touchableInsets, contentInsets,
6415 visibleInsets);
6416 }
Romain Guy06882f82009-06-10 13:36:04 -07006417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006418 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6419 getWindowDisplayFrame(this, window, outDisplayFrame);
6420 }
Romain Guy06882f82009-06-10 13:36:04 -07006421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006422 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006423 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006424 TAG, "IWindow finishDrawing called for " + window);
6425 finishDrawingWindow(this, window);
6426 }
6427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006428 public void setInTouchMode(boolean mode) {
6429 synchronized(mWindowMap) {
6430 mInTouchMode = mode;
6431 }
6432 }
6433
6434 public boolean getInTouchMode() {
6435 synchronized(mWindowMap) {
6436 return mInTouchMode;
6437 }
6438 }
6439
6440 public boolean performHapticFeedback(IWindow window, int effectId,
6441 boolean always) {
6442 synchronized(mWindowMap) {
6443 long ident = Binder.clearCallingIdentity();
6444 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006445 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006446 windowForClientLocked(this, window, true),
6447 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 } finally {
6449 Binder.restoreCallingIdentity(ident);
6450 }
6451 }
6452 }
Romain Guy06882f82009-06-10 13:36:04 -07006453
Christopher Tatea53146c2010-09-07 11:57:52 -07006454 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006455 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006456 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006457 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006458 width, height, outSurface);
6459 }
6460
6461 public boolean performDrag(IWindow window, IBinder dragToken,
6462 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6463 ClipData data) {
6464 if (DEBUG_DRAG) {
6465 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6466 }
6467
6468 synchronized (mWindowMap) {
6469 if (mDragState == null) {
6470 Slog.w(TAG, "No drag prepared");
6471 throw new IllegalStateException("performDrag() without prepareDrag()");
6472 }
6473
6474 if (dragToken != mDragState.mToken) {
6475 Slog.w(TAG, "Performing mismatched drag");
6476 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6477 }
6478
6479 WindowState callingWin = windowForClientLocked(null, window, false);
6480 if (callingWin == null) {
6481 Slog.w(TAG, "Bad requesting window " + window);
6482 return false; // !!! TODO: throw here?
6483 }
6484
6485 // !!! TODO: if input is not still focused on the initiating window, fail
6486 // the drag initiation (e.g. an alarm window popped up just as the application
6487 // called performDrag()
6488
6489 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6490
Christopher Tate2c095f32010-10-04 14:13:40 -07006491 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6492 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006493
Chris Tateb478f462010-10-15 16:02:26 -07006494 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6495 // the actual drag event dispatch stuff in the dragstate
6496
Christopher Tatea53146c2010-09-07 11:57:52 -07006497 mDragState.register();
6498 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006499 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6500 mDragState.mServerChannel)) {
6501 Slog.e(TAG, "Unable to transfer touch focus");
6502 mDragState.unregister();
6503 mDragState = null;
6504 mInputMonitor.updateInputWindowsLw();
6505 return false;
6506 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006507
6508 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006509 mDragState.mCurrentX = touchX;
6510 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006511 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006512
6513 // remember the thumb offsets for later
6514 mDragState.mThumbOffsetX = thumbCenterX;
6515 mDragState.mThumbOffsetY = thumbCenterY;
6516
6517 // Make the surface visible at the proper location
6518 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006519 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006520 try {
6521 surface.setPosition((int)(touchX - thumbCenterX),
6522 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006523 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006524 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006525 surface.show();
6526 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006527 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006528 }
6529 }
6530
6531 return true; // success!
6532 }
6533
Chris Tated4533f142010-10-19 15:15:08 -07006534 public void reportDropResult(IWindow window, boolean consumed) {
6535 IBinder token = window.asBinder();
6536 if (DEBUG_DRAG) {
6537 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6538 }
6539
6540 synchronized (mWindowMap) {
6541 if (mDragState.mToken != token) {
6542 Slog.w(TAG, "Invalid drop-result claim by " + window);
6543 throw new IllegalStateException("reportDropResult() by non-recipient");
6544 }
6545
6546 // The right window has responded, even if it's no longer around,
6547 // so be sure to halt the timeout even if the later WindowState
6548 // lookup fails.
6549 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6550
6551 WindowState callingWin = windowForClientLocked(null, window, false);
6552 if (callingWin == null) {
6553 Slog.w(TAG, "Bad result-reporting window " + window);
6554 return; // !!! TODO: throw here?
6555 }
6556
6557 mDragState.mDragResult = consumed;
6558 mDragState.endDragLw();
6559 }
6560 }
6561
Christopher Tatea53146c2010-09-07 11:57:52 -07006562 public void dragRecipientEntered(IWindow window) {
6563 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006564 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006565 }
6566 }
6567
6568 public void dragRecipientExited(IWindow window) {
6569 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006570 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006571 }
6572 }
6573
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006574 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006575 synchronized(mWindowMap) {
6576 long ident = Binder.clearCallingIdentity();
6577 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006578 setWindowWallpaperPositionLocked(
6579 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006580 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006581 } finally {
6582 Binder.restoreCallingIdentity(ident);
6583 }
6584 }
6585 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006586
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006587 public void wallpaperOffsetsComplete(IBinder window) {
6588 WindowManagerService.this.wallpaperOffsetsComplete(window);
6589 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006590
Dianne Hackborn75804932009-10-20 20:15:20 -07006591 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6592 int z, Bundle extras, boolean sync) {
6593 synchronized(mWindowMap) {
6594 long ident = Binder.clearCallingIdentity();
6595 try {
6596 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006597 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006598 action, x, y, z, extras, sync);
6599 } finally {
6600 Binder.restoreCallingIdentity(ident);
6601 }
6602 }
6603 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006604
Dianne Hackborn75804932009-10-20 20:15:20 -07006605 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6606 WindowManagerService.this.wallpaperCommandComplete(window, result);
6607 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 void windowAddedLocked() {
6610 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006611 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006612 TAG, "First window added to " + this + ", creating SurfaceSession");
6613 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006614 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006615 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006616 mSessions.add(this);
6617 }
6618 mNumWindow++;
6619 }
6620
6621 void windowRemovedLocked() {
6622 mNumWindow--;
6623 killSessionLocked();
6624 }
Romain Guy06882f82009-06-10 13:36:04 -07006625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 void killSessionLocked() {
6627 if (mNumWindow <= 0 && mClientDead) {
6628 mSessions.remove(this);
6629 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006630 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006631 TAG, "Last window removed from " + this
6632 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006633 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006634 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 try {
6636 mSurfaceSession.kill();
6637 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006638 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006639 + mSurfaceSession + " in session " + this
6640 + ": " + e.toString());
6641 }
6642 mSurfaceSession = null;
6643 }
6644 }
6645 }
Romain Guy06882f82009-06-10 13:36:04 -07006646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006647 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006648 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6649 pw.print(" mClientDead="); pw.print(mClientDead);
6650 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 }
6652
6653 @Override
6654 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006655 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 }
6657 }
6658
6659 // -------------------------------------------------------------
6660 // Client Window State
6661 // -------------------------------------------------------------
6662
6663 private final class WindowState implements WindowManagerPolicy.WindowState {
6664 final Session mSession;
6665 final IWindow mClient;
6666 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006667 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006668 AppWindowToken mAppToken;
6669 AppWindowToken mTargetAppToken;
6670 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6671 final DeathRecipient mDeathRecipient;
6672 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006673 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006674 final int mBaseLayer;
6675 final int mSubLayer;
6676 final boolean mLayoutAttached;
6677 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006678 final boolean mIsWallpaper;
6679 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006680 int mViewVisibility;
6681 boolean mPolicyVisibility = true;
6682 boolean mPolicyVisibilityAfterAnim = true;
6683 boolean mAppFreezing;
6684 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006685 boolean mReportDestroySurface;
6686 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006687 boolean mAttachedHidden; // is our parent window hidden?
6688 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006689 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 int mRequestedWidth;
6691 int mRequestedHeight;
6692 int mLastRequestedWidth;
6693 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006694 int mLayer;
6695 int mAnimLayer;
6696 int mLastLayer;
6697 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006698 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006699 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006700
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006701 int mLayoutSeq = -1;
6702
6703 Configuration mConfiguration = null;
6704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006705 // Actual frame shown on-screen (may be modified by animation)
6706 final Rect mShownFrame = new Rect();
6707 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006710 * Set when we have changed the size of the surface, to know that
6711 * we must tell them application to resize (and thus redraw itself).
6712 */
6713 boolean mSurfaceResized;
6714
6715 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 * Insets that determine the actually visible area
6717 */
6718 final Rect mVisibleInsets = new Rect();
6719 final Rect mLastVisibleInsets = new Rect();
6720 boolean mVisibleInsetsChanged;
6721
6722 /**
6723 * Insets that are covered by system windows
6724 */
6725 final Rect mContentInsets = new Rect();
6726 final Rect mLastContentInsets = new Rect();
6727 boolean mContentInsetsChanged;
6728
6729 /**
6730 * Set to true if we are waiting for this window to receive its
6731 * given internal insets before laying out other windows based on it.
6732 */
6733 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 /**
6736 * These are the content insets that were given during layout for
6737 * this window, to be applied to windows behind it.
6738 */
6739 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006741 /**
6742 * These are the visible insets that were given during layout for
6743 * this window, to be applied to windows behind it.
6744 */
6745 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 /**
6748 * Flag indicating whether the touchable region should be adjusted by
6749 * the visible insets; if false the area outside the visible insets is
6750 * NOT touchable, so we must use those to adjust the frame during hit
6751 * tests.
6752 */
6753 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006756 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006757 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6758 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6759 float mHScale=1, mVScale=1;
6760 float mLastHScale=1, mLastVScale=1;
6761 final Matrix mTmpMatrix = new Matrix();
6762
6763 // "Real" frame that the application sees.
6764 final Rect mFrame = new Rect();
6765 final Rect mLastFrame = new Rect();
6766
6767 final Rect mContainingFrame = new Rect();
6768 final Rect mDisplayFrame = new Rect();
6769 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006770 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 final Rect mVisibleFrame = new Rect();
6772
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006773 boolean mContentChanged;
6774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006775 float mShownAlpha = 1;
6776 float mAlpha = 1;
6777 float mLastAlpha = 1;
6778
6779 // Set to true if, when the window gets displayed, it should perform
6780 // an enter animation.
6781 boolean mEnterAnimationPending;
6782
6783 // Currently running animation.
6784 boolean mAnimating;
6785 boolean mLocalAnimating;
6786 Animation mAnimation;
6787 boolean mAnimationIsEntrance;
6788 boolean mHasTransformation;
6789 boolean mHasLocalTransformation;
6790 final Transformation mTransformation = new Transformation();
6791
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006792 // If a window showing a wallpaper: the requested offset for the
6793 // wallpaper; if a wallpaper window: the currently applied offset.
6794 float mWallpaperX = -1;
6795 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006796
6797 // If a window showing a wallpaper: what fraction of the offset
6798 // range corresponds to a full virtual screen.
6799 float mWallpaperXStep = -1;
6800 float mWallpaperYStep = -1;
6801
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006802 // Wallpaper windows: pixels offset based on above variables.
6803 int mXOffset;
6804 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 // This is set after IWindowSession.relayout() has been called at
6807 // least once for the window. It allows us to detect the situation
6808 // where we don't yet have a surface, but should have one soon, so
6809 // we can give the window focus before waiting for the relayout.
6810 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 // This is set after the Surface has been created but before the
6813 // window has been drawn. During this time the surface is hidden.
6814 boolean mDrawPending;
6815
6816 // This is set after the window has finished drawing for the first
6817 // time but before its surface is shown. The surface will be
6818 // displayed when the next layout is run.
6819 boolean mCommitDrawPending;
6820
6821 // This is set during the time after the window's drawing has been
6822 // committed, and before its surface is actually shown. It is used
6823 // to delay showing the surface until all windows in a token are ready
6824 // to be shown.
6825 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 // Set when the window has been shown in the screen the first time.
6828 boolean mHasDrawn;
6829
6830 // Currently running an exit animation?
6831 boolean mExiting;
6832
6833 // Currently on the mDestroySurface list?
6834 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 // Completely remove from window manager after exit animation?
6837 boolean mRemoveOnExit;
6838
6839 // Set when the orientation is changing and this window has not yet
6840 // been updated for the new orientation.
6841 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 // Is this window now (or just being) removed?
6844 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006845
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006846 // Temp for keeping track of windows that have been removed when
6847 // rebuilding window list.
6848 boolean mRebuilding;
6849
Dianne Hackborn16064f92010-03-25 00:47:24 -07006850 // For debugging, this is the last information given to the surface flinger.
6851 boolean mSurfaceShown;
6852 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6853 int mSurfaceLayer;
6854 float mSurfaceAlpha;
6855
Jeff Brown928e0542011-01-10 11:17:36 -08006856 // Input channel and input window handle used by the input dispatcher.
6857 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006858 InputChannel mInputChannel;
6859
Mattias Petersson1622eee2010-12-21 10:15:11 +01006860 // Used to improve performance of toString()
6861 String mStringNameCache;
6862 CharSequence mLastTitle;
6863 boolean mWasPaused;
6864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006865 WindowState(Session s, IWindow c, WindowToken token,
6866 WindowState attachedWindow, WindowManager.LayoutParams a,
6867 int viewVisibility) {
6868 mSession = s;
6869 mClient = c;
6870 mToken = token;
6871 mAttrs.copyFrom(a);
6872 mViewVisibility = viewVisibility;
6873 DeathRecipient deathRecipient = new DeathRecipient();
6874 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006875 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006876 TAG, "Window " + this + " client=" + c.asBinder()
6877 + " token=" + token + " (" + mAttrs.token + ")");
6878 try {
6879 c.asBinder().linkToDeath(deathRecipient, 0);
6880 } catch (RemoteException e) {
6881 mDeathRecipient = null;
6882 mAttachedWindow = null;
6883 mLayoutAttached = false;
6884 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006885 mIsWallpaper = false;
6886 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 mBaseLayer = 0;
6888 mSubLayer = 0;
6889 return;
6890 }
6891 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6894 mAttrs.type <= LAST_SUB_WINDOW)) {
6895 // The multiplier here is to reserve space for multiple
6896 // windows in the same type layer.
6897 mBaseLayer = mPolicy.windowTypeToLayerLw(
6898 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6899 + TYPE_LAYER_OFFSET;
6900 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6901 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006902 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 mAttachedWindow.mChildWindows.add(this);
6904 mLayoutAttached = mAttrs.type !=
6905 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6906 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6907 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006908 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6909 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006910 } else {
6911 // The multiplier here is to reserve space for multiple
6912 // windows in the same type layer.
6913 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6914 * TYPE_LAYER_MULTIPLIER
6915 + TYPE_LAYER_OFFSET;
6916 mSubLayer = 0;
6917 mAttachedWindow = null;
6918 mLayoutAttached = false;
6919 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6920 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006921 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6922 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006923 }
6924
6925 WindowState appWin = this;
6926 while (appWin.mAttachedWindow != null) {
6927 appWin = mAttachedWindow;
6928 }
6929 WindowToken appToken = appWin.mToken;
6930 while (appToken.appWindowToken == null) {
6931 WindowToken parent = mTokenMap.get(appToken.token);
6932 if (parent == null || appToken == parent) {
6933 break;
6934 }
6935 appToken = parent;
6936 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006937 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 mAppToken = appToken.appWindowToken;
6939
6940 mSurface = null;
6941 mRequestedWidth = 0;
6942 mRequestedHeight = 0;
6943 mLastRequestedWidth = 0;
6944 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006945 mXOffset = 0;
6946 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 mLayer = 0;
6948 mAnimLayer = 0;
6949 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08006950 mInputWindowHandle = new InputWindowHandle(
6951 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 }
6953
6954 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006955 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 TAG, "Attaching " + this + " token=" + mToken
6957 + ", list=" + mToken.windows);
6958 mSession.windowAddedLocked();
6959 }
6960
6961 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6962 mHaveFrame = true;
6963
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006964 final Rect container = mContainingFrame;
6965 container.set(pf);
6966
6967 final Rect display = mDisplayFrame;
6968 display.set(df);
6969
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006970 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006971 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006972 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6973 display.intersect(mCompatibleScreenFrame);
6974 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006975 }
6976
6977 final int pw = container.right - container.left;
6978 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006979
6980 int w,h;
6981 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6982 w = mAttrs.width < 0 ? pw : mAttrs.width;
6983 h = mAttrs.height< 0 ? ph : mAttrs.height;
6984 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006985 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6986 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006987 }
Romain Guy06882f82009-06-10 13:36:04 -07006988
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006989 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006990 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
6991 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006992 mParentFrame.set(pf);
6993 mContentChanged = true;
6994 }
6995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006996 final Rect content = mContentFrame;
6997 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 final Rect visible = mVisibleFrame;
7000 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007002 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007003 final int fw = frame.width();
7004 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007006 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7007 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7008
7009 Gravity.apply(mAttrs.gravity, w, h, container,
7010 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7011 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7012
7013 //System.out.println("Out: " + mFrame);
7014
7015 // Now make sure the window fits in the overall display.
7016 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 // Make sure the content and visible frames are inside of the
7019 // final window frame.
7020 if (content.left < frame.left) content.left = frame.left;
7021 if (content.top < frame.top) content.top = frame.top;
7022 if (content.right > frame.right) content.right = frame.right;
7023 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7024 if (visible.left < frame.left) visible.left = frame.left;
7025 if (visible.top < frame.top) visible.top = frame.top;
7026 if (visible.right > frame.right) visible.right = frame.right;
7027 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 final Rect contentInsets = mContentInsets;
7030 contentInsets.left = content.left-frame.left;
7031 contentInsets.top = content.top-frame.top;
7032 contentInsets.right = frame.right-content.right;
7033 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 final Rect visibleInsets = mVisibleInsets;
7036 visibleInsets.left = visible.left-frame.left;
7037 visibleInsets.top = visible.top-frame.top;
7038 visibleInsets.right = frame.right-visible.right;
7039 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007040
Dianne Hackborn284ac932009-08-28 10:34:25 -07007041 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7042 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007043 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007046 if (localLOGV) {
7047 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7048 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007049 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050 + mRequestedWidth + ", mRequestedheight="
7051 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7052 + "): frame=" + mFrame.toShortString()
7053 + " ci=" + contentInsets.toShortString()
7054 + " vi=" + visibleInsets.toShortString());
7055 //}
7056 }
7057 }
Romain Guy06882f82009-06-10 13:36:04 -07007058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007059 public Rect getFrameLw() {
7060 return mFrame;
7061 }
7062
7063 public Rect getShownFrameLw() {
7064 return mShownFrame;
7065 }
7066
7067 public Rect getDisplayFrameLw() {
7068 return mDisplayFrame;
7069 }
7070
7071 public Rect getContentFrameLw() {
7072 return mContentFrame;
7073 }
7074
7075 public Rect getVisibleFrameLw() {
7076 return mVisibleFrame;
7077 }
7078
7079 public boolean getGivenInsetsPendingLw() {
7080 return mGivenInsetsPending;
7081 }
7082
7083 public Rect getGivenContentInsetsLw() {
7084 return mGivenContentInsets;
7085 }
Romain Guy06882f82009-06-10 13:36:04 -07007086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007087 public Rect getGivenVisibleInsetsLw() {
7088 return mGivenVisibleInsets;
7089 }
Romain Guy06882f82009-06-10 13:36:04 -07007090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 public WindowManager.LayoutParams getAttrs() {
7092 return mAttrs;
7093 }
7094
7095 public int getSurfaceLayer() {
7096 return mLayer;
7097 }
Romain Guy06882f82009-06-10 13:36:04 -07007098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 public IApplicationToken getAppToken() {
7100 return mAppToken != null ? mAppToken.appToken : null;
7101 }
Jeff Brown349703e2010-06-22 01:27:15 -07007102
7103 public long getInputDispatchingTimeoutNanos() {
7104 return mAppToken != null
7105 ? mAppToken.inputDispatchingTimeoutNanos
7106 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108
7109 public boolean hasAppShownWindows() {
7110 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7111 }
7112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007113 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007114 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 TAG, "Setting animation in " + this + ": " + anim);
7116 mAnimating = false;
7117 mLocalAnimating = false;
7118 mAnimation = anim;
7119 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7120 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7121 }
7122
7123 public void clearAnimation() {
7124 if (mAnimation != null) {
7125 mAnimating = true;
7126 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007127 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007128 mAnimation = null;
7129 }
7130 }
Romain Guy06882f82009-06-10 13:36:04 -07007131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007132 Surface createSurfaceLocked() {
7133 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007134 mReportDestroySurface = false;
7135 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 mDrawPending = true;
7137 mCommitDrawPending = false;
7138 mReadyToShow = false;
7139 if (mAppToken != null) {
7140 mAppToken.allDrawn = false;
7141 }
7142
7143 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007144
7145 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7146 flags |= Surface.SECURE;
7147 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007148 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 TAG, "Creating surface in session "
7150 + mSession.mSurfaceSession + " window " + this
7151 + " w=" + mFrame.width()
7152 + " h=" + mFrame.height() + " format="
7153 + mAttrs.format + " flags=" + flags);
7154
7155 int w = mFrame.width();
7156 int h = mFrame.height();
7157 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7158 // for a scaled surface, we always want the requested
7159 // size.
7160 w = mRequestedWidth;
7161 h = mRequestedHeight;
7162 }
7163
Romain Guy9825ec62009-10-01 00:58:09 -07007164 // Something is wrong and SurfaceFlinger will not like this,
7165 // try to revert to sane values
7166 if (w <= 0) w = 1;
7167 if (h <= 0) h = 1;
7168
Dianne Hackborn16064f92010-03-25 00:47:24 -07007169 mSurfaceShown = false;
7170 mSurfaceLayer = 0;
7171 mSurfaceAlpha = 1;
7172 mSurfaceX = 0;
7173 mSurfaceY = 0;
7174 mSurfaceW = w;
7175 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007176 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007177 final boolean isHwAccelerated = (mAttrs.flags &
7178 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7179 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7180 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7181 flags |= Surface.OPAQUE;
7182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007183 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007184 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007185 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007186 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007187 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007188 + mSurface + " IN SESSION "
7189 + mSession.mSurfaceSession
7190 + ": pid=" + mSession.mPid + " format="
7191 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007192 + Integer.toHexString(flags)
7193 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007195 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 reclaimSomeSurfaceMemoryLocked(this, "create");
7197 return null;
7198 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007199 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007200 return null;
7201 }
Romain Guy06882f82009-06-10 13:36:04 -07007202
Joe Onorato8a9b2202010-02-26 18:56:32 -08007203 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007204 TAG, "Got surface: " + mSurface
7205 + ", set left=" + mFrame.left + " top=" + mFrame.top
7206 + ", animLayer=" + mAnimLayer);
7207 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007208 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007209 if (SHOW_TRANSACTIONS) logSurface(this,
7210 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7211 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7212 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007213 }
7214 Surface.openTransaction();
7215 try {
7216 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007217 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007218 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007219 mSurface.setPosition(mSurfaceX, mSurfaceY);
7220 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007221 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007222 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 mSurface.hide();
7224 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007225 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007226 mSurface.setFlags(Surface.SURFACE_DITHER,
7227 Surface.SURFACE_DITHER);
7228 }
7229 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007230 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7232 }
7233 mLastHidden = true;
7234 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007235 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 Surface.closeTransaction();
7237 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007238 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 TAG, "Created surface " + this);
7240 }
7241 return mSurface;
7242 }
Romain Guy06882f82009-06-10 13:36:04 -07007243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007245 if (mAppToken != null && this == mAppToken.startingWindow) {
7246 mAppToken.startingDisplayed = false;
7247 }
Romain Guy06882f82009-06-10 13:36:04 -07007248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007249 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007250 mDrawPending = false;
7251 mCommitDrawPending = false;
7252 mReadyToShow = false;
7253
7254 int i = mChildWindows.size();
7255 while (i > 0) {
7256 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007257 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007258 c.mAttachedHidden = true;
7259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007260
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007261 if (mReportDestroySurface) {
7262 mReportDestroySurface = false;
7263 mSurfacePendingDestroy = true;
7264 try {
7265 mClient.dispatchGetNewSurface();
7266 // We'll really destroy on the next time around.
7267 return;
7268 } catch (RemoteException e) {
7269 }
7270 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007272 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007273 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007274 RuntimeException e = null;
7275 if (!HIDE_STACK_CRAWLS) {
7276 e = new RuntimeException();
7277 e.fillInStackTrace();
7278 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007279 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007280 + mSurface + ", session " + mSession, e);
7281 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007282 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007283 RuntimeException e = null;
7284 if (!HIDE_STACK_CRAWLS) {
7285 e = new RuntimeException();
7286 e.fillInStackTrace();
7287 }
7288 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007290 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007292 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 + " surface " + mSurface + " session " + mSession
7294 + ": " + e.toString());
7295 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007296
Dianne Hackborn16064f92010-03-25 00:47:24 -07007297 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 }
7300 }
7301
7302 boolean finishDrawingLocked() {
7303 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007304 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 TAG, "finishDrawingLocked: " + mSurface);
7306 mCommitDrawPending = true;
7307 mDrawPending = false;
7308 return true;
7309 }
7310 return false;
7311 }
7312
7313 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007314 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007315 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007317 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007318 }
7319 mCommitDrawPending = false;
7320 mReadyToShow = true;
7321 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7322 final AppWindowToken atoken = mAppToken;
7323 if (atoken == null || atoken.allDrawn || starting) {
7324 performShowLocked();
7325 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007326 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007327 }
7328
7329 // This must be called while inside a transaction.
7330 boolean performShowLocked() {
7331 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007332 RuntimeException e = null;
7333 if (!HIDE_STACK_CRAWLS) {
7334 e = new RuntimeException();
7335 e.fillInStackTrace();
7336 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007337 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7339 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7340 }
7341 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007342 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7343 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007344 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 + " during animation: policyVis=" + mPolicyVisibility
7346 + " attHidden=" + mAttachedHidden
7347 + " tok.hiddenRequested="
7348 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007349 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 + (mAppToken != null ? mAppToken.hidden : false)
7351 + " animating=" + mAnimating
7352 + " tok animating="
7353 + (mAppToken != null ? mAppToken.animating : false));
7354 if (!showSurfaceRobustlyLocked(this)) {
7355 return false;
7356 }
7357 mLastAlpha = -1;
7358 mHasDrawn = true;
7359 mLastHidden = false;
7360 mReadyToShow = false;
7361 enableScreenIfNeededLocked();
7362
7363 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 int i = mChildWindows.size();
7366 while (i > 0) {
7367 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007368 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007369 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007370 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007371 if (c.mSurface != null) {
7372 c.performShowLocked();
7373 // It hadn't been shown, which means layout not
7374 // performed on it, so now we want to make sure to
7375 // do a layout. If called from within the transaction
7376 // loop, this will cause it to restart with a new
7377 // layout.
7378 mLayoutNeeded = true;
7379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 }
7381 }
Romain Guy06882f82009-06-10 13:36:04 -07007382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 if (mAttrs.type != TYPE_APPLICATION_STARTING
7384 && mAppToken != null) {
7385 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007386
Dianne Hackborn248b1882009-09-16 16:46:44 -07007387 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007388 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007389 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007390 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007391 // If this initial window is animating, stop it -- we
7392 // will do an animation to reveal it from behind the
7393 // starting window, so there is no need for it to also
7394 // be doing its own stuff.
7395 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007396 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007397 mAnimation = null;
7398 // Make sure we clean up the animation.
7399 mAnimating = true;
7400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 mFinishedStarting.add(mAppToken);
7402 mH.sendEmptyMessage(H.FINISHED_STARTING);
7403 }
7404 mAppToken.updateReportedVisibilityLocked();
7405 }
7406 }
7407 return true;
7408 }
Romain Guy06882f82009-06-10 13:36:04 -07007409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 // This must be called while inside a transaction. Returns true if
7411 // there is more animation to run.
7412 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007413 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007416 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7417 mHasTransformation = true;
7418 mHasLocalTransformation = true;
7419 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007420 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 TAG, "Starting animation in " + this +
7422 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7423 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7424 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7425 mAnimation.setStartTime(currentTime);
7426 mLocalAnimating = true;
7427 mAnimating = true;
7428 }
7429 mTransformation.clear();
7430 final boolean more = mAnimation.getTransformation(
7431 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007432 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 TAG, "Stepped animation in " + this +
7434 ": more=" + more + ", xform=" + mTransformation);
7435 if (more) {
7436 // we're not done!
7437 return true;
7438 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007439 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 TAG, "Finished animation in " + this +
7441 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007442
7443 if (mAnimation != null) {
7444 mAnimation.cancel();
7445 mAnimation = null;
7446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 //WindowManagerService.this.dump();
7448 }
7449 mHasLocalTransformation = false;
7450 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007451 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 // When our app token is animating, we kind-of pretend like
7453 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7454 // part of this check means that we will only do this if
7455 // our window is not currently exiting, or it is not
7456 // locally animating itself. The idea being that one that
7457 // is exiting and doing a local animation should be removed
7458 // once that animation is done.
7459 mAnimating = true;
7460 mHasTransformation = true;
7461 mTransformation.clear();
7462 return false;
7463 } else if (mHasTransformation) {
7464 // Little trick to get through the path below to act like
7465 // we have finished an animation.
7466 mAnimating = true;
7467 } else if (isAnimating()) {
7468 mAnimating = true;
7469 }
7470 } else if (mAnimation != null) {
7471 // If the display is frozen, and there is a pending animation,
7472 // clear it and make sure we run the cleanup code.
7473 mAnimating = true;
7474 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007475 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 mAnimation = null;
7477 }
Romain Guy06882f82009-06-10 13:36:04 -07007478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 if (!mAnimating && !mLocalAnimating) {
7480 return false;
7481 }
7482
Joe Onorato8a9b2202010-02-26 18:56:32 -08007483 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 TAG, "Animation done in " + this + ": exiting=" + mExiting
7485 + ", reportedVisible="
7486 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007488 mAnimating = false;
7489 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007490 if (mAnimation != null) {
7491 mAnimation.cancel();
7492 mAnimation = null;
7493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 mAnimLayer = mLayer;
7495 if (mIsImWindow) {
7496 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007497 } else if (mIsWallpaper) {
7498 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007500 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 + " anim layer: " + mAnimLayer);
7502 mHasTransformation = false;
7503 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007504 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7505 if (DEBUG_VISIBILITY) {
7506 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7507 + mPolicyVisibilityAfterAnim);
7508 }
7509 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7510 if (!mPolicyVisibility) {
7511 if (mCurrentFocus == this) {
7512 mFocusMayChange = true;
7513 }
7514 // Window is no longer visible -- make sure if we were waiting
7515 // for it to be displayed before enabling the display, that
7516 // we allow the display to be enabled now.
7517 enableScreenIfNeededLocked();
7518 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 mTransformation.clear();
7521 if (mHasDrawn
7522 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7523 && mAppToken != null
7524 && mAppToken.firstWindowDrawn
7525 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007526 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 + mToken + ": first real window done animating");
7528 mFinishedStarting.add(mAppToken);
7529 mH.sendEmptyMessage(H.FINISHED_STARTING);
7530 }
Romain Guy06882f82009-06-10 13:36:04 -07007531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 finishExit();
7533
7534 if (mAppToken != null) {
7535 mAppToken.updateReportedVisibilityLocked();
7536 }
7537
7538 return false;
7539 }
7540
7541 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007542 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 TAG, "finishExit in " + this
7544 + ": exiting=" + mExiting
7545 + " remove=" + mRemoveOnExit
7546 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 final int N = mChildWindows.size();
7549 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007550 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 }
Romain Guy06882f82009-06-10 13:36:04 -07007552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 if (!mExiting) {
7554 return;
7555 }
Romain Guy06882f82009-06-10 13:36:04 -07007556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 if (isWindowAnimating()) {
7558 return;
7559 }
7560
Joe Onorato8a9b2202010-02-26 18:56:32 -08007561 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 TAG, "Exit animation finished in " + this
7563 + ": remove=" + mRemoveOnExit);
7564 if (mSurface != null) {
7565 mDestroySurface.add(this);
7566 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007567 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007568 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 try {
7570 mSurface.hide();
7571 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007572 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 }
7574 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 }
7576 mExiting = false;
7577 if (mRemoveOnExit) {
7578 mPendingRemove.add(this);
7579 mRemoveOnExit = false;
7580 }
7581 }
Romain Guy06882f82009-06-10 13:36:04 -07007582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7584 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7585 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7586 if (dtdx < -.000001f || dtdx > .000001f) return false;
7587 if (dsdy < -.000001f || dsdy > .000001f) return false;
7588 return true;
7589 }
Romain Guy06882f82009-06-10 13:36:04 -07007590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 void computeShownFrameLocked() {
7592 final boolean selfTransformation = mHasLocalTransformation;
7593 Transformation attachedTransformation =
7594 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7595 ? mAttachedWindow.mTransformation : null;
7596 Transformation appTransformation =
7597 (mAppToken != null && mAppToken.hasTransformation)
7598 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007599
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007600 // Wallpapers are animated based on the "real" window they
7601 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007602 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007603 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007604 if (mWallpaperTarget.mHasLocalTransformation &&
7605 mWallpaperTarget.mAnimation != null &&
7606 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007607 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007608 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007609 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007610 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007611 }
7612 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007613 mWallpaperTarget.mAppToken.hasTransformation &&
7614 mWallpaperTarget.mAppToken.animation != null &&
7615 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007616 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007617 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007618 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007619 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007620 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007621 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007622
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007623 final boolean screenAnimation = mScreenRotationAnimation != null
7624 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007625 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007626 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007627 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007628 final Rect frame = mFrame;
7629 final float tmpFloats[] = mTmpFloats;
7630 final Matrix tmpMatrix = mTmpMatrix;
7631
7632 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007633 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007634 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007635 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007636 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007637 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007639 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 }
7641 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007642 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007644 if (screenAnimation) {
7645 tmpMatrix.postConcat(
7646 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007648
7649 // "convert" it into SurfaceFlinger's format
7650 // (a 2x2 matrix + an offset)
7651 // Here we must not transform the position of the surface
7652 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007653 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007654
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007655 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007656 tmpMatrix.getValues(tmpFloats);
7657 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007658 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7659 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007661 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7662 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 int w = frame.width();
7664 int h = frame.height();
7665 mShownFrame.set(x, y, x+w, y+h);
7666
7667 // Now set the alpha... but because our current hardware
7668 // can't do alpha transformation on a non-opaque surface,
7669 // turn it off if we are running an animation that is also
7670 // transforming since it is more important to have that
7671 // animation be smooth.
7672 mShownAlpha = mAlpha;
7673 if (!mLimitedAlphaCompositing
7674 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7675 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7676 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007677 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 if (selfTransformation) {
7679 mShownAlpha *= mTransformation.getAlpha();
7680 }
7681 if (attachedTransformation != null) {
7682 mShownAlpha *= attachedTransformation.getAlpha();
7683 }
7684 if (appTransformation != null) {
7685 mShownAlpha *= appTransformation.getAlpha();
7686 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007687 if (screenAnimation) {
7688 mShownAlpha *=
7689 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007691 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007692 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007693 }
Romain Guy06882f82009-06-10 13:36:04 -07007694
Joe Onorato8a9b2202010-02-26 18:56:32 -08007695 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 TAG, "Continuing animation in " + this +
7697 ": " + mShownFrame +
7698 ", alpha=" + mTransformation.getAlpha());
7699 return;
7700 }
Romain Guy06882f82009-06-10 13:36:04 -07007701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007703 if (mXOffset != 0 || mYOffset != 0) {
7704 mShownFrame.offset(mXOffset, mYOffset);
7705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007707 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 mDsDx = 1;
7709 mDtDx = 0;
7710 mDsDy = 0;
7711 mDtDy = 1;
7712 }
Romain Guy06882f82009-06-10 13:36:04 -07007713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007714 /**
7715 * Is this window visible? It is not visible if there is no
7716 * surface, or we are in the process of running an exit animation
7717 * that will remove the surface, or its app token has been hidden.
7718 */
7719 public boolean isVisibleLw() {
7720 final AppWindowToken atoken = mAppToken;
7721 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7722 && (atoken == null || !atoken.hiddenRequested)
7723 && !mExiting && !mDestroying;
7724 }
7725
7726 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007727 * Like {@link #isVisibleLw}, but also counts a window that is currently
7728 * "hidden" behind the keyguard as visible. This allows us to apply
7729 * things like window flags that impact the keyguard.
7730 * XXX I am starting to think we need to have ANOTHER visibility flag
7731 * for this "hidden behind keyguard" state rather than overloading
7732 * mPolicyVisibility. Ungh.
7733 */
7734 public boolean isVisibleOrBehindKeyguardLw() {
7735 final AppWindowToken atoken = mAppToken;
7736 return mSurface != null && !mAttachedHidden
7737 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007738 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007739 && !mExiting && !mDestroying;
7740 }
7741
7742 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 * Is this window visible, ignoring its app token? It is not visible
7744 * if there is no surface, or we are in the process of running an exit animation
7745 * that will remove the surface.
7746 */
7747 public boolean isWinVisibleLw() {
7748 final AppWindowToken atoken = mAppToken;
7749 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7750 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7751 && !mExiting && !mDestroying;
7752 }
7753
7754 /**
7755 * The same as isVisible(), but follows the current hidden state of
7756 * the associated app token, not the pending requested hidden state.
7757 */
7758 boolean isVisibleNow() {
7759 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007760 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 }
7762
7763 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007764 * Can this window possibly be a drag/drop target? The test here is
7765 * a combination of the above "visible now" with the check that the
7766 * Input Manager uses when discarding windows from input consideration.
7767 */
7768 boolean isPotentialDragTarget() {
7769 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7770 }
7771
7772 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007773 * Same as isVisible(), but we also count it as visible between the
7774 * call to IWindowSession.add() and the first relayout().
7775 */
7776 boolean isVisibleOrAdding() {
7777 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007778 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007779 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7780 && mPolicyVisibility && !mAttachedHidden
7781 && (atoken == null || !atoken.hiddenRequested)
7782 && !mExiting && !mDestroying;
7783 }
7784
7785 /**
7786 * Is this window currently on-screen? It is on-screen either if it
7787 * is visible or it is currently running an animation before no longer
7788 * being visible.
7789 */
7790 boolean isOnScreen() {
7791 final AppWindowToken atoken = mAppToken;
7792 if (atoken != null) {
7793 return mSurface != null && mPolicyVisibility && !mDestroying
7794 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007795 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 } else {
7797 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007798 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 }
7800 }
Romain Guy06882f82009-06-10 13:36:04 -07007801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007802 /**
7803 * Like isOnScreen(), but we don't return true if the window is part
7804 * of a transition that has not yet been started.
7805 */
7806 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007807 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007808 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007809 return false;
7810 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007812 final boolean animating = atoken != null
7813 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007814 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007815 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7816 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007817 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007818 }
7819
7820 /** Is the window or its container currently animating? */
7821 boolean isAnimating() {
7822 final WindowState attached = mAttachedWindow;
7823 final AppWindowToken atoken = mAppToken;
7824 return mAnimation != null
7825 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007826 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007827 (atoken.animation != null
7828 || atoken.inPendingTransaction));
7829 }
7830
7831 /** Is this window currently animating? */
7832 boolean isWindowAnimating() {
7833 return mAnimation != null;
7834 }
7835
7836 /**
7837 * Like isOnScreen, but returns false if the surface hasn't yet
7838 * been drawn.
7839 */
7840 public boolean isDisplayedLw() {
7841 final AppWindowToken atoken = mAppToken;
7842 return mSurface != null && mPolicyVisibility && !mDestroying
7843 && !mDrawPending && !mCommitDrawPending
7844 && ((!mAttachedHidden &&
7845 (atoken == null || !atoken.hiddenRequested))
7846 || mAnimating);
7847 }
7848
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007849 /**
7850 * Returns true if the window has a surface that it has drawn a
7851 * complete UI in to.
7852 */
7853 public boolean isDrawnLw() {
7854 final AppWindowToken atoken = mAppToken;
7855 return mSurface != null && !mDestroying
7856 && !mDrawPending && !mCommitDrawPending;
7857 }
7858
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007859 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007860 * Return true if the window is opaque and fully drawn. This indicates
7861 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007862 */
7863 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007864 return (mAttrs.format == PixelFormat.OPAQUE
7865 || mAttrs.type == TYPE_WALLPAPER)
7866 && mSurface != null && mAnimation == null
7867 && (mAppToken == null || mAppToken.animation == null)
7868 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007869 }
7870
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007871 /**
7872 * Return whether this window is wanting to have a translation
7873 * animation applied to it for an in-progress move. (Only makes
7874 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7875 */
7876 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007877 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007878 && (mFrame.top != mLastFrame.top
7879 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007880 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007881 && mPolicy.isScreenOn();
7882 }
7883
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007884 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7885 return
7886 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007887 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7888 // only if it's visible
7889 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007890 // and only if the application fills the compatible screen
7891 mFrame.left <= mCompatibleScreenFrame.left &&
7892 mFrame.top <= mCompatibleScreenFrame.top &&
7893 mFrame.right >= mCompatibleScreenFrame.right &&
7894 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007895 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007896 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007897 }
7898
7899 boolean isFullscreen(int screenWidth, int screenHeight) {
7900 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007901 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007902 }
7903
7904 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007905 disposeInputChannel();
7906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007908 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007909 mAttachedWindow.mChildWindows.remove(this);
7910 }
7911 destroySurfaceLocked();
7912 mSession.windowRemovedLocked();
7913 try {
7914 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7915 } catch (RuntimeException e) {
7916 // Ignore if it has already been removed (usually because
7917 // we are doing this as part of processing a death note.)
7918 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007919 }
7920
7921 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007922 if (mInputChannel != null) {
7923 mInputManager.unregisterInputChannel(mInputChannel);
7924
7925 mInputChannel.dispose();
7926 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007928 }
7929
7930 private class DeathRecipient implements IBinder.DeathRecipient {
7931 public void binderDied() {
7932 try {
7933 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007934 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007935 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 if (win != null) {
7937 removeWindowLocked(mSession, win);
7938 }
7939 }
7940 } catch (IllegalArgumentException ex) {
7941 // This will happen if the window has already been
7942 // removed.
7943 }
7944 }
7945 }
7946
7947 /** Returns true if this window desires key events. */
7948 public final boolean canReceiveKeys() {
7949 return isVisibleOrAdding()
7950 && (mViewVisibility == View.VISIBLE)
7951 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7952 }
7953
7954 public boolean hasDrawnLw() {
7955 return mHasDrawn;
7956 }
7957
7958 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007959 return showLw(doAnimation, true);
7960 }
7961
7962 boolean showLw(boolean doAnimation, boolean requestAnim) {
7963 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7964 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007965 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007966 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007967 if (doAnimation) {
7968 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7969 + mPolicyVisibility + " mAnimation=" + mAnimation);
7970 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7971 doAnimation = false;
7972 } else if (mPolicyVisibility && mAnimation == null) {
7973 // Check for the case where we are currently visible and
7974 // not animating; we do not want to do animation at such a
7975 // point to become visible when we already are.
7976 doAnimation = false;
7977 }
7978 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007979 mPolicyVisibility = true;
7980 mPolicyVisibilityAfterAnim = true;
7981 if (doAnimation) {
7982 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7983 }
7984 if (requestAnim) {
7985 requestAnimationLocked(0);
7986 }
7987 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 }
7989
7990 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007991 return hideLw(doAnimation, true);
7992 }
7993
7994 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007995 if (doAnimation) {
7996 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7997 doAnimation = false;
7998 }
7999 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008000 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8001 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008002 if (!current) {
8003 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008005 if (doAnimation) {
8006 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8007 if (mAnimation == null) {
8008 doAnimation = false;
8009 }
8010 }
8011 if (doAnimation) {
8012 mPolicyVisibilityAfterAnim = false;
8013 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008014 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008015 mPolicyVisibilityAfterAnim = false;
8016 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008017 // Window is no longer visible -- make sure if we were waiting
8018 // for it to be displayed before enabling the display, that
8019 // we allow the display to be enabled now.
8020 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008021 if (mCurrentFocus == this) {
8022 mFocusMayChange = true;
8023 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008024 }
8025 if (requestAnim) {
8026 requestAnimationLocked(0);
8027 }
8028 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008029 }
8030
8031 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008032 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8033 pw.print(" mClient="); pw.println(mClient.asBinder());
8034 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8035 if (mAttachedWindow != null || mLayoutAttached) {
8036 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8037 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8038 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008039 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8040 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8041 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008042 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8043 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008044 }
8045 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8046 pw.print(" mSubLayer="); pw.print(mSubLayer);
8047 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8048 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8049 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8050 pw.print("="); pw.print(mAnimLayer);
8051 pw.print(" mLastLayer="); pw.println(mLastLayer);
8052 if (mSurface != null) {
8053 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008054 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8055 pw.print(" layer="); pw.print(mSurfaceLayer);
8056 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8057 pw.print(" rect=("); pw.print(mSurfaceX);
8058 pw.print(","); pw.print(mSurfaceY);
8059 pw.print(") "); pw.print(mSurfaceW);
8060 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008061 }
8062 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8063 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8064 if (mAppToken != null) {
8065 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8066 }
8067 if (mTargetAppToken != null) {
8068 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8069 }
8070 pw.print(prefix); pw.print("mViewVisibility=0x");
8071 pw.print(Integer.toHexString(mViewVisibility));
8072 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008073 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8074 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008075 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8076 pw.print(prefix); pw.print("mPolicyVisibility=");
8077 pw.print(mPolicyVisibility);
8078 pw.print(" mPolicyVisibilityAfterAnim=");
8079 pw.print(mPolicyVisibilityAfterAnim);
8080 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8081 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008082 if (!mRelayoutCalled) {
8083 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8084 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008085 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008086 pw.print(" h="); pw.print(mRequestedHeight);
8087 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008088 if (mXOffset != 0 || mYOffset != 0) {
8089 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8090 pw.print(" y="); pw.println(mYOffset);
8091 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008092 pw.print(prefix); pw.print("mGivenContentInsets=");
8093 mGivenContentInsets.printShortString(pw);
8094 pw.print(" mGivenVisibleInsets=");
8095 mGivenVisibleInsets.printShortString(pw);
8096 pw.println();
8097 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8098 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8099 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8100 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008101 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008102 pw.print(prefix); pw.print("mShownFrame=");
8103 mShownFrame.printShortString(pw);
8104 pw.print(" last="); mLastShownFrame.printShortString(pw);
8105 pw.println();
8106 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8107 pw.print(" last="); mLastFrame.printShortString(pw);
8108 pw.println();
8109 pw.print(prefix); pw.print("mContainingFrame=");
8110 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008111 pw.print(" mParentFrame=");
8112 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008113 pw.print(" mDisplayFrame=");
8114 mDisplayFrame.printShortString(pw);
8115 pw.println();
8116 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8117 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8118 pw.println();
8119 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8120 pw.print(" last="); mLastContentInsets.printShortString(pw);
8121 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8122 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8123 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008124 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8125 || mAnimation != null) {
8126 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8127 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8128 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8129 pw.print(" mAnimation="); pw.println(mAnimation);
8130 }
8131 if (mHasTransformation || mHasLocalTransformation) {
8132 pw.print(prefix); pw.print("XForm: has=");
8133 pw.print(mHasTransformation);
8134 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8135 pw.print(" "); mTransformation.printShortString(pw);
8136 pw.println();
8137 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008138 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8139 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8140 pw.print(" mAlpha="); pw.print(mAlpha);
8141 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8142 }
8143 if (mHaveMatrix) {
8144 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8145 pw.print(" mDtDx="); pw.print(mDtDx);
8146 pw.print(" mDsDy="); pw.print(mDsDy);
8147 pw.print(" mDtDy="); pw.println(mDtDy);
8148 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008149 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8150 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8151 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8152 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8153 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8154 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8155 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8156 pw.print(" mDestroying="); pw.print(mDestroying);
8157 pw.print(" mRemoved="); pw.println(mRemoved);
8158 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008159 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008160 pw.print(prefix); pw.print("mOrientationChanging=");
8161 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008162 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8163 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008164 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008165 if (mHScale != 1 || mVScale != 1) {
8166 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8167 pw.print(" mVScale="); pw.println(mVScale);
8168 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008169 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008170 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8171 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8172 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008173 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8174 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8175 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8176 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008177 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008178
8179 String makeInputChannelName() {
8180 return Integer.toHexString(System.identityHashCode(this))
8181 + " " + mAttrs.getTitle();
8182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008183
8184 @Override
8185 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008186 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8187 || mWasPaused != mToken.paused) {
8188 mLastTitle = mAttrs.getTitle();
8189 mWasPaused = mToken.paused;
8190 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8191 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8192 }
8193 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 }
8195 }
Romain Guy06882f82009-06-10 13:36:04 -07008196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008197 // -------------------------------------------------------------
8198 // Window Token State
8199 // -------------------------------------------------------------
8200
8201 class WindowToken {
8202 // The actual token.
8203 final IBinder token;
8204
8205 // The type of window this token is for, as per WindowManager.LayoutParams.
8206 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008208 // Set if this token was explicitly added by a client, so should
8209 // not be removed when all windows are removed.
8210 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008211
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008212 // For printing.
8213 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008215 // If this is an AppWindowToken, this is non-null.
8216 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008218 // All of the windows associated with this token.
8219 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8220
8221 // Is key dispatching paused for this token?
8222 boolean paused = false;
8223
8224 // Should this token's windows be hidden?
8225 boolean hidden;
8226
8227 // Temporary for finding which tokens no longer have visible windows.
8228 boolean hasVisible;
8229
Dianne Hackborna8f60182009-09-01 19:01:50 -07008230 // Set to true when this token is in a pending transaction where it
8231 // will be shown.
8232 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008233
Dianne Hackborna8f60182009-09-01 19:01:50 -07008234 // Set to true when this token is in a pending transaction where it
8235 // will be hidden.
8236 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008237
Dianne Hackborna8f60182009-09-01 19:01:50 -07008238 // Set to true when this token is in a pending transaction where its
8239 // windows will be put to the bottom of the list.
8240 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008241
Dianne Hackborna8f60182009-09-01 19:01:50 -07008242 // Set to true when this token is in a pending transaction where its
8243 // windows will be put to the top of the list.
8244 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008246 WindowToken(IBinder _token, int type, boolean _explicit) {
8247 token = _token;
8248 windowType = type;
8249 explicit = _explicit;
8250 }
8251
8252 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008253 pw.print(prefix); pw.print("token="); pw.println(token);
8254 pw.print(prefix); pw.print("windows="); pw.println(windows);
8255 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8256 pw.print(" hidden="); pw.print(hidden);
8257 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008258 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8259 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8260 pw.print(" waitingToHide="); pw.print(waitingToHide);
8261 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8262 pw.print(" sendingToTop="); pw.println(sendingToTop);
8263 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008264 }
8265
8266 @Override
8267 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008268 if (stringName == null) {
8269 StringBuilder sb = new StringBuilder();
8270 sb.append("WindowToken{");
8271 sb.append(Integer.toHexString(System.identityHashCode(this)));
8272 sb.append(" token="); sb.append(token); sb.append('}');
8273 stringName = sb.toString();
8274 }
8275 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008276 }
8277 };
8278
8279 class AppWindowToken extends WindowToken {
8280 // Non-null only for application tokens.
8281 final IApplicationToken appToken;
8282
8283 // All of the windows and child windows that are included in this
8284 // application token. Note this list is NOT sorted!
8285 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8286
8287 int groupId = -1;
8288 boolean appFullscreen;
8289 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008290
8291 // The input dispatching timeout for this application token in nanoseconds.
8292 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008294 // These are used for determining when all windows associated with
8295 // an activity have been drawn, so they can be made visible together
8296 // at the same time.
8297 int lastTransactionSequence = mTransactionSequence-1;
8298 int numInterestingWindows;
8299 int numDrawnWindows;
8300 boolean inPendingTransaction;
8301 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008303 // Is this token going to be hidden in a little while? If so, it
8304 // won't be taken into account for setting the screen orientation.
8305 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307 // Is this window's surface needed? This is almost like hidden, except
8308 // it will sometimes be true a little earlier: when the token has
8309 // been shown, but is still waiting for its app transition to execute
8310 // before making its windows shown.
8311 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 // Have we told the window clients to hide themselves?
8314 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 // Last visibility state we reported to the app token.
8317 boolean reportedVisible;
8318
8319 // Set to true when the token has been removed from the window mgr.
8320 boolean removed;
8321
8322 // Have we been asked to have this token keep the screen frozen?
8323 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008325 boolean animating;
8326 Animation animation;
8327 boolean hasTransformation;
8328 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008330 // Offset to the window of all layers in the token, for use by
8331 // AppWindowToken animations.
8332 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008334 // Information about an application starting window if displayed.
8335 StartingData startingData;
8336 WindowState startingWindow;
8337 View startingView;
8338 boolean startingDisplayed;
8339 boolean startingMoved;
8340 boolean firstWindowDrawn;
8341
Jeff Brown928e0542011-01-10 11:17:36 -08008342 // Input application handle used by the input dispatcher.
8343 InputApplicationHandle mInputApplicationHandle;
8344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008345 AppWindowToken(IApplicationToken _token) {
8346 super(_token.asBinder(),
8347 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8348 appWindowToken = this;
8349 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008350 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008351 }
Romain Guy06882f82009-06-10 13:36:04 -07008352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008354 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008355 TAG, "Setting animation in " + this + ": " + anim);
8356 animation = anim;
8357 animating = false;
8358 anim.restrictDuration(MAX_ANIMATION_DURATION);
8359 anim.scaleCurrentDuration(mTransitionAnimationScale);
8360 int zorder = anim.getZAdjustment();
8361 int adj = 0;
8362 if (zorder == Animation.ZORDER_TOP) {
8363 adj = TYPE_LAYER_OFFSET;
8364 } else if (zorder == Animation.ZORDER_BOTTOM) {
8365 adj = -TYPE_LAYER_OFFSET;
8366 }
Romain Guy06882f82009-06-10 13:36:04 -07008367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008368 if (animLayerAdjustment != adj) {
8369 animLayerAdjustment = adj;
8370 updateLayers();
8371 }
8372 }
Romain Guy06882f82009-06-10 13:36:04 -07008373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008374 public void setDummyAnimation() {
8375 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008376 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 TAG, "Setting dummy animation in " + this);
8378 animation = sDummyAnimation;
8379 }
8380 }
8381
8382 public void clearAnimation() {
8383 if (animation != null) {
8384 animation = null;
8385 animating = true;
8386 }
8387 }
Romain Guy06882f82009-06-10 13:36:04 -07008388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008389 void updateLayers() {
8390 final int N = allAppWindows.size();
8391 final int adj = animLayerAdjustment;
8392 for (int i=0; i<N; i++) {
8393 WindowState w = allAppWindows.get(i);
8394 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008395 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008396 + w.mAnimLayer);
8397 if (w == mInputMethodTarget) {
8398 setInputMethodAnimLayerAdjustment(adj);
8399 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008400 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008401 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 }
8404 }
Romain Guy06882f82009-06-10 13:36:04 -07008405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 void sendAppVisibilityToClients() {
8407 final int N = allAppWindows.size();
8408 for (int i=0; i<N; i++) {
8409 WindowState win = allAppWindows.get(i);
8410 if (win == startingWindow && clientHidden) {
8411 // Don't hide the starting window.
8412 continue;
8413 }
8414 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008415 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008416 "Setting visibility of " + win + ": " + (!clientHidden));
8417 win.mClient.dispatchAppVisibility(!clientHidden);
8418 } catch (RemoteException e) {
8419 }
8420 }
8421 }
Romain Guy06882f82009-06-10 13:36:04 -07008422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008423 void showAllWindowsLocked() {
8424 final int NW = allAppWindows.size();
8425 for (int i=0; i<NW; i++) {
8426 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008427 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428 "performing show on: " + w);
8429 w.performShowLocked();
8430 }
8431 }
Romain Guy06882f82009-06-10 13:36:04 -07008432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 // This must be called while inside a transaction.
8434 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008435 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438 if (animation == sDummyAnimation) {
8439 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008440 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 // when it is really time to animate, this will be set to
8442 // a real animation and the next call will execute normally.
8443 return false;
8444 }
Romain Guy06882f82009-06-10 13:36:04 -07008445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008446 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8447 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008448 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 TAG, "Starting animation in " + this +
8450 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8451 + " scale=" + mTransitionAnimationScale
8452 + " allDrawn=" + allDrawn + " animating=" + animating);
8453 animation.initialize(dw, dh, dw, dh);
8454 animation.setStartTime(currentTime);
8455 animating = true;
8456 }
8457 transformation.clear();
8458 final boolean more = animation.getTransformation(
8459 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008460 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008461 TAG, "Stepped animation in " + this +
8462 ": more=" + more + ", xform=" + transformation);
8463 if (more) {
8464 // we're done!
8465 hasTransformation = true;
8466 return true;
8467 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008468 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 TAG, "Finished animation in " + this +
8470 " @ " + currentTime);
8471 animation = null;
8472 }
8473 } else if (animation != null) {
8474 // If the display is frozen, and there is a pending animation,
8475 // clear it and make sure we run the cleanup code.
8476 animating = true;
8477 animation = null;
8478 }
8479
8480 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 if (!animating) {
8483 return false;
8484 }
8485
8486 clearAnimation();
8487 animating = false;
8488 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8489 moveInputMethodWindowsIfNeededLocked(true);
8490 }
Romain Guy06882f82009-06-10 13:36:04 -07008491
Joe Onorato8a9b2202010-02-26 18:56:32 -08008492 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 TAG, "Animation done in " + this
8494 + ": reportedVisible=" + reportedVisible);
8495
8496 transformation.clear();
8497 if (animLayerAdjustment != 0) {
8498 animLayerAdjustment = 0;
8499 updateLayers();
8500 }
Romain Guy06882f82009-06-10 13:36:04 -07008501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008502 final int N = windows.size();
8503 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008504 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008505 }
8506 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008508 return false;
8509 }
8510
8511 void updateReportedVisibilityLocked() {
8512 if (appToken == null) {
8513 return;
8514 }
Romain Guy06882f82009-06-10 13:36:04 -07008515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 int numInteresting = 0;
8517 int numVisible = 0;
8518 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008519
Joe Onorato8a9b2202010-02-26 18:56:32 -08008520 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008521 final int N = allAppWindows.size();
8522 for (int i=0; i<N; i++) {
8523 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008524 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008525 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008526 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8527 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008528 continue;
8529 }
8530 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008531 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008532 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008533 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008534 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008535 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 + " pv=" + win.mPolicyVisibility
8537 + " dp=" + win.mDrawPending
8538 + " cdp=" + win.mCommitDrawPending
8539 + " ah=" + win.mAttachedHidden
8540 + " th="
8541 + (win.mAppToken != null
8542 ? win.mAppToken.hiddenRequested : false)
8543 + " a=" + win.mAnimating);
8544 }
8545 }
8546 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008547 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 if (!win.isAnimating()) {
8549 numVisible++;
8550 }
8551 nowGone = false;
8552 } else if (win.isAnimating()) {
8553 nowGone = false;
8554 }
8555 }
Romain Guy06882f82009-06-10 13:36:04 -07008556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008558 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 + numInteresting + " visible=" + numVisible);
8560 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008561 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562 TAG, "Visibility changed in " + this
8563 + ": vis=" + nowVisible);
8564 reportedVisible = nowVisible;
8565 Message m = mH.obtainMessage(
8566 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8567 nowVisible ? 1 : 0,
8568 nowGone ? 1 : 0,
8569 this);
8570 mH.sendMessage(m);
8571 }
8572 }
Romain Guy06882f82009-06-10 13:36:04 -07008573
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008574 WindowState findMainWindow() {
8575 int j = windows.size();
8576 while (j > 0) {
8577 j--;
8578 WindowState win = windows.get(j);
8579 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8580 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8581 return win;
8582 }
8583 }
8584 return null;
8585 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 void dump(PrintWriter pw, String prefix) {
8588 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008589 if (appToken != null) {
8590 pw.print(prefix); pw.println("app=true");
8591 }
8592 if (allAppWindows.size() > 0) {
8593 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8594 }
8595 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008596 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008597 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8598 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8599 pw.print(" clientHidden="); pw.print(clientHidden);
8600 pw.print(" willBeHidden="); pw.print(willBeHidden);
8601 pw.print(" reportedVisible="); pw.println(reportedVisible);
8602 if (paused || freezingScreen) {
8603 pw.print(prefix); pw.print("paused="); pw.print(paused);
8604 pw.print(" freezingScreen="); pw.println(freezingScreen);
8605 }
8606 if (numInterestingWindows != 0 || numDrawnWindows != 0
8607 || inPendingTransaction || allDrawn) {
8608 pw.print(prefix); pw.print("numInterestingWindows=");
8609 pw.print(numInterestingWindows);
8610 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8611 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8612 pw.print(" allDrawn="); pw.println(allDrawn);
8613 }
8614 if (animating || animation != null) {
8615 pw.print(prefix); pw.print("animating="); pw.print(animating);
8616 pw.print(" animation="); pw.println(animation);
8617 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008618 if (hasTransformation) {
8619 pw.print(prefix); pw.print("XForm: ");
8620 transformation.printShortString(pw);
8621 pw.println();
8622 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008623 if (animLayerAdjustment != 0) {
8624 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8625 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008626 if (startingData != null || removed || firstWindowDrawn) {
8627 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8628 pw.print(" removed="); pw.print(removed);
8629 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8630 }
8631 if (startingWindow != null || startingView != null
8632 || startingDisplayed || startingMoved) {
8633 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8634 pw.print(" startingView="); pw.print(startingView);
8635 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8636 pw.print(" startingMoved"); pw.println(startingMoved);
8637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 }
8639
8640 @Override
8641 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008642 if (stringName == null) {
8643 StringBuilder sb = new StringBuilder();
8644 sb.append("AppWindowToken{");
8645 sb.append(Integer.toHexString(System.identityHashCode(this)));
8646 sb.append(" token="); sb.append(token); sb.append('}');
8647 stringName = sb.toString();
8648 }
8649 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008650 }
8651 }
Romain Guy06882f82009-06-10 13:36:04 -07008652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 // -------------------------------------------------------------
8654 // DummyAnimation
8655 // -------------------------------------------------------------
8656
8657 // This is an animation that does nothing: it just immediately finishes
8658 // itself every time it is called. It is used as a stub animation in cases
8659 // where we want to synchronize multiple things that may be animating.
8660 static final class DummyAnimation extends Animation {
8661 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8662 return false;
8663 }
8664 }
8665 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008667 // -------------------------------------------------------------
8668 // Async Handler
8669 // -------------------------------------------------------------
8670
8671 static final class StartingData {
8672 final String pkg;
8673 final int theme;
8674 final CharSequence nonLocalizedLabel;
8675 final int labelRes;
8676 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008677 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008680 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 pkg = _pkg;
8682 theme = _theme;
8683 nonLocalizedLabel = _nonLocalizedLabel;
8684 labelRes = _labelRes;
8685 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008686 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008687 }
8688 }
8689
8690 private final class H extends Handler {
8691 public static final int REPORT_FOCUS_CHANGE = 2;
8692 public static final int REPORT_LOSING_FOCUS = 3;
8693 public static final int ANIMATE = 4;
8694 public static final int ADD_STARTING = 5;
8695 public static final int REMOVE_STARTING = 6;
8696 public static final int FINISHED_STARTING = 7;
8697 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8699 public static final int HOLD_SCREEN_CHANGED = 12;
8700 public static final int APP_TRANSITION_TIMEOUT = 13;
8701 public static final int PERSIST_ANIMATION_SCALE = 14;
8702 public static final int FORCE_GC = 15;
8703 public static final int ENABLE_SCREEN = 16;
8704 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008705 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008706 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008707 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008708 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008712 public H() {
8713 }
Romain Guy06882f82009-06-10 13:36:04 -07008714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008715 @Override
8716 public void handleMessage(Message msg) {
8717 switch (msg.what) {
8718 case REPORT_FOCUS_CHANGE: {
8719 WindowState lastFocus;
8720 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008722 synchronized(mWindowMap) {
8723 lastFocus = mLastFocus;
8724 newFocus = mCurrentFocus;
8725 if (lastFocus == newFocus) {
8726 // Focus is not changing, so nothing to do.
8727 return;
8728 }
8729 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008730 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008731 // + " to " + newFocus);
8732 if (newFocus != null && lastFocus != null
8733 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008734 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008735 mLosingFocus.add(lastFocus);
8736 lastFocus = null;
8737 }
8738 }
8739
8740 if (lastFocus != newFocus) {
8741 //System.out.println("Changing focus from " + lastFocus
8742 // + " to " + newFocus);
8743 if (newFocus != null) {
8744 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008745 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8747 } catch (RemoteException e) {
8748 // Ignore if process has died.
8749 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008750 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008751 }
8752
8753 if (lastFocus != null) {
8754 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008755 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008756 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8757 } catch (RemoteException e) {
8758 // Ignore if process has died.
8759 }
8760 }
8761 }
8762 } break;
8763
8764 case REPORT_LOSING_FOCUS: {
8765 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008767 synchronized(mWindowMap) {
8768 losers = mLosingFocus;
8769 mLosingFocus = new ArrayList<WindowState>();
8770 }
8771
8772 final int N = losers.size();
8773 for (int i=0; i<N; i++) {
8774 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008775 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008776 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8777 } catch (RemoteException e) {
8778 // Ignore if process has died.
8779 }
8780 }
8781 } break;
8782
8783 case ANIMATE: {
8784 synchronized(mWindowMap) {
8785 mAnimationPending = false;
8786 performLayoutAndPlaceSurfacesLocked();
8787 }
8788 } break;
8789
8790 case ADD_STARTING: {
8791 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8792 final StartingData sd = wtoken.startingData;
8793
8794 if (sd == null) {
8795 // Animation has been canceled... do nothing.
8796 return;
8797 }
Romain Guy06882f82009-06-10 13:36:04 -07008798
Joe Onorato8a9b2202010-02-26 18:56:32 -08008799 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008800 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802 View view = null;
8803 try {
8804 view = mPolicy.addStartingWindow(
8805 wtoken.token, sd.pkg,
8806 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008807 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008808 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008809 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 }
8811
8812 if (view != null) {
8813 boolean abort = false;
8814
8815 synchronized(mWindowMap) {
8816 if (wtoken.removed || wtoken.startingData == null) {
8817 // If the window was successfully added, then
8818 // we need to remove it.
8819 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008820 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 "Aborted starting " + wtoken
8822 + ": removed=" + wtoken.removed
8823 + " startingData=" + wtoken.startingData);
8824 wtoken.startingWindow = null;
8825 wtoken.startingData = null;
8826 abort = true;
8827 }
8828 } else {
8829 wtoken.startingView = view;
8830 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008831 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008832 "Added starting " + wtoken
8833 + ": startingWindow="
8834 + wtoken.startingWindow + " startingView="
8835 + wtoken.startingView);
8836 }
8837
8838 if (abort) {
8839 try {
8840 mPolicy.removeStartingWindow(wtoken.token, view);
8841 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008842 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 }
8844 }
8845 }
8846 } break;
8847
8848 case REMOVE_STARTING: {
8849 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8850 IBinder token = null;
8851 View view = null;
8852 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008853 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008854 + wtoken + ": startingWindow="
8855 + wtoken.startingWindow + " startingView="
8856 + wtoken.startingView);
8857 if (wtoken.startingWindow != null) {
8858 view = wtoken.startingView;
8859 token = wtoken.token;
8860 wtoken.startingData = null;
8861 wtoken.startingView = null;
8862 wtoken.startingWindow = null;
8863 }
8864 }
8865 if (view != null) {
8866 try {
8867 mPolicy.removeStartingWindow(token, view);
8868 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008869 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008870 }
8871 }
8872 } break;
8873
8874 case FINISHED_STARTING: {
8875 IBinder token = null;
8876 View view = null;
8877 while (true) {
8878 synchronized (mWindowMap) {
8879 final int N = mFinishedStarting.size();
8880 if (N <= 0) {
8881 break;
8882 }
8883 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8884
Joe Onorato8a9b2202010-02-26 18:56:32 -08008885 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008886 "Finished starting " + wtoken
8887 + ": startingWindow=" + wtoken.startingWindow
8888 + " startingView=" + wtoken.startingView);
8889
8890 if (wtoken.startingWindow == null) {
8891 continue;
8892 }
8893
8894 view = wtoken.startingView;
8895 token = wtoken.token;
8896 wtoken.startingData = null;
8897 wtoken.startingView = null;
8898 wtoken.startingWindow = null;
8899 }
8900
8901 try {
8902 mPolicy.removeStartingWindow(token, view);
8903 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008904 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 }
8906 }
8907 } break;
8908
8909 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8910 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8911
8912 boolean nowVisible = msg.arg1 != 0;
8913 boolean nowGone = msg.arg2 != 0;
8914
8915 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008916 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008917 TAG, "Reporting visible in " + wtoken
8918 + " visible=" + nowVisible
8919 + " gone=" + nowGone);
8920 if (nowVisible) {
8921 wtoken.appToken.windowsVisible();
8922 } else {
8923 wtoken.appToken.windowsGone();
8924 }
8925 } catch (RemoteException ex) {
8926 }
8927 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008929 case WINDOW_FREEZE_TIMEOUT: {
8930 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008931 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 int i = mWindows.size();
8933 while (i > 0) {
8934 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008935 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008936 if (w.mOrientationChanging) {
8937 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008938 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008939 }
8940 }
8941 performLayoutAndPlaceSurfacesLocked();
8942 }
8943 break;
8944 }
Romain Guy06882f82009-06-10 13:36:04 -07008945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008946 case HOLD_SCREEN_CHANGED: {
8947 Session oldHold;
8948 Session newHold;
8949 synchronized (mWindowMap) {
8950 oldHold = mLastReportedHold;
8951 newHold = (Session)msg.obj;
8952 mLastReportedHold = newHold;
8953 }
Romain Guy06882f82009-06-10 13:36:04 -07008954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008955 if (oldHold != newHold) {
8956 try {
8957 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008958 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008959 "window",
8960 BatteryStats.WAKE_TYPE_WINDOW);
8961 }
8962 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008963 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008964 "window",
8965 BatteryStats.WAKE_TYPE_WINDOW);
8966 }
8967 } catch (RemoteException e) {
8968 }
8969 }
8970 break;
8971 }
Romain Guy06882f82009-06-10 13:36:04 -07008972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 case APP_TRANSITION_TIMEOUT: {
8974 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008975 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008976 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008977 "*** APP TRANSITION TIMEOUT");
8978 mAppTransitionReady = true;
8979 mAppTransitionTimeout = true;
8980 performLayoutAndPlaceSurfacesLocked();
8981 }
8982 }
8983 break;
8984 }
Romain Guy06882f82009-06-10 13:36:04 -07008985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 case PERSIST_ANIMATION_SCALE: {
8987 Settings.System.putFloat(mContext.getContentResolver(),
8988 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8989 Settings.System.putFloat(mContext.getContentResolver(),
8990 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8991 break;
8992 }
Romain Guy06882f82009-06-10 13:36:04 -07008993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008994 case FORCE_GC: {
8995 synchronized(mWindowMap) {
8996 if (mAnimationPending) {
8997 // If we are animating, don't do the gc now but
8998 // delay a bit so we don't interrupt the animation.
8999 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9000 2000);
9001 return;
9002 }
9003 // If we are currently rotating the display, it will
9004 // schedule a new message when done.
9005 if (mDisplayFrozen) {
9006 return;
9007 }
9008 mFreezeGcPending = 0;
9009 }
9010 Runtime.getRuntime().gc();
9011 break;
9012 }
Romain Guy06882f82009-06-10 13:36:04 -07009013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009014 case ENABLE_SCREEN: {
9015 performEnableScreen();
9016 break;
9017 }
Romain Guy06882f82009-06-10 13:36:04 -07009018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 case APP_FREEZE_TIMEOUT: {
9020 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009021 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009022 int i = mAppTokens.size();
9023 while (i > 0) {
9024 i--;
9025 AppWindowToken tok = mAppTokens.get(i);
9026 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009027 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009028 unsetAppFreezingScreenLocked(tok, true, true);
9029 }
9030 }
9031 }
9032 break;
9033 }
Romain Guy06882f82009-06-10 13:36:04 -07009034
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009035 case SEND_NEW_CONFIGURATION: {
9036 removeMessages(SEND_NEW_CONFIGURATION);
9037 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009038 break;
9039 }
Romain Guy06882f82009-06-10 13:36:04 -07009040
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009041 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009042 if (mWindowsChanged) {
9043 synchronized (mWindowMap) {
9044 mWindowsChanged = false;
9045 }
9046 notifyWindowsChanged();
9047 }
9048 break;
9049 }
9050
Christopher Tatea53146c2010-09-07 11:57:52 -07009051 case DRAG_START_TIMEOUT: {
9052 IBinder win = (IBinder)msg.obj;
9053 if (DEBUG_DRAG) {
9054 Slog.w(TAG, "Timeout starting drag by win " + win);
9055 }
9056 synchronized (mWindowMap) {
9057 // !!! TODO: ANR the app that has failed to start the drag in time
9058 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009059 mDragState.unregister();
9060 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009061 mDragState.reset();
9062 mDragState = null;
9063 }
9064 }
Chris Tated4533f142010-10-19 15:15:08 -07009065 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009066 }
9067
Chris Tated4533f142010-10-19 15:15:08 -07009068 case DRAG_END_TIMEOUT: {
9069 IBinder win = (IBinder)msg.obj;
9070 if (DEBUG_DRAG) {
9071 Slog.w(TAG, "Timeout ending drag to win " + win);
9072 }
9073 synchronized (mWindowMap) {
9074 // !!! TODO: ANR the drag-receiving app
9075 mDragState.mDragResult = false;
9076 mDragState.endDragLw();
9077 }
9078 break;
9079 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009080 }
9081 }
9082 }
9083
9084 // -------------------------------------------------------------
9085 // IWindowManager API
9086 // -------------------------------------------------------------
9087
9088 public IWindowSession openSession(IInputMethodClient client,
9089 IInputContext inputContext) {
9090 if (client == null) throw new IllegalArgumentException("null client");
9091 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009092 Session session = new Session(client, inputContext);
9093 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009094 }
9095
9096 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9097 synchronized (mWindowMap) {
9098 // The focus for the client is the window immediately below
9099 // where we would place the input method window.
9100 int idx = findDesiredInputMethodWindowIndexLocked(false);
9101 WindowState imFocus;
9102 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009103 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009104 if (imFocus != null) {
9105 if (imFocus.mSession.mClient != null &&
9106 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9107 return true;
9108 }
9109 }
9110 }
9111 }
9112 return false;
9113 }
Romain Guy06882f82009-06-10 13:36:04 -07009114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009115 // -------------------------------------------------------------
9116 // Internals
9117 // -------------------------------------------------------------
9118
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009119 final WindowState windowForClientLocked(Session session, IWindow client,
9120 boolean throwOnError) {
9121 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009122 }
Romain Guy06882f82009-06-10 13:36:04 -07009123
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009124 final WindowState windowForClientLocked(Session session, IBinder client,
9125 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009127 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009128 TAG, "Looking up client " + client + ": " + win);
9129 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009130 RuntimeException ex = new IllegalArgumentException(
9131 "Requested window " + client + " does not exist");
9132 if (throwOnError) {
9133 throw ex;
9134 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009135 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009136 return null;
9137 }
9138 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009139 RuntimeException ex = new IllegalArgumentException(
9140 "Requested window " + client + " is in session " +
9141 win.mSession + ", not " + session);
9142 if (throwOnError) {
9143 throw ex;
9144 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009145 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009146 return null;
9147 }
9148
9149 return win;
9150 }
9151
Dianne Hackborna8f60182009-09-01 19:01:50 -07009152 final void rebuildAppWindowListLocked() {
9153 int NW = mWindows.size();
9154 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009155 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009156 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009157
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009158 if (mRebuildTmp.length < NW) {
9159 mRebuildTmp = new WindowState[NW+10];
9160 }
9161
Dianne Hackborna8f60182009-09-01 19:01:50 -07009162 // First remove all existing app windows.
9163 i=0;
9164 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009165 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009166 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009167 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009168 win.mRebuilding = true;
9169 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009170 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009171 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009172 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009173 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009174 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009175 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009176 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9177 && lastWallpaper == i-1) {
9178 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009179 }
9180 i++;
9181 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009182
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009183 // The wallpaper window(s) typically live at the bottom of the stack,
9184 // so skip them before adding app tokens.
9185 lastWallpaper++;
9186 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009187
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009188 // First add all of the exiting app tokens... these are no longer
9189 // in the main app list, but still have windows shown. We put them
9190 // in the back because now that the animation is over we no longer
9191 // will care about them.
9192 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009193 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009194 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9195 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009196
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009197 // And add in the still active app tokens in Z order.
9198 NT = mAppTokens.size();
9199 for (int j=0; j<NT; j++) {
9200 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009201 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009202
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009203 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009204 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009205 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009206 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009207 for (i=0; i<numRemoved; i++) {
9208 WindowState ws = mRebuildTmp[i];
9209 if (ws.mRebuilding) {
9210 StringWriter sw = new StringWriter();
9211 PrintWriter pw = new PrintWriter(sw);
9212 ws.dump(pw, "");
9213 pw.flush();
9214 Slog.w(TAG, "This window was lost: " + ws);
9215 Slog.w(TAG, sw.toString());
9216 }
9217 }
9218 Slog.w(TAG, "Current app token list:");
9219 dumpAppTokensLocked();
9220 Slog.w(TAG, "Final window list:");
9221 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009222 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009223 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009225 private final void assignLayersLocked() {
9226 int N = mWindows.size();
9227 int curBaseLayer = 0;
9228 int curLayer = 0;
9229 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009230
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009231 if (DEBUG_LAYERS) {
9232 RuntimeException here = new RuntimeException("here");
9233 here.fillInStackTrace();
9234 Log.v(TAG, "Assigning layers", here);
9235 }
9236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009237 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009238 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009239 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9240 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009241 curLayer += WINDOW_LAYER_MULTIPLIER;
9242 w.mLayer = curLayer;
9243 } else {
9244 curBaseLayer = curLayer = w.mBaseLayer;
9245 w.mLayer = curLayer;
9246 }
9247 if (w.mTargetAppToken != null) {
9248 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9249 } else if (w.mAppToken != null) {
9250 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9251 } else {
9252 w.mAnimLayer = w.mLayer;
9253 }
9254 if (w.mIsImWindow) {
9255 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009256 } else if (w.mIsWallpaper) {
9257 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009259 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 + w.mAnimLayer);
9261 //System.out.println(
9262 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9263 }
9264 }
9265
9266 private boolean mInLayout = false;
9267 private final void performLayoutAndPlaceSurfacesLocked() {
9268 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009269 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 throw new RuntimeException("Recursive call!");
9271 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009272 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009273 return;
9274 }
9275
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009276 if (mWaitingForConfig) {
9277 // Our configuration has changed (most likely rotation), but we
9278 // don't yet have the complete configuration to report to
9279 // applications. Don't do any window layout until we have it.
9280 return;
9281 }
9282
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009283 if (mDisplay == null) {
9284 // Not yet initialized, nothing to do.
9285 return;
9286 }
9287
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009288 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009289 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009290
9291 try {
9292 if (mForceRemoves != null) {
9293 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009294 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009295 for (int i=0; i<mForceRemoves.size(); i++) {
9296 WindowState ws = mForceRemoves.get(i);
9297 Slog.i(TAG, "Force removing: " + ws);
9298 removeWindowInnerLocked(ws.mSession, ws);
9299 }
9300 mForceRemoves = null;
9301 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9302 Object tmp = new Object();
9303 synchronized (tmp) {
9304 try {
9305 tmp.wait(250);
9306 } catch (InterruptedException e) {
9307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009308 }
9309 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009310 } catch (RuntimeException e) {
9311 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009314 try {
9315 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009316
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009317 int N = mPendingRemove.size();
9318 if (N > 0) {
9319 if (mPendingRemoveTmp.length < N) {
9320 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009321 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009322 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009324 for (int i=0; i<N; i++) {
9325 WindowState w = mPendingRemoveTmp[i];
9326 removeWindowInnerLocked(w.mSession, w);
9327 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009328
9329 mInLayout = false;
9330 assignLayersLocked();
9331 mLayoutNeeded = true;
9332 performLayoutAndPlaceSurfacesLocked();
9333
9334 } else {
9335 mInLayout = false;
9336 if (mLayoutNeeded) {
9337 requestAnimationLocked(0);
9338 }
9339 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009340 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009341 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9342 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 } catch (RuntimeException e) {
9345 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009346 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 }
9348 }
9349
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009350 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009351 if (!mLayoutNeeded) {
9352 return 0;
9353 }
9354
9355 mLayoutNeeded = false;
9356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009357 final int dw = mDisplay.getWidth();
9358 final int dh = mDisplay.getHeight();
9359
9360 final int N = mWindows.size();
9361 int i;
9362
Joe Onorato8a9b2202010-02-26 18:56:32 -08009363 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009364 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9365
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009366 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009367
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009368 int seq = mLayoutSeq+1;
9369 if (seq < 0) seq = 0;
9370 mLayoutSeq = seq;
9371
9372 // First perform layout of any root windows (not attached
9373 // to another window).
9374 int topAttached = -1;
9375 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009376 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009377
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009378 // Don't do layout of a window if it is not visible, or
9379 // soon won't be visible, to avoid wasting time and funky
9380 // changes while a window is animating away.
9381 final AppWindowToken atoken = win.mAppToken;
9382 final boolean gone = win.mViewVisibility == View.GONE
9383 || !win.mRelayoutCalled
9384 || win.mRootToken.hidden
9385 || (atoken != null && atoken.hiddenRequested)
9386 || win.mAttachedHidden
9387 || win.mExiting || win.mDestroying;
9388
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009389 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9390 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009391 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9392 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009393 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009394 + win.mViewVisibility + " mRelayoutCalled="
9395 + win.mRelayoutCalled + " hidden="
9396 + win.mRootToken.hidden + " hiddenRequested="
9397 + (atoken != null && atoken.hiddenRequested)
9398 + " mAttachedHidden=" + win.mAttachedHidden);
9399 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009400
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009401 // If this view is GONE, then skip it -- keep the current
9402 // frame, and let the caller know so they can ignore it
9403 // if they want. (We do the normal layout for INVISIBLE
9404 // windows, since that means "perform layout as normal,
9405 // just don't display").
9406 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009407 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009408 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009409 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009410 win.mContentChanged = false;
9411 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009412 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9413 win.mLayoutSeq = seq;
9414 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9415 + win.mFrame + " mContainingFrame="
9416 + win.mContainingFrame + " mDisplayFrame="
9417 + win.mDisplayFrame);
9418 } else {
9419 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009420 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009423
9424 // Now perform layout of attached windows, which usually
9425 // depend on the position of the window they are attached to.
9426 // XXX does not deal with windows that are attached to windows
9427 // that are themselves attached.
9428 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009429 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009430
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009431 if (win.mLayoutAttached) {
9432 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9433 + " mHaveFrame=" + win.mHaveFrame
9434 + " mViewVisibility=" + win.mViewVisibility
9435 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009436 // If this view is GONE, then skip it -- keep the current
9437 // frame, and let the caller know so they can ignore it
9438 // if they want. (We do the normal layout for INVISIBLE
9439 // windows, since that means "perform layout as normal,
9440 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009441 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9442 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009443 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009444 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009445 win.mContentChanged = false;
9446 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009447 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9448 win.mLayoutSeq = seq;
9449 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9450 + win.mFrame + " mContainingFrame="
9451 + win.mContainingFrame + " mDisplayFrame="
9452 + win.mDisplayFrame);
9453 }
9454 }
9455 }
Jeff Brown349703e2010-06-22 01:27:15 -07009456
9457 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009458 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009459
9460 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009461 }
Romain Guy06882f82009-06-10 13:36:04 -07009462
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009463 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009464 private final void performLayoutAndPlaceSurfacesLockedInner(
9465 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009466 if (mDisplay == null) {
9467 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9468 return;
9469 }
9470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471 final long currentTime = SystemClock.uptimeMillis();
9472 final int dw = mDisplay.getWidth();
9473 final int dh = mDisplay.getHeight();
9474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009475 int i;
9476
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009477 if (mFocusMayChange) {
9478 mFocusMayChange = false;
9479 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9480 }
9481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009482 // Initialize state of exiting tokens.
9483 for (i=mExitingTokens.size()-1; i>=0; i--) {
9484 mExitingTokens.get(i).hasVisible = false;
9485 }
9486
9487 // Initialize state of exiting applications.
9488 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9489 mExitingAppTokens.get(i).hasVisible = false;
9490 }
9491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009492 boolean orientationChangeComplete = true;
9493 Session holdScreen = null;
9494 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009495 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009496 boolean focusDisplayed = false;
9497 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009498 boolean createWatermark = false;
9499
9500 if (mFxSession == null) {
9501 mFxSession = new SurfaceSession();
9502 createWatermark = true;
9503 }
9504
9505 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009506
9507 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009508
9509 if (createWatermark) {
9510 createWatermark();
9511 }
9512 if (mWatermark != null) {
9513 mWatermark.positionSurface(dw, dh);
9514 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009515 if (mStrictModeFlash != null) {
9516 mStrictModeFlash.positionSurface(dw, dh);
9517 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009520 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009521 int repeats = 0;
9522 int changes = 0;
9523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009524 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009525 repeats++;
9526 if (repeats > 6) {
9527 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9528 mLayoutNeeded = false;
9529 break;
9530 }
9531
9532 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9533 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9534 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9535 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9536 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9537 assignLayersLocked();
9538 mLayoutNeeded = true;
9539 }
9540 }
9541 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9542 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9543 if (updateOrientationFromAppTokensLocked()) {
9544 mLayoutNeeded = true;
9545 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9546 }
9547 }
9548 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9549 mLayoutNeeded = true;
9550 }
9551 }
9552
9553 // FIRST LOOP: Perform a layout, if needed.
9554 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009555 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009556 if (changes != 0) {
9557 continue;
9558 }
9559 } else {
9560 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9561 changes = 0;
9562 }
9563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009564 final int transactionSequence = ++mTransactionSequence;
9565
9566 // Update animations of all applications, including those
9567 // associated with exiting/removed apps
9568 boolean tokensAnimating = false;
9569 final int NAT = mAppTokens.size();
9570 for (i=0; i<NAT; i++) {
9571 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9572 tokensAnimating = true;
9573 }
9574 }
9575 final int NEAT = mExitingAppTokens.size();
9576 for (i=0; i<NEAT; i++) {
9577 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9578 tokensAnimating = true;
9579 }
9580 }
9581
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009582 // SECOND LOOP: Execute animations and update visibility of windows.
9583
Joe Onorato8a9b2202010-02-26 18:56:32 -08009584 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009585 + transactionSequence + " tokensAnimating="
9586 + tokensAnimating);
9587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009590 if (mScreenRotationAnimation != null) {
9591 if (mScreenRotationAnimation.isAnimating()) {
9592 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9593 animating = true;
9594 } else {
9595 mScreenRotationAnimation = null;
9596 }
9597 }
9598 }
9599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009601 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009602 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009603 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604
9605 mPolicy.beginAnimationLw(dw, dh);
9606
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009607 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009609 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009610 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009611
9612 final WindowManager.LayoutParams attrs = w.mAttrs;
9613
9614 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009615 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009616 if (w.commitFinishDrawingLocked(currentTime)) {
9617 if ((w.mAttrs.flags
9618 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009619 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009620 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009621 wallpaperMayChange = true;
9622 }
9623 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009624
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009625 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009626
9627 int animDw = dw;
9628 int animDh = dh;
9629
9630 // If the window has moved due to its containing
9631 // content frame changing, then we'd like to animate
9632 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009633 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009634 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009635 // Frame has moved, containing content frame
9636 // has also moved, and we're not currently animating...
9637 // let's do something.
9638 Animation a = AnimationUtils.loadAnimation(mContext,
9639 com.android.internal.R.anim.window_move_from_decor);
9640 w.setAnimation(a);
9641 animDw = w.mLastFrame.left - w.mFrame.left;
9642 animDh = w.mLastFrame.top - w.mFrame.top;
9643 }
9644
9645 // Execute animation.
9646 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9647 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009648
9649 // If this window is animating, make a note that we have
9650 // an animating window and take care of a request to run
9651 // a detached wallpaper animation.
9652 if (nowAnimating) {
9653 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9654 windowDetachedWallpaper = w;
9655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009656 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009657 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009658
9659 // If this window's app token is running a detached wallpaper
9660 // animation, make a note so we can ensure the wallpaper is
9661 // displayed behind it.
9662 if (w.mAppToken != null && w.mAppToken.animation != null
9663 && w.mAppToken.animation.getDetachWallpaper()) {
9664 windowDetachedWallpaper = w;
9665 }
9666
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009667 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9668 wallpaperMayChange = true;
9669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009670
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009671 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009672 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009673 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009674 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009675 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009676 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009677 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009678 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9679 forceHiding = true;
9680 }
9681 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9682 boolean changed;
9683 if (forceHiding) {
9684 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009685 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9686 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009687 } else {
9688 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009689 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9690 "Now policy shown: " + w);
9691 if (changed) {
9692 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009693 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009694 // Assume we will need to animate. If
9695 // we don't (because the wallpaper will
9696 // stay with the lock screen), then we will
9697 // clean up later.
9698 Animation a = mPolicy.createForceHideEnterAnimation();
9699 if (a != null) {
9700 w.setAnimation(a);
9701 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009702 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009703 if (mCurrentFocus == null ||
9704 mCurrentFocus.mLayer < w.mLayer) {
9705 // We are showing on to of the current
9706 // focus, so re-evaluate focus to make
9707 // sure it is correct.
9708 mFocusMayChange = true;
9709 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009710 }
9711 }
9712 if (changed && (attrs.flags
9713 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9714 wallpaperMayChange = true;
9715 }
9716 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009718 mPolicy.animatingWindowLw(w, attrs);
9719 }
9720
9721 final AppWindowToken atoken = w.mAppToken;
9722 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9723 if (atoken.lastTransactionSequence != transactionSequence) {
9724 atoken.lastTransactionSequence = transactionSequence;
9725 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9726 atoken.startingDisplayed = false;
9727 }
9728 if ((w.isOnScreen() || w.mAttrs.type
9729 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9730 && !w.mExiting && !w.mDestroying) {
9731 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009732 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009733 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009734 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009735 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009736 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009737 + " pv=" + w.mPolicyVisibility
9738 + " dp=" + w.mDrawPending
9739 + " cdp=" + w.mCommitDrawPending
9740 + " ah=" + w.mAttachedHidden
9741 + " th=" + atoken.hiddenRequested
9742 + " a=" + w.mAnimating);
9743 }
9744 }
9745 if (w != atoken.startingWindow) {
9746 if (!atoken.freezingScreen || !w.mAppFreezing) {
9747 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009748 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009749 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 "tokenMayBeDrawn: " + atoken
9752 + " freezingScreen=" + atoken.freezingScreen
9753 + " mAppFreezing=" + w.mAppFreezing);
9754 tokenMayBeDrawn = true;
9755 }
9756 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009757 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 atoken.startingDisplayed = true;
9759 }
9760 }
9761 } else if (w.mReadyToShow) {
9762 w.performShowLocked();
9763 }
9764 }
9765
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009766 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767
9768 if (tokenMayBeDrawn) {
9769 // See if any windows have been drawn, so they (and others
9770 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009771 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009773 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009774 if (wtoken.freezingScreen) {
9775 int numInteresting = wtoken.numInterestingWindows;
9776 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009777 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009778 "allDrawn: " + wtoken
9779 + " interesting=" + numInteresting
9780 + " drawn=" + wtoken.numDrawnWindows);
9781 wtoken.showAllWindowsLocked();
9782 unsetAppFreezingScreenLocked(wtoken, false, true);
9783 orientationChangeComplete = true;
9784 }
9785 } else if (!wtoken.allDrawn) {
9786 int numInteresting = wtoken.numInterestingWindows;
9787 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009788 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789 "allDrawn: " + wtoken
9790 + " interesting=" + numInteresting
9791 + " drawn=" + wtoken.numDrawnWindows);
9792 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009793 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794
9795 // We can now show all of the drawn windows!
9796 if (!mOpeningApps.contains(wtoken)) {
9797 wtoken.showAllWindowsLocked();
9798 }
9799 }
9800 }
9801 }
9802 }
9803
9804 // If we are ready to perform an app transition, check through
9805 // all of the app tokens to be shown and see if they are ready
9806 // to go.
9807 if (mAppTransitionReady) {
9808 int NN = mOpeningApps.size();
9809 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009810 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811 "Checking " + NN + " opening apps (frozen="
9812 + mDisplayFrozen + " timeout="
9813 + mAppTransitionTimeout + ")...");
9814 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9815 // If the display isn't frozen, wait to do anything until
9816 // all of the apps are ready. Otherwise just go because
9817 // we'll unfreeze the display when everyone is ready.
9818 for (i=0; i<NN && goodToGo; i++) {
9819 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009820 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009821 "Check opening app" + wtoken + ": allDrawn="
9822 + wtoken.allDrawn + " startingDisplayed="
9823 + wtoken.startingDisplayed);
9824 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9825 && !wtoken.startingMoved) {
9826 goodToGo = false;
9827 }
9828 }
9829 }
9830 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009831 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009832 int transit = mNextAppTransition;
9833 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009834 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009835 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009836 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009837 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009838 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 mAppTransitionTimeout = false;
9840 mStartingIconInTransition = false;
9841 mSkipAppTransitionAnimation = false;
9842
9843 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9844
Dianne Hackborna8f60182009-09-01 19:01:50 -07009845 // If there are applications waiting to come to the
9846 // top of the stack, now is the time to move their windows.
9847 // (Note that we don't do apps going to the bottom
9848 // here -- we want to keep their windows in the old
9849 // Z-order until the animation completes.)
9850 if (mToTopApps.size() > 0) {
9851 NN = mAppTokens.size();
9852 for (i=0; i<NN; i++) {
9853 AppWindowToken wtoken = mAppTokens.get(i);
9854 if (wtoken.sendingToTop) {
9855 wtoken.sendingToTop = false;
9856 moveAppWindowsLocked(wtoken, NN, false);
9857 }
9858 }
9859 mToTopApps.clear();
9860 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009861
Dianne Hackborn25994b42009-09-04 14:21:19 -07009862 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009863
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009864 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009865 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009866
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009867 // The top-most window will supply the layout params,
9868 // and we will determine it below.
9869 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009870 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009871 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009872
Joe Onorato8a9b2202010-02-26 18:56:32 -08009873 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009874 "New wallpaper target=" + mWallpaperTarget
9875 + ", lower target=" + mLowerWallpaperTarget
9876 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009877 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009878 // Do a first pass through the tokens for two
9879 // things:
9880 // (1) Determine if both the closing and opening
9881 // app token sets are wallpaper targets, in which
9882 // case special animations are needed
9883 // (since the wallpaper needs to stay static
9884 // behind them).
9885 // (2) Find the layout params of the top-most
9886 // application window in the tokens, which is
9887 // what will control the animation theme.
9888 final int NC = mClosingApps.size();
9889 NN = NC + mOpeningApps.size();
9890 for (i=0; i<NN; i++) {
9891 AppWindowToken wtoken;
9892 int mode;
9893 if (i < NC) {
9894 wtoken = mClosingApps.get(i);
9895 mode = 1;
9896 } else {
9897 wtoken = mOpeningApps.get(i-NC);
9898 mode = 2;
9899 }
9900 if (mLowerWallpaperTarget != null) {
9901 if (mLowerWallpaperTarget.mAppToken == wtoken
9902 || mUpperWallpaperTarget.mAppToken == wtoken) {
9903 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009904 }
9905 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009906 if (wtoken.appFullscreen) {
9907 WindowState ws = wtoken.findMainWindow();
9908 if (ws != null) {
9909 // If this is a compatibility mode
9910 // window, we will always use its anim.
9911 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9912 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009913 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009914 bestAnimLayer = Integer.MAX_VALUE;
9915 } else if (ws.mLayer > bestAnimLayer) {
9916 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009917 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009918 bestAnimLayer = ws.mLayer;
9919 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009920 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009921 }
9922 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009923
Dianne Hackborn25994b42009-09-04 14:21:19 -07009924 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009925 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009926 "Wallpaper animation!");
9927 switch (transit) {
9928 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9929 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9930 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9931 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9932 break;
9933 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9934 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9935 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9936 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9937 break;
9938 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009939 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009940 "New transit: " + transit);
9941 } else if (oldWallpaper != null) {
9942 // We are transitioning from an activity with
9943 // a wallpaper to one without.
9944 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009945 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009946 "New transit away from wallpaper: " + transit);
9947 } else if (mWallpaperTarget != null) {
9948 // We are transitioning from an activity without
9949 // a wallpaper to now showing the wallpaper
9950 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009951 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009952 "New transit into wallpaper: " + transit);
9953 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009954
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009955 // If all closing windows are obscured, then there is
9956 // no need to do an animation. This is the case, for
9957 // example, when this transition is being done behind
9958 // the lock screen.
9959 if (!mPolicy.allowAppAnimationsLw()) {
9960 animLp = null;
9961 }
9962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 NN = mOpeningApps.size();
9964 for (i=0; i<NN; i++) {
9965 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009966 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009967 "Now opening app" + wtoken);
9968 wtoken.reportedVisible = false;
9969 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009970 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009971 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009972 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009973 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009974 wtoken.showAllWindowsLocked();
9975 }
9976 NN = mClosingApps.size();
9977 for (i=0; i<NN; i++) {
9978 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009979 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 "Now closing app" + wtoken);
9981 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009982 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009983 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009985 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 // Force the allDrawn flag, because we want to start
9987 // this guy's animations regardless of whether it's
9988 // gotten drawn.
9989 wtoken.allDrawn = true;
9990 }
9991
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009992 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009994 mOpeningApps.clear();
9995 mClosingApps.clear();
9996
9997 // This has changed the visibility of windows, so perform
9998 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009999 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010001 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10002 assignLayersLocked();
10003 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010005 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 }
10007 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010008
Dianne Hackborn16064f92010-03-25 00:47:24 -070010009 int adjResult = 0;
10010
Dianne Hackborna8f60182009-09-01 19:01:50 -070010011 if (!animating && mAppTransitionRunning) {
10012 // We have finished the animation of an app transition. To do
10013 // this, we have delayed a lot of operations like showing and
10014 // hiding apps, moving apps in Z-order, etc. The app token list
10015 // reflects the correct Z-order, but the window list may now
10016 // be out of sync with it. So here we will just rebuild the
10017 // entire app window list. Fun!
10018 mAppTransitionRunning = false;
10019 // Clear information about apps that were moving.
10020 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010021
Dianne Hackborna8f60182009-09-01 19:01:50 -070010022 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010023 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010024 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010025 moveInputMethodWindowsIfNeededLocked(false);
10026 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010027 // Since the window list has been rebuilt, focus might
10028 // have to be recomputed since the actual order of windows
10029 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010030 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010032
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010033 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010034 // At this point, there was a window with a wallpaper that
10035 // was force hiding other windows behind it, but now it
10036 // is going away. This may be simple -- just animate
10037 // away the wallpaper and its window -- or it may be
10038 // hard -- the wallpaper now needs to be shown behind
10039 // something that was hidden.
10040 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010041 if (mLowerWallpaperTarget != null
10042 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010043 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010044 "wallpaperForceHiding changed with lower="
10045 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010046 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010047 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10048 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10049 if (mLowerWallpaperTarget.mAppToken.hidden) {
10050 // The lower target has become hidden before we
10051 // actually started the animation... let's completely
10052 // re-evaluate everything.
10053 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010054 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010055 }
10056 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010057 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010058 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010059 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010060 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010061 + " NEW: " + mWallpaperTarget
10062 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010063 if (mLowerWallpaperTarget == null) {
10064 // Whoops, we don't need a special wallpaper animation.
10065 // Clear them out.
10066 forceHiding = false;
10067 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010068 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010069 if (w.mSurface != null) {
10070 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010071 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010072 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010073 forceHiding = true;
10074 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10075 if (!w.mAnimating) {
10076 // We set the animation above so it
10077 // is not yet running.
10078 w.clearAnimation();
10079 }
10080 }
10081 }
10082 }
10083 }
10084 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010085
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010086 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10087 if (DEBUG_WALLPAPER) Slog.v(TAG,
10088 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10089 + windowDetachedWallpaper);
10090 mWindowDetachedWallpaper = windowDetachedWallpaper;
10091 wallpaperMayChange = true;
10092 }
10093
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010094 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010095 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010096 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010097 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010098 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010099
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010100 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010101 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010102 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010103 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010104 assignLayersLocked();
10105 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010106 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010107 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010108 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010110
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010111 if (mFocusMayChange) {
10112 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010113 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010114 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010115 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010116 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010117 }
10118
10119 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010120 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010122
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010123 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10124 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010125
Jeff Browne33348b2010-07-15 23:54:05 -070010126 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010127 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010128
10129 // THIRD LOOP: Update the surfaces of all windows.
10130
10131 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10132
10133 boolean obscured = false;
10134 boolean blurring = false;
10135 boolean dimming = false;
10136 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010137 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010138 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010139
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010140 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010142 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010143 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144
10145 boolean displayed = false;
10146 final WindowManager.LayoutParams attrs = w.mAttrs;
10147 final int attrFlags = attrs.flags;
10148
10149 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010150 // XXX NOTE: The logic here could be improved. We have
10151 // the decision about whether to resize a window separated
10152 // from whether to hide the surface. This can cause us to
10153 // resize a surface even if we are going to hide it. You
10154 // can see this by (1) holding device in landscape mode on
10155 // home screen; (2) tapping browser icon (device will rotate
10156 // to landscape; (3) tap home. The wallpaper will be resized
10157 // in step 2 but then immediately hidden, causing us to
10158 // have to resize and then redraw it again in step 3. It
10159 // would be nice to figure out how to avoid this, but it is
10160 // difficult because we do need to resize surfaces in some
10161 // cases while they are hidden such as when first showing a
10162 // window.
10163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010164 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010165 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 TAG, "Placing surface #" + i + " " + w.mSurface
10167 + ": new=" + w.mShownFrame + ", old="
10168 + w.mLastShownFrame);
10169
10170 boolean resize;
10171 int width, height;
10172 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10173 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10174 w.mLastRequestedHeight != w.mRequestedHeight;
10175 // for a scaled surface, we just want to use
10176 // the requested size.
10177 width = w.mRequestedWidth;
10178 height = w.mRequestedHeight;
10179 w.mLastRequestedWidth = width;
10180 w.mLastRequestedHeight = height;
10181 w.mLastShownFrame.set(w.mShownFrame);
10182 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010183 if (SHOW_TRANSACTIONS) logSurface(w,
10184 "POS " + w.mShownFrame.left
10185 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010186 w.mSurfaceX = w.mShownFrame.left;
10187 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010188 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10189 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010190 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010191 if (!recoveringMemory) {
10192 reclaimSomeSurfaceMemoryLocked(w, "position");
10193 }
10194 }
10195 } else {
10196 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10197 width = w.mShownFrame.width();
10198 height = w.mShownFrame.height();
10199 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010200 }
10201
10202 if (resize) {
10203 if (width < 1) width = 1;
10204 if (height < 1) height = 1;
10205 if (w.mSurface != null) {
10206 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010207 if (SHOW_TRANSACTIONS) logSurface(w,
10208 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010209 + w.mShownFrame.top + " SIZE "
10210 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010211 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010212 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010213 w.mSurfaceW = width;
10214 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010215 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010216 w.mSurfaceX = w.mShownFrame.left;
10217 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010218 w.mSurface.setPosition(w.mShownFrame.left,
10219 w.mShownFrame.top);
10220 } catch (RuntimeException e) {
10221 // If something goes wrong with the surface (such
10222 // as running out of memory), don't take down the
10223 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010224 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010225 + "size=(" + width + "x" + height
10226 + "), pos=(" + w.mShownFrame.left
10227 + "," + w.mShownFrame.top + ")", e);
10228 if (!recoveringMemory) {
10229 reclaimSomeSurfaceMemoryLocked(w, "size");
10230 }
10231 }
10232 }
10233 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010234 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 w.mContentInsetsChanged =
10236 !w.mLastContentInsets.equals(w.mContentInsets);
10237 w.mVisibleInsetsChanged =
10238 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010239 boolean configChanged =
10240 w.mConfiguration != mCurConfiguration
10241 && (w.mConfiguration == null
10242 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010243 if (DEBUG_CONFIGURATION && configChanged) {
10244 Slog.v(TAG, "Win " + w + " config changed: "
10245 + mCurConfiguration);
10246 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010247 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010248 + ": configChanged=" + configChanged
10249 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010250 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010251 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010252 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010253 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010254 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010255 w.mLastFrame.set(w.mFrame);
10256 w.mLastContentInsets.set(w.mContentInsets);
10257 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010258 // If the screen is currently frozen, then keep
10259 // it frozen until this window draws at its new
10260 // orientation.
10261 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010262 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010263 "Resizing while display frozen: " + w);
10264 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010265 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010266 mWindowsFreezingScreen = true;
10267 // XXX should probably keep timeout from
10268 // when we first froze the display.
10269 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10270 mH.sendMessageDelayed(mH.obtainMessage(
10271 H.WINDOW_FREEZE_TIMEOUT), 2000);
10272 }
10273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010274 // If the orientation is changing, then we need to
10275 // hold off on unfreezing the display until this
10276 // window has been redrawn; to do that, we need
10277 // to go through the process of getting informed
10278 // by the application when it has finished drawing.
10279 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010280 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 "Orientation start waiting for draw in "
10282 + w + ", surface " + w.mSurface);
10283 w.mDrawPending = true;
10284 w.mCommitDrawPending = false;
10285 w.mReadyToShow = false;
10286 if (w.mAppToken != null) {
10287 w.mAppToken.allDrawn = false;
10288 }
10289 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010290 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010291 "Resizing window " + w + " to " + w.mFrame);
10292 mResizingWindows.add(w);
10293 } else if (w.mOrientationChanging) {
10294 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010295 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010296 "Orientation not waiting for draw in "
10297 + w + ", surface " + w.mSurface);
10298 w.mOrientationChanging = false;
10299 }
10300 }
10301 }
10302
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010303 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 if (!w.mLastHidden) {
10305 //dump();
10306 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010307 if (SHOW_TRANSACTIONS) logSurface(w,
10308 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010309 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010310 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 try {
10312 w.mSurface.hide();
10313 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010314 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010315 }
10316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010317 }
10318 // If we are waiting for this window to handle an
10319 // orientation change, well, it is hidden, so
10320 // doesn't really matter. Note that this does
10321 // introduce a potential glitch if the window
10322 // becomes unhidden before it has drawn for the
10323 // new orientation.
10324 if (w.mOrientationChanging) {
10325 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010326 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 "Orientation change skips hidden " + w);
10328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 } else if (w.mLastLayer != w.mAnimLayer
10330 || w.mLastAlpha != w.mShownAlpha
10331 || w.mLastDsDx != w.mDsDx
10332 || w.mLastDtDx != w.mDtDx
10333 || w.mLastDsDy != w.mDsDy
10334 || w.mLastDtDy != w.mDtDy
10335 || w.mLastHScale != w.mHScale
10336 || w.mLastVScale != w.mVScale
10337 || w.mLastHidden) {
10338 displayed = true;
10339 w.mLastAlpha = w.mShownAlpha;
10340 w.mLastLayer = w.mAnimLayer;
10341 w.mLastDsDx = w.mDsDx;
10342 w.mLastDtDx = w.mDtDx;
10343 w.mLastDsDy = w.mDsDy;
10344 w.mLastDtDy = w.mDtDy;
10345 w.mLastHScale = w.mHScale;
10346 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010347 if (SHOW_TRANSACTIONS) logSurface(w,
10348 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010349 + " matrix=[" + (w.mDsDx*w.mHScale)
10350 + "," + (w.mDtDx*w.mVScale)
10351 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010352 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 if (w.mSurface != null) {
10354 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010355 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010356 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010357 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010358 w.mSurface.setLayer(w.mAnimLayer);
10359 w.mSurface.setMatrix(
10360 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10361 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10362 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010363 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 if (!recoveringMemory) {
10365 reclaimSomeSurfaceMemoryLocked(w, "update");
10366 }
10367 }
10368 }
10369
10370 if (w.mLastHidden && !w.mDrawPending
10371 && !w.mCommitDrawPending
10372 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010373 if (SHOW_TRANSACTIONS) logSurface(w,
10374 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010375 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010376 + " during relayout");
10377 if (showSurfaceRobustlyLocked(w)) {
10378 w.mHasDrawn = true;
10379 w.mLastHidden = false;
10380 } else {
10381 w.mOrientationChanging = false;
10382 }
10383 }
10384 if (w.mSurface != null) {
10385 w.mToken.hasVisible = true;
10386 }
10387 } else {
10388 displayed = true;
10389 }
10390
10391 if (displayed) {
10392 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010393 if (attrs.width == LayoutParams.MATCH_PARENT
10394 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010395 covered = true;
10396 }
10397 }
10398 if (w.mOrientationChanging) {
10399 if (w.mDrawPending || w.mCommitDrawPending) {
10400 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010401 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010402 "Orientation continue waiting for draw in " + w);
10403 } else {
10404 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010405 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010406 "Orientation change complete in " + w);
10407 }
10408 }
10409 w.mToken.hasVisible = true;
10410 }
10411 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010412 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 "Orientation change skips hidden " + w);
10414 w.mOrientationChanging = false;
10415 }
10416
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010417 if (w.mContentChanged) {
10418 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10419 w.mContentChanged = false;
10420 }
10421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010422 final boolean canBeSeen = w.isDisplayedLw();
10423
10424 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10425 focusDisplayed = true;
10426 }
10427
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010428 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010430 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010431 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 if (w.mSurface != null) {
10433 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10434 holdScreen = w.mSession;
10435 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010436 if (!syswin && w.mAttrs.screenBrightness >= 0
10437 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010438 screenBrightness = w.mAttrs.screenBrightness;
10439 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010440 if (!syswin && w.mAttrs.buttonBrightness >= 0
10441 && buttonBrightness < 0) {
10442 buttonBrightness = w.mAttrs.buttonBrightness;
10443 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010444 if (canBeSeen
10445 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10446 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10447 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010448 syswin = true;
10449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010451
Dianne Hackborn25994b42009-09-04 14:21:19 -070010452 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10453 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 // This window completely covers everything behind it,
10455 // so we want to leave all of them as unblurred (for
10456 // performance reasons).
10457 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010458 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010459 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010460 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010461 obscured = true;
10462 if (mBackgroundFillerSurface == null) {
10463 try {
10464 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010465 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010466 0, dw, dh,
10467 PixelFormat.OPAQUE,
10468 Surface.FX_SURFACE_NORMAL);
10469 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010470 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010471 }
10472 }
10473 try {
10474 mBackgroundFillerSurface.setPosition(0, 0);
10475 mBackgroundFillerSurface.setSize(dw, dh);
10476 // Using the same layer as Dim because they will never be shown at the
10477 // same time.
10478 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10479 mBackgroundFillerSurface.show();
10480 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010481 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010482 }
10483 backgroundFillerShown = true;
10484 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010485 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010486 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010487 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 + ": blurring=" + blurring
10489 + " obscured=" + obscured
10490 + " displayed=" + displayed);
10491 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10492 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010493 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010494 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010495 if (mDimAnimator == null) {
10496 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010497 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010498 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010499 mDimAnimator.updateParameters(mContext.getResources(),
10500 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 }
10503 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10504 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010505 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010508 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 + mBlurSurface + ": CREATE");
10510 try {
Romain Guy06882f82009-06-10 13:36:04 -070010511 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010512 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 -1, 16, 16,
10514 PixelFormat.OPAQUE,
10515 Surface.FX_SURFACE_BLUR);
10516 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010517 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 }
10519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010520 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010521 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10522 + mBlurSurface + ": pos=(0,0) (" +
10523 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 mBlurSurface.setPosition(0, 0);
10525 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010526 mBlurSurface.setLayer(w.mAnimLayer-2);
10527 if (!mBlurShown) {
10528 try {
10529 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10530 + mBlurSurface + ": SHOW");
10531 mBlurSurface.show();
10532 } catch (RuntimeException e) {
10533 Slog.w(TAG, "Failure showing blur surface", e);
10534 }
10535 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 }
10537 }
10538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010539 }
10540 }
10541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010542
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010543 if (obscuredChanged && mWallpaperTarget == w) {
10544 // This is the wallpaper target and its obscured state
10545 // changed... make sure the current wallaper's visibility
10546 // has been updated accordingly.
10547 updateWallpaperVisibilityLocked();
10548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010550
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010551 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10552 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010553 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010554 try {
10555 mBackgroundFillerSurface.hide();
10556 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010557 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010558 }
10559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010560
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010561 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010562 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10563 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010564 }
Romain Guy06882f82009-06-10 13:36:04 -070010565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010566 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010567 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010568 + ": HIDE");
10569 try {
10570 mBlurSurface.hide();
10571 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010572 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 }
10574 mBlurShown = false;
10575 }
10576
Joe Onorato8a9b2202010-02-26 18:56:32 -080010577 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 }
10581
Jeff Browne33348b2010-07-15 23:54:05 -070010582 mInputMonitor.updateInputWindowsLw();
10583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010585
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010586 if (mWatermark != null) {
10587 mWatermark.drawIfNeeded();
10588 }
10589
Joe Onorato8a9b2202010-02-26 18:56:32 -080010590 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010591 "With display frozen, orientationChangeComplete="
10592 + orientationChangeComplete);
10593 if (orientationChangeComplete) {
10594 if (mWindowsFreezingScreen) {
10595 mWindowsFreezingScreen = false;
10596 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10597 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010598 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 }
Romain Guy06882f82009-06-10 13:36:04 -070010600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 i = mResizingWindows.size();
10602 if (i > 0) {
10603 do {
10604 i--;
10605 WindowState win = mResizingWindows.get(i);
10606 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010607 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10608 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010609 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010610 boolean configChanged =
10611 win.mConfiguration != mCurConfiguration
10612 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010613 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10614 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10615 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010616 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010617 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010618 + " / " + mCurConfiguration + " / 0x"
10619 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010620 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010621 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010622 win.mClient.resized(win.mFrame.width(),
10623 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010624 win.mLastVisibleInsets, win.mDrawPending,
10625 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 win.mContentInsetsChanged = false;
10627 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010628 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010629 } catch (RemoteException e) {
10630 win.mOrientationChanging = false;
10631 }
10632 } while (i > 0);
10633 mResizingWindows.clear();
10634 }
Romain Guy06882f82009-06-10 13:36:04 -070010635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010636 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010637 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010638 i = mDestroySurface.size();
10639 if (i > 0) {
10640 do {
10641 i--;
10642 WindowState win = mDestroySurface.get(i);
10643 win.mDestroying = false;
10644 if (mInputMethodWindow == win) {
10645 mInputMethodWindow = null;
10646 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010647 if (win == mWallpaperTarget) {
10648 wallpaperDestroyed = true;
10649 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010650 win.destroySurfaceLocked();
10651 } while (i > 0);
10652 mDestroySurface.clear();
10653 }
10654
10655 // Time to remove any exiting tokens?
10656 for (i=mExitingTokens.size()-1; i>=0; i--) {
10657 WindowToken token = mExitingTokens.get(i);
10658 if (!token.hasVisible) {
10659 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010660 if (token.windowType == TYPE_WALLPAPER) {
10661 mWallpaperTokens.remove(token);
10662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010663 }
10664 }
10665
10666 // Time to remove any exiting applications?
10667 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10668 AppWindowToken token = mExitingAppTokens.get(i);
10669 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010670 // Make sure there is no animation running on this token,
10671 // so any windows associated with it will be removed as
10672 // soon as their animations are complete
10673 token.animation = null;
10674 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010675 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10676 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010677 mAppTokens.remove(token);
10678 mExitingAppTokens.remove(i);
10679 }
10680 }
10681
Dianne Hackborna8f60182009-09-01 19:01:50 -070010682 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010683
Dianne Hackborna8f60182009-09-01 19:01:50 -070010684 if (!animating && mAppTransitionRunning) {
10685 // We have finished the animation of an app transition. To do
10686 // this, we have delayed a lot of operations like showing and
10687 // hiding apps, moving apps in Z-order, etc. The app token list
10688 // reflects the correct Z-order, but the window list may now
10689 // be out of sync with it. So here we will just rebuild the
10690 // entire app window list. Fun!
10691 mAppTransitionRunning = false;
10692 needRelayout = true;
10693 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010694 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010695 // Clear information about apps that were moving.
10696 mToBottomApps.clear();
10697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010699 if (focusDisplayed) {
10700 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10701 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010702 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010703 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010704 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010705 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010706 requestAnimationLocked(0);
10707 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010708 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10709 }
Jeff Browneb857f12010-07-16 10:06:33 -070010710
Jeff Browne33348b2010-07-15 23:54:05 -070010711 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010712
Jeff Brown8e03b752010-06-13 19:16:55 -070010713 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010714 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10715 mPowerManager.setScreenBrightnessOverride(-1);
10716 } else {
10717 mPowerManager.setScreenBrightnessOverride((int)
10718 (screenBrightness * Power.BRIGHTNESS_ON));
10719 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010720 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10721 mPowerManager.setButtonBrightnessOverride(-1);
10722 } else {
10723 mPowerManager.setButtonBrightnessOverride((int)
10724 (buttonBrightness * Power.BRIGHTNESS_ON));
10725 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010726 if (holdScreen != mHoldingScreenOn) {
10727 mHoldingScreenOn = holdScreen;
10728 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10729 mH.sendMessage(m);
10730 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010731
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010732 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010733 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010734 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10735 LocalPowerManager.BUTTON_EVENT, true);
10736 mTurnOnScreen = false;
10737 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010738
10739 // Check to see if we are now in a state where the screen should
10740 // be enabled, because the window obscured flags have changed.
10741 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010742 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010743
10744 /**
10745 * Must be called with the main window manager lock held.
10746 */
10747 void setHoldScreenLocked(boolean holding) {
10748 boolean state = mHoldingScreenWakeLock.isHeld();
10749 if (holding != state) {
10750 if (holding) {
10751 mHoldingScreenWakeLock.acquire();
10752 } else {
10753 mPolicy.screenOnStoppedLw();
10754 mHoldingScreenWakeLock.release();
10755 }
10756 }
10757 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010758
10759 void requestAnimationLocked(long delay) {
10760 if (!mAnimationPending) {
10761 mAnimationPending = true;
10762 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10763 }
10764 }
Romain Guy06882f82009-06-10 13:36:04 -070010765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010766 /**
10767 * Have the surface flinger show a surface, robustly dealing with
10768 * error conditions. In particular, if there is not enough memory
10769 * to show the surface, then we will try to get rid of other surfaces
10770 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010771 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010772 * @return Returns true if the surface was successfully shown.
10773 */
10774 boolean showSurfaceRobustlyLocked(WindowState win) {
10775 try {
10776 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010777 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010778 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010779 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010780 if (DEBUG_VISIBILITY) Slog.v(TAG,
10781 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010782 win.mTurnOnScreen = false;
10783 mTurnOnScreen = true;
10784 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 }
10786 return true;
10787 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010788 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010789 }
Romain Guy06882f82009-06-10 13:36:04 -070010790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010791 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 return false;
10794 }
Romain Guy06882f82009-06-10 13:36:04 -070010795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10797 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010798
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010799 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010800 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010802 if (mForceRemoves == null) {
10803 mForceRemoves = new ArrayList<WindowState>();
10804 }
Romain Guy06882f82009-06-10 13:36:04 -070010805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 long callingIdentity = Binder.clearCallingIdentity();
10807 try {
10808 // There was some problem... first, do a sanity check of the
10809 // window list to make sure we haven't left any dangling surfaces
10810 // around.
10811 int N = mWindows.size();
10812 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010813 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010814 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010815 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010816 if (ws.mSurface != null) {
10817 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010818 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010819 + ws + " surface=" + ws.mSurface
10820 + " token=" + win.mToken
10821 + " pid=" + ws.mSession.mPid
10822 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010823 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010824 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010825 ws.mSurface = null;
10826 mForceRemoves.add(ws);
10827 i--;
10828 N--;
10829 leakedSurface = true;
10830 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010831 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010832 + ws + " surface=" + ws.mSurface
10833 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010834 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010835 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010836 ws.mSurface = null;
10837 leakedSurface = true;
10838 }
10839 }
10840 }
Romain Guy06882f82009-06-10 13:36:04 -070010841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010842 boolean killedApps = false;
10843 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010844 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845 SparseIntArray pidCandidates = new SparseIntArray();
10846 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010847 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010848 if (ws.mSurface != null) {
10849 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10850 }
10851 }
10852 if (pidCandidates.size() > 0) {
10853 int[] pids = new int[pidCandidates.size()];
10854 for (int i=0; i<pids.length; i++) {
10855 pids[i] = pidCandidates.keyAt(i);
10856 }
10857 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010858 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010859 killedApps = true;
10860 }
10861 } catch (RemoteException e) {
10862 }
10863 }
10864 }
Romain Guy06882f82009-06-10 13:36:04 -070010865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 if (leakedSurface || killedApps) {
10867 // We managed to reclaim some memory, so get rid of the trouble
10868 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010869 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010870 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010871 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010872 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873 win.mSurface = null;
10874 }
Romain Guy06882f82009-06-10 13:36:04 -070010875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010876 try {
10877 win.mClient.dispatchGetNewSurface();
10878 } catch (RemoteException e) {
10879 }
10880 }
10881 } finally {
10882 Binder.restoreCallingIdentity(callingIdentity);
10883 }
10884 }
Romain Guy06882f82009-06-10 13:36:04 -070010885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010886 private boolean updateFocusedWindowLocked(int mode) {
10887 WindowState newFocus = computeFocusedWindowLocked();
10888 if (mCurrentFocus != newFocus) {
10889 // This check makes sure that we don't already have the focus
10890 // change message pending.
10891 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10892 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010893 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10895 final WindowState oldFocus = mCurrentFocus;
10896 mCurrentFocus = newFocus;
10897 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010899 final WindowState imWindow = mInputMethodWindow;
10900 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010901 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010903 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10904 mLayoutNeeded = true;
10905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010906 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010907 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010908 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10909 // Client will do the layout, but we need to assign layers
10910 // for handleNewWindowLocked() below.
10911 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912 }
10913 }
Jeff Brown349703e2010-06-22 01:27:15 -070010914
10915 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10916 // If we defer assigning layers, then the caller is responsible for
10917 // doing this part.
10918 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010920 return true;
10921 }
10922 return false;
10923 }
Jeff Brown349703e2010-06-22 01:27:15 -070010924
10925 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010926 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010928
10929 private WindowState computeFocusedWindowLocked() {
10930 WindowState result = null;
10931 WindowState win;
10932
10933 int i = mWindows.size() - 1;
10934 int nextAppIndex = mAppTokens.size()-1;
10935 WindowToken nextApp = nextAppIndex >= 0
10936 ? mAppTokens.get(nextAppIndex) : null;
10937
10938 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010939 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010940
Joe Onorato8a9b2202010-02-26 18:56:32 -080010941 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010942 TAG, "Looking for focus: " + i
10943 + " = " + win
10944 + ", flags=" + win.mAttrs.flags
10945 + ", canReceive=" + win.canReceiveKeys());
10946
10947 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010949 // If this window's application has been removed, just skip it.
10950 if (thisApp != null && thisApp.removed) {
10951 i--;
10952 continue;
10953 }
Romain Guy06882f82009-06-10 13:36:04 -070010954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010955 // If there is a focused app, don't allow focus to go to any
10956 // windows below it. If this is an application window, step
10957 // through the app tokens until we find its app.
10958 if (thisApp != null && nextApp != null && thisApp != nextApp
10959 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10960 int origAppIndex = nextAppIndex;
10961 while (nextAppIndex > 0) {
10962 if (nextApp == mFocusedApp) {
10963 // Whoops, we are below the focused app... no focus
10964 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010965 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010966 TAG, "Reached focused app: " + mFocusedApp);
10967 return null;
10968 }
10969 nextAppIndex--;
10970 nextApp = mAppTokens.get(nextAppIndex);
10971 if (nextApp == thisApp) {
10972 break;
10973 }
10974 }
10975 if (thisApp != nextApp) {
10976 // Uh oh, the app token doesn't exist! This shouldn't
10977 // happen, but if it does we can get totally hosed...
10978 // so restart at the original app.
10979 nextAppIndex = origAppIndex;
10980 nextApp = mAppTokens.get(nextAppIndex);
10981 }
10982 }
10983
10984 // Dispatch to this window if it is wants key events.
10985 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010986 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 TAG, "Found focus @ " + i + " = " + win);
10988 result = win;
10989 break;
10990 }
10991
10992 i--;
10993 }
10994
10995 return result;
10996 }
10997
10998 private void startFreezingDisplayLocked() {
10999 if (mDisplayFrozen) {
11000 return;
11001 }
Romain Guy06882f82009-06-10 13:36:04 -070011002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011003 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011005 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011006 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 if (mFreezeGcPending != 0) {
11008 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011009 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011010 mH.removeMessages(H.FORCE_GC);
11011 Runtime.getRuntime().gc();
11012 mFreezeGcPending = now;
11013 }
11014 } else {
11015 mFreezeGcPending = now;
11016 }
Romain Guy06882f82009-06-10 13:36:04 -070011017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011018 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011019
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011020 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011021
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011022 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11023 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011024 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011025 mAppTransitionReady = true;
11026 }
Romain Guy06882f82009-06-10 13:36:04 -070011027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011028 if (PROFILE_ORIENTATION) {
11029 File file = new File("/data/system/frozen");
11030 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11031 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011032
11033 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011034 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11035 mScreenRotationAnimation.kill();
11036 mScreenRotationAnimation = null;
11037 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011038 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011039 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
11040 mDisplay, mFxSession);
Dianne Hackborna1111872010-11-23 20:55:11 -080011041 }
11042 } else {
11043 Surface.freezeDisplay(0);
11044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011045 }
Romain Guy06882f82009-06-10 13:36:04 -070011046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011047 private void stopFreezingDisplayLocked() {
11048 if (!mDisplayFrozen) {
11049 return;
11050 }
Romain Guy06882f82009-06-10 13:36:04 -070011051
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011052 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11053 return;
11054 }
11055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011056 mDisplayFrozen = false;
11057 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11058 if (PROFILE_ORIENTATION) {
11059 Debug.stopMethodTracing();
11060 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011061
11062 if (CUSTOM_SCREEN_ROTATION) {
11063 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011064 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11065 mTransitionAnimationScale)) {
11066 requestAnimationLocked(0);
11067 } else {
11068 mScreenRotationAnimation = null;
11069 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011070 }
11071 } else {
11072 Surface.unfreezeDisplay(0);
11073 }
Romain Guy06882f82009-06-10 13:36:04 -070011074
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011075 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011076
Christopher Tateb696aee2010-04-02 19:08:30 -070011077 // While the display is frozen we don't re-compute the orientation
11078 // to avoid inconsistent states. However, something interesting
11079 // could have actually changed during that time so re-evaluate it
11080 // now to catch that.
11081 if (updateOrientationFromAppTokensLocked()) {
11082 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11083 }
11084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011085 // A little kludge: a lot could have happened while the
11086 // display was frozen, so now that we are coming back we
11087 // do a gc so that any remote references the system
11088 // processes holds on others can be released if they are
11089 // no longer needed.
11090 mH.removeMessages(H.FORCE_GC);
11091 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11092 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011094 mScreenFrozenLock.release();
11095 }
Romain Guy06882f82009-06-10 13:36:04 -070011096
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011097 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11098 DisplayMetrics dm) {
11099 if (index < tokens.length) {
11100 String str = tokens[index];
11101 if (str != null && str.length() > 0) {
11102 try {
11103 int val = Integer.parseInt(str);
11104 return val;
11105 } catch (Exception e) {
11106 }
11107 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011108 }
11109 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11110 return defDps;
11111 }
11112 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11113 return val;
11114 }
11115
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011116 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011117 final String[] mTokens;
11118 final String mText;
11119 final Paint mTextPaint;
11120 final int mTextWidth;
11121 final int mTextHeight;
11122 final int mTextAscent;
11123 final int mTextDescent;
11124 final int mDeltaX;
11125 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011126
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011127 Surface mSurface;
11128 int mLastDW;
11129 int mLastDH;
11130 boolean mDrawNeeded;
11131
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011132 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011133 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011134 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011135
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011136 if (false) {
11137 Log.i(TAG, "*********************** WATERMARK");
11138 for (int i=0; i<tokens.length; i++) {
11139 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11140 }
11141 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011142
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011143 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011144
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011145 StringBuilder builder = new StringBuilder(32);
11146 int len = mTokens[0].length();
11147 len = len & ~1;
11148 for (int i=0; i<len; i+=2) {
11149 int c1 = mTokens[0].charAt(i);
11150 int c2 = mTokens[0].charAt(i+1);
11151 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11152 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11153 else c1 -= '0';
11154 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11155 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11156 else c2 -= '0';
11157 builder.append((char)(255-((c1*16)+c2)));
11158 }
11159 mText = builder.toString();
11160 if (false) {
11161 Log.i(TAG, "Final text: " + mText);
11162 }
11163
11164 int fontSize = getPropertyInt(tokens, 1,
11165 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11166
11167 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11168 mTextPaint.setTextSize(fontSize);
11169 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11170
11171 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11172 mTextWidth = (int)mTextPaint.measureText(mText);
11173 mTextAscent = fm.ascent;
11174 mTextDescent = fm.descent;
11175 mTextHeight = fm.descent - fm.ascent;
11176
11177 mDeltaX = getPropertyInt(tokens, 2,
11178 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11179 mDeltaY = getPropertyInt(tokens, 3,
11180 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11181 int shadowColor = getPropertyInt(tokens, 4,
11182 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11183 int color = getPropertyInt(tokens, 5,
11184 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11185 int shadowRadius = getPropertyInt(tokens, 6,
11186 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11187 int shadowDx = getPropertyInt(tokens, 8,
11188 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11189 int shadowDy = getPropertyInt(tokens, 9,
11190 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11191
11192 mTextPaint.setColor(color);
11193 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011194
11195 try {
11196 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011197 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011198 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011199 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011200 mSurface.show();
11201 } catch (OutOfResourcesException e) {
11202 }
11203 }
11204
11205 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011206 if (mLastDW != dw || mLastDH != dh) {
11207 mLastDW = dw;
11208 mLastDH = dh;
11209 mSurface.setSize(dw, dh);
11210 mDrawNeeded = true;
11211 }
11212 }
11213
11214 void drawIfNeeded() {
11215 if (mDrawNeeded) {
11216 final int dw = mLastDW;
11217 final int dh = mLastDH;
11218
11219 mDrawNeeded = false;
11220 Rect dirty = new Rect(0, 0, dw, dh);
11221 Canvas c = null;
11222 try {
11223 c = mSurface.lockCanvas(dirty);
11224 } catch (IllegalArgumentException e) {
11225 } catch (OutOfResourcesException e) {
11226 }
11227 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011228 c.drawColor(0, PorterDuff.Mode.CLEAR);
11229
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011230 int deltaX = mDeltaX;
11231 int deltaY = mDeltaY;
11232
11233 // deltaX shouldn't be close to a round fraction of our
11234 // x step, or else things will line up too much.
11235 int div = (dw+mTextWidth)/deltaX;
11236 int rem = (dw+mTextWidth) - (div*deltaX);
11237 int qdelta = deltaX/4;
11238 if (rem < qdelta || rem > (deltaX-qdelta)) {
11239 deltaX += deltaX/3;
11240 }
11241
11242 int y = -mTextHeight;
11243 int x = -mTextWidth;
11244 while (y < (dh+mTextHeight)) {
11245 c.drawText(mText, x, y, mTextPaint);
11246 x += deltaX;
11247 if (x >= dw) {
11248 x -= (dw+mTextWidth);
11249 y += deltaY;
11250 }
11251 }
11252 mSurface.unlockCanvasAndPost(c);
11253 }
11254 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011255 }
11256 }
11257
11258 void createWatermark() {
11259 if (mWatermark != null) {
11260 return;
11261 }
11262
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011263 File file = new File("/system/etc/setup.conf");
11264 FileInputStream in = null;
11265 try {
11266 in = new FileInputStream(file);
11267 DataInputStream ind = new DataInputStream(in);
11268 String line = ind.readLine();
11269 if (line != null) {
11270 String[] toks = line.split("%");
11271 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011272 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011273 }
11274 }
11275 } catch (FileNotFoundException e) {
11276 } catch (IOException e) {
11277 } finally {
11278 if (in != null) {
11279 try {
11280 in.close();
11281 } catch (IOException e) {
11282 }
11283 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011284 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011285 }
11286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011287 @Override
11288 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11289 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11290 != PackageManager.PERMISSION_GRANTED) {
11291 pw.println("Permission Denial: can't dump WindowManager from from pid="
11292 + Binder.getCallingPid()
11293 + ", uid=" + Binder.getCallingUid());
11294 return;
11295 }
Romain Guy06882f82009-06-10 13:36:04 -070011296
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011297 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011298 pw.println(" ");
11299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011300 synchronized(mWindowMap) {
11301 pw.println("Current Window Manager state:");
11302 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011303 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011304 pw.print(" Window #"); pw.print(i); pw.print(' ');
11305 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011306 w.dump(pw, " ");
11307 }
11308 if (mInputMethodDialogs.size() > 0) {
11309 pw.println(" ");
11310 pw.println(" Input method dialogs:");
11311 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11312 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011313 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011314 }
11315 }
11316 if (mPendingRemove.size() > 0) {
11317 pw.println(" ");
11318 pw.println(" Remove pending for:");
11319 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11320 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011321 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11322 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011323 w.dump(pw, " ");
11324 }
11325 }
11326 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11327 pw.println(" ");
11328 pw.println(" Windows force removing:");
11329 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11330 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011331 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11332 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011333 w.dump(pw, " ");
11334 }
11335 }
11336 if (mDestroySurface.size() > 0) {
11337 pw.println(" ");
11338 pw.println(" Windows waiting to destroy their surface:");
11339 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11340 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011341 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11342 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011343 w.dump(pw, " ");
11344 }
11345 }
11346 if (mLosingFocus.size() > 0) {
11347 pw.println(" ");
11348 pw.println(" Windows losing focus:");
11349 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11350 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011351 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11352 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011353 w.dump(pw, " ");
11354 }
11355 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011356 if (mResizingWindows.size() > 0) {
11357 pw.println(" ");
11358 pw.println(" Windows waiting to resize:");
11359 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11360 WindowState w = mResizingWindows.get(i);
11361 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11362 pw.print(w); pw.println(":");
11363 w.dump(pw, " ");
11364 }
11365 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011366 if (mSessions.size() > 0) {
11367 pw.println(" ");
11368 pw.println(" All active sessions:");
11369 Iterator<Session> it = mSessions.iterator();
11370 while (it.hasNext()) {
11371 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011372 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011373 s.dump(pw, " ");
11374 }
11375 }
11376 if (mTokenMap.size() > 0) {
11377 pw.println(" ");
11378 pw.println(" All tokens:");
11379 Iterator<WindowToken> it = mTokenMap.values().iterator();
11380 while (it.hasNext()) {
11381 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011382 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011383 token.dump(pw, " ");
11384 }
11385 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011386 if (mWallpaperTokens.size() > 0) {
11387 pw.println(" ");
11388 pw.println(" Wallpaper tokens:");
11389 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11390 WindowToken token = mWallpaperTokens.get(i);
11391 pw.print(" Wallpaper #"); pw.print(i);
11392 pw.print(' '); pw.print(token); pw.println(':');
11393 token.dump(pw, " ");
11394 }
11395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011396 if (mAppTokens.size() > 0) {
11397 pw.println(" ");
11398 pw.println(" Application tokens in Z order:");
11399 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011400 pw.print(" App #"); pw.print(i); pw.print(": ");
11401 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011402 }
11403 }
11404 if (mFinishedStarting.size() > 0) {
11405 pw.println(" ");
11406 pw.println(" Finishing start of application tokens:");
11407 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11408 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011409 pw.print(" Finished Starting #"); pw.print(i);
11410 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011411 token.dump(pw, " ");
11412 }
11413 }
11414 if (mExitingTokens.size() > 0) {
11415 pw.println(" ");
11416 pw.println(" Exiting tokens:");
11417 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11418 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011419 pw.print(" Exiting #"); pw.print(i);
11420 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011421 token.dump(pw, " ");
11422 }
11423 }
11424 if (mExitingAppTokens.size() > 0) {
11425 pw.println(" ");
11426 pw.println(" Exiting application tokens:");
11427 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11428 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011429 pw.print(" Exiting App #"); pw.print(i);
11430 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011431 token.dump(pw, " ");
11432 }
11433 }
11434 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011435 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11436 pw.print(" mLastFocus="); pw.println(mLastFocus);
11437 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11438 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11439 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011440 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011441 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11442 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11443 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11444 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011445 if (mWindowDetachedWallpaper != null) {
11446 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11447 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011448 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11449 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11450 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011451 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11452 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11453 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11454 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011455 if (mDimAnimator != null) {
11456 mDimAnimator.printTo(pw);
11457 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011458 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011459 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011460 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011461 pw.print(mInputMethodAnimLayerAdjustment);
11462 pw.print(" mWallpaperAnimLayerAdjustment=");
11463 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011464 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11465 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011466 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11467 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011468 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11469 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011470 pw.print(" mRotation="); pw.print(mRotation);
11471 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11472 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11473 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11474 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11475 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11476 pw.print(" mNextAppTransition=0x");
11477 pw.print(Integer.toHexString(mNextAppTransition));
11478 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011479 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011480 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011481 if (mNextAppTransitionPackage != null) {
11482 pw.print(" mNextAppTransitionPackage=");
11483 pw.print(mNextAppTransitionPackage);
11484 pw.print(", mNextAppTransitionEnter=0x");
11485 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11486 pw.print(", mNextAppTransitionExit=0x");
11487 pw.print(Integer.toHexString(mNextAppTransitionExit));
11488 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011489 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11490 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11491 if (mOpeningApps.size() > 0) {
11492 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11493 }
11494 if (mClosingApps.size() > 0) {
11495 pw.print(" mClosingApps="); pw.println(mClosingApps);
11496 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011497 if (mToTopApps.size() > 0) {
11498 pw.print(" mToTopApps="); pw.println(mToTopApps);
11499 }
11500 if (mToBottomApps.size() > 0) {
11501 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11502 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011503 if (mDisplay != null) {
11504 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11505 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11506 } else {
11507 pw.println(" NO DISPLAY");
11508 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011509 pw.println(" Policy:");
11510 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011511 }
11512 }
11513
Jeff Brown349703e2010-06-22 01:27:15 -070011514 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011515 public void monitor() {
11516 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011517 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011519
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011520 /**
11521 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011522 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011523 */
11524 private static class DimAnimator {
11525 Surface mDimSurface;
11526 boolean mDimShown = false;
11527 float mDimCurrentAlpha;
11528 float mDimTargetAlpha;
11529 float mDimDeltaPerMs;
11530 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011531
11532 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011533
11534 DimAnimator (SurfaceSession session) {
11535 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011536 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011537 + mDimSurface + ": CREATE");
11538 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011539 mDimSurface = new Surface(session, 0,
11540 "DimSurface",
11541 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011542 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011543 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011544 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011545 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011546 }
11547 }
11548 }
11549
11550 /**
11551 * Show the dim surface.
11552 */
11553 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011554 if (!mDimShown) {
11555 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11556 dw + "x" + dh + ")");
11557 mDimShown = true;
11558 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011559 mLastDimWidth = dw;
11560 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011561 mDimSurface.setPosition(0, 0);
11562 mDimSurface.setSize(dw, dh);
11563 mDimSurface.show();
11564 } catch (RuntimeException e) {
11565 Slog.w(TAG, "Failure showing dim surface", e);
11566 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011567 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11568 mLastDimWidth = dw;
11569 mLastDimHeight = dh;
11570 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011571 }
11572 }
11573
11574 /**
11575 * Set's the dim surface's layer and update dim parameters that will be used in
11576 * {@link updateSurface} after all windows are examined.
11577 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011578 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011579 mDimSurface.setLayer(w.mAnimLayer-1);
11580
11581 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011582 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011583 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011584 if (mDimTargetAlpha != target) {
11585 // If the desired dim level has changed, then
11586 // start an animation to it.
11587 mLastDimAnimTime = currentTime;
11588 long duration = (w.mAnimating && w.mAnimation != null)
11589 ? w.mAnimation.computeDurationHint()
11590 : DEFAULT_DIM_DURATION;
11591 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011592 TypedValue tv = new TypedValue();
11593 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11594 tv, true);
11595 if (tv.type == TypedValue.TYPE_FRACTION) {
11596 duration = (long)tv.getFraction((float)duration, (float)duration);
11597 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11598 && tv.type <= TypedValue.TYPE_LAST_INT) {
11599 duration = tv.data;
11600 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011601 }
11602 if (duration < 1) {
11603 // Don't divide by zero
11604 duration = 1;
11605 }
11606 mDimTargetAlpha = target;
11607 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11608 }
11609 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011610
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011611 /**
11612 * Updating the surface's alpha. Returns true if the animation continues, or returns
11613 * false when the animation is finished and the dim surface is hidden.
11614 */
11615 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11616 if (!dimming) {
11617 if (mDimTargetAlpha != 0) {
11618 mLastDimAnimTime = currentTime;
11619 mDimTargetAlpha = 0;
11620 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11621 }
11622 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011623
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011624 boolean animating = false;
11625 if (mLastDimAnimTime != 0) {
11626 mDimCurrentAlpha += mDimDeltaPerMs
11627 * (currentTime-mLastDimAnimTime);
11628 boolean more = true;
11629 if (displayFrozen) {
11630 // If the display is frozen, there is no reason to animate.
11631 more = false;
11632 } else if (mDimDeltaPerMs > 0) {
11633 if (mDimCurrentAlpha > mDimTargetAlpha) {
11634 more = false;
11635 }
11636 } else if (mDimDeltaPerMs < 0) {
11637 if (mDimCurrentAlpha < mDimTargetAlpha) {
11638 more = false;
11639 }
11640 } else {
11641 more = false;
11642 }
11643
11644 // Do we need to continue animating?
11645 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011646 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011647 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11648 mLastDimAnimTime = currentTime;
11649 mDimSurface.setAlpha(mDimCurrentAlpha);
11650 animating = true;
11651 } else {
11652 mDimCurrentAlpha = mDimTargetAlpha;
11653 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011654 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011655 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11656 mDimSurface.setAlpha(mDimCurrentAlpha);
11657 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011658 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011659 + ": HIDE");
11660 try {
11661 mDimSurface.hide();
11662 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011663 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011664 }
11665 mDimShown = false;
11666 }
11667 }
11668 }
11669 return animating;
11670 }
11671
11672 public void printTo(PrintWriter pw) {
11673 pw.print(" mDimShown="); pw.print(mDimShown);
11674 pw.print(" current="); pw.print(mDimCurrentAlpha);
11675 pw.print(" target="); pw.print(mDimTargetAlpha);
11676 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11677 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11678 }
11679 }
11680
11681 /**
11682 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11683 * This is used for opening/closing transition for apps in compatible mode.
11684 */
11685 private static class FadeInOutAnimation extends Animation {
11686 int mWidth;
11687 boolean mFadeIn;
11688
11689 public FadeInOutAnimation(boolean fadeIn) {
11690 setInterpolator(new AccelerateInterpolator());
11691 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11692 mFadeIn = fadeIn;
11693 }
11694
11695 @Override
11696 protected void applyTransformation(float interpolatedTime, Transformation t) {
11697 float x = interpolatedTime;
11698 if (!mFadeIn) {
11699 x = 1.0f - x; // reverse the interpolation for fade out
11700 }
11701 if (x < 0.5) {
11702 // move the window out of the screen.
11703 t.getMatrix().setTranslate(mWidth, 0);
11704 } else {
11705 t.getMatrix().setTranslate(0, 0);// show
11706 t.setAlpha((x - 0.5f) * 2);
11707 }
11708 }
11709
11710 @Override
11711 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11712 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11713 mWidth = width;
11714 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011715
11716 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011717 public int getZAdjustment() {
11718 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011719 }
11720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011721}