blob: fb87d696e8f40520c9b25dced62084b110b481d9 [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.MEMORY_TYPE_PUSH_BUFFERS;
32import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
33import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070036import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38import com.android.internal.app.IBatteryStats;
39import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080040import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070041import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import com.android.internal.view.IInputContext;
43import com.android.internal.view.IInputMethodClient;
44import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080045import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import com.android.server.am.BatteryStatsService;
47
48import android.Manifest;
49import android.app.ActivityManagerNative;
50import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070053import android.content.ClipData;
54import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070056import android.content.Intent;
57import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070062import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070066import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.Rect;
68import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070069import android.graphics.Typeface;
70import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.BatteryStats;
72import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070073import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074import android.os.Debug;
75import android.os.Handler;
76import android.os.IBinder;
77import android.os.LocalPowerManager;
78import android.os.Looper;
79import android.os.Message;
80import android.os.Parcel;
81import android.os.ParcelFileDescriptor;
82import android.os.Power;
83import android.os.PowerManager;
84import android.os.Process;
85import android.os.RemoteException;
86import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070087import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import android.os.SystemClock;
89import android.os.SystemProperties;
90import android.os.TokenWatcher;
91import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070092import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070094import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080095import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070097import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -070099import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Gravity;
101import android.view.IApplicationToken;
102import android.view.IOnKeyguardExitResult;
103import android.view.IRotationWatcher;
104import android.view.IWindow;
105import android.view.IWindowManager;
106import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700107import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700108import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700109import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700110import android.view.InputHandler;
111import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112import android.view.KeyEvent;
113import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.Surface;
115import android.view.SurfaceSession;
116import android.view.View;
117import android.view.ViewTreeObserver;
118import android.view.WindowManager;
119import android.view.WindowManagerImpl;
120import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700121import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700123import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.animation.Animation;
125import android.view.animation.AnimationUtils;
126import android.view.animation.Transformation;
127
128import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.File;
131import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700132import java.io.FileInputStream;
133import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134import java.io.IOException;
135import java.io.OutputStream;
136import java.io.OutputStreamWriter;
137import java.io.PrintWriter;
138import java.io.StringWriter;
139import java.net.Socket;
140import java.util.ArrayList;
141import java.util.HashMap;
142import java.util.HashSet;
143import java.util.Iterator;
144import java.util.List;
145
146/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700147public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700148 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 static final String TAG = "WindowManager";
150 static final boolean DEBUG = false;
151 static final boolean DEBUG_FOCUS = false;
152 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800153 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800154 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_LAYERS = false;
156 static final boolean DEBUG_INPUT = false;
157 static final boolean DEBUG_INPUT_METHOD = false;
158 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700159 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700161 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_APP_TRANSITIONS = false;
163 static final boolean DEBUG_STARTING_WINDOW = false;
164 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700165 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700166 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700168 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean PROFILE_ORIENTATION = false;
171 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700172 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** How much to multiply the policy's type layer, to reserve room
175 * for multiple windows of the same type and Z-ordering adjustment
176 * with TYPE_LAYER_OFFSET. */
177 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
180 * or below others in the same layer. */
181 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** How much to increment the layer for each window, to reserve room
184 * for effect surfaces between them.
185 */
186 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 /** The maximum length we will accept for a loaded animation duration:
189 * this is 10 seconds.
190 */
191 static final int MAX_ANIMATION_DURATION = 10*1000;
192
193 /** Amount of time (in milliseconds) to animate the dim surface from one
194 * value to another, when no window animation is driving it.
195 */
196 static final int DEFAULT_DIM_DURATION = 200;
197
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700198 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
199 * compatible windows.
200 */
201 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 /** Adjustment to time to perform a dim, to make it more dramatic.
204 */
205 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700206
207 // Maximum number of milliseconds to wait for input event injection.
208 // FIXME is this value reasonable?
209 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700210
211 // Default input dispatching timeout in nanoseconds.
212 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 static final int UPDATE_FOCUS_NORMAL = 0;
215 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
216 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
217 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700220 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221
222 /**
223 * Condition waited on by {@link #reenableKeyguard} to know the call to
224 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500225 * This is set to true only if mKeyguardTokenWatcher.acquired() has
226 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500228 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229
Jim Miller284b62e2010-06-08 14:27:42 -0700230 private static final int ALLOW_DISABLE_YES = 1;
231 private static final int ALLOW_DISABLE_NO = 0;
232 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
233 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
234
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
236 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700238 if (shouldAllowDisableKeyguard()) {
239 mPolicy.enableKeyguard(false);
240 mKeyguardDisabled = true;
241 } else {
242 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700246 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500247 synchronized (mKeyguardTokenWatcher) {
248 mKeyguardDisabled = false;
249 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 }
251 }
252 };
253
Jim Miller284b62e2010-06-08 14:27:42 -0700254 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
255 @Override
256 public void onReceive(Context context, Intent intent) {
257 mPolicy.enableKeyguard(true);
258 synchronized(mKeyguardTokenWatcher) {
259 // lazily evaluate this next time we're asked to disable keyguard
260 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
261 mKeyguardDisabled = false;
262 }
263 }
264 };
265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 final Context mContext;
267
268 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
273
274 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * All currently active sessions with clients.
280 */
281 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 /**
284 * Mapping from an IWindow IBinder to the server's Window object.
285 * This is also used as the lock for all of our state.
286 */
287 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
288
289 /**
290 * Mapping from a token IBinder to a WindowToken object.
291 */
292 final HashMap<IBinder, WindowToken> mTokenMap =
293 new HashMap<IBinder, WindowToken>();
294
295 /**
296 * The same tokens as mTokenMap, stored in a list for efficient iteration
297 * over them.
298 */
299 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 /**
302 * Window tokens that are in the process of exiting, but still
303 * on screen for animations.
304 */
305 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
306
307 /**
308 * Z-ordered (bottom-most first) list of all application tokens, for
309 * controlling the ordering of windows in different applications. This
310 * contains WindowToken objects.
311 */
312 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
313
314 /**
315 * Application tokens that are in the process of exiting, but still
316 * on screen for animations.
317 */
318 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
319
320 /**
321 * List of window tokens that have finished starting their application,
322 * and now need to have the policy remove their windows.
323 */
324 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
325
326 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700327 * This was the app token that was used to retrieve the last enter
328 * animation. It will be used for the next exit animation.
329 */
330 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800331
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700332 /**
333 * These were the layout params used to retrieve the last enter animation.
334 * They will be used for the next exit animation.
335 */
336 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800337
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700338 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 * Z-ordered (bottom-most first) list of all Window objects.
340 */
Jeff Browne33348b2010-07-15 23:54:05 -0700341 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342
343 /**
344 * Windows that are being resized. Used so we can tell the client about
345 * the resize after closing the transaction in which we resized the
346 * underlying surface.
347 */
348 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
349
350 /**
351 * Windows whose animations have ended and now must be removed.
352 */
353 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
354
355 /**
356 * Windows whose surface should be destroyed.
357 */
358 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
359
360 /**
361 * Windows that have lost input focus and are waiting for the new
362 * focus window to be displayed before they are told about this.
363 */
364 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
365
366 /**
367 * This is set when we have run out of memory, and will either be an empty
368 * list or contain windows that need to be force removed.
369 */
370 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700375 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 Surface mBlurSurface;
377 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700378 Watermark mWatermark;
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;
445 WindowState mUpcomingInputMethodTarget = null;
446 boolean mInputMethodTargetWaitingAnim;
447 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 WindowState mInputMethodWindow = null;
450 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
451
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700452 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800453
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700454 // If non-null, this is the currently visible window that is associated
455 // with the wallpaper.
456 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700457 // If non-null, we are in the middle of animating from one wallpaper target
458 // to another, and this is the lower one in Z-order.
459 WindowState mLowerWallpaperTarget = null;
460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the higher one in Z-order.
462 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800463 // Window currently running an animation that has requested it be detached
464 // from the wallpaper. This means we need to ensure the wallpaper is
465 // visible behind it in case it animates in a way that would allow it to be
466 // seen.
467 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700468 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700469 float mLastWallpaperX = -1;
470 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800471 float mLastWallpaperXStep = -1;
472 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700473 // This is set when we are waiting for a wallpaper to tell us it is done
474 // changing its scroll position.
475 WindowState mWaitingOnWallpaper;
476 // The last time we had a timeout when waiting for a wallpaper.
477 long mLastWallpaperTimeoutTime;
478 // We give a wallpaper up to 150ms to finish scrolling.
479 static final long WALLPAPER_TIMEOUT = 150;
480 // Time we wait after a timeout before trying to wait again.
481 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 AppWindowToken mFocusedApp = null;
484
485 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 float mWindowAnimationScale = 1.0f;
488 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700489
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700490 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491
492 // Who is holding the screen on.
493 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700494 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700495
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700496 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700499 * Drag/drop state
500 */
501 class DragState {
502 IBinder mToken;
503 Surface mSurface;
504 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700505 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700506 ClipData mData;
507 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700508 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700509 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700510 float mThumbOffsetX, mThumbOffsetY;
511 InputChannel mServerChannel, mClientChannel;
512 WindowState mTargetWindow;
513 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700514 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515
516 private final Rect tmpRect = new Rect();
517
Chris Tate7b362e42010-11-04 16:02:52 -0700518 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700519 mToken = token;
520 mSurface = surface;
521 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700522 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700523 mNotifiedWindows = new ArrayList<WindowState>();
524 }
525
526 void reset() {
527 if (mSurface != null) {
528 mSurface.destroy();
529 }
530 mSurface = null;
531 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700532 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700533 mToken = null;
534 mData = null;
535 mThumbOffsetX = mThumbOffsetY = 0;
536 mNotifiedWindows = null;
537 }
538
539 void register() {
540 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
541 if (mClientChannel != null) {
542 Slog.e(TAG, "Duplicate register of drag input channel");
543 } else {
544 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
545 mServerChannel = channels[0];
546 mClientChannel = channels[1];
547 mInputManager.registerInputChannel(mServerChannel);
548 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
549 mH.getLooper().getQueue());
550 }
551 }
552
553 void unregister() {
554 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
555 if (mClientChannel == null) {
556 Slog.e(TAG, "Unregister of nonexistent drag input channel");
557 } else {
558 mInputManager.unregisterInputChannel(mServerChannel);
559 InputQueue.unregisterInputChannel(mClientChannel);
560 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700561 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700562 mClientChannel = null;
563 mServerChannel = null;
564 }
565 }
566
Chris Tatea32dcf72010-10-14 12:13:50 -0700567 int getDragLayerLw() {
568 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
569 * TYPE_LAYER_MULTIPLIER
570 + TYPE_LAYER_OFFSET;
571 }
572
Christopher Tatea53146c2010-09-07 11:57:52 -0700573 /* call out to each visible window/session informing it about the drag
574 */
Chris Tateb8203e92010-10-12 14:23:21 -0700575 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700576 // Cache a base-class instance of the clip metadata so that parceling
577 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700578 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700579 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700580 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700581
582 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700583 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 }
585
Christopher Tate2c095f32010-10-04 14:13:40 -0700586 final int N = mWindows.size();
587 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700588 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700590 }
591
592 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
593 * designated window is potentially a drop recipient. There are race situations
594 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
595 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700596 *
597 * This method clones the 'event' parameter if it's being delivered to the same
598 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700599 */
Chris Tateb478f462010-10-15 16:02:26 -0700600 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
601 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700602 // Don't actually send the event if the drag is supposed to be pinned
603 // to the originating window but 'newWin' is not that window.
604 if (mLocalOnly) {
605 final IBinder winBinder = newWin.mClient.asBinder();
606 if (winBinder != mLocalWin) {
607 if (DEBUG_DRAG) {
608 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
609 }
610 return;
611 }
612 }
613
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700614 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700615 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
616 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700617 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700618 try {
619 newWin.mClient.dispatchDragEvent(event);
620 // track each window that we've notified that the drag is starting
621 mNotifiedWindows.add(newWin);
622 } catch (RemoteException e) {
623 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700624 } finally {
625 // if the callee was local, the dispatch has already recycled the event
626 if (Process.myPid() != newWin.mSession.mPid) {
627 event.recycle();
628 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700629 }
630 }
631 }
632
633 /* helper - construct and send a DRAG_STARTED event only if the window has not
634 * previously been notified, i.e. it became visible after the drag operation
635 * was begun. This is a rare case.
636 */
637 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700638 if (mDragInProgress) {
639 // If we have sent the drag-started, we needn't do so again
640 for (WindowState ws : mNotifiedWindows) {
641 if (ws == newWin) {
642 return;
643 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700644 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700645 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700646 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700647 }
Chris Tateb478f462010-10-15 16:02:26 -0700648 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700650 }
651
Chris Tated4533f142010-10-19 15:15:08 -0700652 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700653 if (DEBUG_DRAG) {
654 Slog.d(TAG, "broadcasting DRAG_ENDED");
655 }
Chris Tated4533f142010-10-19 15:15:08 -0700656 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
657 0, 0, null, null, mDragResult);
658 for (WindowState ws: mNotifiedWindows) {
659 try {
660 ws.mClient.dispatchDragEvent(evt);
661 } catch (RemoteException e) {
662 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700664 }
Chris Tated4533f142010-10-19 15:15:08 -0700665 mNotifiedWindows.clear();
666 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700667 evt.recycle();
668 }
669
Chris Tated4533f142010-10-19 15:15:08 -0700670 void endDragLw() {
671 mDragState.broadcastDragEndedLw();
672
673 // stop intercepting input
674 mDragState.unregister();
675 mInputMonitor.updateInputWindowsLw();
676
677 // free our resources and drop all the object references
678 mDragState.reset();
679 mDragState = null;
680 }
681
Christopher Tatea53146c2010-09-07 11:57:52 -0700682 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700683 final int myPid = Process.myPid();
684
685 // Move the surface to the given touch
686 mSurface.openTransaction();
687 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
688 mSurface.closeTransaction();
689
690 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700691 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700692 if (mLocalOnly) {
693 final IBinder touchedBinder = touchedWin.mClient.asBinder();
694 if (touchedBinder != mLocalWin) {
695 // This drag is pinned only to the originating window, but the drag
696 // point is outside that window. Pretend it's over empty space.
697 touchedWin = null;
698 }
699 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700700 try {
701 // have we dragged over a new window?
702 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
703 if (DEBUG_DRAG) {
704 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
705 }
706 // force DRAG_EXITED_EVENT if appropriate
707 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700708 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700709 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700710 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700711 if (myPid != mTargetWindow.mSession.mPid) {
712 evt.recycle();
713 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700714 }
715 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700716 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700717 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
718 }
719 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700720 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700721 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700722 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700723 if (myPid != touchedWin.mSession.mPid) {
724 evt.recycle();
725 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700726 }
727 } catch (RemoteException e) {
728 Slog.w(TAG, "can't send drag notification to windows");
729 }
730 mTargetWindow = touchedWin;
731 }
732
Chris Tated4533f142010-10-19 15:15:08 -0700733 // Tell the drop target about the data. Returns 'true' if we can immediately
734 // dispatch the global drag-ended message, 'false' if we need to wait for a
735 // result from the recipient.
736 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700737 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700738 if (touchedWin == null) {
739 // "drop" outside a valid window -- no recipient to apply a
740 // timeout to, and we can send the drag-ended message immediately.
741 mDragResult = false;
742 return true;
743 }
744
745 if (DEBUG_DRAG) {
746 Slog.d(TAG, "sending DROP to " + touchedWin);
747 }
748 final int myPid = Process.myPid();
749 final IBinder token = touchedWin.mClient.asBinder();
750 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
751 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
752 null, mData, false);
753 try {
754 touchedWin.mClient.dispatchDragEvent(evt);
755
756 // 5 second timeout for this window to respond to the drop
757 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
758 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
759 mH.sendMessageDelayed(msg, 5000);
760 } catch (RemoteException e) {
761 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
762 return true;
763 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700764 if (myPid != touchedWin.mSession.mPid) {
765 evt.recycle();
766 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700767 }
Chris Tated4533f142010-10-19 15:15:08 -0700768 mToken = token;
769 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700770 }
771
772 // Find the visible, touch-deliverable window under the given point
773 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
774 WindowState touchedWin = null;
775 final int x = (int) xf;
776 final int y = (int) yf;
777 final ArrayList<WindowState> windows = mWindows;
778 final int N = windows.size();
779 for (int i = N - 1; i >= 0; i--) {
780 WindowState child = windows.get(i);
781 final int flags = child.mAttrs.flags;
782 if (!child.isVisibleLw()) {
783 // not visible == don't tell about drags
784 continue;
785 }
786 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
787 // not touchable == don't tell about drags
788 continue;
789 }
790 // account for the window's decor etc
791 tmpRect.set(child.mFrame);
792 if (child.mTouchableInsets == ViewTreeObserver
793 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
794 // The point is inside of the window if it is
795 // inside the frame, AND the content part of that
796 // frame that was given by the application.
797 tmpRect.left += child.mGivenContentInsets.left;
798 tmpRect.top += child.mGivenContentInsets.top;
799 tmpRect.right -= child.mGivenContentInsets.right;
800 tmpRect.bottom -= child.mGivenContentInsets.bottom;
801 } else if (child.mTouchableInsets == ViewTreeObserver
802 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
803 // The point is inside of the window if it is
804 // inside the frame, AND the visible part of that
805 // frame that was given by the application.
806 tmpRect.left += child.mGivenVisibleInsets.left;
807 tmpRect.top += child.mGivenVisibleInsets.top;
808 tmpRect.right -= child.mGivenVisibleInsets.right;
809 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
810 }
811 final int touchFlags = flags &
812 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
813 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
814 if (tmpRect.contains(x, y) || touchFlags == 0) {
815 // Found it
816 touchedWin = child;
817 break;
818 }
819 }
820
821 return touchedWin;
822 }
823 }
824
825 DragState mDragState = null;
826 private final InputHandler mDragInputHandler = new BaseInputHandler() {
827 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700828 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
829 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700830 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700831 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
832 && mDragState != null) {
833 boolean endDrag = false;
834 final float newX = event.getRawX();
835 final float newY = event.getRawY();
836
Christopher Tatea53146c2010-09-07 11:57:52 -0700837 switch (event.getAction()) {
838 case MotionEvent.ACTION_DOWN: {
839 if (DEBUG_DRAG) {
840 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
841 }
842 } break;
843
844 case MotionEvent.ACTION_MOVE: {
845 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700846 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700847 mDragState.notifyMoveLw(newX, newY);
848 }
849 } break;
850
851 case MotionEvent.ACTION_UP: {
852 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
853 + newX + "," + newY);
854 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700855 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700856 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700857 } break;
858
859 case MotionEvent.ACTION_CANCEL: {
860 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
861 endDrag = true;
862 } break;
863 }
864
865 if (endDrag) {
866 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
867 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700868 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700869 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700870 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700871 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700872
873 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700874 }
875 } catch (Exception e) {
876 Slog.e(TAG, "Exception caught by drag handleMotion", e);
877 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700878 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700879 }
880 }
881 };
882
883 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 * Whether the UI is currently running in touch mode (not showing
885 * navigational focus because the user is directly pressing the screen).
886 */
887 boolean mInTouchMode = false;
888
889 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700890 private ArrayList<WindowChangeListener> mWindowChangeListeners =
891 new ArrayList<WindowChangeListener>();
892 private boolean mWindowsChanged = false;
893
894 public interface WindowChangeListener {
895 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700896 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898
Dianne Hackbornc485a602009-03-24 22:39:49 -0700899 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700900 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700901
902 // The frame use to limit the size of the app running in compatibility mode.
903 Rect mCompatibleScreenFrame = new Rect();
904 // The surface used to fill the outer rim of the app running in compatibility mode.
905 Surface mBackgroundFillerSurface = null;
906 boolean mBackgroundFillerShown = false;
907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 public static WindowManagerService main(Context context,
909 PowerManagerService pm, boolean haveInputMethods) {
910 WMThread thr = new WMThread(context, pm, haveInputMethods);
911 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 synchronized (thr) {
914 while (thr.mService == null) {
915 try {
916 thr.wait();
917 } catch (InterruptedException e) {
918 }
919 }
920 }
Romain Guy06882f82009-06-10 13:36:04 -0700921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 return thr.mService;
923 }
Romain Guy06882f82009-06-10 13:36:04 -0700924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 static class WMThread extends Thread {
926 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 private final Context mContext;
929 private final PowerManagerService mPM;
930 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 public WMThread(Context context, PowerManagerService pm,
933 boolean haveInputMethods) {
934 super("WindowManager");
935 mContext = context;
936 mPM = pm;
937 mHaveInputMethods = haveInputMethods;
938 }
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 public void run() {
941 Looper.prepare();
942 WindowManagerService s = new WindowManagerService(mContext, mPM,
943 mHaveInputMethods);
944 android.os.Process.setThreadPriority(
945 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700946 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 synchronized (this) {
949 mService = s;
950 notifyAll();
951 }
Romain Guy06882f82009-06-10 13:36:04 -0700952
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700953 // For debug builds, log event loop stalls to dropbox for analysis.
954 if (StrictMode.conditionallyEnableDebugLogging()) {
955 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
956 }
957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 Looper.loop();
959 }
960 }
961
962 static class PolicyThread extends Thread {
963 private final WindowManagerPolicy mPolicy;
964 private final WindowManagerService mService;
965 private final Context mContext;
966 private final PowerManagerService mPM;
967 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 public PolicyThread(WindowManagerPolicy policy,
970 WindowManagerService service, Context context,
971 PowerManagerService pm) {
972 super("WindowManagerPolicy");
973 mPolicy = policy;
974 mService = service;
975 mContext = context;
976 mPM = pm;
977 }
Romain Guy06882f82009-06-10 13:36:04 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 public void run() {
980 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800981 WindowManagerPolicyThread.set(this, Looper.myLooper());
982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800984 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 android.os.Process.setThreadPriority(
986 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700987 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 synchronized (this) {
991 mRunning = true;
992 notifyAll();
993 }
Romain Guy06882f82009-06-10 13:36:04 -0700994
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700995 // For debug builds, log event loop stalls to dropbox for analysis.
996 if (StrictMode.conditionallyEnableDebugLogging()) {
997 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
998 }
999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 Looper.loop();
1001 }
1002 }
1003
1004 private WindowManagerService(Context context, PowerManagerService pm,
1005 boolean haveInputMethods) {
1006 mContext = context;
1007 mHaveInputMethods = haveInputMethods;
1008 mLimitedAlphaCompositing = context.getResources().getBoolean(
1009 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 mPowerManager = pm;
1012 mPowerManager.setPolicy(mPolicy);
1013 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1014 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1015 "SCREEN_FROZEN");
1016 mScreenFrozenLock.setReferenceCounted(false);
1017
1018 mActivityManager = ActivityManagerNative.getDefault();
1019 mBatteryStats = BatteryStatsService.getService();
1020
1021 // Get persisted window scale setting
1022 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1023 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1024 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1025 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001026
Jim Miller284b62e2010-06-08 14:27:42 -07001027 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1028 IntentFilter filter = new IntentFilter();
1029 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1030 mContext.registerReceiver(mBroadcastReceiver, filter);
1031
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001032 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1033 "KEEP_SCREEN_ON_FLAG");
1034 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035
Jeff Browne33348b2010-07-15 23:54:05 -07001036 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1039 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 synchronized (thr) {
1042 while (!thr.mRunning) {
1043 try {
1044 thr.wait();
1045 } catch (InterruptedException e) {
1046 }
1047 }
1048 }
Romain Guy06882f82009-06-10 13:36:04 -07001049
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001050 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 // Add ourself to the Watchdog monitors.
1053 Watchdog.getInstance().addMonitor(this);
1054 }
1055
1056 @Override
1057 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1058 throws RemoteException {
1059 try {
1060 return super.onTransact(code, data, reply, flags);
1061 } catch (RuntimeException e) {
1062 // The window manager only throws security exceptions, so let's
1063 // log all others.
1064 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001065 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
1067 throw e;
1068 }
1069 }
1070
Jeff Browne33348b2010-07-15 23:54:05 -07001071 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001073 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 TAG, "Adding window " + window + " at "
1075 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1076 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001077 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
1079
Jeff Browne33348b2010-07-15 23:54:05 -07001080 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001082 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 TAG, "Adding window " + window + " at "
1084 + i + " of " + mWindows.size() + " (before " + pos + ")");
1085 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001086 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 }
1088
1089 //This method finds out the index of a window that has the same app token as
1090 //win. used for z ordering the windows in mWindows
1091 private int findIdxBasedOnAppTokens(WindowState win) {
1092 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001093 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 int jmax = localmWindows.size();
1095 if(jmax == 0) {
1096 return -1;
1097 }
1098 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001099 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 if(wentry.mAppToken == win.mAppToken) {
1101 return j;
1102 }
1103 }
1104 return -1;
1105 }
Romain Guy06882f82009-06-10 13:36:04 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1108 final IWindow client = win.mClient;
1109 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001110 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 final int N = localmWindows.size();
1113 final WindowState attached = win.mAttachedWindow;
1114 int i;
1115 if (attached == null) {
1116 int tokenWindowsPos = token.windows.size();
1117 if (token.appWindowToken != null) {
1118 int index = tokenWindowsPos-1;
1119 if (index >= 0) {
1120 // If this application has existing windows, we
1121 // simply place the new window on top of them... but
1122 // keep the starting window on top.
1123 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1124 // Base windows go behind everything else.
1125 placeWindowBefore(token.windows.get(0), win);
1126 tokenWindowsPos = 0;
1127 } else {
1128 AppWindowToken atoken = win.mAppToken;
1129 if (atoken != null &&
1130 token.windows.get(index) == atoken.startingWindow) {
1131 placeWindowBefore(token.windows.get(index), win);
1132 tokenWindowsPos--;
1133 } else {
1134 int newIdx = findIdxBasedOnAppTokens(win);
1135 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001136 //there is a window above this one associated with the same
1137 //apptoken note that the window could be a floating window
1138 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001140 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001141 TAG, "Adding window " + win + " at "
1142 + (newIdx+1) + " of " + N);
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 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001221 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001222 TAG, "Adding window " + win + " at "
1223 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001225 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 }
1227 }
1228 }
1229 } else {
1230 // Figure out where window should go, based on layer.
1231 final int myLayer = win.mBaseLayer;
1232 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001233 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 i++;
1235 break;
1236 }
1237 }
1238 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001239 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001240 TAG, "Adding window " + win + " at "
1241 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001243 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 }
1245 if (addToToken) {
1246 token.windows.add(tokenWindowsPos, win);
1247 }
1248
1249 } else {
1250 // Figure out this window's ordering relative to the window
1251 // it is attached to.
1252 final int NA = token.windows.size();
1253 final int sublayer = win.mSubLayer;
1254 int largestSublayer = Integer.MIN_VALUE;
1255 WindowState windowWithLargestSublayer = null;
1256 for (i=0; i<NA; i++) {
1257 WindowState w = token.windows.get(i);
1258 final int wSublayer = w.mSubLayer;
1259 if (wSublayer >= largestSublayer) {
1260 largestSublayer = wSublayer;
1261 windowWithLargestSublayer = w;
1262 }
1263 if (sublayer < 0) {
1264 // For negative sublayers, we go below all windows
1265 // in the same sublayer.
1266 if (wSublayer >= sublayer) {
1267 if (addToToken) {
1268 token.windows.add(i, win);
1269 }
1270 placeWindowBefore(
1271 wSublayer >= 0 ? attached : w, win);
1272 break;
1273 }
1274 } else {
1275 // For positive sublayers, we go above all windows
1276 // in the same sublayer.
1277 if (wSublayer > sublayer) {
1278 if (addToToken) {
1279 token.windows.add(i, win);
1280 }
1281 placeWindowBefore(w, win);
1282 break;
1283 }
1284 }
1285 }
1286 if (i >= NA) {
1287 if (addToToken) {
1288 token.windows.add(win);
1289 }
1290 if (sublayer < 0) {
1291 placeWindowBefore(attached, win);
1292 } else {
1293 placeWindowAfter(largestSublayer >= 0
1294 ? windowWithLargestSublayer
1295 : attached,
1296 win);
1297 }
1298 }
1299 }
Romain Guy06882f82009-06-10 13:36:04 -07001300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 if (win.mAppToken != null && addToToken) {
1302 win.mAppToken.allAppWindows.add(win);
1303 }
1304 }
Romain Guy06882f82009-06-10 13:36:04 -07001305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 static boolean canBeImeTarget(WindowState w) {
1307 final int fl = w.mAttrs.flags
1308 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1309 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1310 return w.isVisibleOrAdding();
1311 }
1312 return false;
1313 }
Romain Guy06882f82009-06-10 13:36:04 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001316 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 final int N = localmWindows.size();
1318 WindowState w = null;
1319 int i = N;
1320 while (i > 0) {
1321 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001322 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001323
Joe Onorato8a9b2202010-02-26 18:56:32 -08001324 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 // + Integer.toHexString(w.mAttrs.flags));
1326 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001327 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 // Yet more tricksyness! If this window is a "starting"
1330 // window, we do actually want to be on top of it, but
1331 // it is not -really- where input will go. So if the caller
1332 // is not actually looking to move the IME, look down below
1333 // for a real window to target...
1334 if (!willMove
1335 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1336 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001337 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1339 i--;
1340 w = wb;
1341 }
1342 }
1343 break;
1344 }
1345 }
Romain Guy06882f82009-06-10 13:36:04 -07001346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001348
Joe Onorato8a9b2202010-02-26 18:56:32 -08001349 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 if (willMove && w != null) {
1353 final WindowState curTarget = mInputMethodTarget;
1354 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 // Now some fun for dealing with window animations that
1357 // modify the Z order. We need to look at all windows below
1358 // the current target that are in this app, finding the highest
1359 // visible one in layering.
1360 AppWindowToken token = curTarget.mAppToken;
1361 WindowState highestTarget = null;
1362 int highestPos = 0;
1363 if (token.animating || token.animation != null) {
1364 int pos = 0;
1365 pos = localmWindows.indexOf(curTarget);
1366 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001367 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 if (win.mAppToken != token) {
1369 break;
1370 }
1371 if (!win.mRemoved) {
1372 if (highestTarget == null || win.mAnimLayer >
1373 highestTarget.mAnimLayer) {
1374 highestTarget = win;
1375 highestPos = pos;
1376 }
1377 }
1378 pos--;
1379 }
1380 }
Romain Guy06882f82009-06-10 13:36:04 -07001381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001383 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 + mNextAppTransition + " " + highestTarget
1385 + " animating=" + highestTarget.isAnimating()
1386 + " layer=" + highestTarget.mAnimLayer
1387 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001388
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001389 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 // If we are currently setting up for an animation,
1391 // hold everything until we can find out what will happen.
1392 mInputMethodTargetWaitingAnim = true;
1393 mInputMethodTarget = highestTarget;
1394 return highestPos + 1;
1395 } else if (highestTarget.isAnimating() &&
1396 highestTarget.mAnimLayer > w.mAnimLayer) {
1397 // If the window we are currently targeting is involved
1398 // with an animation, and it is on top of the next target
1399 // we will be over, then hold off on moving until
1400 // that is done.
1401 mInputMethodTarget = highestTarget;
1402 return highestPos + 1;
1403 }
1404 }
1405 }
1406 }
Romain Guy06882f82009-06-10 13:36:04 -07001407
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 if (w != null) {
1410 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001411 if (DEBUG_INPUT_METHOD) {
1412 RuntimeException e = null;
1413 if (!HIDE_STACK_CRAWLS) {
1414 e = new RuntimeException();
1415 e.fillInStackTrace();
1416 }
1417 Slog.w(TAG, "Moving IM target from "
1418 + mInputMethodTarget + " to " + w, e);
1419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 mInputMethodTarget = w;
1421 if (w.mAppToken != null) {
1422 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1423 } else {
1424 setInputMethodAnimLayerAdjustment(0);
1425 }
1426 }
1427 return i+1;
1428 }
1429 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001430 if (DEBUG_INPUT_METHOD) {
1431 RuntimeException e = null;
1432 if (!HIDE_STACK_CRAWLS) {
1433 e = new RuntimeException();
1434 e.fillInStackTrace();
1435 }
1436 Slog.w(TAG, "Moving IM target from "
1437 + mInputMethodTarget + " to null", e);
1438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 mInputMethodTarget = null;
1440 setInputMethodAnimLayerAdjustment(0);
1441 }
1442 return -1;
1443 }
Romain Guy06882f82009-06-10 13:36:04 -07001444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 void addInputMethodWindowToListLocked(WindowState win) {
1446 int pos = findDesiredInputMethodWindowIndexLocked(true);
1447 if (pos >= 0) {
1448 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001449 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001450 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001452 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 moveInputMethodDialogsLocked(pos+1);
1454 return;
1455 }
1456 win.mTargetAppToken = null;
1457 addWindowToListInOrderLocked(win, true);
1458 moveInputMethodDialogsLocked(pos);
1459 }
Romain Guy06882f82009-06-10 13:36:04 -07001460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 mInputMethodAnimLayerAdjustment = adj;
1464 WindowState imw = mInputMethodWindow;
1465 if (imw != null) {
1466 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 + " anim layer: " + imw.mAnimLayer);
1469 int wi = imw.mChildWindows.size();
1470 while (wi > 0) {
1471 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001472 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001474 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 + " anim layer: " + cw.mAnimLayer);
1476 }
1477 }
1478 int di = mInputMethodDialogs.size();
1479 while (di > 0) {
1480 di --;
1481 imw = mInputMethodDialogs.get(di);
1482 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001483 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 + " anim layer: " + imw.mAnimLayer);
1485 }
1486 }
Romain Guy06882f82009-06-10 13:36:04 -07001487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1489 int wpos = mWindows.indexOf(win);
1490 if (wpos >= 0) {
1491 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001492 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001494 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 int NC = win.mChildWindows.size();
1496 while (NC > 0) {
1497 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001498 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 int cpos = mWindows.indexOf(cw);
1500 if (cpos >= 0) {
1501 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001503 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 mWindows.remove(cpos);
1505 }
1506 }
1507 }
1508 return interestingPos;
1509 }
Romain Guy06882f82009-06-10 13:36:04 -07001510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 private void reAddWindowToListInOrderLocked(WindowState win) {
1512 addWindowToListInOrderLocked(win, false);
1513 // This is a hack to get all of the child windows added as well
1514 // at the right position. Child windows should be rare and
1515 // this case should be rare, so it shouldn't be that big a deal.
1516 int wpos = mWindows.indexOf(win);
1517 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001518 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001519 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001521 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 reAddWindowLocked(wpos, win);
1523 }
1524 }
Romain Guy06882f82009-06-10 13:36:04 -07001525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 void logWindowList(String prefix) {
1527 int N = mWindows.size();
1528 while (N > 0) {
1529 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001530 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 }
1532 }
Romain Guy06882f82009-06-10 13:36:04 -07001533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 void moveInputMethodDialogsLocked(int pos) {
1535 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001538 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 for (int i=0; i<N; i++) {
1540 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1541 }
1542 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 logWindowList(" ");
1545 }
Romain Guy06882f82009-06-10 13:36:04 -07001546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 if (pos >= 0) {
1548 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1549 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001550 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 if (wp == mInputMethodWindow) {
1552 pos++;
1553 }
1554 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001555 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 for (int i=0; i<N; i++) {
1557 WindowState win = dialogs.get(i);
1558 win.mTargetAppToken = targetAppToken;
1559 pos = reAddWindowLocked(pos, win);
1560 }
1561 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 logWindowList(" ");
1564 }
1565 return;
1566 }
1567 for (int i=0; i<N; i++) {
1568 WindowState win = dialogs.get(i);
1569 win.mTargetAppToken = null;
1570 reAddWindowToListInOrderLocked(win);
1571 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001572 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 logWindowList(" ");
1574 }
1575 }
1576 }
Romain Guy06882f82009-06-10 13:36:04 -07001577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1579 final WindowState imWin = mInputMethodWindow;
1580 final int DN = mInputMethodDialogs.size();
1581 if (imWin == null && DN == 0) {
1582 return false;
1583 }
Romain Guy06882f82009-06-10 13:36:04 -07001584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1586 if (imPos >= 0) {
1587 // In this case, the input method windows are to be placed
1588 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 // First check to see if the input method windows are already
1591 // located here, and contiguous.
1592 final int N = mWindows.size();
1593 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001594 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 // Figure out the actual input method window that should be
1597 // at the bottom of their stack.
1598 WindowState baseImWin = imWin != null
1599 ? imWin : mInputMethodDialogs.get(0);
1600 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001601 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 if (cw.mSubLayer < 0) baseImWin = cw;
1603 }
Romain Guy06882f82009-06-10 13:36:04 -07001604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 if (firstImWin == baseImWin) {
1606 // The windows haven't moved... but are they still contiguous?
1607 // First find the top IM window.
1608 int pos = imPos+1;
1609 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001610 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 break;
1612 }
1613 pos++;
1614 }
1615 pos++;
1616 // Now there should be no more input method windows above.
1617 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001618 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 break;
1620 }
1621 pos++;
1622 }
1623 if (pos >= N) {
1624 // All is good!
1625 return false;
1626 }
1627 }
Romain Guy06882f82009-06-10 13:36:04 -07001628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 if (imWin != null) {
1630 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001631 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 logWindowList(" ");
1633 }
1634 imPos = tmpRemoveWindowLocked(imPos, imWin);
1635 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001636 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 logWindowList(" ");
1638 }
1639 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1640 reAddWindowLocked(imPos, imWin);
1641 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 logWindowList(" ");
1644 }
1645 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1646 } else {
1647 moveInputMethodDialogsLocked(imPos);
1648 }
Romain Guy06882f82009-06-10 13:36:04 -07001649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 } else {
1651 // In this case, the input method windows go in a fixed layer,
1652 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 tmpRemoveWindowLocked(0, imWin);
1657 imWin.mTargetAppToken = null;
1658 reAddWindowToListInOrderLocked(imWin);
1659 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001660 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 logWindowList(" ");
1662 }
1663 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1664 } else {
1665 moveInputMethodDialogsLocked(-1);;
1666 }
Romain Guy06882f82009-06-10 13:36:04 -07001667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 }
Romain Guy06882f82009-06-10 13:36:04 -07001669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 if (needAssignLayers) {
1671 assignLayersLocked();
1672 }
Romain Guy06882f82009-06-10 13:36:04 -07001673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 return true;
1675 }
Romain Guy06882f82009-06-10 13:36:04 -07001676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 void adjustInputMethodDialogsLocked() {
1678 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1679 }
Romain Guy06882f82009-06-10 13:36:04 -07001680
Dianne Hackborn25994b42009-09-04 14:21:19 -07001681 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001683 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1684 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1685 ? wallpaperTarget.mAppToken.animation : null)
1686 + " upper=" + mUpperWallpaperTarget
1687 + " lower=" + mLowerWallpaperTarget);
1688 return (wallpaperTarget != null
1689 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1690 && wallpaperTarget.mAppToken.animation != null)))
1691 || mUpperWallpaperTarget != null
1692 || mLowerWallpaperTarget != null;
1693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001694
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001695 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1696 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001697
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001698 int adjustWallpaperWindowsLocked() {
1699 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001700
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001701 final int dw = mDisplay.getWidth();
1702 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001703
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001704 // First find top-most window that has asked to be on top of the
1705 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001706 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001707 int N = localmWindows.size();
1708 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001709 WindowState foundW = null;
1710 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001711 WindowState topCurW = null;
1712 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001713 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001714 int i = N;
1715 while (i > 0) {
1716 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001717 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001718 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1719 if (topCurW == null) {
1720 topCurW = w;
1721 topCurI = i;
1722 }
1723 continue;
1724 }
1725 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001726 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001727 // If this window's app token is hidden and not animating,
1728 // it is of no interest to us.
1729 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001730 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001731 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001732 continue;
1733 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001734 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001735 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001736 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1737 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001738 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001739 && (mWallpaperTarget == w
1740 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001741 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001743 foundW = w;
1744 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001745 if (w == mWallpaperTarget && ((w.mAppToken != null
1746 && w.mAppToken.animation != null)
1747 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001748 // The current wallpaper target is animating, so we'll
1749 // look behind it for another possible target and figure
1750 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001751 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001752 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001753 continue;
1754 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001755 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001756 } else if (w == mWindowDetachedWallpaper) {
1757 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001758 }
1759 }
1760
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001761 if (foundW == null && windowDetachedI >= 0) {
1762 if (DEBUG_WALLPAPER) Slog.v(TAG,
1763 "Found animating detached wallpaper activity: #" + i + "=" + w);
1764 foundW = w;
1765 foundI = windowDetachedI;
1766 }
1767
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001768 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001769 // If we are currently waiting for an app transition, and either
1770 // the current target or the next target are involved with it,
1771 // then hold off on doing anything with the wallpaper.
1772 // Note that we are checking here for just whether the target
1773 // is part of an app token... which is potentially overly aggressive
1774 // (the app token may not be involved in the transition), but good
1775 // enough (we'll just wait until whatever transition is pending
1776 // executes).
1777 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001778 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001779 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001780 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001781 }
1782 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001783 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001785 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001786 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001787 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001788
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001789 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001790 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001791 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001792 + " oldTarget: " + mWallpaperTarget);
1793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001794
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001795 mLowerWallpaperTarget = null;
1796 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001797
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001798 WindowState oldW = mWallpaperTarget;
1799 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001800
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 // Now what is happening... if the current and new targets are
1802 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001803 if (foundW != null && oldW != null) {
1804 boolean oldAnim = oldW.mAnimation != null
1805 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1806 boolean foundAnim = foundW.mAnimation != null
1807 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001808 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001810 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001811 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001812 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001813 int oldI = localmWindows.indexOf(oldW);
1814 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 }
1817 if (oldI >= 0) {
1818 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001819 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001820 + "=" + oldW + "; new#" + foundI
1821 + "=" + foundW);
1822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001823
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001824 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001825 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001826 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001827 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001828 }
1829 mWallpaperTarget = oldW;
1830 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001831
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001832 // Now set the upper and lower wallpaper targets
1833 // correctly, and make sure that we are positioning
1834 // the wallpaper below the lower.
1835 if (foundI > oldI) {
1836 // The new target is on top of the old one.
1837 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001838 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001839 }
1840 mUpperWallpaperTarget = foundW;
1841 mLowerWallpaperTarget = oldW;
1842 foundW = oldW;
1843 foundI = oldI;
1844 } else {
1845 // The new target is below the old one.
1846 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001847 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001848 }
1849 mUpperWallpaperTarget = oldW;
1850 mLowerWallpaperTarget = foundW;
1851 }
1852 }
1853 }
1854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001855
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001856 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001857 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001858 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1859 || (mLowerWallpaperTarget.mAppToken != null
1860 && mLowerWallpaperTarget.mAppToken.animation != null);
1861 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1862 || (mUpperWallpaperTarget.mAppToken != null
1863 && mUpperWallpaperTarget.mAppToken.animation != null);
1864 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001866 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001867 }
1868 mLowerWallpaperTarget = null;
1869 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001870 }
1871 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001873 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001874 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001875 // The window is visible to the compositor... but is it visible
1876 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001877 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001880 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001881 // its layer adjustment. Only do this if we are not transfering
1882 // between two wallpaper targets.
1883 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001884 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001885 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001886
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001887 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1888 * TYPE_LAYER_MULTIPLIER
1889 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001890
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001891 // Now w is the window we are supposed to be behind... but we
1892 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001893 // AND any starting window associated with it, AND below the
1894 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001895 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001896 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001897 if (wb.mBaseLayer < maxLayer &&
1898 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001899 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001900 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001901 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001902 // This window is not related to the previous one in any
1903 // interesting way, so stop here.
1904 break;
1905 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001906 foundW = wb;
1907 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001908 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001909 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001910 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001912
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001913 if (foundW == null && topCurW != null) {
1914 // There is no wallpaper target, so it goes at the bottom.
1915 // We will assume it is the same place as last time, if known.
1916 foundW = topCurW;
1917 foundI = topCurI+1;
1918 } else {
1919 // Okay i is the position immediately above the wallpaper. Look at
1920 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001921 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001922 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001923
Dianne Hackborn284ac932009-08-28 10:34:25 -07001924 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001925 if (mWallpaperTarget.mWallpaperX >= 0) {
1926 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001927 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001928 }
1929 if (mWallpaperTarget.mWallpaperY >= 0) {
1930 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001931 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001932 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001933 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 // Start stepping backwards from here, ensuring that our wallpaper windows
1936 // are correctly placed.
1937 int curTokenIndex = mWallpaperTokens.size();
1938 while (curTokenIndex > 0) {
1939 curTokenIndex--;
1940 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001941 if (token.hidden == visible) {
1942 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1943 token.hidden = !visible;
1944 // Need to do a layout to ensure the wallpaper now has the
1945 // correct size.
1946 mLayoutNeeded = true;
1947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001948
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001949 int curWallpaperIndex = token.windows.size();
1950 while (curWallpaperIndex > 0) {
1951 curWallpaperIndex--;
1952 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001954 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001955 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001957
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001958 // First, make sure the client has the current visibility
1959 // state.
1960 if (wallpaper.mWallpaperVisible != visible) {
1961 wallpaper.mWallpaperVisible = visible;
1962 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001963 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001964 "Setting visibility of wallpaper " + wallpaper
1965 + ": " + visible);
1966 wallpaper.mClient.dispatchAppVisibility(visible);
1967 } catch (RemoteException e) {
1968 }
1969 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001970
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001971 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001972 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001973 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001974
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001975 // First, if this window is at the current index, then all
1976 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001977 if (wallpaper == foundW) {
1978 foundI--;
1979 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001980 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 continue;
1982 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001983
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001984 // The window didn't match... the current wallpaper window,
1985 // wherever it is, is in the wrong place, so make sure it is
1986 // not in the list.
1987 int oldIndex = localmWindows.indexOf(wallpaper);
1988 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001989 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001990 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001991 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001992 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001993 if (oldIndex < foundI) {
1994 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001995 }
1996 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001997
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001998 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001999 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002000 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002001 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002002
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002003 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002004 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002005 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002006 }
2007 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002008
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002009 return changed;
2010 }
2011
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002012 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002014 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002015 mWallpaperAnimLayerAdjustment = adj;
2016 int curTokenIndex = mWallpaperTokens.size();
2017 while (curTokenIndex > 0) {
2018 curTokenIndex--;
2019 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2020 int curWallpaperIndex = token.windows.size();
2021 while (curWallpaperIndex > 0) {
2022 curWallpaperIndex--;
2023 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2024 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002025 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002026 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002027 }
2028 }
2029 }
2030
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002031 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2032 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002033 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002034 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002035 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002036 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002037 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2038 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2039 changed = wallpaperWin.mXOffset != offset;
2040 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002041 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002042 + wallpaperWin + " x: " + offset);
2043 wallpaperWin.mXOffset = offset;
2044 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002045 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002046 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002047 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002048 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002049 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002050
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002051 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002052 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002053 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2054 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2055 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002056 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002057 + wallpaperWin + " y: " + offset);
2058 changed = true;
2059 wallpaperWin.mYOffset = offset;
2060 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002061 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002062 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002063 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002064 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002065 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002066
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002067 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002068 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002069 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002070 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2071 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002072 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002073 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002074 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002075 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002076 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2077 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002078 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002079 if (mWaitingOnWallpaper != null) {
2080 long start = SystemClock.uptimeMillis();
2081 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2082 < start) {
2083 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002084 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002085 "Waiting for offset complete...");
2086 mWindowMap.wait(WALLPAPER_TIMEOUT);
2087 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002088 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002089 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002090 if ((start+WALLPAPER_TIMEOUT)
2091 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002092 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002093 + wallpaperWin);
2094 mLastWallpaperTimeoutTime = start;
2095 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002096 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002097 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002098 }
2099 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002100 } catch (RemoteException e) {
2101 }
2102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002103
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002104 return changed;
2105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002106
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002107 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002108 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002109 if (mWaitingOnWallpaper != null &&
2110 mWaitingOnWallpaper.mClient.asBinder() == window) {
2111 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002112 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002113 }
2114 }
2115 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002116
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002117 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002118 final int dw = mDisplay.getWidth();
2119 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002120
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002121 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002122
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002123 WindowState target = mWallpaperTarget;
2124 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002125 if (target.mWallpaperX >= 0) {
2126 mLastWallpaperX = target.mWallpaperX;
2127 } else if (changingTarget.mWallpaperX >= 0) {
2128 mLastWallpaperX = changingTarget.mWallpaperX;
2129 }
2130 if (target.mWallpaperY >= 0) {
2131 mLastWallpaperY = target.mWallpaperY;
2132 } else if (changingTarget.mWallpaperY >= 0) {
2133 mLastWallpaperY = changingTarget.mWallpaperY;
2134 }
2135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002136
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002137 int curTokenIndex = mWallpaperTokens.size();
2138 while (curTokenIndex > 0) {
2139 curTokenIndex--;
2140 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2141 int curWallpaperIndex = token.windows.size();
2142 while (curWallpaperIndex > 0) {
2143 curWallpaperIndex--;
2144 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2145 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2146 wallpaper.computeShownFrameLocked();
2147 changed = true;
2148 // We only want to be synchronous with one wallpaper.
2149 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002150 }
2151 }
2152 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002153
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002154 return changed;
2155 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002156
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002157 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002158 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002159 final int dw = mDisplay.getWidth();
2160 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002161
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002162 int curTokenIndex = mWallpaperTokens.size();
2163 while (curTokenIndex > 0) {
2164 curTokenIndex--;
2165 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002166 if (token.hidden == visible) {
2167 token.hidden = !visible;
2168 // Need to do a layout to ensure the wallpaper now has the
2169 // correct size.
2170 mLayoutNeeded = true;
2171 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002172
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002173 int curWallpaperIndex = token.windows.size();
2174 while (curWallpaperIndex > 0) {
2175 curWallpaperIndex--;
2176 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2177 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002178 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002179 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002180
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002181 if (wallpaper.mWallpaperVisible != visible) {
2182 wallpaper.mWallpaperVisible = visible;
2183 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002185 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002186 + ": " + visible);
2187 wallpaper.mClient.dispatchAppVisibility(visible);
2188 } catch (RemoteException e) {
2189 }
2190 }
2191 }
2192 }
2193 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 public int addWindow(Session session, IWindow client,
2196 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002197 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 int res = mPolicy.checkAddPermission(attrs);
2199 if (res != WindowManagerImpl.ADD_OKAY) {
2200 return res;
2201 }
Romain Guy06882f82009-06-10 13:36:04 -07002202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 boolean reportNewConfig = false;
2204 WindowState attachedWindow = null;
2205 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002206 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002210 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 }
Romain Guy06882f82009-06-10 13:36:04 -07002212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002214 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2216 }
2217
2218 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002219 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002221 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 + attrs.token + ". Aborting.");
2223 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2224 }
2225 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2226 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002227 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 + attrs.token + ". Aborting.");
2229 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2230 }
2231 }
2232
2233 boolean addToken = false;
2234 WindowToken token = mTokenMap.get(attrs.token);
2235 if (token == null) {
2236 if (attrs.type >= FIRST_APPLICATION_WINDOW
2237 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002238 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 + attrs.token + ". Aborting.");
2240 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2241 }
2242 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002243 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 + attrs.token + ". Aborting.");
2245 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2246 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002247 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002248 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002249 + attrs.token + ". Aborting.");
2250 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 token = new WindowToken(attrs.token, -1, false);
2253 addToken = true;
2254 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2255 && attrs.type <= LAST_APPLICATION_WINDOW) {
2256 AppWindowToken atoken = token.appWindowToken;
2257 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002258 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 + token + ". Aborting.");
2260 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2261 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002262 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 + token + ". Aborting.");
2264 return WindowManagerImpl.ADD_APP_EXITING;
2265 }
2266 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2267 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002268 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2270 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2271 }
2272 } else if (attrs.type == TYPE_INPUT_METHOD) {
2273 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002274 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 + attrs.token + ". Aborting.");
2276 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2277 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002278 } else if (attrs.type == TYPE_WALLPAPER) {
2279 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002280 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002281 + attrs.token + ". Aborting.");
2282 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 }
2285
2286 win = new WindowState(session, client, token,
2287 attachedWindow, attrs, viewVisibility);
2288 if (win.mDeathRecipient == null) {
2289 // Client has apparently died, so there is no reason to
2290 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002291 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 + " that is dead, aborting.");
2293 return WindowManagerImpl.ADD_APP_EXITING;
2294 }
2295
2296 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 res = mPolicy.prepareAddWindowLw(win, attrs);
2299 if (res != WindowManagerImpl.ADD_OKAY) {
2300 return res;
2301 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002302
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002303 if (outInputChannel != null) {
2304 String name = win.makeInputChannelName();
2305 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2306 win.mInputChannel = inputChannels[0];
2307 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2308
2309 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311
2312 // From now on, no exceptions or errors allowed!
2313
2314 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002315
Dianne Hackborn5132b372010-07-29 12:51:35 -07002316 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 if (addToken) {
2319 mTokenMap.put(attrs.token, token);
2320 mTokenList.add(token);
2321 }
2322 win.attach();
2323 mWindowMap.put(client.asBinder(), win);
2324
2325 if (attrs.type == TYPE_APPLICATION_STARTING &&
2326 token.appWindowToken != null) {
2327 token.appWindowToken.startingWindow = win;
2328 }
2329
2330 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 if (attrs.type == TYPE_INPUT_METHOD) {
2333 mInputMethodWindow = win;
2334 addInputMethodWindowToListLocked(win);
2335 imMayMove = false;
2336 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2337 mInputMethodDialogs.add(win);
2338 addWindowToListInOrderLocked(win, true);
2339 adjustInputMethodDialogsLocked();
2340 imMayMove = false;
2341 } else {
2342 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002343 if (attrs.type == TYPE_WALLPAPER) {
2344 mLastWallpaperTimeoutTime = 0;
2345 adjustWallpaperWindowsLocked();
2346 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002347 adjustWallpaperWindowsLocked();
2348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 }
Romain Guy06882f82009-06-10 13:36:04 -07002350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002351 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (mInTouchMode) {
2356 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2357 }
2358 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2359 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2360 }
Romain Guy06882f82009-06-10 13:36:04 -07002361
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002362 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002364 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2365 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 imMayMove = false;
2367 }
2368 }
Romain Guy06882f82009-06-10 13:36:04 -07002369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002371 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 }
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 assignLayersLocked();
2375 // Don't do layout here, the window must call
2376 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 //dump();
2379
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002380 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002381 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002382 }
Jeff Brown349703e2010-06-22 01:27:15 -07002383
Joe Onorato8a9b2202010-02-26 18:56:32 -08002384 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 TAG, "New client " + client.asBinder()
2386 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002387
2388 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2389 reportNewConfig = true;
2390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 }
2392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 if (reportNewConfig) {
2394 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 return res;
2400 }
Romain Guy06882f82009-06-10 13:36:04 -07002401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 public void removeWindow(Session session, IWindow client) {
2403 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002404 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 if (win == null) {
2406 return;
2407 }
2408 removeWindowLocked(session, win);
2409 }
2410 }
Romain Guy06882f82009-06-10 13:36:04 -07002411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 public void removeWindowLocked(Session session, WindowState win) {
2413
Joe Onorato8a9b2202010-02-26 18:56:32 -08002414 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 TAG, "Remove " + win + " client="
2416 + Integer.toHexString(System.identityHashCode(
2417 win.mClient.asBinder()))
2418 + ", surface=" + win.mSurface);
2419
2420 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002421
2422 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002423
Joe Onorato8a9b2202010-02-26 18:56:32 -08002424 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2426 + " mExiting=" + win.mExiting
2427 + " isAnimating=" + win.isAnimating()
2428 + " app-animation="
2429 + (win.mAppToken != null ? win.mAppToken.animation : null)
2430 + " inPendingTransaction="
2431 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2432 + " mDisplayFrozen=" + mDisplayFrozen);
2433 // Visibility of the removed window. Will be used later to update orientation later on.
2434 boolean wasVisible = false;
2435 // First, see if we need to run an animation. If we do, we have
2436 // to hold off on removing the window until the animation is done.
2437 // If the display is frozen, just remove immediately, since the
2438 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002439 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 // If we are not currently running the exit animation, we
2441 // need to see about starting one.
2442 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2445 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2446 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2447 }
2448 // Try starting an animation.
2449 if (applyAnimationLocked(win, transit, false)) {
2450 win.mExiting = true;
2451 }
2452 }
2453 if (win.mExiting || win.isAnimating()) {
2454 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002455 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 win.mExiting = true;
2457 win.mRemoveOnExit = true;
2458 mLayoutNeeded = true;
2459 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2460 performLayoutAndPlaceSurfacesLocked();
2461 if (win.mAppToken != null) {
2462 win.mAppToken.updateReportedVisibilityLocked();
2463 }
2464 //dump();
2465 Binder.restoreCallingIdentity(origId);
2466 return;
2467 }
2468 }
2469
2470 removeWindowInnerLocked(session, win);
2471 // Removing a visible window will effect the computed orientation
2472 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002473 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002474 != mForcedAppOrientation
2475 && updateOrientationFromAppTokensLocked()) {
2476 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 }
2478 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2479 Binder.restoreCallingIdentity(origId);
2480 }
Romain Guy06882f82009-06-10 13:36:04 -07002481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 if (mInputMethodTarget == win) {
2486 moveInputMethodWindowsIfNeededLocked(false);
2487 }
Romain Guy06882f82009-06-10 13:36:04 -07002488
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002489 if (false) {
2490 RuntimeException e = new RuntimeException("here");
2491 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002492 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002493 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 mPolicy.removeWindowLw(win);
2496 win.removeLocked();
2497
2498 mWindowMap.remove(win.mClient.asBinder());
2499 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002500 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002501 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502
2503 if (mInputMethodWindow == win) {
2504 mInputMethodWindow = null;
2505 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2506 mInputMethodDialogs.remove(win);
2507 }
Romain Guy06882f82009-06-10 13:36:04 -07002508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 final WindowToken token = win.mToken;
2510 final AppWindowToken atoken = win.mAppToken;
2511 token.windows.remove(win);
2512 if (atoken != null) {
2513 atoken.allAppWindows.remove(win);
2514 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002515 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 TAG, "**** Removing window " + win + ": count="
2517 + token.windows.size());
2518 if (token.windows.size() == 0) {
2519 if (!token.explicit) {
2520 mTokenMap.remove(token.token);
2521 mTokenList.remove(token);
2522 } else if (atoken != null) {
2523 atoken.firstWindowDrawn = false;
2524 }
2525 }
2526
2527 if (atoken != null) {
2528 if (atoken.startingWindow == win) {
2529 atoken.startingWindow = null;
2530 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2531 // If this is the last window and we had requested a starting
2532 // transition window, well there is no point now.
2533 atoken.startingData = null;
2534 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2535 // If this is the last window except for a starting transition
2536 // window, we need to get rid of the starting transition.
2537 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002538 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 + ": no more real windows");
2540 }
2541 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2542 mH.sendMessage(m);
2543 }
2544 }
Romain Guy06882f82009-06-10 13:36:04 -07002545
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002546 if (win.mAttrs.type == TYPE_WALLPAPER) {
2547 mLastWallpaperTimeoutTime = 0;
2548 adjustWallpaperWindowsLocked();
2549 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002550 adjustWallpaperWindowsLocked();
2551 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 if (!mInLayout) {
2554 assignLayersLocked();
2555 mLayoutNeeded = true;
2556 performLayoutAndPlaceSurfacesLocked();
2557 if (win.mAppToken != null) {
2558 win.mAppToken.updateReportedVisibilityLocked();
2559 }
2560 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002561
2562 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 }
2564
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002565 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2566 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2567 + ": " + msg + " / " + w.mAttrs.getTitle();
2568 if (where != null) {
2569 Slog.i(TAG, str, where);
2570 } else {
2571 Slog.i(TAG, str);
2572 }
2573 }
2574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2576 long origId = Binder.clearCallingIdentity();
2577 try {
2578 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002579 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 Surface.openTransaction();
2583 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002584 if (SHOW_TRANSACTIONS) logSurface(w,
2585 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 w.mSurface.setTransparentRegionHint(region);
2587 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002588 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 Surface.closeTransaction();
2590 }
2591 }
2592 }
2593 } finally {
2594 Binder.restoreCallingIdentity(origId);
2595 }
2596 }
2597
2598 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002599 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 Rect visibleInsets) {
2601 long origId = Binder.clearCallingIdentity();
2602 try {
2603 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002604 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 if (w != null) {
2606 w.mGivenInsetsPending = false;
2607 w.mGivenContentInsets.set(contentInsets);
2608 w.mGivenVisibleInsets.set(visibleInsets);
2609 w.mTouchableInsets = touchableInsets;
2610 mLayoutNeeded = true;
2611 performLayoutAndPlaceSurfacesLocked();
2612 }
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(origId);
2616 }
2617 }
Romain Guy06882f82009-06-10 13:36:04 -07002618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 public void getWindowDisplayFrame(Session session, IWindow client,
2620 Rect outDisplayFrame) {
2621 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002622 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 if (win == null) {
2624 outDisplayFrame.setEmpty();
2625 return;
2626 }
2627 outDisplayFrame.set(win.mDisplayFrame);
2628 }
2629 }
2630
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002631 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2632 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002633 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2634 window.mWallpaperX = x;
2635 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002636 window.mWallpaperXStep = xStep;
2637 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002638 if (updateWallpaperOffsetLocked(window, true)) {
2639 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002640 }
2641 }
2642 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002643
Dianne Hackborn75804932009-10-20 20:15:20 -07002644 void wallpaperCommandComplete(IBinder window, Bundle result) {
2645 synchronized (mWindowMap) {
2646 if (mWaitingOnWallpaper != null &&
2647 mWaitingOnWallpaper.mClient.asBinder() == window) {
2648 mWaitingOnWallpaper = null;
2649 mWindowMap.notifyAll();
2650 }
2651 }
2652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002653
Dianne Hackborn75804932009-10-20 20:15:20 -07002654 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2655 String action, int x, int y, int z, Bundle extras, boolean sync) {
2656 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2657 || window == mUpperWallpaperTarget) {
2658 boolean doWait = sync;
2659 int curTokenIndex = mWallpaperTokens.size();
2660 while (curTokenIndex > 0) {
2661 curTokenIndex--;
2662 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2663 int curWallpaperIndex = token.windows.size();
2664 while (curWallpaperIndex > 0) {
2665 curWallpaperIndex--;
2666 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2667 try {
2668 wallpaper.mClient.dispatchWallpaperCommand(action,
2669 x, y, z, extras, sync);
2670 // We only want to be synchronous with one wallpaper.
2671 sync = false;
2672 } catch (RemoteException e) {
2673 }
2674 }
2675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002676
Dianne Hackborn75804932009-10-20 20:15:20 -07002677 if (doWait) {
2678 // XXX Need to wait for result.
2679 }
2680 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002681
Dianne Hackborn75804932009-10-20 20:15:20 -07002682 return null;
2683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 public int relayoutWindow(Session session, IWindow client,
2686 WindowManager.LayoutParams attrs, int requestedWidth,
2687 int requestedHeight, int viewVisibility, boolean insetsPending,
2688 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002689 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 boolean displayed = false;
2691 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002692 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002696 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 if (win == null) {
2698 return 0;
2699 }
2700 win.mRequestedWidth = requestedWidth;
2701 win.mRequestedHeight = requestedHeight;
2702
2703 if (attrs != null) {
2704 mPolicy.adjustWindowParamsLw(attrs);
2705 }
Romain Guy06882f82009-06-10 13:36:04 -07002706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 int attrChanges = 0;
2708 int flagChanges = 0;
2709 if (attrs != null) {
2710 flagChanges = win.mAttrs.flags ^= attrs.flags;
2711 attrChanges = win.mAttrs.copyFrom(attrs);
2712 }
2713
Joe Onorato8a9b2202010-02-26 18:56:32 -08002714 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715
2716 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2717 win.mAlpha = attrs.alpha;
2718 }
2719
2720 final boolean scaledWindow =
2721 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2722
2723 if (scaledWindow) {
2724 // requested{Width|Height} Surface's physical size
2725 // attrs.{width|height} Size on screen
2726 win.mHScale = (attrs.width != requestedWidth) ?
2727 (attrs.width / (float)requestedWidth) : 1.0f;
2728 win.mVScale = (attrs.height != requestedHeight) ?
2729 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002730 } else {
2731 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002732 }
2733
2734 boolean imMayMove = (flagChanges&(
2735 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2736 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 boolean focusMayChange = win.mViewVisibility != viewVisibility
2739 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2740 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002741
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002742 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2743 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002745 win.mRelayoutCalled = true;
2746 final int oldVisibility = win.mViewVisibility;
2747 win.mViewVisibility = viewVisibility;
2748 if (viewVisibility == View.VISIBLE &&
2749 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2750 displayed = !win.isVisibleLw();
2751 if (win.mExiting) {
2752 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002753 if (win.mAnimation != null) {
2754 win.mAnimation.cancel();
2755 win.mAnimation = null;
2756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 }
2758 if (win.mDestroying) {
2759 win.mDestroying = false;
2760 mDestroySurface.remove(win);
2761 }
2762 if (oldVisibility == View.GONE) {
2763 win.mEnterAnimationPending = true;
2764 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002765 if (displayed) {
2766 if (win.mSurface != null && !win.mDrawPending
2767 && !win.mCommitDrawPending && !mDisplayFrozen
2768 && mPolicy.isScreenOn()) {
2769 applyEnterAnimationLocked(win);
2770 }
2771 if ((win.mAttrs.flags
2772 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2773 if (DEBUG_VISIBILITY) Slog.v(TAG,
2774 "Relayout window turning screen on: " + win);
2775 win.mTurnOnScreen = true;
2776 }
2777 int diff = 0;
2778 if (win.mConfiguration != mCurConfiguration
2779 && (win.mConfiguration == null
2780 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2781 win.mConfiguration = mCurConfiguration;
2782 if (DEBUG_CONFIGURATION) {
2783 Slog.i(TAG, "Window " + win + " visible with new config: "
2784 + win.mConfiguration + " / 0x"
2785 + Integer.toHexString(diff));
2786 }
2787 outConfig.setTo(mCurConfiguration);
2788 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002789 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2791 // To change the format, we need to re-build the surface.
2792 win.destroySurfaceLocked();
2793 displayed = true;
2794 }
2795 try {
2796 Surface surface = win.createSurfaceLocked();
2797 if (surface != null) {
2798 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002799 win.mReportDestroySurface = false;
2800 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002801 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002802 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002804 // For some reason there isn't a surface. Clear the
2805 // caller's object so they see the same state.
2806 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 }
2808 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002809 mInputMonitor.updateInputWindowsLw();
2810
Joe Onorato8a9b2202010-02-26 18:56:32 -08002811 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002812 + client + " (" + win.mAttrs.getTitle() + ")",
2813 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 Binder.restoreCallingIdentity(origId);
2815 return 0;
2816 }
2817 if (displayed) {
2818 focusMayChange = true;
2819 }
2820 if (win.mAttrs.type == TYPE_INPUT_METHOD
2821 && mInputMethodWindow == null) {
2822 mInputMethodWindow = win;
2823 imMayMove = true;
2824 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002825 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2826 && win.mAppToken != null
2827 && win.mAppToken.startingWindow != null) {
2828 // Special handling of starting window over the base
2829 // window of the app: propagate lock screen flags to it,
2830 // to provide the correct semantics while starting.
2831 final int mask =
2832 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002833 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2834 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002835 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2836 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 } else {
2839 win.mEnterAnimationPending = false;
2840 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002841 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002842 + ": mExiting=" + win.mExiting
2843 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 // If we are not currently running the exit animation, we
2845 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002846 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 // Try starting an animation; if there isn't one, we
2848 // can destroy the surface right away.
2849 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2850 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2851 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2852 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002853 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002855 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 } else if (win.isAnimating()) {
2858 // Currently in a hide animation... turn this into
2859 // an exit.
2860 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002861 } else if (win == mWallpaperTarget) {
2862 // If the wallpaper is currently behind this
2863 // window, we need to change both of them inside
2864 // of a transaction to avoid artifacts.
2865 win.mExiting = true;
2866 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 } else {
2868 if (mInputMethodWindow == win) {
2869 mInputMethodWindow = null;
2870 }
2871 win.destroySurfaceLocked();
2872 }
2873 }
2874 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002875
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002876 if (win.mSurface == null || (win.getAttrs().flags
2877 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2878 || win.mSurfacePendingDestroy) {
2879 // We are being called from a local process, which
2880 // means outSurface holds its current surface. Ensure the
2881 // surface object is cleared, but we don't want it actually
2882 // destroyed at this point.
2883 win.mSurfacePendingDestroy = false;
2884 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002885 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002886 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002887 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002888 "Keeping surface, will report destroy: " + win);
2889 win.mReportDestroySurface = true;
2890 outSurface.copyFrom(win.mSurface);
2891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 }
2893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 if (focusMayChange) {
2895 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2896 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 imMayMove = false;
2898 }
2899 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2900 }
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002902 // updateFocusedWindowLocked() already assigned layers so we only need to
2903 // reassign them at this point if the IM window state gets shuffled
2904 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002907 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2908 // Little hack here -- we -should- be able to rely on the
2909 // function to return true if the IME has moved and needs
2910 // its layer recomputed. However, if the IME was hidden
2911 // and isn't actually moved in the list, its layer may be
2912 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 assignLayers = true;
2914 }
2915 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002916 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002917 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002918 assignLayers = true;
2919 }
2920 }
Romain Guy06882f82009-06-10 13:36:04 -07002921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 mLayoutNeeded = true;
2923 win.mGivenInsetsPending = insetsPending;
2924 if (assignLayers) {
2925 assignLayersLocked();
2926 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002927 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002929 if (displayed && win.mIsWallpaper) {
2930 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002931 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 if (win.mAppToken != null) {
2934 win.mAppToken.updateReportedVisibilityLocked();
2935 }
2936 outFrame.set(win.mFrame);
2937 outContentInsets.set(win.mContentInsets);
2938 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002939 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002941 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 + ", requestedHeight=" + requestedHeight
2943 + ", viewVisibility=" + viewVisibility
2944 + "\nRelayout returning frame=" + outFrame
2945 + ", surface=" + outSurface);
2946
Joe Onorato8a9b2202010-02-26 18:56:32 -08002947 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2949
2950 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002951
2952 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 }
2954
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002955 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 sendNewConfiguration();
2957 }
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2962 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2963 }
2964
2965 public void finishDrawingWindow(Session session, IWindow client) {
2966 final long origId = Binder.clearCallingIdentity();
2967 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002968 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002970 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2971 adjustWallpaperWindowsLocked();
2972 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 mLayoutNeeded = true;
2974 performLayoutAndPlaceSurfacesLocked();
2975 }
2976 }
2977 Binder.restoreCallingIdentity(origId);
2978 }
2979
2980 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002981 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 + (lp != null ? lp.packageName : null)
2983 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2984 if (lp != null && lp.windowAnimations != 0) {
2985 // If this is a system resource, don't try to load it from the
2986 // application resources. It is nice to avoid loading application
2987 // resources if we can.
2988 String packageName = lp.packageName != null ? lp.packageName : "android";
2989 int resId = lp.windowAnimations;
2990 if ((resId&0xFF000000) == 0x01000000) {
2991 packageName = "android";
2992 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002993 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 + packageName);
2995 return AttributeCache.instance().get(packageName, resId,
2996 com.android.internal.R.styleable.WindowAnimation);
2997 }
2998 return null;
2999 }
Romain Guy06882f82009-06-10 13:36:04 -07003000
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003001 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003002 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003003 + packageName + " resId=0x" + Integer.toHexString(resId));
3004 if (packageName != null) {
3005 if ((resId&0xFF000000) == 0x01000000) {
3006 packageName = "android";
3007 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003008 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003009 + packageName);
3010 return AttributeCache.instance().get(packageName, resId,
3011 com.android.internal.R.styleable.WindowAnimation);
3012 }
3013 return null;
3014 }
3015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 private void applyEnterAnimationLocked(WindowState win) {
3017 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3018 if (win.mEnterAnimationPending) {
3019 win.mEnterAnimationPending = false;
3020 transit = WindowManagerPolicy.TRANSIT_ENTER;
3021 }
3022
3023 applyAnimationLocked(win, transit, true);
3024 }
3025
3026 private boolean applyAnimationLocked(WindowState win,
3027 int transit, boolean isEntrance) {
3028 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3029 // If we are trying to apply an animation, but already running
3030 // an animation of the same type, then just leave that one alone.
3031 return true;
3032 }
Romain Guy06882f82009-06-10 13:36:04 -07003033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 // Only apply an animation if the display isn't frozen. If it is
3035 // frozen, there is no reason to animate and it can cause strange
3036 // artifacts when we unfreeze the display if some different animation
3037 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003038 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 int anim = mPolicy.selectAnimationLw(win, transit);
3040 int attr = -1;
3041 Animation a = null;
3042 if (anim != 0) {
3043 a = AnimationUtils.loadAnimation(mContext, anim);
3044 } else {
3045 switch (transit) {
3046 case WindowManagerPolicy.TRANSIT_ENTER:
3047 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3048 break;
3049 case WindowManagerPolicy.TRANSIT_EXIT:
3050 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3051 break;
3052 case WindowManagerPolicy.TRANSIT_SHOW:
3053 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3054 break;
3055 case WindowManagerPolicy.TRANSIT_HIDE:
3056 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3057 break;
3058 }
3059 if (attr >= 0) {
3060 a = loadAnimation(win.mAttrs, attr);
3061 }
3062 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003063 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3065 + " mAnimation=" + win.mAnimation
3066 + " isEntrance=" + isEntrance);
3067 if (a != null) {
3068 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003069 RuntimeException e = null;
3070 if (!HIDE_STACK_CRAWLS) {
3071 e = new RuntimeException();
3072 e.fillInStackTrace();
3073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003074 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003075 }
3076 win.setAnimation(a);
3077 win.mAnimationIsEntrance = isEntrance;
3078 }
3079 } else {
3080 win.clearAnimation();
3081 }
3082
3083 return win.mAnimation != null;
3084 }
3085
3086 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3087 int anim = 0;
3088 Context context = mContext;
3089 if (animAttr >= 0) {
3090 AttributeCache.Entry ent = getCachedAnimations(lp);
3091 if (ent != null) {
3092 context = ent.context;
3093 anim = ent.array.getResourceId(animAttr, 0);
3094 }
3095 }
3096 if (anim != 0) {
3097 return AnimationUtils.loadAnimation(context, anim);
3098 }
3099 return null;
3100 }
Romain Guy06882f82009-06-10 13:36:04 -07003101
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003102 private Animation loadAnimation(String packageName, int resId) {
3103 int anim = 0;
3104 Context context = mContext;
3105 if (resId >= 0) {
3106 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3107 if (ent != null) {
3108 context = ent.context;
3109 anim = resId;
3110 }
3111 }
3112 if (anim != 0) {
3113 return AnimationUtils.loadAnimation(context, anim);
3114 }
3115 return null;
3116 }
3117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 private boolean applyAnimationLocked(AppWindowToken wtoken,
3119 WindowManager.LayoutParams lp, int transit, boolean enter) {
3120 // Only apply an animation if the display isn't frozen. If it is
3121 // frozen, there is no reason to animate and it can cause strange
3122 // artifacts when we unfreeze the display if some different animation
3123 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003124 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003125 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003126 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003127 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003128 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003129 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003130 } else if (mNextAppTransitionPackage != null) {
3131 a = loadAnimation(mNextAppTransitionPackage, enter ?
3132 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003133 } else {
3134 int animAttr = 0;
3135 switch (transit) {
3136 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3137 animAttr = enter
3138 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3139 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3140 break;
3141 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3142 animAttr = enter
3143 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3144 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3145 break;
3146 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3147 animAttr = enter
3148 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3149 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3150 break;
3151 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3152 animAttr = enter
3153 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3154 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3155 break;
3156 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3157 animAttr = enter
3158 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3159 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3160 break;
3161 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3162 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003163 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003164 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3165 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003166 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003167 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003168 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3169 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003170 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003171 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003172 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003173 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3174 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3175 break;
3176 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3177 animAttr = enter
3178 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3179 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3180 break;
3181 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3182 animAttr = enter
3183 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3184 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003185 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003186 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003187 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003188 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003189 + " anim=" + a
3190 + " animAttr=0x" + Integer.toHexString(animAttr)
3191 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 if (a != null) {
3194 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003195 RuntimeException e = null;
3196 if (!HIDE_STACK_CRAWLS) {
3197 e = new RuntimeException();
3198 e.fillInStackTrace();
3199 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003200 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 }
3202 wtoken.setAnimation(a);
3203 }
3204 } else {
3205 wtoken.clearAnimation();
3206 }
3207
3208 return wtoken.animation != null;
3209 }
3210
3211 // -------------------------------------------------------------
3212 // Application Window Tokens
3213 // -------------------------------------------------------------
3214
3215 public void validateAppTokens(List tokens) {
3216 int v = tokens.size()-1;
3217 int m = mAppTokens.size()-1;
3218 while (v >= 0 && m >= 0) {
3219 AppWindowToken wtoken = mAppTokens.get(m);
3220 if (wtoken.removed) {
3221 m--;
3222 continue;
3223 }
3224 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003225 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3227 }
3228 v--;
3229 m--;
3230 }
3231 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003232 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 v--;
3234 }
3235 while (m >= 0) {
3236 AppWindowToken wtoken = mAppTokens.get(m);
3237 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003238 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 }
3240 m--;
3241 }
3242 }
3243
3244 boolean checkCallingPermission(String permission, String func) {
3245 // Quick check: if the calling permission is me, it's all okay.
3246 if (Binder.getCallingPid() == Process.myPid()) {
3247 return true;
3248 }
Romain Guy06882f82009-06-10 13:36:04 -07003249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 if (mContext.checkCallingPermission(permission)
3251 == PackageManager.PERMISSION_GRANTED) {
3252 return true;
3253 }
3254 String msg = "Permission Denial: " + func + " from pid="
3255 + Binder.getCallingPid()
3256 + ", uid=" + Binder.getCallingUid()
3257 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003258 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 return false;
3260 }
Romain Guy06882f82009-06-10 13:36:04 -07003261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 AppWindowToken findAppWindowToken(IBinder token) {
3263 WindowToken wtoken = mTokenMap.get(token);
3264 if (wtoken == null) {
3265 return null;
3266 }
3267 return wtoken.appWindowToken;
3268 }
Romain Guy06882f82009-06-10 13:36:04 -07003269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 public void addWindowToken(IBinder token, int type) {
3271 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3272 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003273 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 }
Romain Guy06882f82009-06-10 13:36:04 -07003275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 synchronized(mWindowMap) {
3277 WindowToken wtoken = mTokenMap.get(token);
3278 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003279 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 return;
3281 }
3282 wtoken = new WindowToken(token, type, true);
3283 mTokenMap.put(token, wtoken);
3284 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003285 if (type == TYPE_WALLPAPER) {
3286 mWallpaperTokens.add(wtoken);
3287 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 }
3289 }
Romain Guy06882f82009-06-10 13:36:04 -07003290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 public void removeWindowToken(IBinder token) {
3292 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3293 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003294 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 }
3296
3297 final long origId = Binder.clearCallingIdentity();
3298 synchronized(mWindowMap) {
3299 WindowToken wtoken = mTokenMap.remove(token);
3300 mTokenList.remove(wtoken);
3301 if (wtoken != null) {
3302 boolean delayed = false;
3303 if (!wtoken.hidden) {
3304 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 final int N = wtoken.windows.size();
3307 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 for (int i=0; i<N; i++) {
3310 WindowState win = wtoken.windows.get(i);
3311
3312 if (win.isAnimating()) {
3313 delayed = true;
3314 }
Romain Guy06882f82009-06-10 13:36:04 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 if (win.isVisibleNow()) {
3317 applyAnimationLocked(win,
3318 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 changed = true;
3320 }
3321 }
3322
3323 if (changed) {
3324 mLayoutNeeded = true;
3325 performLayoutAndPlaceSurfacesLocked();
3326 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3327 }
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 if (delayed) {
3330 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003331 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3332 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 }
3334 }
Romain Guy06882f82009-06-10 13:36:04 -07003335
Jeff Brownc5ed5912010-07-14 18:48:53 -07003336 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003338 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 }
3340 }
3341 Binder.restoreCallingIdentity(origId);
3342 }
3343
3344 public void addAppToken(int addPos, IApplicationToken token,
3345 int groupId, int requestedOrientation, boolean fullscreen) {
3346 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3347 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003348 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 }
Jeff Brown349703e2010-06-22 01:27:15 -07003350
3351 // Get the dispatching timeout here while we are not holding any locks so that it
3352 // can be cached by the AppWindowToken. The timeout value is used later by the
3353 // input dispatcher in code that does hold locks. If we did not cache the value
3354 // here we would run the chance of introducing a deadlock between the window manager
3355 // (which holds locks while updating the input dispatcher state) and the activity manager
3356 // (which holds locks while querying the application token).
3357 long inputDispatchingTimeoutNanos;
3358 try {
3359 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3360 } catch (RemoteException ex) {
3361 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3362 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3363 }
Romain Guy06882f82009-06-10 13:36:04 -07003364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 synchronized(mWindowMap) {
3366 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3367 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003368 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 return;
3370 }
3371 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003372 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 wtoken.groupId = groupId;
3374 wtoken.appFullscreen = fullscreen;
3375 wtoken.requestedOrientation = requestedOrientation;
3376 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003377 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 mTokenMap.put(token.asBinder(), wtoken);
3379 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 // Application tokens start out hidden.
3382 wtoken.hidden = true;
3383 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 //dump();
3386 }
3387 }
Romain Guy06882f82009-06-10 13:36:04 -07003388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 public void setAppGroupId(IBinder token, int groupId) {
3390 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3391 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003392 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 }
3394
3395 synchronized(mWindowMap) {
3396 AppWindowToken wtoken = findAppWindowToken(token);
3397 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003398 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 return;
3400 }
3401 wtoken.groupId = groupId;
3402 }
3403 }
Romain Guy06882f82009-06-10 13:36:04 -07003404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 public int getOrientationFromWindowsLocked() {
3406 int pos = mWindows.size() - 1;
3407 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003408 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 pos--;
3410 if (wtoken.mAppToken != null) {
3411 // We hit an application window. so the orientation will be determined by the
3412 // app window. No point in continuing further.
3413 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3414 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003415 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003416 continue;
3417 }
3418 int req = wtoken.mAttrs.screenOrientation;
3419 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3420 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3421 continue;
3422 } else {
3423 return req;
3424 }
3425 }
3426 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3427 }
Romain Guy06882f82009-06-10 13:36:04 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003430 int pos = mAppTokens.size() - 1;
3431 int curGroup = 0;
3432 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3433 boolean findingBehind = false;
3434 boolean haveGroup = false;
3435 boolean lastFullscreen = false;
3436 while (pos >= 0) {
3437 AppWindowToken wtoken = mAppTokens.get(pos);
3438 pos--;
3439 // if we're about to tear down this window and not seek for
3440 // the behind activity, don't use it for orientation
3441 if (!findingBehind
3442 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3443 continue;
3444 }
3445
3446 if (!haveGroup) {
3447 // We ignore any hidden applications on the top.
3448 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003449 continue;
3450 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003451 haveGroup = true;
3452 curGroup = wtoken.groupId;
3453 lastOrientation = wtoken.requestedOrientation;
3454 } else if (curGroup != wtoken.groupId) {
3455 // If we have hit a new application group, and the bottom
3456 // of the previous group didn't explicitly say to use
3457 // the orientation behind it, and the last app was
3458 // full screen, then we'll stick with the
3459 // user's orientation.
3460 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3461 && lastFullscreen) {
3462 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003465 int or = wtoken.requestedOrientation;
3466 // If this application is fullscreen, and didn't explicitly say
3467 // to use the orientation behind it, then just take whatever
3468 // orientation it has and ignores whatever is under it.
3469 lastFullscreen = wtoken.appFullscreen;
3470 if (lastFullscreen
3471 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3472 return or;
3473 }
3474 // If this application has requested an explicit orientation,
3475 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003476 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3477 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003478 return or;
3479 }
3480 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3481 }
3482 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 }
Romain Guy06882f82009-06-10 13:36:04 -07003484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003486 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003487 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3488 "updateOrientationFromAppTokens()")) {
3489 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3490 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003491
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003492 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003494
3495 synchronized(mWindowMap) {
3496 if (updateOrientationFromAppTokensLocked()) {
3497 if (freezeThisOneIfNeeded != null) {
3498 AppWindowToken wtoken = findAppWindowToken(
3499 freezeThisOneIfNeeded);
3500 if (wtoken != null) {
3501 startAppFreezingScreenLocked(wtoken,
3502 ActivityInfo.CONFIG_ORIENTATION);
3503 }
3504 }
3505 config = computeNewConfigurationLocked();
3506
3507 } else if (currentConfig != null) {
3508 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003509 // state mismatches the activity manager's, update it,
3510 // disregarding font scale, which should remain set to
3511 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003512 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003513 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003514 if (computeNewConfigurationLocked(mTempConfiguration)) {
3515 if (currentConfig.diff(mTempConfiguration) != 0) {
3516 mWaitingForConfig = true;
3517 mLayoutNeeded = true;
3518 startFreezingDisplayLocked();
3519 config = new Configuration(mTempConfiguration);
3520 }
3521 }
3522 }
3523 }
3524
Dianne Hackborncfaef692009-06-15 14:24:44 -07003525 Binder.restoreCallingIdentity(ident);
3526 return config;
3527 }
3528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003530 * Determine the new desired orientation of the display, returning
3531 * a non-null new Configuration if it has changed from the current
3532 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3533 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3534 * SCREEN. This will typically be done for you if you call
3535 * sendNewConfiguration().
3536 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 * The orientation is computed from non-application windows first. If none of
3538 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003539 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3541 * android.os.IBinder)
3542 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003543 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003544 if (mDisplayFrozen) {
3545 // If the display is frozen, some activities may be in the middle
3546 // of restarting, and thus have removed their old window. If the
3547 // window has the flag to hide the lock screen, then the lock screen
3548 // can re-appear and inflict its own orientation on us. Keep the
3549 // orientation stable until this all settles down.
3550 return false;
3551 }
3552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 long ident = Binder.clearCallingIdentity();
3555 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003556 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 mForcedAppOrientation = req;
3560 //send a message to Policy indicating orientation change to take
3561 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003562 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003563 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3564 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3565 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 }
3567 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003568
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003569 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 } finally {
3571 Binder.restoreCallingIdentity(ident);
3572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003573 }
Romain Guy06882f82009-06-10 13:36:04 -07003574
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003575 int computeForcedAppOrientationLocked() {
3576 int req = getOrientationFromWindowsLocked();
3577 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3578 req = getOrientationFromAppTokensLocked();
3579 }
3580 return req;
3581 }
Romain Guy06882f82009-06-10 13:36:04 -07003582
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003583 public void setNewConfiguration(Configuration config) {
3584 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3585 "setNewConfiguration()")) {
3586 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3587 }
3588
3589 synchronized(mWindowMap) {
3590 mCurConfiguration = new Configuration(config);
3591 mWaitingForConfig = false;
3592 performLayoutAndPlaceSurfacesLocked();
3593 }
3594 }
3595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3598 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 }
Romain Guy06882f82009-06-10 13:36:04 -07003601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 synchronized(mWindowMap) {
3603 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3604 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003605 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 return;
3607 }
Romain Guy06882f82009-06-10 13:36:04 -07003608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 wtoken.requestedOrientation = requestedOrientation;
3610 }
3611 }
Romain Guy06882f82009-06-10 13:36:04 -07003612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 public int getAppOrientation(IApplicationToken token) {
3614 synchronized(mWindowMap) {
3615 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3616 if (wtoken == null) {
3617 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3618 }
Romain Guy06882f82009-06-10 13:36:04 -07003619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 return wtoken.requestedOrientation;
3621 }
3622 }
Romain Guy06882f82009-06-10 13:36:04 -07003623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3625 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3626 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003627 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 }
3629
3630 synchronized(mWindowMap) {
3631 boolean changed = false;
3632 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003633 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 changed = mFocusedApp != null;
3635 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003636 if (changed) {
3637 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 } else {
3640 AppWindowToken newFocus = findAppWindowToken(token);
3641 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003642 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003643 return;
3644 }
3645 changed = mFocusedApp != newFocus;
3646 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003647 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003648 if (changed) {
3649 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 }
3652
3653 if (moveFocusNow && changed) {
3654 final long origId = Binder.clearCallingIdentity();
3655 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3656 Binder.restoreCallingIdentity(origId);
3657 }
3658 }
3659 }
3660
3661 public void prepareAppTransition(int transit) {
3662 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3663 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003664 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 }
Romain Guy06882f82009-06-10 13:36:04 -07003666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003668 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 TAG, "Prepare app transition: transit=" + transit
3670 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003671 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003672 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3673 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003675 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3676 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3677 // Opening a new task always supersedes a close for the anim.
3678 mNextAppTransition = transit;
3679 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3680 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3681 // Opening a new activity always supersedes a close for the anim.
3682 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 }
3684 mAppTransitionReady = false;
3685 mAppTransitionTimeout = false;
3686 mStartingIconInTransition = false;
3687 mSkipAppTransitionAnimation = false;
3688 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3689 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3690 5000);
3691 }
3692 }
3693 }
3694
3695 public int getPendingAppTransition() {
3696 return mNextAppTransition;
3697 }
Romain Guy06882f82009-06-10 13:36:04 -07003698
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003699 public void overridePendingAppTransition(String packageName,
3700 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003701 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003702 mNextAppTransitionPackage = packageName;
3703 mNextAppTransitionEnter = enterAnim;
3704 mNextAppTransitionExit = exitAnim;
3705 }
3706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 public void executeAppTransition() {
3709 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3710 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003711 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 }
Romain Guy06882f82009-06-10 13:36:04 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003715 if (DEBUG_APP_TRANSITIONS) {
3716 RuntimeException e = new RuntimeException("here");
3717 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003718 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003719 + mNextAppTransition, e);
3720 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003721 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 mAppTransitionReady = true;
3723 final long origId = Binder.clearCallingIdentity();
3724 performLayoutAndPlaceSurfacesLocked();
3725 Binder.restoreCallingIdentity(origId);
3726 }
3727 }
3728 }
3729
3730 public void setAppStartingWindow(IBinder token, String pkg,
3731 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3732 IBinder transferFrom, boolean createIfNeeded) {
3733 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3734 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003735 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 }
3737
3738 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003739 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3741 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 AppWindowToken wtoken = findAppWindowToken(token);
3744 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003745 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 return;
3747 }
3748
3749 // If the display is frozen, we won't do anything until the
3750 // actual window is displayed so there is no reason to put in
3751 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003752 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 return;
3754 }
Romain Guy06882f82009-06-10 13:36:04 -07003755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 if (wtoken.startingData != null) {
3757 return;
3758 }
Romain Guy06882f82009-06-10 13:36:04 -07003759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 if (transferFrom != null) {
3761 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3762 if (ttoken != null) {
3763 WindowState startingWindow = ttoken.startingWindow;
3764 if (startingWindow != null) {
3765 if (mStartingIconInTransition) {
3766 // In this case, the starting icon has already
3767 // been displayed, so start letting windows get
3768 // shown immediately without any more transitions.
3769 mSkipAppTransitionAnimation = true;
3770 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003771 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 "Moving existing starting from " + ttoken
3773 + " to " + wtoken);
3774 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 // Transfer the starting window over to the new
3777 // token.
3778 wtoken.startingData = ttoken.startingData;
3779 wtoken.startingView = ttoken.startingView;
3780 wtoken.startingWindow = startingWindow;
3781 ttoken.startingData = null;
3782 ttoken.startingView = null;
3783 ttoken.startingWindow = null;
3784 ttoken.startingMoved = true;
3785 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003786 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003788 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003789 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003791 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 ttoken.windows.remove(startingWindow);
3793 ttoken.allAppWindows.remove(startingWindow);
3794 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 // Propagate other interesting state between the
3797 // tokens. If the old token is displayed, we should
3798 // immediately force the new one to be displayed. If
3799 // it is animating, we need to move that animation to
3800 // the new one.
3801 if (ttoken.allDrawn) {
3802 wtoken.allDrawn = true;
3803 }
3804 if (ttoken.firstWindowDrawn) {
3805 wtoken.firstWindowDrawn = true;
3806 }
3807 if (!ttoken.hidden) {
3808 wtoken.hidden = false;
3809 wtoken.hiddenRequested = false;
3810 wtoken.willBeHidden = false;
3811 }
3812 if (wtoken.clientHidden != ttoken.clientHidden) {
3813 wtoken.clientHidden = ttoken.clientHidden;
3814 wtoken.sendAppVisibilityToClients();
3815 }
3816 if (ttoken.animation != null) {
3817 wtoken.animation = ttoken.animation;
3818 wtoken.animating = ttoken.animating;
3819 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3820 ttoken.animation = null;
3821 ttoken.animLayerAdjustment = 0;
3822 wtoken.updateLayers();
3823 ttoken.updateLayers();
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 mLayoutNeeded = true;
3828 performLayoutAndPlaceSurfacesLocked();
3829 Binder.restoreCallingIdentity(origId);
3830 return;
3831 } else if (ttoken.startingData != null) {
3832 // The previous app was getting ready to show a
3833 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003834 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 "Moving pending starting from " + ttoken
3836 + " to " + wtoken);
3837 wtoken.startingData = ttoken.startingData;
3838 ttoken.startingData = null;
3839 ttoken.startingMoved = true;
3840 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3841 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3842 // want to process the message ASAP, before any other queued
3843 // messages.
3844 mH.sendMessageAtFrontOfQueue(m);
3845 return;
3846 }
3847 }
3848 }
3849
3850 // There is no existing starting window, and the caller doesn't
3851 // want us to create one, so that's it!
3852 if (!createIfNeeded) {
3853 return;
3854 }
Romain Guy06882f82009-06-10 13:36:04 -07003855
Dianne Hackborn284ac932009-08-28 10:34:25 -07003856 // If this is a translucent or wallpaper window, then don't
3857 // show a starting window -- the current effect (a full-screen
3858 // opaque starting window that fades away to the real contents
3859 // when it is ready) does not work for this.
3860 if (theme != 0) {
3861 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3862 com.android.internal.R.styleable.Window);
3863 if (ent.array.getBoolean(
3864 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3865 return;
3866 }
3867 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003868 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3869 return;
3870 }
3871 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003872 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3873 return;
3874 }
3875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003877 mStartingIconInTransition = true;
3878 wtoken.startingData = new StartingData(
3879 pkg, theme, nonLocalizedLabel,
3880 labelRes, icon);
3881 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3882 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3883 // want to process the message ASAP, before any other queued
3884 // messages.
3885 mH.sendMessageAtFrontOfQueue(m);
3886 }
3887 }
3888
3889 public void setAppWillBeHidden(IBinder token) {
3890 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3891 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003892 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 }
3894
3895 AppWindowToken wtoken;
3896
3897 synchronized(mWindowMap) {
3898 wtoken = findAppWindowToken(token);
3899 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003900 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 -08003901 return;
3902 }
3903 wtoken.willBeHidden = true;
3904 }
3905 }
Romain Guy06882f82009-06-10 13:36:04 -07003906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3908 boolean visible, int transit, boolean performLayout) {
3909 boolean delayed = false;
3910
3911 if (wtoken.clientHidden == visible) {
3912 wtoken.clientHidden = !visible;
3913 wtoken.sendAppVisibilityToClients();
3914 }
Romain Guy06882f82009-06-10 13:36:04 -07003915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 wtoken.willBeHidden = false;
3917 if (wtoken.hidden == visible) {
3918 final int N = wtoken.allAppWindows.size();
3919 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003920 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3922 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003924 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003925
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003926 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 if (wtoken.animation == sDummyAnimation) {
3928 wtoken.animation = null;
3929 }
3930 applyAnimationLocked(wtoken, lp, transit, visible);
3931 changed = true;
3932 if (wtoken.animation != null) {
3933 delayed = runningAppAnimation = true;
3934 }
3935 }
Romain Guy06882f82009-06-10 13:36:04 -07003936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003937 for (int i=0; i<N; i++) {
3938 WindowState win = wtoken.allAppWindows.get(i);
3939 if (win == wtoken.startingWindow) {
3940 continue;
3941 }
3942
3943 if (win.isAnimating()) {
3944 delayed = true;
3945 }
Romain Guy06882f82009-06-10 13:36:04 -07003946
Joe Onorato8a9b2202010-02-26 18:56:32 -08003947 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 //win.dump(" ");
3949 if (visible) {
3950 if (!win.isVisibleNow()) {
3951 if (!runningAppAnimation) {
3952 applyAnimationLocked(win,
3953 WindowManagerPolicy.TRANSIT_ENTER, true);
3954 }
3955 changed = true;
3956 }
3957 } else if (win.isVisibleNow()) {
3958 if (!runningAppAnimation) {
3959 applyAnimationLocked(win,
3960 WindowManagerPolicy.TRANSIT_EXIT, false);
3961 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 changed = true;
3963 }
3964 }
3965
3966 wtoken.hidden = wtoken.hiddenRequested = !visible;
3967 if (!visible) {
3968 unsetAppFreezingScreenLocked(wtoken, true, true);
3969 } else {
3970 // If we are being set visible, and the starting window is
3971 // not yet displayed, then make sure it doesn't get displayed.
3972 WindowState swin = wtoken.startingWindow;
3973 if (swin != null && (swin.mDrawPending
3974 || swin.mCommitDrawPending)) {
3975 swin.mPolicyVisibility = false;
3976 swin.mPolicyVisibilityAfterAnim = false;
3977 }
3978 }
Romain Guy06882f82009-06-10 13:36:04 -07003979
Joe Onorato8a9b2202010-02-26 18:56:32 -08003980 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3982 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003983
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003984 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003986 if (performLayout) {
3987 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3988 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003989 } else {
3990 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 }
3993 }
3994
3995 if (wtoken.animation != null) {
3996 delayed = true;
3997 }
Romain Guy06882f82009-06-10 13:36:04 -07003998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 return delayed;
4000 }
4001
4002 public void setAppVisibility(IBinder token, boolean visible) {
4003 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4004 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004005 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 }
4007
4008 AppWindowToken wtoken;
4009
4010 synchronized(mWindowMap) {
4011 wtoken = findAppWindowToken(token);
4012 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 return;
4015 }
4016
4017 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004018 RuntimeException e = null;
4019 if (!HIDE_STACK_CRAWLS) {
4020 e = new RuntimeException();
4021 e.fillInStackTrace();
4022 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004023 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 + "): mNextAppTransition=" + mNextAppTransition
4025 + " hidden=" + wtoken.hidden
4026 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4027 }
Romain Guy06882f82009-06-10 13:36:04 -07004028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 // If we are preparing an app transition, then delay changing
4030 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004031 if (!mDisplayFrozen && mPolicy.isScreenOn()
4032 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 // Already in requested state, don't do anything more.
4034 if (wtoken.hiddenRequested != visible) {
4035 return;
4036 }
4037 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004038
Joe Onorato8a9b2202010-02-26 18:56:32 -08004039 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 TAG, "Setting dummy animation on: " + wtoken);
4041 wtoken.setDummyAnimation();
4042 mOpeningApps.remove(wtoken);
4043 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004044 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 wtoken.inPendingTransaction = true;
4046 if (visible) {
4047 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 wtoken.startingDisplayed = false;
4049 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004050
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004051 // If the token is currently hidden (should be the
4052 // common case), then we need to set up to wait for
4053 // its windows to be ready.
4054 if (wtoken.hidden) {
4055 wtoken.allDrawn = false;
4056 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004057
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004058 if (wtoken.clientHidden) {
4059 // In the case where we are making an app visible
4060 // but holding off for a transition, we still need
4061 // to tell the client to make its windows visible so
4062 // they get drawn. Otherwise, we will wait on
4063 // performing the transition until all windows have
4064 // been drawn, they never will be, and we are sad.
4065 wtoken.clientHidden = false;
4066 wtoken.sendAppVisibilityToClients();
4067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 }
4069 } else {
4070 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004071
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004072 // If the token is currently visible (should be the
4073 // common case), then set up to wait for it to be hidden.
4074 if (!wtoken.hidden) {
4075 wtoken.waitingToHide = true;
4076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 }
4078 return;
4079 }
Romain Guy06882f82009-06-10 13:36:04 -07004080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004082 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 wtoken.updateReportedVisibilityLocked();
4084 Binder.restoreCallingIdentity(origId);
4085 }
4086 }
4087
4088 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4089 boolean unfreezeSurfaceNow, boolean force) {
4090 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004091 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 + " force=" + force);
4093 final int N = wtoken.allAppWindows.size();
4094 boolean unfrozeWindows = false;
4095 for (int i=0; i<N; i++) {
4096 WindowState w = wtoken.allAppWindows.get(i);
4097 if (w.mAppFreezing) {
4098 w.mAppFreezing = false;
4099 if (w.mSurface != null && !w.mOrientationChanging) {
4100 w.mOrientationChanging = true;
4101 }
4102 unfrozeWindows = true;
4103 }
4104 }
4105 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004106 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004107 wtoken.freezingScreen = false;
4108 mAppsFreezingScreen--;
4109 }
4110 if (unfreezeSurfaceNow) {
4111 if (unfrozeWindows) {
4112 mLayoutNeeded = true;
4113 performLayoutAndPlaceSurfacesLocked();
4114 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004115 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117 }
4118 }
Romain Guy06882f82009-06-10 13:36:04 -07004119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004120 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4121 int configChanges) {
4122 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004123 RuntimeException e = null;
4124 if (!HIDE_STACK_CRAWLS) {
4125 e = new RuntimeException();
4126 e.fillInStackTrace();
4127 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004128 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 + ": hidden=" + wtoken.hidden + " freezing="
4130 + wtoken.freezingScreen, e);
4131 }
4132 if (!wtoken.hiddenRequested) {
4133 if (!wtoken.freezingScreen) {
4134 wtoken.freezingScreen = true;
4135 mAppsFreezingScreen++;
4136 if (mAppsFreezingScreen == 1) {
4137 startFreezingDisplayLocked();
4138 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4139 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4140 5000);
4141 }
4142 }
4143 final int N = wtoken.allAppWindows.size();
4144 for (int i=0; i<N; i++) {
4145 WindowState w = wtoken.allAppWindows.get(i);
4146 w.mAppFreezing = true;
4147 }
4148 }
4149 }
Romain Guy06882f82009-06-10 13:36:04 -07004150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 public void startAppFreezingScreen(IBinder token, int configChanges) {
4152 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4153 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004154 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004155 }
4156
4157 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004158 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004159 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 return;
4161 }
Romain Guy06882f82009-06-10 13:36:04 -07004162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 AppWindowToken wtoken = findAppWindowToken(token);
4164 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004165 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 return;
4167 }
4168 final long origId = Binder.clearCallingIdentity();
4169 startAppFreezingScreenLocked(wtoken, configChanges);
4170 Binder.restoreCallingIdentity(origId);
4171 }
4172 }
Romain Guy06882f82009-06-10 13:36:04 -07004173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 public void stopAppFreezingScreen(IBinder token, boolean force) {
4175 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4176 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004177 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004178 }
4179
4180 synchronized(mWindowMap) {
4181 AppWindowToken wtoken = findAppWindowToken(token);
4182 if (wtoken == null || wtoken.appToken == null) {
4183 return;
4184 }
4185 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004186 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4188 unsetAppFreezingScreenLocked(wtoken, true, force);
4189 Binder.restoreCallingIdentity(origId);
4190 }
4191 }
Romain Guy06882f82009-06-10 13:36:04 -07004192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 public void removeAppToken(IBinder token) {
4194 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4195 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004196 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 }
4198
4199 AppWindowToken wtoken = null;
4200 AppWindowToken startingToken = null;
4201 boolean delayed = false;
4202
4203 final long origId = Binder.clearCallingIdentity();
4204 synchronized(mWindowMap) {
4205 WindowToken basewtoken = mTokenMap.remove(token);
4206 mTokenList.remove(basewtoken);
4207 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004208 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004209 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 wtoken.inPendingTransaction = false;
4211 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004212 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 if (mClosingApps.contains(wtoken)) {
4214 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004215 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004217 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 delayed = true;
4219 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004220 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 TAG, "Removing app " + wtoken + " delayed=" + delayed
4222 + " animation=" + wtoken.animation
4223 + " animating=" + wtoken.animating);
4224 if (delayed) {
4225 // set the token aside because it has an active animation to be finished
4226 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004227 } else {
4228 // Make sure there is no animation running on this token,
4229 // so any windows associated with it will be removed as
4230 // soon as their animations are complete
4231 wtoken.animation = null;
4232 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004233 }
4234 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004235 if (mLastEnterAnimToken == wtoken) {
4236 mLastEnterAnimToken = null;
4237 mLastEnterAnimParams = null;
4238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 wtoken.removed = true;
4240 if (wtoken.startingData != null) {
4241 startingToken = wtoken;
4242 }
4243 unsetAppFreezingScreenLocked(wtoken, true, true);
4244 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004245 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 mFocusedApp = null;
4247 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004248 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 }
4250 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004251 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 if (!delayed && wtoken != null) {
4255 wtoken.updateReportedVisibilityLocked();
4256 }
4257 }
4258 Binder.restoreCallingIdentity(origId);
4259
4260 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004261 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 + startingToken + ": app token removed");
4263 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4264 mH.sendMessage(m);
4265 }
4266 }
4267
4268 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4269 final int NW = token.windows.size();
4270 for (int i=0; i<NW; i++) {
4271 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004272 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004274 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 int j = win.mChildWindows.size();
4276 while (j > 0) {
4277 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004278 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004279 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004280 "Tmp removing child window " + cwin);
4281 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 }
4283 }
4284 return NW > 0;
4285 }
4286
4287 void dumpAppTokensLocked() {
4288 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004289 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 }
4291 }
Romain Guy06882f82009-06-10 13:36:04 -07004292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 void dumpWindowsLocked() {
4294 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004295 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 }
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 private int findWindowOffsetLocked(int tokenPos) {
4300 final int NW = mWindows.size();
4301
4302 if (tokenPos >= mAppTokens.size()) {
4303 int i = NW;
4304 while (i > 0) {
4305 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004306 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 if (win.getAppToken() != null) {
4308 return i+1;
4309 }
4310 }
4311 }
4312
4313 while (tokenPos > 0) {
4314 // Find the first app token below the new position that has
4315 // a window displayed.
4316 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004317 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004319 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004320 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004321 "Skipping token -- currently sending to bottom");
4322 tokenPos--;
4323 continue;
4324 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 int i = wtoken.windows.size();
4326 while (i > 0) {
4327 i--;
4328 WindowState win = wtoken.windows.get(i);
4329 int j = win.mChildWindows.size();
4330 while (j > 0) {
4331 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004332 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004333 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 for (int pos=NW-1; pos>=0; pos--) {
4335 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004336 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 "Found child win @" + (pos+1));
4338 return pos+1;
4339 }
4340 }
4341 }
4342 }
4343 for (int pos=NW-1; pos>=0; pos--) {
4344 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004345 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 return pos+1;
4347 }
4348 }
4349 }
4350 tokenPos--;
4351 }
4352
4353 return 0;
4354 }
4355
4356 private final int reAddWindowLocked(int index, WindowState win) {
4357 final int NCW = win.mChildWindows.size();
4358 boolean added = false;
4359 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004360 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004363 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 mWindows.add(index, win);
4365 index++;
4366 added = true;
4367 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004368 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004369 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 mWindows.add(index, cwin);
4371 index++;
4372 }
4373 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004374 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004375 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 mWindows.add(index, win);
4377 index++;
4378 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004379 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 return index;
4381 }
Romain Guy06882f82009-06-10 13:36:04 -07004382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4384 final int NW = token.windows.size();
4385 for (int i=0; i<NW; i++) {
4386 index = reAddWindowLocked(index, token.windows.get(i));
4387 }
4388 return index;
4389 }
4390
4391 public void moveAppToken(int index, IBinder token) {
4392 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4393 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004394 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 }
4396
4397 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004398 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004399 if (DEBUG_REORDER) dumpAppTokensLocked();
4400 final AppWindowToken wtoken = findAppWindowToken(token);
4401 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004402 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 + token + " (" + wtoken + ")");
4404 return;
4405 }
4406 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004407 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004411 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004412 if (DEBUG_REORDER) dumpWindowsLocked();
4413 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004414 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 if (DEBUG_REORDER) dumpWindowsLocked();
4416 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004417 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 if (DEBUG_REORDER) dumpWindowsLocked();
4419 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 mLayoutNeeded = true;
4421 performLayoutAndPlaceSurfacesLocked();
4422 }
4423 Binder.restoreCallingIdentity(origId);
4424 }
4425 }
4426
4427 private void removeAppTokensLocked(List<IBinder> tokens) {
4428 // XXX This should be done more efficiently!
4429 // (take advantage of the fact that both lists should be
4430 // ordered in the same way.)
4431 int N = tokens.size();
4432 for (int i=0; i<N; i++) {
4433 IBinder token = tokens.get(i);
4434 final AppWindowToken wtoken = findAppWindowToken(token);
4435 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004436 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 + token + " (" + wtoken + ")");
4438 i--;
4439 N--;
4440 }
4441 }
4442 }
4443
Dianne Hackborna8f60182009-09-01 19:01:50 -07004444 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4445 boolean updateFocusAndLayout) {
4446 // First remove all of the windows from the list.
4447 tmpRemoveAppWindowsLocked(wtoken);
4448
4449 // Where to start adding?
4450 int pos = findWindowOffsetLocked(tokenPos);
4451
4452 // And now add them back at the correct place.
4453 pos = reAddAppWindowsLocked(pos, wtoken);
4454
4455 if (updateFocusAndLayout) {
4456 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4457 assignLayersLocked();
4458 }
4459 mLayoutNeeded = true;
4460 performLayoutAndPlaceSurfacesLocked();
4461 }
4462 }
4463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4465 // First remove all of the windows from the list.
4466 final int N = tokens.size();
4467 int i;
4468 for (i=0; i<N; i++) {
4469 WindowToken token = mTokenMap.get(tokens.get(i));
4470 if (token != null) {
4471 tmpRemoveAppWindowsLocked(token);
4472 }
4473 }
4474
4475 // Where to start adding?
4476 int pos = findWindowOffsetLocked(tokenPos);
4477
4478 // And now add them back at the correct place.
4479 for (i=0; i<N; i++) {
4480 WindowToken token = mTokenMap.get(tokens.get(i));
4481 if (token != null) {
4482 pos = reAddAppWindowsLocked(pos, token);
4483 }
4484 }
4485
Dianne Hackborna8f60182009-09-01 19:01:50 -07004486 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4487 assignLayersLocked();
4488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 mLayoutNeeded = true;
4490 performLayoutAndPlaceSurfacesLocked();
4491
4492 //dump();
4493 }
4494
4495 public void moveAppTokensToTop(List<IBinder> tokens) {
4496 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4497 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004498 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 }
4500
4501 final long origId = Binder.clearCallingIdentity();
4502 synchronized(mWindowMap) {
4503 removeAppTokensLocked(tokens);
4504 final int N = tokens.size();
4505 for (int i=0; i<N; i++) {
4506 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4507 if (wt != null) {
4508 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004509 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004510 mToTopApps.remove(wt);
4511 mToBottomApps.remove(wt);
4512 mToTopApps.add(wt);
4513 wt.sendingToBottom = false;
4514 wt.sendingToTop = true;
4515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 }
4517 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004518
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004519 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004520 moveAppWindowsLocked(tokens, mAppTokens.size());
4521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 }
4523 Binder.restoreCallingIdentity(origId);
4524 }
4525
4526 public void moveAppTokensToBottom(List<IBinder> tokens) {
4527 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4528 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004529 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 }
4531
4532 final long origId = Binder.clearCallingIdentity();
4533 synchronized(mWindowMap) {
4534 removeAppTokensLocked(tokens);
4535 final int N = tokens.size();
4536 int pos = 0;
4537 for (int i=0; i<N; i++) {
4538 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4539 if (wt != null) {
4540 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004541 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004542 mToTopApps.remove(wt);
4543 mToBottomApps.remove(wt);
4544 mToBottomApps.add(i, wt);
4545 wt.sendingToTop = false;
4546 wt.sendingToBottom = true;
4547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 pos++;
4549 }
4550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004551
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004552 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004553 moveAppWindowsLocked(tokens, 0);
4554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 }
4556 Binder.restoreCallingIdentity(origId);
4557 }
4558
4559 // -------------------------------------------------------------
4560 // Misc IWindowSession methods
4561 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004562
Jim Miller284b62e2010-06-08 14:27:42 -07004563 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004564 {
Jim Miller284b62e2010-06-08 14:27:42 -07004565 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4566 // called before DevicePolicyManagerService has started.
4567 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4568 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4569 Context.DEVICE_POLICY_SERVICE);
4570 if (dpm != null) {
4571 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4572 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4573 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4574 }
Jim Millerd6b57052010-06-07 17:52:42 -07004575 }
Jim Miller284b62e2010-06-08 14:27:42 -07004576 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004577 }
4578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004580 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 != PackageManager.PERMISSION_GRANTED) {
4582 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4583 }
Jim Millerd6b57052010-06-07 17:52:42 -07004584
Jim Miller284b62e2010-06-08 14:27:42 -07004585 synchronized (mKeyguardTokenWatcher) {
4586 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 }
4589
4590 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004591 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 != PackageManager.PERMISSION_GRANTED) {
4593 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595
Jim Miller284b62e2010-06-08 14:27:42 -07004596 synchronized (mKeyguardTokenWatcher) {
4597 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004598
Jim Miller284b62e2010-06-08 14:27:42 -07004599 if (!mKeyguardTokenWatcher.isAcquired()) {
4600 // If we are the last one to reenable the keyguard wait until
4601 // we have actually finished reenabling until returning.
4602 // It is possible that reenableKeyguard() can be called before
4603 // the previous disableKeyguard() is handled, in which case
4604 // neither mKeyguardTokenWatcher.acquired() or released() would
4605 // be called. In that case mKeyguardDisabled will be false here
4606 // and we have nothing to wait for.
4607 while (mKeyguardDisabled) {
4608 try {
4609 mKeyguardTokenWatcher.wait();
4610 } catch (InterruptedException e) {
4611 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 }
4613 }
4614 }
4615 }
4616 }
4617
4618 /**
4619 * @see android.app.KeyguardManager#exitKeyguardSecurely
4620 */
4621 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004622 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 != PackageManager.PERMISSION_GRANTED) {
4624 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4625 }
4626 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4627 public void onKeyguardExitResult(boolean success) {
4628 try {
4629 callback.onKeyguardExitResult(success);
4630 } catch (RemoteException e) {
4631 // Client has died, we don't care.
4632 }
4633 }
4634 });
4635 }
4636
4637 public boolean inKeyguardRestrictedInputMode() {
4638 return mPolicy.inKeyguardRestrictedKeyInputMode();
4639 }
Romain Guy06882f82009-06-10 13:36:04 -07004640
Dianne Hackbornffa42482009-09-23 22:20:11 -07004641 public void closeSystemDialogs(String reason) {
4642 synchronized(mWindowMap) {
4643 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004644 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004645 if (w.mSurface != null) {
4646 try {
4647 w.mClient.closeSystemDialogs(reason);
4648 } catch (RemoteException e) {
4649 }
4650 }
4651 }
4652 }
4653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 static float fixScale(float scale) {
4656 if (scale < 0) scale = 0;
4657 else if (scale > 20) scale = 20;
4658 return Math.abs(scale);
4659 }
Romain Guy06882f82009-06-10 13:36:04 -07004660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 public void setAnimationScale(int which, float scale) {
4662 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4663 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004664 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 }
4666
4667 if (scale < 0) scale = 0;
4668 else if (scale > 20) scale = 20;
4669 scale = Math.abs(scale);
4670 switch (which) {
4671 case 0: mWindowAnimationScale = fixScale(scale); break;
4672 case 1: mTransitionAnimationScale = fixScale(scale); break;
4673 }
Romain Guy06882f82009-06-10 13:36:04 -07004674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004675 // Persist setting
4676 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4677 }
Romain Guy06882f82009-06-10 13:36:04 -07004678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 public void setAnimationScales(float[] scales) {
4680 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4681 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004682 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
4684
4685 if (scales != null) {
4686 if (scales.length >= 1) {
4687 mWindowAnimationScale = fixScale(scales[0]);
4688 }
4689 if (scales.length >= 2) {
4690 mTransitionAnimationScale = fixScale(scales[1]);
4691 }
4692 }
Romain Guy06882f82009-06-10 13:36:04 -07004693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 // Persist setting
4695 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4696 }
Romain Guy06882f82009-06-10 13:36:04 -07004697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004698 public float getAnimationScale(int which) {
4699 switch (which) {
4700 case 0: return mWindowAnimationScale;
4701 case 1: return mTransitionAnimationScale;
4702 }
4703 return 0;
4704 }
Romain Guy06882f82009-06-10 13:36:04 -07004705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 public float[] getAnimationScales() {
4707 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4708 }
Romain Guy06882f82009-06-10 13:36:04 -07004709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 public int getSwitchState(int sw) {
4711 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4712 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004713 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004715 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 }
Romain Guy06882f82009-06-10 13:36:04 -07004717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 public int getSwitchStateForDevice(int devid, int sw) {
4719 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4720 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004721 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004723 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 }
Romain Guy06882f82009-06-10 13:36:04 -07004725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004726 public int getScancodeState(int sw) {
4727 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4728 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004729 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004730 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004731 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 }
Romain Guy06882f82009-06-10 13:36:04 -07004733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004734 public int getScancodeStateForDevice(int devid, int sw) {
4735 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4736 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004737 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004739 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004740 }
Romain Guy06882f82009-06-10 13:36:04 -07004741
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004742 public int getTrackballScancodeState(int sw) {
4743 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4744 "getTrackballScancodeState()")) {
4745 throw new SecurityException("Requires READ_INPUT_STATE permission");
4746 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004747 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004748 }
4749
4750 public int getDPadScancodeState(int sw) {
4751 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4752 "getDPadScancodeState()")) {
4753 throw new SecurityException("Requires READ_INPUT_STATE permission");
4754 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004755 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004756 }
4757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004758 public int getKeycodeState(int sw) {
4759 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4760 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004761 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004762 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004763 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 public int getKeycodeStateForDevice(int devid, int sw) {
4767 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4768 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004769 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004771 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004772 }
Romain Guy06882f82009-06-10 13:36:04 -07004773
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004774 public int getTrackballKeycodeState(int sw) {
4775 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4776 "getTrackballKeycodeState()")) {
4777 throw new SecurityException("Requires READ_INPUT_STATE permission");
4778 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004779 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004780 }
4781
4782 public int getDPadKeycodeState(int sw) {
4783 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4784 "getDPadKeycodeState()")) {
4785 throw new SecurityException("Requires READ_INPUT_STATE permission");
4786 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004787 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004788 }
Jeff Browna41ca772010-08-11 14:46:32 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004791 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 }
Romain Guy06882f82009-06-10 13:36:04 -07004793
Jeff Browna41ca772010-08-11 14:46:32 -07004794 public InputChannel monitorInput(String inputChannelName) {
4795 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4796 "monitorInput()")) {
4797 throw new SecurityException("Requires READ_INPUT_STATE permission");
4798 }
4799 return mInputManager.monitorInput(inputChannelName);
4800 }
4801
Jeff Brown8d608662010-08-30 03:02:23 -07004802 public InputDevice getInputDevice(int deviceId) {
4803 return mInputManager.getInputDevice(deviceId);
4804 }
4805
4806 public int[] getInputDeviceIds() {
4807 return mInputManager.getInputDeviceIds();
4808 }
4809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 public void enableScreenAfterBoot() {
4811 synchronized(mWindowMap) {
4812 if (mSystemBooted) {
4813 return;
4814 }
4815 mSystemBooted = true;
4816 }
Romain Guy06882f82009-06-10 13:36:04 -07004817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 performEnableScreen();
4819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 public void enableScreenIfNeededLocked() {
4822 if (mDisplayEnabled) {
4823 return;
4824 }
4825 if (!mSystemBooted) {
4826 return;
4827 }
4828 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4829 }
Romain Guy06882f82009-06-10 13:36:04 -07004830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 public void performEnableScreen() {
4832 synchronized(mWindowMap) {
4833 if (mDisplayEnabled) {
4834 return;
4835 }
4836 if (!mSystemBooted) {
4837 return;
4838 }
Romain Guy06882f82009-06-10 13:36:04 -07004839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004840 // Don't enable the screen until all existing windows
4841 // have been drawn.
4842 final int N = mWindows.size();
4843 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004844 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004845 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 return;
4847 }
4848 }
Romain Guy06882f82009-06-10 13:36:04 -07004849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 mDisplayEnabled = true;
4851 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004852 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 StringWriter sw = new StringWriter();
4854 PrintWriter pw = new PrintWriter(sw);
4855 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004856 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 }
4858 try {
4859 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4860 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004861 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 Parcel data = Parcel.obtain();
4863 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4864 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4865 data, null, 0);
4866 data.recycle();
4867 }
4868 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004869 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 }
4871 }
Romain Guy06882f82009-06-10 13:36:04 -07004872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004876 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4877 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004878 }
Romain Guy06882f82009-06-10 13:36:04 -07004879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 public void setInTouchMode(boolean mode) {
4881 synchronized(mWindowMap) {
4882 mInTouchMode = mode;
4883 }
4884 }
4885
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004886 public void freezeRotation() {
4887 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4888 "setRotation()")) {
4889 throw new SecurityException("Requires SET_ORIENTATION permission");
4890 }
4891
4892 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4893 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4894 }
4895
4896 public void thawRotation() {
4897 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4898 "setRotation()")) {
4899 throw new SecurityException("Requires SET_ORIENTATION permission");
4900 }
4901
4902 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4903 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4904 }
4905
Romain Guy06882f82009-06-10 13:36:04 -07004906 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004907 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004909 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004910 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 }
4912
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004913 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914 }
Romain Guy06882f82009-06-10 13:36:04 -07004915
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004916 public void setRotationUnchecked(int rotation,
4917 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004918 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 long origId = Binder.clearCallingIdentity();
4922 boolean changed;
4923 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004924 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 }
Romain Guy06882f82009-06-10 13:36:04 -07004926
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004927 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 sendNewConfiguration();
4929 }
Romain Guy06882f82009-06-10 13:36:04 -07004930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 Binder.restoreCallingIdentity(origId);
4932 }
Romain Guy06882f82009-06-10 13:36:04 -07004933
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004934 /**
4935 * Apply a new rotation to the screen, respecting the requests of
4936 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4937 * re-evaluate the desired rotation.
4938 *
4939 * Returns null if the rotation has been changed. In this case YOU
4940 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4941 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004942 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004943 boolean changed;
4944 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4945 rotation = mRequestedRotation;
4946 } else {
4947 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004948 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004950 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004951 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004953 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004954 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004956 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004957 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004958 "Rotation changed to " + rotation
4959 + " from " + mRotation
4960 + " (forceApp=" + mForcedAppOrientation
4961 + ", req=" + mRequestedRotation + ")");
4962 mRotation = rotation;
4963 mWindowsFreezingScreen = true;
4964 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4965 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4966 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004967 mWaitingForConfig = true;
4968 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004969 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004970 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004971 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004972 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004973 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004974 }
4975 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004976 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004977 if (w.mSurface != null) {
4978 w.mOrientationChanging = true;
4979 }
4980 }
4981 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4982 try {
4983 mRotationWatchers.get(i).onRotationChanged(rotation);
4984 } catch (RemoteException e) {
4985 }
4986 }
4987 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004989 return changed;
4990 }
Romain Guy06882f82009-06-10 13:36:04 -07004991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004992 public int getRotation() {
4993 return mRotation;
4994 }
4995
4996 public int watchRotation(IRotationWatcher watcher) {
4997 final IBinder watcherBinder = watcher.asBinder();
4998 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4999 public void binderDied() {
5000 synchronized (mWindowMap) {
5001 for (int i=0; i<mRotationWatchers.size(); i++) {
5002 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005003 IRotationWatcher removed = mRotationWatchers.remove(i);
5004 if (removed != null) {
5005 removed.asBinder().unlinkToDeath(this, 0);
5006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005007 i--;
5008 }
5009 }
5010 }
5011 }
5012 };
Romain Guy06882f82009-06-10 13:36:04 -07005013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005014 synchronized (mWindowMap) {
5015 try {
5016 watcher.asBinder().linkToDeath(dr, 0);
5017 mRotationWatchers.add(watcher);
5018 } catch (RemoteException e) {
5019 // Client died, no cleanup needed.
5020 }
Romain Guy06882f82009-06-10 13:36:04 -07005021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005022 return mRotation;
5023 }
5024 }
5025
5026 /**
5027 * Starts the view server on the specified port.
5028 *
5029 * @param port The port to listener to.
5030 *
5031 * @return True if the server was successfully started, false otherwise.
5032 *
5033 * @see com.android.server.ViewServer
5034 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5035 */
5036 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005037 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005038 return false;
5039 }
5040
5041 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5042 return false;
5043 }
5044
5045 if (port < 1024) {
5046 return false;
5047 }
5048
5049 if (mViewServer != null) {
5050 if (!mViewServer.isRunning()) {
5051 try {
5052 return mViewServer.start();
5053 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005054 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 }
5056 }
5057 return false;
5058 }
5059
5060 try {
5061 mViewServer = new ViewServer(this, port);
5062 return mViewServer.start();
5063 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005064 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 }
5066 return false;
5067 }
5068
Romain Guy06882f82009-06-10 13:36:04 -07005069 private boolean isSystemSecure() {
5070 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5071 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5072 }
5073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005074 /**
5075 * Stops the view server if it exists.
5076 *
5077 * @return True if the server stopped, false if it wasn't started or
5078 * couldn't be stopped.
5079 *
5080 * @see com.android.server.ViewServer
5081 */
5082 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005083 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005084 return false;
5085 }
5086
5087 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5088 return false;
5089 }
5090
5091 if (mViewServer != null) {
5092 return mViewServer.stop();
5093 }
5094 return false;
5095 }
5096
5097 /**
5098 * Indicates whether the view server is running.
5099 *
5100 * @return True if the server is running, false otherwise.
5101 *
5102 * @see com.android.server.ViewServer
5103 */
5104 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005105 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 return false;
5107 }
5108
5109 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5110 return false;
5111 }
5112
5113 return mViewServer != null && mViewServer.isRunning();
5114 }
5115
5116 /**
5117 * Lists all availble windows in the system. The listing is written in the
5118 * specified Socket's output stream with the following syntax:
5119 * windowHashCodeInHexadecimal windowName
5120 * Each line of the ouput represents a different window.
5121 *
5122 * @param client The remote client to send the listing to.
5123 * @return False if an error occured, true otherwise.
5124 */
5125 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005126 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005127 return false;
5128 }
5129
5130 boolean result = true;
5131
Jeff Browne33348b2010-07-15 23:54:05 -07005132 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005133 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005135 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 }
5137
5138 BufferedWriter out = null;
5139
5140 // Any uncaught exception will crash the system process
5141 try {
5142 OutputStream clientStream = client.getOutputStream();
5143 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5144
5145 final int count = windows.length;
5146 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005147 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005148 out.write(Integer.toHexString(System.identityHashCode(w)));
5149 out.write(' ');
5150 out.append(w.mAttrs.getTitle());
5151 out.write('\n');
5152 }
5153
5154 out.write("DONE.\n");
5155 out.flush();
5156 } catch (Exception e) {
5157 result = false;
5158 } finally {
5159 if (out != null) {
5160 try {
5161 out.close();
5162 } catch (IOException e) {
5163 result = false;
5164 }
5165 }
5166 }
5167
5168 return result;
5169 }
5170
5171 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005172 * Returns the focused window in the following format:
5173 * windowHashCodeInHexadecimal windowName
5174 *
5175 * @param client The remote client to send the listing to.
5176 * @return False if an error occurred, true otherwise.
5177 */
5178 boolean viewServerGetFocusedWindow(Socket client) {
5179 if (isSystemSecure()) {
5180 return false;
5181 }
5182
5183 boolean result = true;
5184
5185 WindowState focusedWindow = getFocusedWindow();
5186
5187 BufferedWriter out = null;
5188
5189 // Any uncaught exception will crash the system process
5190 try {
5191 OutputStream clientStream = client.getOutputStream();
5192 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5193
5194 if(focusedWindow != null) {
5195 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5196 out.write(' ');
5197 out.append(focusedWindow.mAttrs.getTitle());
5198 }
5199 out.write('\n');
5200 out.flush();
5201 } catch (Exception e) {
5202 result = false;
5203 } finally {
5204 if (out != null) {
5205 try {
5206 out.close();
5207 } catch (IOException e) {
5208 result = false;
5209 }
5210 }
5211 }
5212
5213 return result;
5214 }
5215
5216 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005217 * Sends a command to a target window. The result of the command, if any, will be
5218 * written in the output stream of the specified socket.
5219 *
5220 * The parameters must follow this syntax:
5221 * windowHashcode extra
5222 *
5223 * Where XX is the length in characeters of the windowTitle.
5224 *
5225 * The first parameter is the target window. The window with the specified hashcode
5226 * will be the target. If no target can be found, nothing happens. The extra parameters
5227 * will be delivered to the target window and as parameters to the command itself.
5228 *
5229 * @param client The remote client to sent the result, if any, to.
5230 * @param command The command to execute.
5231 * @param parameters The command parameters.
5232 *
5233 * @return True if the command was successfully delivered, false otherwise. This does
5234 * not indicate whether the command itself was successful.
5235 */
5236 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005237 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 return false;
5239 }
5240
5241 boolean success = true;
5242 Parcel data = null;
5243 Parcel reply = null;
5244
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005245 BufferedWriter out = null;
5246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 // Any uncaught exception will crash the system process
5248 try {
5249 // Find the hashcode of the window
5250 int index = parameters.indexOf(' ');
5251 if (index == -1) {
5252 index = parameters.length();
5253 }
5254 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005255 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256
5257 // Extract the command's parameter after the window description
5258 if (index < parameters.length()) {
5259 parameters = parameters.substring(index + 1);
5260 } else {
5261 parameters = "";
5262 }
5263
5264 final WindowManagerService.WindowState window = findWindow(hashCode);
5265 if (window == null) {
5266 return false;
5267 }
5268
5269 data = Parcel.obtain();
5270 data.writeInterfaceToken("android.view.IWindow");
5271 data.writeString(command);
5272 data.writeString(parameters);
5273 data.writeInt(1);
5274 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5275
5276 reply = Parcel.obtain();
5277
5278 final IBinder binder = window.mClient.asBinder();
5279 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5280 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5281
5282 reply.readException();
5283
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005284 if (!client.isOutputShutdown()) {
5285 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5286 out.write("DONE\n");
5287 out.flush();
5288 }
5289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005290 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005291 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005292 success = false;
5293 } finally {
5294 if (data != null) {
5295 data.recycle();
5296 }
5297 if (reply != null) {
5298 reply.recycle();
5299 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005300 if (out != null) {
5301 try {
5302 out.close();
5303 } catch (IOException e) {
5304
5305 }
5306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005307 }
5308
5309 return success;
5310 }
5311
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005312 public void addWindowChangeListener(WindowChangeListener listener) {
5313 synchronized(mWindowMap) {
5314 mWindowChangeListeners.add(listener);
5315 }
5316 }
5317
5318 public void removeWindowChangeListener(WindowChangeListener listener) {
5319 synchronized(mWindowMap) {
5320 mWindowChangeListeners.remove(listener);
5321 }
5322 }
5323
5324 private void notifyWindowsChanged() {
5325 WindowChangeListener[] windowChangeListeners;
5326 synchronized(mWindowMap) {
5327 if(mWindowChangeListeners.isEmpty()) {
5328 return;
5329 }
5330 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5331 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5332 }
5333 int N = windowChangeListeners.length;
5334 for(int i = 0; i < N; i++) {
5335 windowChangeListeners[i].windowsChanged();
5336 }
5337 }
5338
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005339 private void notifyFocusChanged() {
5340 WindowChangeListener[] windowChangeListeners;
5341 synchronized(mWindowMap) {
5342 if(mWindowChangeListeners.isEmpty()) {
5343 return;
5344 }
5345 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5346 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5347 }
5348 int N = windowChangeListeners.length;
5349 for(int i = 0; i < N; i++) {
5350 windowChangeListeners[i].focusChanged();
5351 }
5352 }
5353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 private WindowState findWindow(int hashCode) {
5355 if (hashCode == -1) {
5356 return getFocusedWindow();
5357 }
5358
5359 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005360 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005361 final int count = windows.size();
5362
5363 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005364 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005365 if (System.identityHashCode(w) == hashCode) {
5366 return w;
5367 }
5368 }
5369 }
5370
5371 return null;
5372 }
5373
5374 /*
5375 * Instruct the Activity Manager to fetch the current configuration and broadcast
5376 * that to config-changed listeners if appropriate.
5377 */
5378 void sendNewConfiguration() {
5379 try {
5380 mActivityManager.updateConfiguration(null);
5381 } catch (RemoteException e) {
5382 }
5383 }
Romain Guy06882f82009-06-10 13:36:04 -07005384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 public Configuration computeNewConfiguration() {
5386 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005387 return computeNewConfigurationLocked();
5388 }
5389 }
Romain Guy06882f82009-06-10 13:36:04 -07005390
Dianne Hackbornc485a602009-03-24 22:39:49 -07005391 Configuration computeNewConfigurationLocked() {
5392 Configuration config = new Configuration();
5393 if (!computeNewConfigurationLocked(config)) {
5394 return null;
5395 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005396 return config;
5397 }
Romain Guy06882f82009-06-10 13:36:04 -07005398
Dianne Hackbornc485a602009-03-24 22:39:49 -07005399 boolean computeNewConfigurationLocked(Configuration config) {
5400 if (mDisplay == null) {
5401 return false;
5402 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005403
5404 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005405
5406 // Use the effective "visual" dimensions based on current rotation
5407 final boolean rotated = (mRotation == Surface.ROTATION_90
5408 || mRotation == Surface.ROTATION_270);
5409 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5410 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5411
Dianne Hackbornc485a602009-03-24 22:39:49 -07005412 int orientation = Configuration.ORIENTATION_SQUARE;
5413 if (dw < dh) {
5414 orientation = Configuration.ORIENTATION_PORTRAIT;
5415 } else if (dw > dh) {
5416 orientation = Configuration.ORIENTATION_LANDSCAPE;
5417 }
5418 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005419
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005420 DisplayMetrics dm = new DisplayMetrics();
5421 mDisplay.getMetrics(dm);
5422 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5423
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005424 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005425 // Note we only do this once because at this point we don't
5426 // expect the screen to change in this way at runtime, and want
5427 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005428 int longSize = dw;
5429 int shortSize = dh;
5430 if (longSize < shortSize) {
5431 int tmp = longSize;
5432 longSize = shortSize;
5433 shortSize = tmp;
5434 }
5435 longSize = (int)(longSize/dm.density);
5436 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005437
Dianne Hackborn723738c2009-06-25 19:48:04 -07005438 // These semi-magic numbers define our compatibility modes for
5439 // applications with different screens. Don't change unless you
5440 // make sure to test lots and lots of apps!
5441 if (longSize < 470) {
5442 // This is shorter than an HVGA normal density screen (which
5443 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005444 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5445 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005446 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005447 // What size is this screen screen?
5448 if (longSize >= 800 && shortSize >= 600) {
5449 // SVGA or larger screens at medium density are the point
5450 // at which we consider it to be an extra large screen.
5451 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005452 } else if (longSize >= 530 && shortSize >= 400) {
5453 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005454 // at which we consider it to be a large screen.
5455 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5456 } else {
5457 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005458
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005459 // If this screen is wider than normal HVGA, or taller
5460 // than FWVGA, then for old apps we want to run in size
5461 // compatibility mode.
5462 if (shortSize > 321 || longSize > 570) {
5463 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5464 }
5465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005466
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005467 // Is this a long screen?
5468 if (((longSize*3)/5) >= (shortSize-1)) {
5469 // Anything wider than WVGA (5:3) is considering to be long.
5470 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5471 } else {
5472 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5473 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005474 }
5475 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005476 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005477
Dianne Hackbornc485a602009-03-24 22:39:49 -07005478 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5479 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5480 mPolicy.adjustConfigurationLw(config);
5481 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005483
5484 // -------------------------------------------------------------
5485 // Drag and drop
5486 // -------------------------------------------------------------
5487
5488 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5489 boolean localOnly, int width, int height, Surface outSurface) {
5490 if (DEBUG_DRAG) {
5491 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5492 + " local=" + localOnly + " win=" + window
5493 + " asbinder=" + window.asBinder());
5494 }
5495
5496 final int callerPid = Binder.getCallingPid();
5497 final long origId = Binder.clearCallingIdentity();
5498 IBinder token = null;
5499
5500 try {
5501 synchronized (mWindowMap) {
5502 try {
5503 // !!! TODO: fail if the given window does not currently have touch focus?
5504
5505 if (mDragState == null) {
5506 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5507 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5508 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005509 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005510 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005511 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005512 mDragState.mSurface = surface;
5513 mDragState.mLocalOnly = localOnly;
5514 token = mDragState.mToken = new Binder();
5515
5516 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005517 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5518 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005519 mH.sendMessageDelayed(msg, 5000);
5520 } else {
5521 Slog.w(TAG, "Drag already in progress");
5522 }
5523 } catch (Surface.OutOfResourcesException e) {
5524 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5525 if (mDragState != null) {
5526 mDragState.reset();
5527 mDragState = null;
5528 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005529 }
5530 }
5531 } finally {
5532 Binder.restoreCallingIdentity(origId);
5533 }
5534
5535 return token;
5536 }
5537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005538 // -------------------------------------------------------------
5539 // Input Events and Focus Management
5540 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005541
Jeff Brown349703e2010-06-22 01:27:15 -07005542 InputMonitor mInputMonitor = new InputMonitor();
5543
5544 /* Tracks the progress of input dispatch and ensures that input dispatch state
5545 * is kept in sync with changes in window focus, visibility, registration, and
5546 * other relevant Window Manager state transitions. */
5547 final class InputMonitor {
5548 // Current window with input focus for keys and other non-touch events. May be null.
5549 private WindowState mInputFocus;
5550
5551 // When true, prevents input dispatch from proceeding until set to false again.
5552 private boolean mInputDispatchFrozen;
5553
5554 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5555 private boolean mInputDispatchEnabled = true;
5556
5557 // Temporary list of windows information to provide to the input dispatcher.
5558 private InputWindowList mTempInputWindows = new InputWindowList();
5559
5560 // Temporary input application object to provide to the input dispatcher.
5561 private InputApplication mTempInputApplication = new InputApplication();
5562
5563 /* Notifies the window manager about a broken input channel.
5564 *
5565 * Called by the InputManager.
5566 */
5567 public void notifyInputChannelBroken(InputChannel inputChannel) {
5568 synchronized (mWindowMap) {
5569 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5570 if (windowState == null) {
5571 return; // irrelevant
5572 }
5573
5574 Slog.i(TAG, "WINDOW DIED " + windowState);
5575 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005576 }
5577 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005578
Jeff Brown519e0242010-09-15 15:18:56 -07005579 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005580 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005581 *
5582 * Called by the InputManager.
5583 */
Jeff Brown519e0242010-09-15 15:18:56 -07005584 public long notifyANR(Object token, InputChannel inputChannel) {
5585 AppWindowToken appWindowToken = null;
5586 if (inputChannel != null) {
5587 synchronized (mWindowMap) {
5588 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5589 if (windowState != null) {
5590 Slog.i(TAG, "Input event dispatching timed out sending to "
5591 + windowState.mAttrs.getTitle());
5592 appWindowToken = windowState.mAppToken;
5593 }
Jeff Brown349703e2010-06-22 01:27:15 -07005594 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005595 }
5596
Jeff Brown519e0242010-09-15 15:18:56 -07005597 if (appWindowToken == null && token != null) {
5598 appWindowToken = (AppWindowToken) token;
5599 Slog.i(TAG, "Input event dispatching timed out sending to application "
5600 + appWindowToken.stringName);
5601 }
Jeff Brown349703e2010-06-22 01:27:15 -07005602
Jeff Brown519e0242010-09-15 15:18:56 -07005603 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005604 try {
5605 // Notify the activity manager about the timeout and let it decide whether
5606 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005607 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005608 if (! abort) {
5609 // The activity manager declined to abort dispatching.
5610 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005611 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005612 }
Jeff Brown349703e2010-06-22 01:27:15 -07005613 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005614 }
5615 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005616 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005617 }
5618
Jeff Brown349703e2010-06-22 01:27:15 -07005619 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5620 synchronized (mWindowMap) {
5621 return getWindowStateForInputChannelLocked(inputChannel);
5622 }
5623 }
5624
5625 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5626 int windowCount = mWindows.size();
5627 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005628 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005629 if (windowState.mInputChannel == inputChannel) {
5630 return windowState;
5631 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005632 }
5633
Jeff Brown349703e2010-06-22 01:27:15 -07005634 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005635 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005636
Chris Tatea32dcf72010-10-14 12:13:50 -07005637 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005638 final InputWindow inputWindow = windowList.add();
5639 inputWindow.inputChannel = mDragState.mServerChannel;
5640 inputWindow.name = "drag";
5641 inputWindow.layoutParamsFlags = 0;
5642 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5643 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5644 inputWindow.visible = true;
5645 inputWindow.canReceiveKeys = false;
5646 inputWindow.hasFocus = true;
5647 inputWindow.hasWallpaper = false;
5648 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005649 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005650 inputWindow.ownerPid = Process.myPid();
5651 inputWindow.ownerUid = Process.myUid();
5652
5653 // The drag window covers the entire display
5654 inputWindow.frameLeft = 0;
5655 inputWindow.frameTop = 0;
5656 inputWindow.frameRight = mDisplay.getWidth();
5657 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005658
Christopher Tatea53146c2010-09-07 11:57:52 -07005659 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5660 inputWindow.visibleFrameTop = inputWindow.frameTop;
5661 inputWindow.visibleFrameRight = inputWindow.frameRight;
5662 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5663
5664 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5665 inputWindow.touchableAreaTop = inputWindow.frameTop;
5666 inputWindow.touchableAreaRight = inputWindow.frameRight;
5667 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5668 }
5669
Jeff Brown349703e2010-06-22 01:27:15 -07005670 /* Updates the cached window information provided to the input dispatcher. */
5671 public void updateInputWindowsLw() {
5672 // Populate the input window list with information about all of the windows that
5673 // could potentially receive input.
5674 // As an optimization, we could try to prune the list of windows but this turns
5675 // out to be difficult because only the native code knows for sure which window
5676 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005677 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005678
5679 // If there's a drag in flight, provide a pseudowindow to catch drag input
5680 final boolean inDrag = (mDragState != null);
5681 if (inDrag) {
5682 if (DEBUG_DRAG) {
5683 Log.d(TAG, "Inserting drag window");
5684 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005685 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005686 }
5687
Jeff Brown7fbdc842010-06-17 20:52:56 -07005688 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005689 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005690 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005691 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005692 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005693 continue;
5694 }
5695
Jeff Brown349703e2010-06-22 01:27:15 -07005696 final int flags = child.mAttrs.flags;
5697 final int type = child.mAttrs.type;
5698
5699 final boolean hasFocus = (child == mInputFocus);
5700 final boolean isVisible = child.isVisibleLw();
5701 final boolean hasWallpaper = (child == mWallpaperTarget)
5702 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005703
5704 // If there's a drag in progress and 'child' is a potential drop target,
5705 // make sure it's been told about the drag
5706 if (inDrag && isVisible) {
5707 mDragState.sendDragStartedIfNeededLw(child);
5708 }
5709
Jeff Brown349703e2010-06-22 01:27:15 -07005710 // Add a window to our list of input windows.
5711 final InputWindow inputWindow = mTempInputWindows.add();
5712 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005713 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005714 inputWindow.layoutParamsFlags = flags;
5715 inputWindow.layoutParamsType = type;
5716 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5717 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005718 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005719 inputWindow.hasFocus = hasFocus;
5720 inputWindow.hasWallpaper = hasWallpaper;
5721 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005722 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005723 inputWindow.ownerPid = child.mSession.mPid;
5724 inputWindow.ownerUid = child.mSession.mUid;
5725
5726 final Rect frame = child.mFrame;
5727 inputWindow.frameLeft = frame.left;
5728 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005729 inputWindow.frameRight = frame.right;
5730 inputWindow.frameBottom = frame.bottom;
5731
5732 final Rect visibleFrame = child.mVisibleFrame;
5733 inputWindow.visibleFrameLeft = visibleFrame.left;
5734 inputWindow.visibleFrameTop = visibleFrame.top;
5735 inputWindow.visibleFrameRight = visibleFrame.right;
5736 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005737
5738 switch (child.mTouchableInsets) {
5739 default:
5740 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5741 inputWindow.touchableAreaLeft = frame.left;
5742 inputWindow.touchableAreaTop = frame.top;
5743 inputWindow.touchableAreaRight = frame.right;
5744 inputWindow.touchableAreaBottom = frame.bottom;
5745 break;
5746
5747 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5748 Rect inset = child.mGivenContentInsets;
5749 inputWindow.touchableAreaLeft = frame.left + inset.left;
5750 inputWindow.touchableAreaTop = frame.top + inset.top;
5751 inputWindow.touchableAreaRight = frame.right - inset.right;
5752 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5753 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005754 }
Jeff Brown349703e2010-06-22 01:27:15 -07005755
5756 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5757 Rect inset = child.mGivenVisibleInsets;
5758 inputWindow.touchableAreaLeft = frame.left + inset.left;
5759 inputWindow.touchableAreaTop = frame.top + inset.top;
5760 inputWindow.touchableAreaRight = frame.right - inset.right;
5761 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005762 break;
5763 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005764 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005765 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005766
Jeff Brown349703e2010-06-22 01:27:15 -07005767 // Send windows to native code.
5768 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005769
Jeff Brown349703e2010-06-22 01:27:15 -07005770 // Clear the list in preparation for the next round.
5771 // Also avoids keeping InputChannel objects referenced unnecessarily.
5772 mTempInputWindows.clear();
5773 }
5774
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005775 /* Notifies that the lid switch changed state. */
5776 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5777 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5778 }
5779
Jeff Brown349703e2010-06-22 01:27:15 -07005780 /* Provides an opportunity for the window manager policy to intercept early key
5781 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005782 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5783 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5784 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5785 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005786 }
5787
5788 /* Provides an opportunity for the window manager policy to process a key before
5789 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005790 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005791 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005792 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005793 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005794 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005795 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005796 }
5797
Jeff Brown3915bb82010-11-05 15:02:16 -07005798 /* Provides an opportunity for the window manager policy to process a key that
5799 * the application did not handle. */
5800 public boolean dispatchUnhandledKey(InputChannel focus,
5801 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
5802 int policyFlags) {
5803 WindowState windowState = getWindowStateForInputChannel(focus);
5804 return mPolicy.dispatchUnhandledKey(windowState, action, flags,
5805 keyCode, scanCode, metaState, repeatCount, policyFlags);
5806 }
5807
Jeff Brown349703e2010-06-22 01:27:15 -07005808 /* Called when the current input focus changes.
5809 * Layer assignment is assumed to be complete by the time this is called.
5810 */
5811 public void setInputFocusLw(WindowState newWindow) {
5812 if (DEBUG_INPUT) {
5813 Slog.d(TAG, "Input focus has changed to " + newWindow);
5814 }
5815
5816 if (newWindow != mInputFocus) {
5817 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005818 // Displaying a window implicitly causes dispatching to be unpaused.
5819 // This is to protect against bugs if someone pauses dispatching but
5820 // forgets to resume.
5821 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005822 }
Jeff Brown349703e2010-06-22 01:27:15 -07005823
5824 mInputFocus = newWindow;
5825 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005826 }
5827 }
5828
Jeff Brown349703e2010-06-22 01:27:15 -07005829 public void setFocusedAppLw(AppWindowToken newApp) {
5830 // Focused app has changed.
5831 if (newApp == null) {
5832 mInputManager.setFocusedApplication(null);
5833 } else {
5834 mTempInputApplication.name = newApp.toString();
5835 mTempInputApplication.dispatchingTimeoutNanos =
5836 newApp.inputDispatchingTimeoutNanos;
5837 mTempInputApplication.token = newApp;
5838
5839 mInputManager.setFocusedApplication(mTempInputApplication);
5840 }
5841 }
5842
Jeff Brown349703e2010-06-22 01:27:15 -07005843 public void pauseDispatchingLw(WindowToken window) {
5844 if (! window.paused) {
5845 if (DEBUG_INPUT) {
5846 Slog.v(TAG, "Pausing WindowToken " + window);
5847 }
5848
5849 window.paused = true;
5850 updateInputWindowsLw();
5851 }
5852 }
5853
5854 public void resumeDispatchingLw(WindowToken window) {
5855 if (window.paused) {
5856 if (DEBUG_INPUT) {
5857 Slog.v(TAG, "Resuming WindowToken " + window);
5858 }
5859
5860 window.paused = false;
5861 updateInputWindowsLw();
5862 }
5863 }
5864
5865 public void freezeInputDispatchingLw() {
5866 if (! mInputDispatchFrozen) {
5867 if (DEBUG_INPUT) {
5868 Slog.v(TAG, "Freezing input dispatching");
5869 }
5870
5871 mInputDispatchFrozen = true;
5872 updateInputDispatchModeLw();
5873 }
5874 }
5875
5876 public void thawInputDispatchingLw() {
5877 if (mInputDispatchFrozen) {
5878 if (DEBUG_INPUT) {
5879 Slog.v(TAG, "Thawing input dispatching");
5880 }
5881
5882 mInputDispatchFrozen = false;
5883 updateInputDispatchModeLw();
5884 }
5885 }
5886
5887 public void setEventDispatchingLw(boolean enabled) {
5888 if (mInputDispatchEnabled != enabled) {
5889 if (DEBUG_INPUT) {
5890 Slog.v(TAG, "Setting event dispatching to " + enabled);
5891 }
5892
5893 mInputDispatchEnabled = enabled;
5894 updateInputDispatchModeLw();
5895 }
5896 }
5897
5898 private void updateInputDispatchModeLw() {
5899 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5900 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005903 public void pauseKeyDispatching(IBinder _token) {
5904 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5905 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005906 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 }
5908
5909 synchronized (mWindowMap) {
5910 WindowToken token = mTokenMap.get(_token);
5911 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005912 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005913 }
5914 }
5915 }
5916
5917 public void resumeKeyDispatching(IBinder _token) {
5918 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5919 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005920 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005921 }
5922
5923 synchronized (mWindowMap) {
5924 WindowToken token = mTokenMap.get(_token);
5925 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005926 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 }
5928 }
5929 }
5930
5931 public void setEventDispatching(boolean enabled) {
5932 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5933 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005934 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935 }
5936
5937 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005938 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005939 }
5940 }
Romain Guy06882f82009-06-10 13:36:04 -07005941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005942 /**
5943 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005944 * Even when sync is false, this method may block while waiting for current
5945 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005946 *
5947 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005948 * {@link SystemClock#uptimeMillis()} as the timebase.)
5949 * @param sync If true, wait for the event to be completed before returning to the caller.
5950 * @return Returns true if event was dispatched, false if it was dropped for any reason
5951 */
5952 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5953 long downTime = ev.getDownTime();
5954 long eventTime = ev.getEventTime();
5955
5956 int action = ev.getAction();
5957 int code = ev.getKeyCode();
5958 int repeatCount = ev.getRepeatCount();
5959 int metaState = ev.getMetaState();
5960 int deviceId = ev.getDeviceId();
5961 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005962 int source = ev.getSource();
5963
5964 if (source == InputDevice.SOURCE_UNKNOWN) {
5965 source = InputDevice.SOURCE_KEYBOARD;
5966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005967
5968 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5969 if (downTime == 0) downTime = eventTime;
5970
5971 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005972 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005973
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005974 final int pid = Binder.getCallingPid();
5975 final int uid = Binder.getCallingUid();
5976 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005977
Jeff Brownbbda99d2010-07-28 15:48:59 -07005978 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5979 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5980 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5981 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005982
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005983 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005984 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005985 }
5986
5987 /**
5988 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005989 * Even when sync is false, this method may block while waiting for current
5990 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005991 *
5992 * @param ev A motion event describing the pointer (touch) action. (As noted in
5993 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005994 * {@link SystemClock#uptimeMillis()} as the timebase.)
5995 * @param sync If true, wait for the event to be completed before returning to the caller.
5996 * @return Returns true if event was dispatched, false if it was dropped for any reason
5997 */
5998 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005999 final int pid = Binder.getCallingPid();
6000 final int uid = Binder.getCallingUid();
6001 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006002
Jeff Brownc5ed5912010-07-14 18:48:53 -07006003 MotionEvent newEvent = MotionEvent.obtain(ev);
6004 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6005 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6006 }
6007
Jeff Brownbbda99d2010-07-28 15:48:59 -07006008 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6009 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6010 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6011 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006012
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006013 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006014 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006015 }
Romain Guy06882f82009-06-10 13:36:04 -07006016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 /**
6018 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006019 * Even when sync is false, this method may block while waiting for current
6020 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006021 *
6022 * @param ev A motion event describing the trackball action. (As noted in
6023 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006024 * {@link SystemClock#uptimeMillis()} as the timebase.)
6025 * @param sync If true, wait for the event to be completed before returning to the caller.
6026 * @return Returns true if event was dispatched, false if it was dropped for any reason
6027 */
6028 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006029 final int pid = Binder.getCallingPid();
6030 final int uid = Binder.getCallingUid();
6031 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006032
Jeff Brownc5ed5912010-07-14 18:48:53 -07006033 MotionEvent newEvent = MotionEvent.obtain(ev);
6034 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6035 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6036 }
6037
Jeff Brownbbda99d2010-07-28 15:48:59 -07006038 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6039 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6040 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6041 INJECTION_TIMEOUT_MILLIS);
6042
6043 Binder.restoreCallingIdentity(ident);
6044 return reportInjectionResult(result);
6045 }
6046
6047 /**
6048 * Inject an input event into the UI without waiting for dispatch to commence.
6049 * This variant is useful for fire-and-forget input event injection. It does not
6050 * block any longer than it takes to enqueue the input event.
6051 *
6052 * @param ev An input event. (Be sure to set the input source correctly.)
6053 * @return Returns true if event was dispatched, false if it was dropped for any reason
6054 */
6055 public boolean injectInputEventNoWait(InputEvent ev) {
6056 final int pid = Binder.getCallingPid();
6057 final int uid = Binder.getCallingUid();
6058 final long ident = Binder.clearCallingIdentity();
6059
6060 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6061 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6062 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006063
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006064 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006065 return reportInjectionResult(result);
6066 }
6067
6068 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006069 switch (result) {
6070 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6071 Slog.w(TAG, "Input event injection permission denied.");
6072 throw new SecurityException(
6073 "Injecting to another application requires INJECT_EVENTS permission");
6074 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006075 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006076 return true;
6077 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6078 Slog.w(TAG, "Input event injection timed out.");
6079 return false;
6080 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6081 default:
6082 Slog.w(TAG, "Input event injection failed.");
6083 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 }
Romain Guy06882f82009-06-10 13:36:04 -07006086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006087 private WindowState getFocusedWindow() {
6088 synchronized (mWindowMap) {
6089 return getFocusedWindowLocked();
6090 }
6091 }
6092
6093 private WindowState getFocusedWindowLocked() {
6094 return mCurrentFocus;
6095 }
Romain Guy06882f82009-06-10 13:36:04 -07006096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006097 public boolean detectSafeMode() {
6098 mSafeMode = mPolicy.detectSafeMode();
6099 return mSafeMode;
6100 }
Romain Guy06882f82009-06-10 13:36:04 -07006101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006102 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006103 synchronized(mWindowMap) {
6104 if (mDisplay != null) {
6105 throw new IllegalStateException("Display already initialized");
6106 }
6107 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6108 mDisplay = wm.getDefaultDisplay();
6109 mInitialDisplayWidth = mDisplay.getWidth();
6110 mInitialDisplayHeight = mDisplay.getHeight();
6111 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6112 }
6113
6114 try {
6115 mActivityManager.updateConfiguration(null);
6116 } catch (RemoteException e) {
6117 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006118
6119 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006120 }
6121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 // -------------------------------------------------------------
6123 // Client Session State
6124 // -------------------------------------------------------------
6125
6126 private final class Session extends IWindowSession.Stub
6127 implements IBinder.DeathRecipient {
6128 final IInputMethodClient mClient;
6129 final IInputContext mInputContext;
6130 final int mUid;
6131 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006132 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 SurfaceSession mSurfaceSession;
6134 int mNumWindow = 0;
6135 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 public Session(IInputMethodClient client, IInputContext inputContext) {
6138 mClient = client;
6139 mInputContext = inputContext;
6140 mUid = Binder.getCallingUid();
6141 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006142 StringBuilder sb = new StringBuilder();
6143 sb.append("Session{");
6144 sb.append(Integer.toHexString(System.identityHashCode(this)));
6145 sb.append(" uid ");
6146 sb.append(mUid);
6147 sb.append("}");
6148 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 synchronized (mWindowMap) {
6151 if (mInputMethodManager == null && mHaveInputMethods) {
6152 IBinder b = ServiceManager.getService(
6153 Context.INPUT_METHOD_SERVICE);
6154 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6155 }
6156 }
6157 long ident = Binder.clearCallingIdentity();
6158 try {
6159 // Note: it is safe to call in to the input method manager
6160 // here because we are not holding our lock.
6161 if (mInputMethodManager != null) {
6162 mInputMethodManager.addClient(client, inputContext,
6163 mUid, mPid);
6164 } else {
6165 client.setUsingInputMethod(false);
6166 }
6167 client.asBinder().linkToDeath(this, 0);
6168 } catch (RemoteException e) {
6169 // The caller has died, so we can just forget about this.
6170 try {
6171 if (mInputMethodManager != null) {
6172 mInputMethodManager.removeClient(client);
6173 }
6174 } catch (RemoteException ee) {
6175 }
6176 } finally {
6177 Binder.restoreCallingIdentity(ident);
6178 }
6179 }
Romain Guy06882f82009-06-10 13:36:04 -07006180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181 @Override
6182 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6183 throws RemoteException {
6184 try {
6185 return super.onTransact(code, data, reply, flags);
6186 } catch (RuntimeException e) {
6187 // Log all 'real' exceptions thrown to the caller
6188 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006189 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006190 }
6191 throw e;
6192 }
6193 }
6194
6195 public void binderDied() {
6196 // Note: it is safe to call in to the input method manager
6197 // here because we are not holding our lock.
6198 try {
6199 if (mInputMethodManager != null) {
6200 mInputMethodManager.removeClient(mClient);
6201 }
6202 } catch (RemoteException e) {
6203 }
6204 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006205 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 mClientDead = true;
6207 killSessionLocked();
6208 }
6209 }
6210
6211 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006212 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6213 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6214 outInputChannel);
6215 }
6216
6217 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006219 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006220 }
Romain Guy06882f82009-06-10 13:36:04 -07006221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 public void remove(IWindow window) {
6223 removeWindow(this, window);
6224 }
Romain Guy06882f82009-06-10 13:36:04 -07006225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006226 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6227 int requestedWidth, int requestedHeight, int viewFlags,
6228 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006229 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006230 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6231 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006232 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006233 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006234 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6235 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006236 }
Romain Guy06882f82009-06-10 13:36:04 -07006237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006238 public void setTransparentRegion(IWindow window, Region region) {
6239 setTransparentRegionWindow(this, window, region);
6240 }
Romain Guy06882f82009-06-10 13:36:04 -07006241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006242 public void setInsets(IWindow window, int touchableInsets,
6243 Rect contentInsets, Rect visibleInsets) {
6244 setInsetsWindow(this, window, touchableInsets, contentInsets,
6245 visibleInsets);
6246 }
Romain Guy06882f82009-06-10 13:36:04 -07006247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006248 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6249 getWindowDisplayFrame(this, window, outDisplayFrame);
6250 }
Romain Guy06882f82009-06-10 13:36:04 -07006251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006252 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006253 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254 TAG, "IWindow finishDrawing called for " + window);
6255 finishDrawingWindow(this, window);
6256 }
6257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258 public void setInTouchMode(boolean mode) {
6259 synchronized(mWindowMap) {
6260 mInTouchMode = mode;
6261 }
6262 }
6263
6264 public boolean getInTouchMode() {
6265 synchronized(mWindowMap) {
6266 return mInTouchMode;
6267 }
6268 }
6269
6270 public boolean performHapticFeedback(IWindow window, int effectId,
6271 boolean always) {
6272 synchronized(mWindowMap) {
6273 long ident = Binder.clearCallingIdentity();
6274 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006275 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006276 windowForClientLocked(this, window, true),
6277 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 } finally {
6279 Binder.restoreCallingIdentity(ident);
6280 }
6281 }
6282 }
Romain Guy06882f82009-06-10 13:36:04 -07006283
Christopher Tatea53146c2010-09-07 11:57:52 -07006284 /* Drag/drop */
6285 public IBinder prepareDrag(IWindow window, boolean localOnly,
6286 int width, int height, Surface outSurface) {
6287 return prepareDragSurface(window, mSurfaceSession, localOnly,
6288 width, height, outSurface);
6289 }
6290
6291 public boolean performDrag(IWindow window, IBinder dragToken,
6292 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6293 ClipData data) {
6294 if (DEBUG_DRAG) {
6295 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6296 }
6297
6298 synchronized (mWindowMap) {
6299 if (mDragState == null) {
6300 Slog.w(TAG, "No drag prepared");
6301 throw new IllegalStateException("performDrag() without prepareDrag()");
6302 }
6303
6304 if (dragToken != mDragState.mToken) {
6305 Slog.w(TAG, "Performing mismatched drag");
6306 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6307 }
6308
6309 WindowState callingWin = windowForClientLocked(null, window, false);
6310 if (callingWin == null) {
6311 Slog.w(TAG, "Bad requesting window " + window);
6312 return false; // !!! TODO: throw here?
6313 }
6314
6315 // !!! TODO: if input is not still focused on the initiating window, fail
6316 // the drag initiation (e.g. an alarm window popped up just as the application
6317 // called performDrag()
6318
6319 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6320
Christopher Tate2c095f32010-10-04 14:13:40 -07006321 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6322 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006323
Chris Tateb478f462010-10-15 16:02:26 -07006324 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6325 // the actual drag event dispatch stuff in the dragstate
6326
Christopher Tatea53146c2010-09-07 11:57:52 -07006327 mDragState.register();
6328 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006329 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6330 mDragState.mServerChannel)) {
6331 Slog.e(TAG, "Unable to transfer touch focus");
6332 mDragState.unregister();
6333 mDragState = null;
6334 mInputMonitor.updateInputWindowsLw();
6335 return false;
6336 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006337
6338 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006339 mDragState.mCurrentX = touchX;
6340 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006341 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006342
6343 // remember the thumb offsets for later
6344 mDragState.mThumbOffsetX = thumbCenterX;
6345 mDragState.mThumbOffsetY = thumbCenterY;
6346
6347 // Make the surface visible at the proper location
6348 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006349 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006350 try {
6351 surface.setPosition((int)(touchX - thumbCenterX),
6352 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006353 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006354 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006355 surface.show();
6356 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006357 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006358 }
6359 }
6360
6361 return true; // success!
6362 }
6363
Chris Tated4533f142010-10-19 15:15:08 -07006364 public void reportDropResult(IWindow window, boolean consumed) {
6365 IBinder token = window.asBinder();
6366 if (DEBUG_DRAG) {
6367 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6368 }
6369
6370 synchronized (mWindowMap) {
6371 if (mDragState.mToken != token) {
6372 Slog.w(TAG, "Invalid drop-result claim by " + window);
6373 throw new IllegalStateException("reportDropResult() by non-recipient");
6374 }
6375
6376 // The right window has responded, even if it's no longer around,
6377 // so be sure to halt the timeout even if the later WindowState
6378 // lookup fails.
6379 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6380
6381 WindowState callingWin = windowForClientLocked(null, window, false);
6382 if (callingWin == null) {
6383 Slog.w(TAG, "Bad result-reporting window " + window);
6384 return; // !!! TODO: throw here?
6385 }
6386
6387 mDragState.mDragResult = consumed;
6388 mDragState.endDragLw();
6389 }
6390 }
6391
Christopher Tatea53146c2010-09-07 11:57:52 -07006392 public void dragRecipientEntered(IWindow window) {
6393 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006394 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006395 }
6396 }
6397
6398 public void dragRecipientExited(IWindow window) {
6399 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006400 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006401 }
6402 }
6403
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006404 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006405 synchronized(mWindowMap) {
6406 long ident = Binder.clearCallingIdentity();
6407 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006408 setWindowWallpaperPositionLocked(
6409 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006410 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006411 } finally {
6412 Binder.restoreCallingIdentity(ident);
6413 }
6414 }
6415 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006416
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006417 public void wallpaperOffsetsComplete(IBinder window) {
6418 WindowManagerService.this.wallpaperOffsetsComplete(window);
6419 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006420
Dianne Hackborn75804932009-10-20 20:15:20 -07006421 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6422 int z, Bundle extras, boolean sync) {
6423 synchronized(mWindowMap) {
6424 long ident = Binder.clearCallingIdentity();
6425 try {
6426 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006427 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006428 action, x, y, z, extras, sync);
6429 } finally {
6430 Binder.restoreCallingIdentity(ident);
6431 }
6432 }
6433 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006434
Dianne Hackborn75804932009-10-20 20:15:20 -07006435 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6436 WindowManagerService.this.wallpaperCommandComplete(window, result);
6437 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 void windowAddedLocked() {
6440 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006441 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 TAG, "First window added to " + this + ", creating SurfaceSession");
6443 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006444 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006445 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006446 mSessions.add(this);
6447 }
6448 mNumWindow++;
6449 }
6450
6451 void windowRemovedLocked() {
6452 mNumWindow--;
6453 killSessionLocked();
6454 }
Romain Guy06882f82009-06-10 13:36:04 -07006455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 void killSessionLocked() {
6457 if (mNumWindow <= 0 && mClientDead) {
6458 mSessions.remove(this);
6459 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006460 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006461 TAG, "Last window removed from " + this
6462 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006463 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006464 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 try {
6466 mSurfaceSession.kill();
6467 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006468 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 + mSurfaceSession + " in session " + this
6470 + ": " + e.toString());
6471 }
6472 mSurfaceSession = null;
6473 }
6474 }
6475 }
Romain Guy06882f82009-06-10 13:36:04 -07006476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006477 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006478 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6479 pw.print(" mClientDead="); pw.print(mClientDead);
6480 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 }
6482
6483 @Override
6484 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006485 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 }
6487 }
6488
6489 // -------------------------------------------------------------
6490 // Client Window State
6491 // -------------------------------------------------------------
6492
6493 private final class WindowState implements WindowManagerPolicy.WindowState {
6494 final Session mSession;
6495 final IWindow mClient;
6496 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006497 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 AppWindowToken mAppToken;
6499 AppWindowToken mTargetAppToken;
6500 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6501 final DeathRecipient mDeathRecipient;
6502 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006503 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006504 final int mBaseLayer;
6505 final int mSubLayer;
6506 final boolean mLayoutAttached;
6507 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006508 final boolean mIsWallpaper;
6509 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 int mViewVisibility;
6511 boolean mPolicyVisibility = true;
6512 boolean mPolicyVisibilityAfterAnim = true;
6513 boolean mAppFreezing;
6514 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006515 boolean mReportDestroySurface;
6516 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 boolean mAttachedHidden; // is our parent window hidden?
6518 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006519 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520 int mRequestedWidth;
6521 int mRequestedHeight;
6522 int mLastRequestedWidth;
6523 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006524 int mLayer;
6525 int mAnimLayer;
6526 int mLastLayer;
6527 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006528 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006529 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006530
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006531 int mLayoutSeq = -1;
6532
6533 Configuration mConfiguration = null;
6534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006535 // Actual frame shown on-screen (may be modified by animation)
6536 final Rect mShownFrame = new Rect();
6537 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006539 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006540 * Set when we have changed the size of the surface, to know that
6541 * we must tell them application to resize (and thus redraw itself).
6542 */
6543 boolean mSurfaceResized;
6544
6545 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006546 * Insets that determine the actually visible area
6547 */
6548 final Rect mVisibleInsets = new Rect();
6549 final Rect mLastVisibleInsets = new Rect();
6550 boolean mVisibleInsetsChanged;
6551
6552 /**
6553 * Insets that are covered by system windows
6554 */
6555 final Rect mContentInsets = new Rect();
6556 final Rect mLastContentInsets = new Rect();
6557 boolean mContentInsetsChanged;
6558
6559 /**
6560 * Set to true if we are waiting for this window to receive its
6561 * given internal insets before laying out other windows based on it.
6562 */
6563 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 /**
6566 * These are the content insets that were given during layout for
6567 * this window, to be applied to windows behind it.
6568 */
6569 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 /**
6572 * These are the visible insets that were given during layout for
6573 * this window, to be applied to windows behind it.
6574 */
6575 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577 /**
6578 * Flag indicating whether the touchable region should be adjusted by
6579 * the visible insets; if false the area outside the visible insets is
6580 * NOT touchable, so we must use those to adjust the frame during hit
6581 * tests.
6582 */
6583 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 // Current transformation being applied.
6586 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6587 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6588 float mHScale=1, mVScale=1;
6589 float mLastHScale=1, mLastVScale=1;
6590 final Matrix mTmpMatrix = new Matrix();
6591
6592 // "Real" frame that the application sees.
6593 final Rect mFrame = new Rect();
6594 final Rect mLastFrame = new Rect();
6595
6596 final Rect mContainingFrame = new Rect();
6597 final Rect mDisplayFrame = new Rect();
6598 final Rect mContentFrame = new Rect();
6599 final Rect mVisibleFrame = new Rect();
6600
6601 float mShownAlpha = 1;
6602 float mAlpha = 1;
6603 float mLastAlpha = 1;
6604
6605 // Set to true if, when the window gets displayed, it should perform
6606 // an enter animation.
6607 boolean mEnterAnimationPending;
6608
6609 // Currently running animation.
6610 boolean mAnimating;
6611 boolean mLocalAnimating;
6612 Animation mAnimation;
6613 boolean mAnimationIsEntrance;
6614 boolean mHasTransformation;
6615 boolean mHasLocalTransformation;
6616 final Transformation mTransformation = new Transformation();
6617
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006618 // If a window showing a wallpaper: the requested offset for the
6619 // wallpaper; if a wallpaper window: the currently applied offset.
6620 float mWallpaperX = -1;
6621 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006622
6623 // If a window showing a wallpaper: what fraction of the offset
6624 // range corresponds to a full virtual screen.
6625 float mWallpaperXStep = -1;
6626 float mWallpaperYStep = -1;
6627
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006628 // Wallpaper windows: pixels offset based on above variables.
6629 int mXOffset;
6630 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006632 // This is set after IWindowSession.relayout() has been called at
6633 // least once for the window. It allows us to detect the situation
6634 // where we don't yet have a surface, but should have one soon, so
6635 // we can give the window focus before waiting for the relayout.
6636 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006638 // This is set after the Surface has been created but before the
6639 // window has been drawn. During this time the surface is hidden.
6640 boolean mDrawPending;
6641
6642 // This is set after the window has finished drawing for the first
6643 // time but before its surface is shown. The surface will be
6644 // displayed when the next layout is run.
6645 boolean mCommitDrawPending;
6646
6647 // This is set during the time after the window's drawing has been
6648 // committed, and before its surface is actually shown. It is used
6649 // to delay showing the surface until all windows in a token are ready
6650 // to be shown.
6651 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006653 // Set when the window has been shown in the screen the first time.
6654 boolean mHasDrawn;
6655
6656 // Currently running an exit animation?
6657 boolean mExiting;
6658
6659 // Currently on the mDestroySurface list?
6660 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662 // Completely remove from window manager after exit animation?
6663 boolean mRemoveOnExit;
6664
6665 // Set when the orientation is changing and this window has not yet
6666 // been updated for the new orientation.
6667 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006669 // Is this window now (or just being) removed?
6670 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006671
Dianne Hackborn16064f92010-03-25 00:47:24 -07006672 // For debugging, this is the last information given to the surface flinger.
6673 boolean mSurfaceShown;
6674 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6675 int mSurfaceLayer;
6676 float mSurfaceAlpha;
6677
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006678 // Input channel
6679 InputChannel mInputChannel;
6680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006681 WindowState(Session s, IWindow c, WindowToken token,
6682 WindowState attachedWindow, WindowManager.LayoutParams a,
6683 int viewVisibility) {
6684 mSession = s;
6685 mClient = c;
6686 mToken = token;
6687 mAttrs.copyFrom(a);
6688 mViewVisibility = viewVisibility;
6689 DeathRecipient deathRecipient = new DeathRecipient();
6690 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006691 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006692 TAG, "Window " + this + " client=" + c.asBinder()
6693 + " token=" + token + " (" + mAttrs.token + ")");
6694 try {
6695 c.asBinder().linkToDeath(deathRecipient, 0);
6696 } catch (RemoteException e) {
6697 mDeathRecipient = null;
6698 mAttachedWindow = null;
6699 mLayoutAttached = false;
6700 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006701 mIsWallpaper = false;
6702 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 mBaseLayer = 0;
6704 mSubLayer = 0;
6705 return;
6706 }
6707 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6710 mAttrs.type <= LAST_SUB_WINDOW)) {
6711 // The multiplier here is to reserve space for multiple
6712 // windows in the same type layer.
6713 mBaseLayer = mPolicy.windowTypeToLayerLw(
6714 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6715 + TYPE_LAYER_OFFSET;
6716 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6717 mAttachedWindow = attachedWindow;
6718 mAttachedWindow.mChildWindows.add(this);
6719 mLayoutAttached = mAttrs.type !=
6720 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6721 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6722 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006723 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6724 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 } else {
6726 // The multiplier here is to reserve space for multiple
6727 // windows in the same type layer.
6728 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6729 * TYPE_LAYER_MULTIPLIER
6730 + TYPE_LAYER_OFFSET;
6731 mSubLayer = 0;
6732 mAttachedWindow = null;
6733 mLayoutAttached = false;
6734 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6735 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006736 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6737 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 }
6739
6740 WindowState appWin = this;
6741 while (appWin.mAttachedWindow != null) {
6742 appWin = mAttachedWindow;
6743 }
6744 WindowToken appToken = appWin.mToken;
6745 while (appToken.appWindowToken == null) {
6746 WindowToken parent = mTokenMap.get(appToken.token);
6747 if (parent == null || appToken == parent) {
6748 break;
6749 }
6750 appToken = parent;
6751 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006752 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 mAppToken = appToken.appWindowToken;
6754
6755 mSurface = null;
6756 mRequestedWidth = 0;
6757 mRequestedHeight = 0;
6758 mLastRequestedWidth = 0;
6759 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006760 mXOffset = 0;
6761 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 mLayer = 0;
6763 mAnimLayer = 0;
6764 mLastLayer = 0;
6765 }
6766
6767 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006768 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 TAG, "Attaching " + this + " token=" + mToken
6770 + ", list=" + mToken.windows);
6771 mSession.windowAddedLocked();
6772 }
6773
6774 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6775 mHaveFrame = true;
6776
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006777 final Rect container = mContainingFrame;
6778 container.set(pf);
6779
6780 final Rect display = mDisplayFrame;
6781 display.set(df);
6782
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006783 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006784 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006785 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6786 display.intersect(mCompatibleScreenFrame);
6787 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006788 }
6789
6790 final int pw = container.right - container.left;
6791 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006792
6793 int w,h;
6794 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6795 w = mAttrs.width < 0 ? pw : mAttrs.width;
6796 h = mAttrs.height< 0 ? ph : mAttrs.height;
6797 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006798 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6799 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 }
Romain Guy06882f82009-06-10 13:36:04 -07006801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 final Rect content = mContentFrame;
6803 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 final Rect visible = mVisibleFrame;
6806 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006809 final int fw = frame.width();
6810 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6813 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6814
6815 Gravity.apply(mAttrs.gravity, w, h, container,
6816 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6817 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6818
6819 //System.out.println("Out: " + mFrame);
6820
6821 // Now make sure the window fits in the overall display.
6822 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006824 // Make sure the content and visible frames are inside of the
6825 // final window frame.
6826 if (content.left < frame.left) content.left = frame.left;
6827 if (content.top < frame.top) content.top = frame.top;
6828 if (content.right > frame.right) content.right = frame.right;
6829 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6830 if (visible.left < frame.left) visible.left = frame.left;
6831 if (visible.top < frame.top) visible.top = frame.top;
6832 if (visible.right > frame.right) visible.right = frame.right;
6833 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006835 final Rect contentInsets = mContentInsets;
6836 contentInsets.left = content.left-frame.left;
6837 contentInsets.top = content.top-frame.top;
6838 contentInsets.right = frame.right-content.right;
6839 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 final Rect visibleInsets = mVisibleInsets;
6842 visibleInsets.left = visible.left-frame.left;
6843 visibleInsets.top = visible.top-frame.top;
6844 visibleInsets.right = frame.right-visible.right;
6845 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006846
Dianne Hackborn284ac932009-08-28 10:34:25 -07006847 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6848 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006849 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006850 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 if (localLOGV) {
6853 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6854 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006855 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 + mRequestedWidth + ", mRequestedheight="
6857 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6858 + "): frame=" + mFrame.toShortString()
6859 + " ci=" + contentInsets.toShortString()
6860 + " vi=" + visibleInsets.toShortString());
6861 //}
6862 }
6863 }
Romain Guy06882f82009-06-10 13:36:04 -07006864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006865 public Rect getFrameLw() {
6866 return mFrame;
6867 }
6868
6869 public Rect getShownFrameLw() {
6870 return mShownFrame;
6871 }
6872
6873 public Rect getDisplayFrameLw() {
6874 return mDisplayFrame;
6875 }
6876
6877 public Rect getContentFrameLw() {
6878 return mContentFrame;
6879 }
6880
6881 public Rect getVisibleFrameLw() {
6882 return mVisibleFrame;
6883 }
6884
6885 public boolean getGivenInsetsPendingLw() {
6886 return mGivenInsetsPending;
6887 }
6888
6889 public Rect getGivenContentInsetsLw() {
6890 return mGivenContentInsets;
6891 }
Romain Guy06882f82009-06-10 13:36:04 -07006892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 public Rect getGivenVisibleInsetsLw() {
6894 return mGivenVisibleInsets;
6895 }
Romain Guy06882f82009-06-10 13:36:04 -07006896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 public WindowManager.LayoutParams getAttrs() {
6898 return mAttrs;
6899 }
6900
6901 public int getSurfaceLayer() {
6902 return mLayer;
6903 }
Romain Guy06882f82009-06-10 13:36:04 -07006904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 public IApplicationToken getAppToken() {
6906 return mAppToken != null ? mAppToken.appToken : null;
6907 }
Jeff Brown349703e2010-06-22 01:27:15 -07006908
6909 public long getInputDispatchingTimeoutNanos() {
6910 return mAppToken != null
6911 ? mAppToken.inputDispatchingTimeoutNanos
6912 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914
6915 public boolean hasAppShownWindows() {
6916 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6917 }
6918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006920 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 TAG, "Setting animation in " + this + ": " + anim);
6922 mAnimating = false;
6923 mLocalAnimating = false;
6924 mAnimation = anim;
6925 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6926 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6927 }
6928
6929 public void clearAnimation() {
6930 if (mAnimation != null) {
6931 mAnimating = true;
6932 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07006933 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 mAnimation = null;
6935 }
6936 }
Romain Guy06882f82009-06-10 13:36:04 -07006937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 Surface createSurfaceLocked() {
6939 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006940 mReportDestroySurface = false;
6941 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006942 mDrawPending = true;
6943 mCommitDrawPending = false;
6944 mReadyToShow = false;
6945 if (mAppToken != null) {
6946 mAppToken.allDrawn = false;
6947 }
6948
6949 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006950 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 flags |= Surface.PUSH_BUFFERS;
6952 }
6953
6954 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6955 flags |= Surface.SECURE;
6956 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006957 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 TAG, "Creating surface in session "
6959 + mSession.mSurfaceSession + " window " + this
6960 + " w=" + mFrame.width()
6961 + " h=" + mFrame.height() + " format="
6962 + mAttrs.format + " flags=" + flags);
6963
6964 int w = mFrame.width();
6965 int h = mFrame.height();
6966 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6967 // for a scaled surface, we always want the requested
6968 // size.
6969 w = mRequestedWidth;
6970 h = mRequestedHeight;
6971 }
6972
Romain Guy9825ec62009-10-01 00:58:09 -07006973 // Something is wrong and SurfaceFlinger will not like this,
6974 // try to revert to sane values
6975 if (w <= 0) w = 1;
6976 if (h <= 0) h = 1;
6977
Dianne Hackborn16064f92010-03-25 00:47:24 -07006978 mSurfaceShown = false;
6979 mSurfaceLayer = 0;
6980 mSurfaceAlpha = 1;
6981 mSurfaceX = 0;
6982 mSurfaceY = 0;
6983 mSurfaceW = w;
6984 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006985 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006986 final boolean isHwAccelerated = (mAttrs.flags &
6987 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6988 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6989 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6990 flags |= Surface.OPAQUE;
6991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006992 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006993 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006994 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006995 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006996 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006997 + mSurface + " IN SESSION "
6998 + mSession.mSurfaceSession
6999 + ": pid=" + mSession.mPid + " format="
7000 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007001 + Integer.toHexString(flags)
7002 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007004 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 reclaimSomeSurfaceMemoryLocked(this, "create");
7006 return null;
7007 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007008 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 return null;
7010 }
Romain Guy06882f82009-06-10 13:36:04 -07007011
Joe Onorato8a9b2202010-02-26 18:56:32 -08007012 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007013 TAG, "Got surface: " + mSurface
7014 + ", set left=" + mFrame.left + " top=" + mFrame.top
7015 + ", animLayer=" + mAnimLayer);
7016 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007017 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007018 if (SHOW_TRANSACTIONS) logSurface(this,
7019 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7020 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7021 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 }
7023 Surface.openTransaction();
7024 try {
7025 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007026 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007027 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007028 mSurface.setPosition(mSurfaceX, mSurfaceY);
7029 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007031 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007032 mSurface.hide();
7033 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007034 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 mSurface.setFlags(Surface.SURFACE_DITHER,
7036 Surface.SURFACE_DITHER);
7037 }
7038 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007039 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007040 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7041 }
7042 mLastHidden = true;
7043 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007044 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 Surface.closeTransaction();
7046 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007047 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048 TAG, "Created surface " + this);
7049 }
7050 return mSurface;
7051 }
Romain Guy06882f82009-06-10 13:36:04 -07007052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007053 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 if (mAppToken != null && this == mAppToken.startingWindow) {
7055 mAppToken.startingDisplayed = false;
7056 }
Romain Guy06882f82009-06-10 13:36:04 -07007057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007058 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007059 mDrawPending = false;
7060 mCommitDrawPending = false;
7061 mReadyToShow = false;
7062
7063 int i = mChildWindows.size();
7064 while (i > 0) {
7065 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007066 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007067 c.mAttachedHidden = true;
7068 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007069
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007070 if (mReportDestroySurface) {
7071 mReportDestroySurface = false;
7072 mSurfacePendingDestroy = true;
7073 try {
7074 mClient.dispatchGetNewSurface();
7075 // We'll really destroy on the next time around.
7076 return;
7077 } catch (RemoteException e) {
7078 }
7079 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007082 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007083 RuntimeException e = null;
7084 if (!HIDE_STACK_CRAWLS) {
7085 e = new RuntimeException();
7086 e.fillInStackTrace();
7087 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007088 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007089 + mSurface + ", session " + mSession, e);
7090 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007092 RuntimeException e = null;
7093 if (!HIDE_STACK_CRAWLS) {
7094 e = new RuntimeException();
7095 e.fillInStackTrace();
7096 }
7097 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007098 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007099 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007100 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007101 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 + " surface " + mSurface + " session " + mSession
7103 + ": " + e.toString());
7104 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007105
Dianne Hackborn16064f92010-03-25 00:47:24 -07007106 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007107 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 }
7109 }
7110
7111 boolean finishDrawingLocked() {
7112 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007113 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007114 TAG, "finishDrawingLocked: " + mSurface);
7115 mCommitDrawPending = true;
7116 mDrawPending = false;
7117 return true;
7118 }
7119 return false;
7120 }
7121
7122 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007123 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007124 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007125 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007126 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007127 }
7128 mCommitDrawPending = false;
7129 mReadyToShow = true;
7130 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7131 final AppWindowToken atoken = mAppToken;
7132 if (atoken == null || atoken.allDrawn || starting) {
7133 performShowLocked();
7134 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007135 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 }
7137
7138 // This must be called while inside a transaction.
7139 boolean performShowLocked() {
7140 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007141 RuntimeException e = null;
7142 if (!HIDE_STACK_CRAWLS) {
7143 e = new RuntimeException();
7144 e.fillInStackTrace();
7145 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007146 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007147 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7148 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7149 }
7150 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007151 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7152 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007153 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154 + " during animation: policyVis=" + mPolicyVisibility
7155 + " attHidden=" + mAttachedHidden
7156 + " tok.hiddenRequested="
7157 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007158 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007159 + (mAppToken != null ? mAppToken.hidden : false)
7160 + " animating=" + mAnimating
7161 + " tok animating="
7162 + (mAppToken != null ? mAppToken.animating : false));
7163 if (!showSurfaceRobustlyLocked(this)) {
7164 return false;
7165 }
7166 mLastAlpha = -1;
7167 mHasDrawn = true;
7168 mLastHidden = false;
7169 mReadyToShow = false;
7170 enableScreenIfNeededLocked();
7171
7172 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007174 int i = mChildWindows.size();
7175 while (i > 0) {
7176 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007177 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007178 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007180 if (c.mSurface != null) {
7181 c.performShowLocked();
7182 // It hadn't been shown, which means layout not
7183 // performed on it, so now we want to make sure to
7184 // do a layout. If called from within the transaction
7185 // loop, this will cause it to restart with a new
7186 // layout.
7187 mLayoutNeeded = true;
7188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 }
7190 }
Romain Guy06882f82009-06-10 13:36:04 -07007191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 if (mAttrs.type != TYPE_APPLICATION_STARTING
7193 && mAppToken != null) {
7194 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007195
Dianne Hackborn248b1882009-09-16 16:46:44 -07007196 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007197 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007198 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007200 // If this initial window is animating, stop it -- we
7201 // will do an animation to reveal it from behind the
7202 // starting window, so there is no need for it to also
7203 // be doing its own stuff.
7204 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007205 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007206 mAnimation = null;
7207 // Make sure we clean up the animation.
7208 mAnimating = true;
7209 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 mFinishedStarting.add(mAppToken);
7211 mH.sendEmptyMessage(H.FINISHED_STARTING);
7212 }
7213 mAppToken.updateReportedVisibilityLocked();
7214 }
7215 }
7216 return true;
7217 }
Romain Guy06882f82009-06-10 13:36:04 -07007218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007219 // This must be called while inside a transaction. Returns true if
7220 // there is more animation to run.
7221 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007222 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7226 mHasTransformation = true;
7227 mHasLocalTransformation = true;
7228 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007229 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007230 TAG, "Starting animation in " + this +
7231 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7232 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7233 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7234 mAnimation.setStartTime(currentTime);
7235 mLocalAnimating = true;
7236 mAnimating = true;
7237 }
7238 mTransformation.clear();
7239 final boolean more = mAnimation.getTransformation(
7240 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007241 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007242 TAG, "Stepped animation in " + this +
7243 ": more=" + more + ", xform=" + mTransformation);
7244 if (more) {
7245 // we're not done!
7246 return true;
7247 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007248 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007249 TAG, "Finished animation in " + this +
7250 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007251
7252 if (mAnimation != null) {
7253 mAnimation.cancel();
7254 mAnimation = null;
7255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007256 //WindowManagerService.this.dump();
7257 }
7258 mHasLocalTransformation = false;
7259 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007260 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 // When our app token is animating, we kind-of pretend like
7262 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7263 // part of this check means that we will only do this if
7264 // our window is not currently exiting, or it is not
7265 // locally animating itself. The idea being that one that
7266 // is exiting and doing a local animation should be removed
7267 // once that animation is done.
7268 mAnimating = true;
7269 mHasTransformation = true;
7270 mTransformation.clear();
7271 return false;
7272 } else if (mHasTransformation) {
7273 // Little trick to get through the path below to act like
7274 // we have finished an animation.
7275 mAnimating = true;
7276 } else if (isAnimating()) {
7277 mAnimating = true;
7278 }
7279 } else if (mAnimation != null) {
7280 // If the display is frozen, and there is a pending animation,
7281 // clear it and make sure we run the cleanup code.
7282 mAnimating = true;
7283 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007284 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007285 mAnimation = null;
7286 }
Romain Guy06882f82009-06-10 13:36:04 -07007287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007288 if (!mAnimating && !mLocalAnimating) {
7289 return false;
7290 }
7291
Joe Onorato8a9b2202010-02-26 18:56:32 -08007292 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 TAG, "Animation done in " + this + ": exiting=" + mExiting
7294 + ", reportedVisible="
7295 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007297 mAnimating = false;
7298 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007299 if (mAnimation != null) {
7300 mAnimation.cancel();
7301 mAnimation = null;
7302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007303 mAnimLayer = mLayer;
7304 if (mIsImWindow) {
7305 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007306 } else if (mIsWallpaper) {
7307 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007308 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007309 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 + " anim layer: " + mAnimLayer);
7311 mHasTransformation = false;
7312 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007313 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7314 if (DEBUG_VISIBILITY) {
7315 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7316 + mPolicyVisibilityAfterAnim);
7317 }
7318 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7319 if (!mPolicyVisibility) {
7320 if (mCurrentFocus == this) {
7321 mFocusMayChange = true;
7322 }
7323 // Window is no longer visible -- make sure if we were waiting
7324 // for it to be displayed before enabling the display, that
7325 // we allow the display to be enabled now.
7326 enableScreenIfNeededLocked();
7327 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 mTransformation.clear();
7330 if (mHasDrawn
7331 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7332 && mAppToken != null
7333 && mAppToken.firstWindowDrawn
7334 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007335 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 + mToken + ": first real window done animating");
7337 mFinishedStarting.add(mAppToken);
7338 mH.sendEmptyMessage(H.FINISHED_STARTING);
7339 }
Romain Guy06882f82009-06-10 13:36:04 -07007340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007341 finishExit();
7342
7343 if (mAppToken != null) {
7344 mAppToken.updateReportedVisibilityLocked();
7345 }
7346
7347 return false;
7348 }
7349
7350 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007351 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 TAG, "finishExit in " + this
7353 + ": exiting=" + mExiting
7354 + " remove=" + mRemoveOnExit
7355 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007357 final int N = mChildWindows.size();
7358 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007359 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 }
Romain Guy06882f82009-06-10 13:36:04 -07007361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 if (!mExiting) {
7363 return;
7364 }
Romain Guy06882f82009-06-10 13:36:04 -07007365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 if (isWindowAnimating()) {
7367 return;
7368 }
7369
Joe Onorato8a9b2202010-02-26 18:56:32 -08007370 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007371 TAG, "Exit animation finished in " + this
7372 + ": remove=" + mRemoveOnExit);
7373 if (mSurface != null) {
7374 mDestroySurface.add(this);
7375 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007376 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007377 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 try {
7379 mSurface.hide();
7380 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007381 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 }
7383 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007384 }
7385 mExiting = false;
7386 if (mRemoveOnExit) {
7387 mPendingRemove.add(this);
7388 mRemoveOnExit = false;
7389 }
7390 }
Romain Guy06882f82009-06-10 13:36:04 -07007391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7393 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7394 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7395 if (dtdx < -.000001f || dtdx > .000001f) return false;
7396 if (dsdy < -.000001f || dsdy > .000001f) return false;
7397 return true;
7398 }
Romain Guy06882f82009-06-10 13:36:04 -07007399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 void computeShownFrameLocked() {
7401 final boolean selfTransformation = mHasLocalTransformation;
7402 Transformation attachedTransformation =
7403 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7404 ? mAttachedWindow.mTransformation : null;
7405 Transformation appTransformation =
7406 (mAppToken != null && mAppToken.hasTransformation)
7407 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007408
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007409 // Wallpapers are animated based on the "real" window they
7410 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007411 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007412 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007413 if (mWallpaperTarget.mHasLocalTransformation &&
7414 mWallpaperTarget.mAnimation != null &&
7415 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007416 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007417 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007418 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007419 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007420 }
7421 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007422 mWallpaperTarget.mAppToken.hasTransformation &&
7423 mWallpaperTarget.mAppToken.animation != null &&
7424 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007425 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007426 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007427 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007428 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007429 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 if (selfTransformation || attachedTransformation != null
7433 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007434 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 final Rect frame = mFrame;
7436 final float tmpFloats[] = mTmpFloats;
7437 final Matrix tmpMatrix = mTmpMatrix;
7438
7439 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007440 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007442 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007444 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007446 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 }
7448 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007449 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 }
7451
7452 // "convert" it into SurfaceFlinger's format
7453 // (a 2x2 matrix + an offset)
7454 // Here we must not transform the position of the surface
7455 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007456 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007458 tmpMatrix.getValues(tmpFloats);
7459 mDsDx = tmpFloats[Matrix.MSCALE_X];
7460 mDtDx = tmpFloats[Matrix.MSKEW_X];
7461 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7462 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007463 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7464 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 int w = frame.width();
7466 int h = frame.height();
7467 mShownFrame.set(x, y, x+w, y+h);
7468
7469 // Now set the alpha... but because our current hardware
7470 // can't do alpha transformation on a non-opaque surface,
7471 // turn it off if we are running an animation that is also
7472 // transforming since it is more important to have that
7473 // animation be smooth.
7474 mShownAlpha = mAlpha;
7475 if (!mLimitedAlphaCompositing
7476 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7477 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7478 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007479 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 if (selfTransformation) {
7481 mShownAlpha *= mTransformation.getAlpha();
7482 }
7483 if (attachedTransformation != null) {
7484 mShownAlpha *= attachedTransformation.getAlpha();
7485 }
7486 if (appTransformation != null) {
7487 mShownAlpha *= appTransformation.getAlpha();
7488 }
7489 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007490 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 }
Romain Guy06882f82009-06-10 13:36:04 -07007492
Joe Onorato8a9b2202010-02-26 18:56:32 -08007493 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 TAG, "Continuing animation in " + this +
7495 ": " + mShownFrame +
7496 ", alpha=" + mTransformation.getAlpha());
7497 return;
7498 }
Romain Guy06882f82009-06-10 13:36:04 -07007499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007501 if (mXOffset != 0 || mYOffset != 0) {
7502 mShownFrame.offset(mXOffset, mYOffset);
7503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 mShownAlpha = mAlpha;
7505 mDsDx = 1;
7506 mDtDx = 0;
7507 mDsDy = 0;
7508 mDtDy = 1;
7509 }
Romain Guy06882f82009-06-10 13:36:04 -07007510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 /**
7512 * Is this window visible? It is not visible if there is no
7513 * surface, or we are in the process of running an exit animation
7514 * that will remove the surface, or its app token has been hidden.
7515 */
7516 public boolean isVisibleLw() {
7517 final AppWindowToken atoken = mAppToken;
7518 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7519 && (atoken == null || !atoken.hiddenRequested)
7520 && !mExiting && !mDestroying;
7521 }
7522
7523 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007524 * Like {@link #isVisibleLw}, but also counts a window that is currently
7525 * "hidden" behind the keyguard as visible. This allows us to apply
7526 * things like window flags that impact the keyguard.
7527 * XXX I am starting to think we need to have ANOTHER visibility flag
7528 * for this "hidden behind keyguard" state rather than overloading
7529 * mPolicyVisibility. Ungh.
7530 */
7531 public boolean isVisibleOrBehindKeyguardLw() {
7532 final AppWindowToken atoken = mAppToken;
7533 return mSurface != null && !mAttachedHidden
7534 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007535 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007536 && !mExiting && !mDestroying;
7537 }
7538
7539 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 * Is this window visible, ignoring its app token? It is not visible
7541 * if there is no surface, or we are in the process of running an exit animation
7542 * that will remove the surface.
7543 */
7544 public boolean isWinVisibleLw() {
7545 final AppWindowToken atoken = mAppToken;
7546 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7547 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7548 && !mExiting && !mDestroying;
7549 }
7550
7551 /**
7552 * The same as isVisible(), but follows the current hidden state of
7553 * the associated app token, not the pending requested hidden state.
7554 */
7555 boolean isVisibleNow() {
7556 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007557 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 }
7559
7560 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007561 * Can this window possibly be a drag/drop target? The test here is
7562 * a combination of the above "visible now" with the check that the
7563 * Input Manager uses when discarding windows from input consideration.
7564 */
7565 boolean isPotentialDragTarget() {
7566 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7567 }
7568
7569 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007570 * Same as isVisible(), but we also count it as visible between the
7571 * call to IWindowSession.add() and the first relayout().
7572 */
7573 boolean isVisibleOrAdding() {
7574 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007575 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7577 && mPolicyVisibility && !mAttachedHidden
7578 && (atoken == null || !atoken.hiddenRequested)
7579 && !mExiting && !mDestroying;
7580 }
7581
7582 /**
7583 * Is this window currently on-screen? It is on-screen either if it
7584 * is visible or it is currently running an animation before no longer
7585 * being visible.
7586 */
7587 boolean isOnScreen() {
7588 final AppWindowToken atoken = mAppToken;
7589 if (atoken != null) {
7590 return mSurface != null && mPolicyVisibility && !mDestroying
7591 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007592 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 } else {
7594 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007595 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 }
7597 }
Romain Guy06882f82009-06-10 13:36:04 -07007598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 /**
7600 * Like isOnScreen(), but we don't return true if the window is part
7601 * of a transition that has not yet been started.
7602 */
7603 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007604 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007605 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007606 return false;
7607 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007608 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007609 final boolean animating = atoken != null
7610 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007612 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7613 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007614 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007615 }
7616
7617 /** Is the window or its container currently animating? */
7618 boolean isAnimating() {
7619 final WindowState attached = mAttachedWindow;
7620 final AppWindowToken atoken = mAppToken;
7621 return mAnimation != null
7622 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007623 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007624 (atoken.animation != null
7625 || atoken.inPendingTransaction));
7626 }
7627
7628 /** Is this window currently animating? */
7629 boolean isWindowAnimating() {
7630 return mAnimation != null;
7631 }
7632
7633 /**
7634 * Like isOnScreen, but returns false if the surface hasn't yet
7635 * been drawn.
7636 */
7637 public boolean isDisplayedLw() {
7638 final AppWindowToken atoken = mAppToken;
7639 return mSurface != null && mPolicyVisibility && !mDestroying
7640 && !mDrawPending && !mCommitDrawPending
7641 && ((!mAttachedHidden &&
7642 (atoken == null || !atoken.hiddenRequested))
7643 || mAnimating);
7644 }
7645
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007646 /**
7647 * Returns true if the window has a surface that it has drawn a
7648 * complete UI in to.
7649 */
7650 public boolean isDrawnLw() {
7651 final AppWindowToken atoken = mAppToken;
7652 return mSurface != null && !mDestroying
7653 && !mDrawPending && !mCommitDrawPending;
7654 }
7655
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007656 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007657 * Return true if the window is opaque and fully drawn. This indicates
7658 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007659 */
7660 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007661 return (mAttrs.format == PixelFormat.OPAQUE
7662 || mAttrs.type == TYPE_WALLPAPER)
7663 && mSurface != null && mAnimation == null
7664 && (mAppToken == null || mAppToken.animation == null)
7665 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007666 }
7667
7668 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7669 return
7670 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007671 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7672 // only if it's visible
7673 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007674 // and only if the application fills the compatible screen
7675 mFrame.left <= mCompatibleScreenFrame.left &&
7676 mFrame.top <= mCompatibleScreenFrame.top &&
7677 mFrame.right >= mCompatibleScreenFrame.right &&
7678 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007679 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007680 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007681 }
7682
7683 boolean isFullscreen(int screenWidth, int screenHeight) {
7684 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007685 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 }
7687
7688 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007689 disposeInputChannel();
7690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007691 if (mAttachedWindow != null) {
7692 mAttachedWindow.mChildWindows.remove(this);
7693 }
7694 destroySurfaceLocked();
7695 mSession.windowRemovedLocked();
7696 try {
7697 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7698 } catch (RuntimeException e) {
7699 // Ignore if it has already been removed (usually because
7700 // we are doing this as part of processing a death note.)
7701 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007702 }
7703
7704 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007705 if (mInputChannel != null) {
7706 mInputManager.unregisterInputChannel(mInputChannel);
7707
7708 mInputChannel.dispose();
7709 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007711 }
7712
7713 private class DeathRecipient implements IBinder.DeathRecipient {
7714 public void binderDied() {
7715 try {
7716 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007717 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007718 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 if (win != null) {
7720 removeWindowLocked(mSession, win);
7721 }
7722 }
7723 } catch (IllegalArgumentException ex) {
7724 // This will happen if the window has already been
7725 // removed.
7726 }
7727 }
7728 }
7729
7730 /** Returns true if this window desires key events. */
7731 public final boolean canReceiveKeys() {
7732 return isVisibleOrAdding()
7733 && (mViewVisibility == View.VISIBLE)
7734 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7735 }
7736
7737 public boolean hasDrawnLw() {
7738 return mHasDrawn;
7739 }
7740
7741 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007742 return showLw(doAnimation, true);
7743 }
7744
7745 boolean showLw(boolean doAnimation, boolean requestAnim) {
7746 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7747 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007749 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007750 if (doAnimation) {
7751 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7752 + mPolicyVisibility + " mAnimation=" + mAnimation);
7753 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7754 doAnimation = false;
7755 } else if (mPolicyVisibility && mAnimation == null) {
7756 // Check for the case where we are currently visible and
7757 // not animating; we do not want to do animation at such a
7758 // point to become visible when we already are.
7759 doAnimation = false;
7760 }
7761 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007762 mPolicyVisibility = true;
7763 mPolicyVisibilityAfterAnim = true;
7764 if (doAnimation) {
7765 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7766 }
7767 if (requestAnim) {
7768 requestAnimationLocked(0);
7769 }
7770 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007771 }
7772
7773 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007774 return hideLw(doAnimation, true);
7775 }
7776
7777 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007778 if (doAnimation) {
7779 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7780 doAnimation = false;
7781 }
7782 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7784 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007785 if (!current) {
7786 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007788 if (doAnimation) {
7789 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7790 if (mAnimation == null) {
7791 doAnimation = false;
7792 }
7793 }
7794 if (doAnimation) {
7795 mPolicyVisibilityAfterAnim = false;
7796 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007797 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007798 mPolicyVisibilityAfterAnim = false;
7799 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007800 // Window is no longer visible -- make sure if we were waiting
7801 // for it to be displayed before enabling the display, that
7802 // we allow the display to be enabled now.
7803 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007804 if (mCurrentFocus == this) {
7805 mFocusMayChange = true;
7806 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007807 }
7808 if (requestAnim) {
7809 requestAnimationLocked(0);
7810 }
7811 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007812 }
7813
7814 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007815 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7816 pw.print(" mClient="); pw.println(mClient.asBinder());
7817 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7818 if (mAttachedWindow != null || mLayoutAttached) {
7819 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7820 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7821 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007822 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7823 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7824 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007825 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7826 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007827 }
7828 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7829 pw.print(" mSubLayer="); pw.print(mSubLayer);
7830 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7831 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7832 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7833 pw.print("="); pw.print(mAnimLayer);
7834 pw.print(" mLastLayer="); pw.println(mLastLayer);
7835 if (mSurface != null) {
7836 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007837 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7838 pw.print(" layer="); pw.print(mSurfaceLayer);
7839 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7840 pw.print(" rect=("); pw.print(mSurfaceX);
7841 pw.print(","); pw.print(mSurfaceY);
7842 pw.print(") "); pw.print(mSurfaceW);
7843 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007844 }
7845 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7846 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7847 if (mAppToken != null) {
7848 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7849 }
7850 if (mTargetAppToken != null) {
7851 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7852 }
7853 pw.print(prefix); pw.print("mViewVisibility=0x");
7854 pw.print(Integer.toHexString(mViewVisibility));
7855 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007856 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7857 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007858 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7859 pw.print(prefix); pw.print("mPolicyVisibility=");
7860 pw.print(mPolicyVisibility);
7861 pw.print(" mPolicyVisibilityAfterAnim=");
7862 pw.print(mPolicyVisibilityAfterAnim);
7863 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7864 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007865 if (!mRelayoutCalled) {
7866 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7867 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007868 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007869 pw.print(" h="); pw.print(mRequestedHeight);
7870 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007871 if (mXOffset != 0 || mYOffset != 0) {
7872 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7873 pw.print(" y="); pw.println(mYOffset);
7874 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007875 pw.print(prefix); pw.print("mGivenContentInsets=");
7876 mGivenContentInsets.printShortString(pw);
7877 pw.print(" mGivenVisibleInsets=");
7878 mGivenVisibleInsets.printShortString(pw);
7879 pw.println();
7880 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7881 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7882 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7883 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007884 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007885 pw.print(prefix); pw.print("mShownFrame=");
7886 mShownFrame.printShortString(pw);
7887 pw.print(" last="); mLastShownFrame.printShortString(pw);
7888 pw.println();
7889 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7890 pw.print(" last="); mLastFrame.printShortString(pw);
7891 pw.println();
7892 pw.print(prefix); pw.print("mContainingFrame=");
7893 mContainingFrame.printShortString(pw);
7894 pw.print(" mDisplayFrame=");
7895 mDisplayFrame.printShortString(pw);
7896 pw.println();
7897 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7898 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7899 pw.println();
7900 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7901 pw.print(" last="); mLastContentInsets.printShortString(pw);
7902 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7903 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7904 pw.println();
7905 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7906 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7907 pw.print(" mAlpha="); pw.print(mAlpha);
7908 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7909 }
7910 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7911 || mAnimation != null) {
7912 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7913 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7914 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7915 pw.print(" mAnimation="); pw.println(mAnimation);
7916 }
7917 if (mHasTransformation || mHasLocalTransformation) {
7918 pw.print(prefix); pw.print("XForm: has=");
7919 pw.print(mHasTransformation);
7920 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7921 pw.print(" "); mTransformation.printShortString(pw);
7922 pw.println();
7923 }
7924 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7925 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7926 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7927 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7928 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7929 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7930 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7931 pw.print(" mDestroying="); pw.print(mDestroying);
7932 pw.print(" mRemoved="); pw.println(mRemoved);
7933 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007934 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007935 pw.print(prefix); pw.print("mOrientationChanging=");
7936 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007937 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7938 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007939 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007940 if (mHScale != 1 || mVScale != 1) {
7941 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7942 pw.print(" mVScale="); pw.println(mVScale);
7943 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007944 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007945 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7946 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7947 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007948 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7949 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7950 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007952 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007953
7954 String makeInputChannelName() {
7955 return Integer.toHexString(System.identityHashCode(this))
7956 + " " + mAttrs.getTitle();
7957 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007958
7959 @Override
7960 public String toString() {
7961 return "Window{"
7962 + Integer.toHexString(System.identityHashCode(this))
7963 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7964 }
7965 }
Romain Guy06882f82009-06-10 13:36:04 -07007966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007967 // -------------------------------------------------------------
7968 // Window Token State
7969 // -------------------------------------------------------------
7970
7971 class WindowToken {
7972 // The actual token.
7973 final IBinder token;
7974
7975 // The type of window this token is for, as per WindowManager.LayoutParams.
7976 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007978 // Set if this token was explicitly added by a client, so should
7979 // not be removed when all windows are removed.
7980 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007981
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007982 // For printing.
7983 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007985 // If this is an AppWindowToken, this is non-null.
7986 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 // All of the windows associated with this token.
7989 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7990
7991 // Is key dispatching paused for this token?
7992 boolean paused = false;
7993
7994 // Should this token's windows be hidden?
7995 boolean hidden;
7996
7997 // Temporary for finding which tokens no longer have visible windows.
7998 boolean hasVisible;
7999
Dianne Hackborna8f60182009-09-01 19:01:50 -07008000 // Set to true when this token is in a pending transaction where it
8001 // will be shown.
8002 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008003
Dianne Hackborna8f60182009-09-01 19:01:50 -07008004 // Set to true when this token is in a pending transaction where it
8005 // will be hidden.
8006 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008007
Dianne Hackborna8f60182009-09-01 19:01:50 -07008008 // Set to true when this token is in a pending transaction where its
8009 // windows will be put to the bottom of the list.
8010 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008011
Dianne Hackborna8f60182009-09-01 19:01:50 -07008012 // Set to true when this token is in a pending transaction where its
8013 // windows will be put to the top of the list.
8014 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 WindowToken(IBinder _token, int type, boolean _explicit) {
8017 token = _token;
8018 windowType = type;
8019 explicit = _explicit;
8020 }
8021
8022 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008023 pw.print(prefix); pw.print("token="); pw.println(token);
8024 pw.print(prefix); pw.print("windows="); pw.println(windows);
8025 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8026 pw.print(" hidden="); pw.print(hidden);
8027 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008028 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8029 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8030 pw.print(" waitingToHide="); pw.print(waitingToHide);
8031 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8032 pw.print(" sendingToTop="); pw.println(sendingToTop);
8033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 }
8035
8036 @Override
8037 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008038 if (stringName == null) {
8039 StringBuilder sb = new StringBuilder();
8040 sb.append("WindowToken{");
8041 sb.append(Integer.toHexString(System.identityHashCode(this)));
8042 sb.append(" token="); sb.append(token); sb.append('}');
8043 stringName = sb.toString();
8044 }
8045 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 }
8047 };
8048
8049 class AppWindowToken extends WindowToken {
8050 // Non-null only for application tokens.
8051 final IApplicationToken appToken;
8052
8053 // All of the windows and child windows that are included in this
8054 // application token. Note this list is NOT sorted!
8055 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8056
8057 int groupId = -1;
8058 boolean appFullscreen;
8059 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008060
8061 // The input dispatching timeout for this application token in nanoseconds.
8062 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008064 // These are used for determining when all windows associated with
8065 // an activity have been drawn, so they can be made visible together
8066 // at the same time.
8067 int lastTransactionSequence = mTransactionSequence-1;
8068 int numInterestingWindows;
8069 int numDrawnWindows;
8070 boolean inPendingTransaction;
8071 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008073 // Is this token going to be hidden in a little while? If so, it
8074 // won't be taken into account for setting the screen orientation.
8075 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008077 // Is this window's surface needed? This is almost like hidden, except
8078 // it will sometimes be true a little earlier: when the token has
8079 // been shown, but is still waiting for its app transition to execute
8080 // before making its windows shown.
8081 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008083 // Have we told the window clients to hide themselves?
8084 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008086 // Last visibility state we reported to the app token.
8087 boolean reportedVisible;
8088
8089 // Set to true when the token has been removed from the window mgr.
8090 boolean removed;
8091
8092 // Have we been asked to have this token keep the screen frozen?
8093 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 boolean animating;
8096 Animation animation;
8097 boolean hasTransformation;
8098 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008100 // Offset to the window of all layers in the token, for use by
8101 // AppWindowToken animations.
8102 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008104 // Information about an application starting window if displayed.
8105 StartingData startingData;
8106 WindowState startingWindow;
8107 View startingView;
8108 boolean startingDisplayed;
8109 boolean startingMoved;
8110 boolean firstWindowDrawn;
8111
8112 AppWindowToken(IApplicationToken _token) {
8113 super(_token.asBinder(),
8114 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8115 appWindowToken = this;
8116 appToken = _token;
8117 }
Romain Guy06882f82009-06-10 13:36:04 -07008118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008120 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 TAG, "Setting animation in " + this + ": " + anim);
8122 animation = anim;
8123 animating = false;
8124 anim.restrictDuration(MAX_ANIMATION_DURATION);
8125 anim.scaleCurrentDuration(mTransitionAnimationScale);
8126 int zorder = anim.getZAdjustment();
8127 int adj = 0;
8128 if (zorder == Animation.ZORDER_TOP) {
8129 adj = TYPE_LAYER_OFFSET;
8130 } else if (zorder == Animation.ZORDER_BOTTOM) {
8131 adj = -TYPE_LAYER_OFFSET;
8132 }
Romain Guy06882f82009-06-10 13:36:04 -07008133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 if (animLayerAdjustment != adj) {
8135 animLayerAdjustment = adj;
8136 updateLayers();
8137 }
8138 }
Romain Guy06882f82009-06-10 13:36:04 -07008139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 public void setDummyAnimation() {
8141 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008142 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008143 TAG, "Setting dummy animation in " + this);
8144 animation = sDummyAnimation;
8145 }
8146 }
8147
8148 public void clearAnimation() {
8149 if (animation != null) {
8150 animation = null;
8151 animating = true;
8152 }
8153 }
Romain Guy06882f82009-06-10 13:36:04 -07008154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008155 void updateLayers() {
8156 final int N = allAppWindows.size();
8157 final int adj = animLayerAdjustment;
8158 for (int i=0; i<N; i++) {
8159 WindowState w = allAppWindows.get(i);
8160 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008161 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 + w.mAnimLayer);
8163 if (w == mInputMethodTarget) {
8164 setInputMethodAnimLayerAdjustment(adj);
8165 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008166 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008167 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008169 }
8170 }
Romain Guy06882f82009-06-10 13:36:04 -07008171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008172 void sendAppVisibilityToClients() {
8173 final int N = allAppWindows.size();
8174 for (int i=0; i<N; i++) {
8175 WindowState win = allAppWindows.get(i);
8176 if (win == startingWindow && clientHidden) {
8177 // Don't hide the starting window.
8178 continue;
8179 }
8180 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008181 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008182 "Setting visibility of " + win + ": " + (!clientHidden));
8183 win.mClient.dispatchAppVisibility(!clientHidden);
8184 } catch (RemoteException e) {
8185 }
8186 }
8187 }
Romain Guy06882f82009-06-10 13:36:04 -07008188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 void showAllWindowsLocked() {
8190 final int NW = allAppWindows.size();
8191 for (int i=0; i<NW; i++) {
8192 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008193 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 "performing show on: " + w);
8195 w.performShowLocked();
8196 }
8197 }
Romain Guy06882f82009-06-10 13:36:04 -07008198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008199 // This must be called while inside a transaction.
8200 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008201 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008202 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008204 if (animation == sDummyAnimation) {
8205 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008206 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008207 // when it is really time to animate, this will be set to
8208 // a real animation and the next call will execute normally.
8209 return false;
8210 }
Romain Guy06882f82009-06-10 13:36:04 -07008211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8213 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008214 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008215 TAG, "Starting animation in " + this +
8216 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8217 + " scale=" + mTransitionAnimationScale
8218 + " allDrawn=" + allDrawn + " animating=" + animating);
8219 animation.initialize(dw, dh, dw, dh);
8220 animation.setStartTime(currentTime);
8221 animating = true;
8222 }
8223 transformation.clear();
8224 final boolean more = animation.getTransformation(
8225 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008226 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008227 TAG, "Stepped animation in " + this +
8228 ": more=" + more + ", xform=" + transformation);
8229 if (more) {
8230 // we're done!
8231 hasTransformation = true;
8232 return true;
8233 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008234 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008235 TAG, "Finished animation in " + this +
8236 " @ " + currentTime);
8237 animation = null;
8238 }
8239 } else if (animation != null) {
8240 // If the display is frozen, and there is a pending animation,
8241 // clear it and make sure we run the cleanup code.
8242 animating = true;
8243 animation = null;
8244 }
8245
8246 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008248 if (!animating) {
8249 return false;
8250 }
8251
8252 clearAnimation();
8253 animating = false;
8254 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8255 moveInputMethodWindowsIfNeededLocked(true);
8256 }
Romain Guy06882f82009-06-10 13:36:04 -07008257
Joe Onorato8a9b2202010-02-26 18:56:32 -08008258 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008259 TAG, "Animation done in " + this
8260 + ": reportedVisible=" + reportedVisible);
8261
8262 transformation.clear();
8263 if (animLayerAdjustment != 0) {
8264 animLayerAdjustment = 0;
8265 updateLayers();
8266 }
Romain Guy06882f82009-06-10 13:36:04 -07008267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 final int N = windows.size();
8269 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008270 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 }
8272 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008274 return false;
8275 }
8276
8277 void updateReportedVisibilityLocked() {
8278 if (appToken == null) {
8279 return;
8280 }
Romain Guy06882f82009-06-10 13:36:04 -07008281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008282 int numInteresting = 0;
8283 int numVisible = 0;
8284 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008285
Joe Onorato8a9b2202010-02-26 18:56:32 -08008286 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008287 final int N = allAppWindows.size();
8288 for (int i=0; i<N; i++) {
8289 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008290 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008291 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008292 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8293 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008294 continue;
8295 }
8296 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008297 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008298 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008299 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008300 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008301 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008302 + " pv=" + win.mPolicyVisibility
8303 + " dp=" + win.mDrawPending
8304 + " cdp=" + win.mCommitDrawPending
8305 + " ah=" + win.mAttachedHidden
8306 + " th="
8307 + (win.mAppToken != null
8308 ? win.mAppToken.hiddenRequested : false)
8309 + " a=" + win.mAnimating);
8310 }
8311 }
8312 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008313 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008314 if (!win.isAnimating()) {
8315 numVisible++;
8316 }
8317 nowGone = false;
8318 } else if (win.isAnimating()) {
8319 nowGone = false;
8320 }
8321 }
Romain Guy06882f82009-06-10 13:36:04 -07008322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008323 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008324 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008325 + numInteresting + " visible=" + numVisible);
8326 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008327 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 TAG, "Visibility changed in " + this
8329 + ": vis=" + nowVisible);
8330 reportedVisible = nowVisible;
8331 Message m = mH.obtainMessage(
8332 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8333 nowVisible ? 1 : 0,
8334 nowGone ? 1 : 0,
8335 this);
8336 mH.sendMessage(m);
8337 }
8338 }
Romain Guy06882f82009-06-10 13:36:04 -07008339
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008340 WindowState findMainWindow() {
8341 int j = windows.size();
8342 while (j > 0) {
8343 j--;
8344 WindowState win = windows.get(j);
8345 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8346 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8347 return win;
8348 }
8349 }
8350 return null;
8351 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 void dump(PrintWriter pw, String prefix) {
8354 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008355 if (appToken != null) {
8356 pw.print(prefix); pw.println("app=true");
8357 }
8358 if (allAppWindows.size() > 0) {
8359 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8360 }
8361 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008362 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008363 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8364 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8365 pw.print(" clientHidden="); pw.print(clientHidden);
8366 pw.print(" willBeHidden="); pw.print(willBeHidden);
8367 pw.print(" reportedVisible="); pw.println(reportedVisible);
8368 if (paused || freezingScreen) {
8369 pw.print(prefix); pw.print("paused="); pw.print(paused);
8370 pw.print(" freezingScreen="); pw.println(freezingScreen);
8371 }
8372 if (numInterestingWindows != 0 || numDrawnWindows != 0
8373 || inPendingTransaction || allDrawn) {
8374 pw.print(prefix); pw.print("numInterestingWindows=");
8375 pw.print(numInterestingWindows);
8376 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8377 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8378 pw.print(" allDrawn="); pw.println(allDrawn);
8379 }
8380 if (animating || animation != null) {
8381 pw.print(prefix); pw.print("animating="); pw.print(animating);
8382 pw.print(" animation="); pw.println(animation);
8383 }
8384 if (animLayerAdjustment != 0) {
8385 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8386 }
8387 if (hasTransformation) {
8388 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8389 pw.print(" transformation="); transformation.printShortString(pw);
8390 pw.println();
8391 }
8392 if (startingData != null || removed || firstWindowDrawn) {
8393 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8394 pw.print(" removed="); pw.print(removed);
8395 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8396 }
8397 if (startingWindow != null || startingView != null
8398 || startingDisplayed || startingMoved) {
8399 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8400 pw.print(" startingView="); pw.print(startingView);
8401 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8402 pw.print(" startingMoved"); pw.println(startingMoved);
8403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008404 }
8405
8406 @Override
8407 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008408 if (stringName == null) {
8409 StringBuilder sb = new StringBuilder();
8410 sb.append("AppWindowToken{");
8411 sb.append(Integer.toHexString(System.identityHashCode(this)));
8412 sb.append(" token="); sb.append(token); sb.append('}');
8413 stringName = sb.toString();
8414 }
8415 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008416 }
8417 }
Romain Guy06882f82009-06-10 13:36:04 -07008418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419 // -------------------------------------------------------------
8420 // DummyAnimation
8421 // -------------------------------------------------------------
8422
8423 // This is an animation that does nothing: it just immediately finishes
8424 // itself every time it is called. It is used as a stub animation in cases
8425 // where we want to synchronize multiple things that may be animating.
8426 static final class DummyAnimation extends Animation {
8427 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8428 return false;
8429 }
8430 }
8431 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 // -------------------------------------------------------------
8434 // Async Handler
8435 // -------------------------------------------------------------
8436
8437 static final class StartingData {
8438 final String pkg;
8439 final int theme;
8440 final CharSequence nonLocalizedLabel;
8441 final int labelRes;
8442 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008444 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8445 int _labelRes, int _icon) {
8446 pkg = _pkg;
8447 theme = _theme;
8448 nonLocalizedLabel = _nonLocalizedLabel;
8449 labelRes = _labelRes;
8450 icon = _icon;
8451 }
8452 }
8453
8454 private final class H extends Handler {
8455 public static final int REPORT_FOCUS_CHANGE = 2;
8456 public static final int REPORT_LOSING_FOCUS = 3;
8457 public static final int ANIMATE = 4;
8458 public static final int ADD_STARTING = 5;
8459 public static final int REMOVE_STARTING = 6;
8460 public static final int FINISHED_STARTING = 7;
8461 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8463 public static final int HOLD_SCREEN_CHANGED = 12;
8464 public static final int APP_TRANSITION_TIMEOUT = 13;
8465 public static final int PERSIST_ANIMATION_SCALE = 14;
8466 public static final int FORCE_GC = 15;
8467 public static final int ENABLE_SCREEN = 16;
8468 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008469 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008470 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008471 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008472 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008474 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008476 public H() {
8477 }
Romain Guy06882f82009-06-10 13:36:04 -07008478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 @Override
8480 public void handleMessage(Message msg) {
8481 switch (msg.what) {
8482 case REPORT_FOCUS_CHANGE: {
8483 WindowState lastFocus;
8484 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 synchronized(mWindowMap) {
8487 lastFocus = mLastFocus;
8488 newFocus = mCurrentFocus;
8489 if (lastFocus == newFocus) {
8490 // Focus is not changing, so nothing to do.
8491 return;
8492 }
8493 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008494 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008495 // + " to " + newFocus);
8496 if (newFocus != null && lastFocus != null
8497 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008498 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008499 mLosingFocus.add(lastFocus);
8500 lastFocus = null;
8501 }
8502 }
8503
8504 if (lastFocus != newFocus) {
8505 //System.out.println("Changing focus from " + lastFocus
8506 // + " to " + newFocus);
8507 if (newFocus != null) {
8508 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008509 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008510 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8511 } catch (RemoteException e) {
8512 // Ignore if process has died.
8513 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008514 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008515 }
8516
8517 if (lastFocus != null) {
8518 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008519 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8521 } catch (RemoteException e) {
8522 // Ignore if process has died.
8523 }
8524 }
8525 }
8526 } break;
8527
8528 case REPORT_LOSING_FOCUS: {
8529 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 synchronized(mWindowMap) {
8532 losers = mLosingFocus;
8533 mLosingFocus = new ArrayList<WindowState>();
8534 }
8535
8536 final int N = losers.size();
8537 for (int i=0; i<N; i++) {
8538 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008539 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8541 } catch (RemoteException e) {
8542 // Ignore if process has died.
8543 }
8544 }
8545 } break;
8546
8547 case ANIMATE: {
8548 synchronized(mWindowMap) {
8549 mAnimationPending = false;
8550 performLayoutAndPlaceSurfacesLocked();
8551 }
8552 } break;
8553
8554 case ADD_STARTING: {
8555 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8556 final StartingData sd = wtoken.startingData;
8557
8558 if (sd == null) {
8559 // Animation has been canceled... do nothing.
8560 return;
8561 }
Romain Guy06882f82009-06-10 13:36:04 -07008562
Joe Onorato8a9b2202010-02-26 18:56:32 -08008563 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008564 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 View view = null;
8567 try {
8568 view = mPolicy.addStartingWindow(
8569 wtoken.token, sd.pkg,
8570 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8571 sd.icon);
8572 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008573 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 }
8575
8576 if (view != null) {
8577 boolean abort = false;
8578
8579 synchronized(mWindowMap) {
8580 if (wtoken.removed || wtoken.startingData == null) {
8581 // If the window was successfully added, then
8582 // we need to remove it.
8583 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008584 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008585 "Aborted starting " + wtoken
8586 + ": removed=" + wtoken.removed
8587 + " startingData=" + wtoken.startingData);
8588 wtoken.startingWindow = null;
8589 wtoken.startingData = null;
8590 abort = true;
8591 }
8592 } else {
8593 wtoken.startingView = view;
8594 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008595 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 "Added starting " + wtoken
8597 + ": startingWindow="
8598 + wtoken.startingWindow + " startingView="
8599 + wtoken.startingView);
8600 }
8601
8602 if (abort) {
8603 try {
8604 mPolicy.removeStartingWindow(wtoken.token, view);
8605 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008606 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 }
8608 }
8609 }
8610 } break;
8611
8612 case REMOVE_STARTING: {
8613 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8614 IBinder token = null;
8615 View view = null;
8616 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008617 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 + wtoken + ": startingWindow="
8619 + wtoken.startingWindow + " startingView="
8620 + wtoken.startingView);
8621 if (wtoken.startingWindow != null) {
8622 view = wtoken.startingView;
8623 token = wtoken.token;
8624 wtoken.startingData = null;
8625 wtoken.startingView = null;
8626 wtoken.startingWindow = null;
8627 }
8628 }
8629 if (view != null) {
8630 try {
8631 mPolicy.removeStartingWindow(token, view);
8632 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008633 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008634 }
8635 }
8636 } break;
8637
8638 case FINISHED_STARTING: {
8639 IBinder token = null;
8640 View view = null;
8641 while (true) {
8642 synchronized (mWindowMap) {
8643 final int N = mFinishedStarting.size();
8644 if (N <= 0) {
8645 break;
8646 }
8647 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8648
Joe Onorato8a9b2202010-02-26 18:56:32 -08008649 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008650 "Finished starting " + wtoken
8651 + ": startingWindow=" + wtoken.startingWindow
8652 + " startingView=" + wtoken.startingView);
8653
8654 if (wtoken.startingWindow == null) {
8655 continue;
8656 }
8657
8658 view = wtoken.startingView;
8659 token = wtoken.token;
8660 wtoken.startingData = null;
8661 wtoken.startingView = null;
8662 wtoken.startingWindow = null;
8663 }
8664
8665 try {
8666 mPolicy.removeStartingWindow(token, view);
8667 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008668 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008669 }
8670 }
8671 } break;
8672
8673 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8674 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8675
8676 boolean nowVisible = msg.arg1 != 0;
8677 boolean nowGone = msg.arg2 != 0;
8678
8679 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008680 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 TAG, "Reporting visible in " + wtoken
8682 + " visible=" + nowVisible
8683 + " gone=" + nowGone);
8684 if (nowVisible) {
8685 wtoken.appToken.windowsVisible();
8686 } else {
8687 wtoken.appToken.windowsGone();
8688 }
8689 } catch (RemoteException ex) {
8690 }
8691 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 case WINDOW_FREEZE_TIMEOUT: {
8694 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008695 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 int i = mWindows.size();
8697 while (i > 0) {
8698 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008699 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008700 if (w.mOrientationChanging) {
8701 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008702 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008703 }
8704 }
8705 performLayoutAndPlaceSurfacesLocked();
8706 }
8707 break;
8708 }
Romain Guy06882f82009-06-10 13:36:04 -07008709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 case HOLD_SCREEN_CHANGED: {
8711 Session oldHold;
8712 Session newHold;
8713 synchronized (mWindowMap) {
8714 oldHold = mLastReportedHold;
8715 newHold = (Session)msg.obj;
8716 mLastReportedHold = newHold;
8717 }
Romain Guy06882f82009-06-10 13:36:04 -07008718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 if (oldHold != newHold) {
8720 try {
8721 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008722 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008723 "window",
8724 BatteryStats.WAKE_TYPE_WINDOW);
8725 }
8726 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008727 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 "window",
8729 BatteryStats.WAKE_TYPE_WINDOW);
8730 }
8731 } catch (RemoteException e) {
8732 }
8733 }
8734 break;
8735 }
Romain Guy06882f82009-06-10 13:36:04 -07008736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 case APP_TRANSITION_TIMEOUT: {
8738 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008739 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008740 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008741 "*** APP TRANSITION TIMEOUT");
8742 mAppTransitionReady = true;
8743 mAppTransitionTimeout = true;
8744 performLayoutAndPlaceSurfacesLocked();
8745 }
8746 }
8747 break;
8748 }
Romain Guy06882f82009-06-10 13:36:04 -07008749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008750 case PERSIST_ANIMATION_SCALE: {
8751 Settings.System.putFloat(mContext.getContentResolver(),
8752 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8753 Settings.System.putFloat(mContext.getContentResolver(),
8754 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8755 break;
8756 }
Romain Guy06882f82009-06-10 13:36:04 -07008757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 case FORCE_GC: {
8759 synchronized(mWindowMap) {
8760 if (mAnimationPending) {
8761 // If we are animating, don't do the gc now but
8762 // delay a bit so we don't interrupt the animation.
8763 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8764 2000);
8765 return;
8766 }
8767 // If we are currently rotating the display, it will
8768 // schedule a new message when done.
8769 if (mDisplayFrozen) {
8770 return;
8771 }
8772 mFreezeGcPending = 0;
8773 }
8774 Runtime.getRuntime().gc();
8775 break;
8776 }
Romain Guy06882f82009-06-10 13:36:04 -07008777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008778 case ENABLE_SCREEN: {
8779 performEnableScreen();
8780 break;
8781 }
Romain Guy06882f82009-06-10 13:36:04 -07008782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 case APP_FREEZE_TIMEOUT: {
8784 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008785 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 int i = mAppTokens.size();
8787 while (i > 0) {
8788 i--;
8789 AppWindowToken tok = mAppTokens.get(i);
8790 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008791 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 unsetAppFreezingScreenLocked(tok, true, true);
8793 }
8794 }
8795 }
8796 break;
8797 }
Romain Guy06882f82009-06-10 13:36:04 -07008798
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008799 case SEND_NEW_CONFIGURATION: {
8800 removeMessages(SEND_NEW_CONFIGURATION);
8801 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008802 break;
8803 }
Romain Guy06882f82009-06-10 13:36:04 -07008804
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008805 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008806 if (mWindowsChanged) {
8807 synchronized (mWindowMap) {
8808 mWindowsChanged = false;
8809 }
8810 notifyWindowsChanged();
8811 }
8812 break;
8813 }
8814
Christopher Tatea53146c2010-09-07 11:57:52 -07008815 case DRAG_START_TIMEOUT: {
8816 IBinder win = (IBinder)msg.obj;
8817 if (DEBUG_DRAG) {
8818 Slog.w(TAG, "Timeout starting drag by win " + win);
8819 }
8820 synchronized (mWindowMap) {
8821 // !!! TODO: ANR the app that has failed to start the drag in time
8822 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008823 mDragState.unregister();
8824 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008825 mDragState.reset();
8826 mDragState = null;
8827 }
8828 }
Chris Tated4533f142010-10-19 15:15:08 -07008829 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008830 }
8831
Chris Tated4533f142010-10-19 15:15:08 -07008832 case DRAG_END_TIMEOUT: {
8833 IBinder win = (IBinder)msg.obj;
8834 if (DEBUG_DRAG) {
8835 Slog.w(TAG, "Timeout ending drag to win " + win);
8836 }
8837 synchronized (mWindowMap) {
8838 // !!! TODO: ANR the drag-receiving app
8839 mDragState.mDragResult = false;
8840 mDragState.endDragLw();
8841 }
8842 break;
8843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008844 }
8845 }
8846 }
8847
8848 // -------------------------------------------------------------
8849 // IWindowManager API
8850 // -------------------------------------------------------------
8851
8852 public IWindowSession openSession(IInputMethodClient client,
8853 IInputContext inputContext) {
8854 if (client == null) throw new IllegalArgumentException("null client");
8855 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008856 Session session = new Session(client, inputContext);
8857 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008858 }
8859
8860 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8861 synchronized (mWindowMap) {
8862 // The focus for the client is the window immediately below
8863 // where we would place the input method window.
8864 int idx = findDesiredInputMethodWindowIndexLocked(false);
8865 WindowState imFocus;
8866 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008867 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 if (imFocus != null) {
8869 if (imFocus.mSession.mClient != null &&
8870 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8871 return true;
8872 }
8873 }
8874 }
8875 }
8876 return false;
8877 }
Romain Guy06882f82009-06-10 13:36:04 -07008878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008879 // -------------------------------------------------------------
8880 // Internals
8881 // -------------------------------------------------------------
8882
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008883 final WindowState windowForClientLocked(Session session, IWindow client,
8884 boolean throwOnError) {
8885 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008886 }
Romain Guy06882f82009-06-10 13:36:04 -07008887
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008888 final WindowState windowForClientLocked(Session session, IBinder client,
8889 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008891 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008892 TAG, "Looking up client " + client + ": " + win);
8893 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008894 RuntimeException ex = new IllegalArgumentException(
8895 "Requested window " + client + " does not exist");
8896 if (throwOnError) {
8897 throw ex;
8898 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 return null;
8901 }
8902 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008903 RuntimeException ex = new IllegalArgumentException(
8904 "Requested window " + client + " is in session " +
8905 win.mSession + ", not " + session);
8906 if (throwOnError) {
8907 throw ex;
8908 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008909 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 return null;
8911 }
8912
8913 return win;
8914 }
8915
Dianne Hackborna8f60182009-09-01 19:01:50 -07008916 final void rebuildAppWindowListLocked() {
8917 int NW = mWindows.size();
8918 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008919 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008920 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008921
Dianne Hackborna8f60182009-09-01 19:01:50 -07008922 // First remove all existing app windows.
8923 i=0;
8924 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008925 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008926 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008927 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008928 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008929 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008930 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008931 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008932 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008933 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008934 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8935 && lastWallpaper == i-1) {
8936 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008937 }
8938 i++;
8939 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008940
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008941 // The wallpaper window(s) typically live at the bottom of the stack,
8942 // so skip them before adding app tokens.
8943 lastWallpaper++;
8944 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008945
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008946 // First add all of the exiting app tokens... these are no longer
8947 // in the main app list, but still have windows shown. We put them
8948 // in the back because now that the animation is over we no longer
8949 // will care about them.
8950 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008951 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008952 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8953 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008954
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008955 // And add in the still active app tokens in Z order.
8956 NT = mAppTokens.size();
8957 for (int j=0; j<NT; j++) {
8958 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008959 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008960
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008961 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008962 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008963 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008964 + " windows but added " + i);
8965 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008966 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008968 private final void assignLayersLocked() {
8969 int N = mWindows.size();
8970 int curBaseLayer = 0;
8971 int curLayer = 0;
8972 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008973
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08008974 if (DEBUG_LAYERS) {
8975 RuntimeException here = new RuntimeException("here");
8976 here.fillInStackTrace();
8977 Log.v(TAG, "Assigning layers", here);
8978 }
8979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008980 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008981 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008982 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8983 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 curLayer += WINDOW_LAYER_MULTIPLIER;
8985 w.mLayer = curLayer;
8986 } else {
8987 curBaseLayer = curLayer = w.mBaseLayer;
8988 w.mLayer = curLayer;
8989 }
8990 if (w.mTargetAppToken != null) {
8991 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8992 } else if (w.mAppToken != null) {
8993 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8994 } else {
8995 w.mAnimLayer = w.mLayer;
8996 }
8997 if (w.mIsImWindow) {
8998 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008999 } else if (w.mIsWallpaper) {
9000 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009002 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009003 + w.mAnimLayer);
9004 //System.out.println(
9005 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9006 }
9007 }
9008
9009 private boolean mInLayout = false;
9010 private final void performLayoutAndPlaceSurfacesLocked() {
9011 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009012 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009013 throw new RuntimeException("Recursive call!");
9014 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009015 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009016 return;
9017 }
9018
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009019 if (mWaitingForConfig) {
9020 // Our configuration has changed (most likely rotation), but we
9021 // don't yet have the complete configuration to report to
9022 // applications. Don't do any window layout until we have it.
9023 return;
9024 }
9025
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009026 if (mDisplay == null) {
9027 // Not yet initialized, nothing to do.
9028 return;
9029 }
9030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009031 boolean recoveringMemory = false;
9032 if (mForceRemoves != null) {
9033 recoveringMemory = true;
9034 // Wait a little it for things to settle down, and off we go.
9035 for (int i=0; i<mForceRemoves.size(); i++) {
9036 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009037 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009038 removeWindowInnerLocked(ws.mSession, ws);
9039 }
9040 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009041 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009042 Object tmp = new Object();
9043 synchronized (tmp) {
9044 try {
9045 tmp.wait(250);
9046 } catch (InterruptedException e) {
9047 }
9048 }
9049 }
Romain Guy06882f82009-06-10 13:36:04 -07009050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009051 mInLayout = true;
9052 try {
9053 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009055 int i = mPendingRemove.size()-1;
9056 if (i >= 0) {
9057 while (i >= 0) {
9058 WindowState w = mPendingRemove.get(i);
9059 removeWindowInnerLocked(w.mSession, w);
9060 i--;
9061 }
9062 mPendingRemove.clear();
9063
9064 mInLayout = false;
9065 assignLayersLocked();
9066 mLayoutNeeded = true;
9067 performLayoutAndPlaceSurfacesLocked();
9068
9069 } else {
9070 mInLayout = false;
9071 if (mLayoutNeeded) {
9072 requestAnimationLocked(0);
9073 }
9074 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009075 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009076 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9077 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009078 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009079 } catch (RuntimeException e) {
9080 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009081 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009082 }
9083 }
9084
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009085 private final int performLayoutLockedInner() {
9086 if (!mLayoutNeeded) {
9087 return 0;
9088 }
9089
9090 mLayoutNeeded = false;
9091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009092 final int dw = mDisplay.getWidth();
9093 final int dh = mDisplay.getHeight();
9094
9095 final int N = mWindows.size();
9096 int i;
9097
Joe Onorato8a9b2202010-02-26 18:56:32 -08009098 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009099 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9100
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009101 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009102
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009103 int seq = mLayoutSeq+1;
9104 if (seq < 0) seq = 0;
9105 mLayoutSeq = seq;
9106
9107 // First perform layout of any root windows (not attached
9108 // to another window).
9109 int topAttached = -1;
9110 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009111 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009112
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009113 // Don't do layout of a window if it is not visible, or
9114 // soon won't be visible, to avoid wasting time and funky
9115 // changes while a window is animating away.
9116 final AppWindowToken atoken = win.mAppToken;
9117 final boolean gone = win.mViewVisibility == View.GONE
9118 || !win.mRelayoutCalled
9119 || win.mRootToken.hidden
9120 || (atoken != null && atoken.hiddenRequested)
9121 || win.mAttachedHidden
9122 || win.mExiting || win.mDestroying;
9123
9124 if (!win.mLayoutAttached) {
9125 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9126 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9127 + " mLayoutAttached=" + win.mLayoutAttached);
9128 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9129 + win.mViewVisibility + " mRelayoutCalled="
9130 + win.mRelayoutCalled + " hidden="
9131 + win.mRootToken.hidden + " hiddenRequested="
9132 + (atoken != null && atoken.hiddenRequested)
9133 + " mAttachedHidden=" + win.mAttachedHidden);
9134 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009135
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009136 // If this view is GONE, then skip it -- keep the current
9137 // frame, and let the caller know so they can ignore it
9138 // if they want. (We do the normal layout for INVISIBLE
9139 // windows, since that means "perform layout as normal,
9140 // just don't display").
9141 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009142 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009143 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9144 win.mLayoutSeq = seq;
9145 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9146 + win.mFrame + " mContainingFrame="
9147 + win.mContainingFrame + " mDisplayFrame="
9148 + win.mDisplayFrame);
9149 } else {
9150 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009151 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009152 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009153 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009154
9155 // Now perform layout of attached windows, which usually
9156 // depend on the position of the window they are attached to.
9157 // XXX does not deal with windows that are attached to windows
9158 // that are themselves attached.
9159 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009160 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009161
9162 // If this view is GONE, then skip it -- keep the current
9163 // frame, and let the caller know so they can ignore it
9164 // if they want. (We do the normal layout for INVISIBLE
9165 // windows, since that means "perform layout as normal,
9166 // just don't display").
9167 if (win.mLayoutAttached) {
9168 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9169 + " mHaveFrame=" + win.mHaveFrame
9170 + " mViewVisibility=" + win.mViewVisibility
9171 + " mRelayoutCalled=" + win.mRelayoutCalled);
9172 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9173 || !win.mHaveFrame) {
9174 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9175 win.mLayoutSeq = seq;
9176 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9177 + win.mFrame + " mContainingFrame="
9178 + win.mContainingFrame + " mDisplayFrame="
9179 + win.mDisplayFrame);
9180 }
9181 }
9182 }
Jeff Brown349703e2010-06-22 01:27:15 -07009183
9184 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009185 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009186
9187 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009188 }
Romain Guy06882f82009-06-10 13:36:04 -07009189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009190 private final void performLayoutAndPlaceSurfacesLockedInner(
9191 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009192 if (mDisplay == null) {
9193 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9194 return;
9195 }
9196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009197 final long currentTime = SystemClock.uptimeMillis();
9198 final int dw = mDisplay.getWidth();
9199 final int dh = mDisplay.getHeight();
9200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009201 int i;
9202
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009203 if (mFocusMayChange) {
9204 mFocusMayChange = false;
9205 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9206 }
9207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009208 // Initialize state of exiting tokens.
9209 for (i=mExitingTokens.size()-1; i>=0; i--) {
9210 mExitingTokens.get(i).hasVisible = false;
9211 }
9212
9213 // Initialize state of exiting applications.
9214 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9215 mExitingAppTokens.get(i).hasVisible = false;
9216 }
9217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 boolean orientationChangeComplete = true;
9219 Session holdScreen = null;
9220 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009221 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 boolean focusDisplayed = false;
9223 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009224 boolean createWatermark = false;
9225
9226 if (mFxSession == null) {
9227 mFxSession = new SurfaceSession();
9228 createWatermark = true;
9229 }
9230
9231 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009232
9233 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009234
9235 if (createWatermark) {
9236 createWatermark();
9237 }
9238 if (mWatermark != null) {
9239 mWatermark.positionSurface(dw, dh);
9240 }
9241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009243 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009244 int repeats = 0;
9245 int changes = 0;
9246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009248 repeats++;
9249 if (repeats > 6) {
9250 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9251 mLayoutNeeded = false;
9252 break;
9253 }
9254
9255 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9256 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9257 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9258 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9259 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9260 assignLayersLocked();
9261 mLayoutNeeded = true;
9262 }
9263 }
9264 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9265 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9266 if (updateOrientationFromAppTokensLocked()) {
9267 mLayoutNeeded = true;
9268 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9269 }
9270 }
9271 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9272 mLayoutNeeded = true;
9273 }
9274 }
9275
9276 // FIRST LOOP: Perform a layout, if needed.
9277 if (repeats < 4) {
9278 changes = performLayoutLockedInner();
9279 if (changes != 0) {
9280 continue;
9281 }
9282 } else {
9283 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9284 changes = 0;
9285 }
9286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009287 final int transactionSequence = ++mTransactionSequence;
9288
9289 // Update animations of all applications, including those
9290 // associated with exiting/removed apps
9291 boolean tokensAnimating = false;
9292 final int NAT = mAppTokens.size();
9293 for (i=0; i<NAT; i++) {
9294 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9295 tokensAnimating = true;
9296 }
9297 }
9298 final int NEAT = mExitingAppTokens.size();
9299 for (i=0; i<NEAT; i++) {
9300 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9301 tokensAnimating = true;
9302 }
9303 }
9304
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009305 // SECOND LOOP: Execute animations and update visibility of windows.
9306
Joe Onorato8a9b2202010-02-26 18:56:32 -08009307 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009308 + transactionSequence + " tokensAnimating="
9309 + tokensAnimating);
9310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312
9313 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009314 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009315 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009316 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317
9318 mPolicy.beginAnimationLw(dw, dh);
9319
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009320 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009323 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009324
9325 final WindowManager.LayoutParams attrs = w.mAttrs;
9326
9327 if (w.mSurface != null) {
9328 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009329 if (w.commitFinishDrawingLocked(currentTime)) {
9330 if ((w.mAttrs.flags
9331 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009332 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009333 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009334 wallpaperMayChange = true;
9335 }
9336 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009337
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009338 final boolean wasAnimating = w.mAnimating;
9339 final boolean nowAnimating = w.stepAnimationLocked(currentTime, dw, dh);
9340
9341 // If this window is animating, make a note that we have
9342 // an animating window and take care of a request to run
9343 // a detached wallpaper animation.
9344 if (nowAnimating) {
9345 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9346 windowDetachedWallpaper = w;
9347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009348 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009349 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009350
9351 // If this window's app token is running a detached wallpaper
9352 // animation, make a note so we can ensure the wallpaper is
9353 // displayed behind it.
9354 if (w.mAppToken != null && w.mAppToken.animation != null
9355 && w.mAppToken.animation.getDetachWallpaper()) {
9356 windowDetachedWallpaper = w;
9357 }
9358
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009359 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9360 wallpaperMayChange = true;
9361 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009362
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009363 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009364 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009365 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009366 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009367 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009368 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009369 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009370 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9371 forceHiding = true;
9372 }
9373 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9374 boolean changed;
9375 if (forceHiding) {
9376 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009377 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9378 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009379 } else {
9380 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009381 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9382 "Now policy shown: " + w);
9383 if (changed) {
9384 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009385 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009386 // Assume we will need to animate. If
9387 // we don't (because the wallpaper will
9388 // stay with the lock screen), then we will
9389 // clean up later.
9390 Animation a = mPolicy.createForceHideEnterAnimation();
9391 if (a != null) {
9392 w.setAnimation(a);
9393 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009394 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009395 if (mCurrentFocus == null ||
9396 mCurrentFocus.mLayer < w.mLayer) {
9397 // We are showing on to of the current
9398 // focus, so re-evaluate focus to make
9399 // sure it is correct.
9400 mFocusMayChange = true;
9401 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009402 }
9403 }
9404 if (changed && (attrs.flags
9405 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9406 wallpaperMayChange = true;
9407 }
9408 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 mPolicy.animatingWindowLw(w, attrs);
9411 }
9412
9413 final AppWindowToken atoken = w.mAppToken;
9414 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9415 if (atoken.lastTransactionSequence != transactionSequence) {
9416 atoken.lastTransactionSequence = transactionSequence;
9417 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9418 atoken.startingDisplayed = false;
9419 }
9420 if ((w.isOnScreen() || w.mAttrs.type
9421 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9422 && !w.mExiting && !w.mDestroying) {
9423 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009424 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009425 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009427 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009428 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 + " pv=" + w.mPolicyVisibility
9430 + " dp=" + w.mDrawPending
9431 + " cdp=" + w.mCommitDrawPending
9432 + " ah=" + w.mAttachedHidden
9433 + " th=" + atoken.hiddenRequested
9434 + " a=" + w.mAnimating);
9435 }
9436 }
9437 if (w != atoken.startingWindow) {
9438 if (!atoken.freezingScreen || !w.mAppFreezing) {
9439 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009440 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009441 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009442 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009443 "tokenMayBeDrawn: " + atoken
9444 + " freezingScreen=" + atoken.freezingScreen
9445 + " mAppFreezing=" + w.mAppFreezing);
9446 tokenMayBeDrawn = true;
9447 }
9448 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009449 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009450 atoken.startingDisplayed = true;
9451 }
9452 }
9453 } else if (w.mReadyToShow) {
9454 w.performShowLocked();
9455 }
9456 }
9457
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009458 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009459
9460 if (tokenMayBeDrawn) {
9461 // See if any windows have been drawn, so they (and others
9462 // associated with them) can now be shown.
9463 final int NT = mTokenList.size();
9464 for (i=0; i<NT; i++) {
9465 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9466 if (wtoken == null) {
9467 continue;
9468 }
9469 if (wtoken.freezingScreen) {
9470 int numInteresting = wtoken.numInterestingWindows;
9471 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009472 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009473 "allDrawn: " + wtoken
9474 + " interesting=" + numInteresting
9475 + " drawn=" + wtoken.numDrawnWindows);
9476 wtoken.showAllWindowsLocked();
9477 unsetAppFreezingScreenLocked(wtoken, false, true);
9478 orientationChangeComplete = true;
9479 }
9480 } else if (!wtoken.allDrawn) {
9481 int numInteresting = wtoken.numInterestingWindows;
9482 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009483 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009484 "allDrawn: " + wtoken
9485 + " interesting=" + numInteresting
9486 + " drawn=" + wtoken.numDrawnWindows);
9487 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009488 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489
9490 // We can now show all of the drawn windows!
9491 if (!mOpeningApps.contains(wtoken)) {
9492 wtoken.showAllWindowsLocked();
9493 }
9494 }
9495 }
9496 }
9497 }
9498
9499 // If we are ready to perform an app transition, check through
9500 // all of the app tokens to be shown and see if they are ready
9501 // to go.
9502 if (mAppTransitionReady) {
9503 int NN = mOpeningApps.size();
9504 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009505 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009506 "Checking " + NN + " opening apps (frozen="
9507 + mDisplayFrozen + " timeout="
9508 + mAppTransitionTimeout + ")...");
9509 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9510 // If the display isn't frozen, wait to do anything until
9511 // all of the apps are ready. Otherwise just go because
9512 // we'll unfreeze the display when everyone is ready.
9513 for (i=0; i<NN && goodToGo; i++) {
9514 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009515 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 "Check opening app" + wtoken + ": allDrawn="
9517 + wtoken.allDrawn + " startingDisplayed="
9518 + wtoken.startingDisplayed);
9519 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9520 && !wtoken.startingMoved) {
9521 goodToGo = false;
9522 }
9523 }
9524 }
9525 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009526 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 int transit = mNextAppTransition;
9528 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009529 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009530 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009531 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009532 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009533 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 mAppTransitionTimeout = false;
9535 mStartingIconInTransition = false;
9536 mSkipAppTransitionAnimation = false;
9537
9538 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9539
Dianne Hackborna8f60182009-09-01 19:01:50 -07009540 // If there are applications waiting to come to the
9541 // top of the stack, now is the time to move their windows.
9542 // (Note that we don't do apps going to the bottom
9543 // here -- we want to keep their windows in the old
9544 // Z-order until the animation completes.)
9545 if (mToTopApps.size() > 0) {
9546 NN = mAppTokens.size();
9547 for (i=0; i<NN; i++) {
9548 AppWindowToken wtoken = mAppTokens.get(i);
9549 if (wtoken.sendingToTop) {
9550 wtoken.sendingToTop = false;
9551 moveAppWindowsLocked(wtoken, NN, false);
9552 }
9553 }
9554 mToTopApps.clear();
9555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009556
Dianne Hackborn25994b42009-09-04 14:21:19 -07009557 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009558
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009559 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009560 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009561
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009562 // The top-most window will supply the layout params,
9563 // and we will determine it below.
9564 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009565 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009566 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009567
Joe Onorato8a9b2202010-02-26 18:56:32 -08009568 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009569 "New wallpaper target=" + mWallpaperTarget
9570 + ", lower target=" + mLowerWallpaperTarget
9571 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009572 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009573 // Do a first pass through the tokens for two
9574 // things:
9575 // (1) Determine if both the closing and opening
9576 // app token sets are wallpaper targets, in which
9577 // case special animations are needed
9578 // (since the wallpaper needs to stay static
9579 // behind them).
9580 // (2) Find the layout params of the top-most
9581 // application window in the tokens, which is
9582 // what will control the animation theme.
9583 final int NC = mClosingApps.size();
9584 NN = NC + mOpeningApps.size();
9585 for (i=0; i<NN; i++) {
9586 AppWindowToken wtoken;
9587 int mode;
9588 if (i < NC) {
9589 wtoken = mClosingApps.get(i);
9590 mode = 1;
9591 } else {
9592 wtoken = mOpeningApps.get(i-NC);
9593 mode = 2;
9594 }
9595 if (mLowerWallpaperTarget != null) {
9596 if (mLowerWallpaperTarget.mAppToken == wtoken
9597 || mUpperWallpaperTarget.mAppToken == wtoken) {
9598 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009599 }
9600 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009601 if (wtoken.appFullscreen) {
9602 WindowState ws = wtoken.findMainWindow();
9603 if (ws != null) {
9604 // If this is a compatibility mode
9605 // window, we will always use its anim.
9606 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9607 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009608 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009609 bestAnimLayer = Integer.MAX_VALUE;
9610 } else if (ws.mLayer > bestAnimLayer) {
9611 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009612 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009613 bestAnimLayer = ws.mLayer;
9614 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009615 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009616 }
9617 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009618
Dianne Hackborn25994b42009-09-04 14:21:19 -07009619 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009620 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009621 "Wallpaper animation!");
9622 switch (transit) {
9623 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9624 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9625 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9626 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9627 break;
9628 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9629 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9630 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9631 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9632 break;
9633 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009634 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009635 "New transit: " + transit);
9636 } else if (oldWallpaper != null) {
9637 // We are transitioning from an activity with
9638 // a wallpaper to one without.
9639 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009640 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009641 "New transit away from wallpaper: " + transit);
9642 } else if (mWallpaperTarget != null) {
9643 // We are transitioning from an activity without
9644 // a wallpaper to now showing the wallpaper
9645 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009646 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009647 "New transit into wallpaper: " + transit);
9648 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009649
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009650 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9651 mLastEnterAnimToken = animToken;
9652 mLastEnterAnimParams = animLp;
9653 } else if (mLastEnterAnimParams != null) {
9654 animLp = mLastEnterAnimParams;
9655 mLastEnterAnimToken = null;
9656 mLastEnterAnimParams = null;
9657 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009658
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009659 // If all closing windows are obscured, then there is
9660 // no need to do an animation. This is the case, for
9661 // example, when this transition is being done behind
9662 // the lock screen.
9663 if (!mPolicy.allowAppAnimationsLw()) {
9664 animLp = null;
9665 }
9666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009667 NN = mOpeningApps.size();
9668 for (i=0; i<NN; i++) {
9669 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009670 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009671 "Now opening app" + wtoken);
9672 wtoken.reportedVisible = false;
9673 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009674 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009675 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009676 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009677 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009678 wtoken.showAllWindowsLocked();
9679 }
9680 NN = mClosingApps.size();
9681 for (i=0; i<NN; i++) {
9682 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009683 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684 "Now closing app" + wtoken);
9685 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009686 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009687 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009688 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009689 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009690 // Force the allDrawn flag, because we want to start
9691 // this guy's animations regardless of whether it's
9692 // gotten drawn.
9693 wtoken.allDrawn = true;
9694 }
9695
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009696 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009698 mOpeningApps.clear();
9699 mClosingApps.clear();
9700
9701 // This has changed the visibility of windows, so perform
9702 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009703 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009704 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009705 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9706 assignLayersLocked();
9707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009708 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009709 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 }
9711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009712
Dianne Hackborn16064f92010-03-25 00:47:24 -07009713 int adjResult = 0;
9714
Dianne Hackborna8f60182009-09-01 19:01:50 -07009715 if (!animating && mAppTransitionRunning) {
9716 // We have finished the animation of an app transition. To do
9717 // this, we have delayed a lot of operations like showing and
9718 // hiding apps, moving apps in Z-order, etc. The app token list
9719 // reflects the correct Z-order, but the window list may now
9720 // be out of sync with it. So here we will just rebuild the
9721 // entire app window list. Fun!
9722 mAppTransitionRunning = false;
9723 // Clear information about apps that were moving.
9724 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009725
Dianne Hackborna8f60182009-09-01 19:01:50 -07009726 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009727 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009728 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009729 moveInputMethodWindowsIfNeededLocked(false);
9730 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009731 // Since the window list has been rebuilt, focus might
9732 // have to be recomputed since the actual order of windows
9733 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009734 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009735 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009736
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009737 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009738 // At this point, there was a window with a wallpaper that
9739 // was force hiding other windows behind it, but now it
9740 // is going away. This may be simple -- just animate
9741 // away the wallpaper and its window -- or it may be
9742 // hard -- the wallpaper now needs to be shown behind
9743 // something that was hidden.
9744 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009745 if (mLowerWallpaperTarget != null
9746 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009747 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009748 "wallpaperForceHiding changed with lower="
9749 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009751 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9752 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9753 if (mLowerWallpaperTarget.mAppToken.hidden) {
9754 // The lower target has become hidden before we
9755 // actually started the animation... let's completely
9756 // re-evaluate everything.
9757 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009758 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009759 }
9760 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009761 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009762 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009763 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009764 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009765 + " NEW: " + mWallpaperTarget
9766 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009767 if (mLowerWallpaperTarget == null) {
9768 // Whoops, we don't need a special wallpaper animation.
9769 // Clear them out.
9770 forceHiding = false;
9771 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009772 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009773 if (w.mSurface != null) {
9774 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009775 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009776 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009777 forceHiding = true;
9778 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9779 if (!w.mAnimating) {
9780 // We set the animation above so it
9781 // is not yet running.
9782 w.clearAnimation();
9783 }
9784 }
9785 }
9786 }
9787 }
9788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009789
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009790 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
9791 if (DEBUG_WALLPAPER) Slog.v(TAG,
9792 "Detached wallpaper changed from " + mWindowDetachedWallpaper
9793 + windowDetachedWallpaper);
9794 mWindowDetachedWallpaper = windowDetachedWallpaper;
9795 wallpaperMayChange = true;
9796 }
9797
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009798 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009799 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009800 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009801 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009802 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009803
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009804 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009805 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009806 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009807 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009808 assignLayersLocked();
9809 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009810 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009811 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009812 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009813 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009814
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009815 if (mFocusMayChange) {
9816 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009817 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009818 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009819 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009820 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009821 }
9822
9823 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009824 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009825 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009826
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009827 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9828 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009829
Jeff Browne33348b2010-07-15 23:54:05 -07009830 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009831 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009832
9833 // THIRD LOOP: Update the surfaces of all windows.
9834
9835 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9836
9837 boolean obscured = false;
9838 boolean blurring = false;
9839 boolean dimming = false;
9840 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009841 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009842 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009843
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009844 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009847 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848
9849 boolean displayed = false;
9850 final WindowManager.LayoutParams attrs = w.mAttrs;
9851 final int attrFlags = attrs.flags;
9852
9853 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009854 // XXX NOTE: The logic here could be improved. We have
9855 // the decision about whether to resize a window separated
9856 // from whether to hide the surface. This can cause us to
9857 // resize a surface even if we are going to hide it. You
9858 // can see this by (1) holding device in landscape mode on
9859 // home screen; (2) tapping browser icon (device will rotate
9860 // to landscape; (3) tap home. The wallpaper will be resized
9861 // in step 2 but then immediately hidden, causing us to
9862 // have to resize and then redraw it again in step 3. It
9863 // would be nice to figure out how to avoid this, but it is
9864 // difficult because we do need to resize surfaces in some
9865 // cases while they are hidden such as when first showing a
9866 // window.
9867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009869 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009870 TAG, "Placing surface #" + i + " " + w.mSurface
9871 + ": new=" + w.mShownFrame + ", old="
9872 + w.mLastShownFrame);
9873
9874 boolean resize;
9875 int width, height;
9876 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9877 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9878 w.mLastRequestedHeight != w.mRequestedHeight;
9879 // for a scaled surface, we just want to use
9880 // the requested size.
9881 width = w.mRequestedWidth;
9882 height = w.mRequestedHeight;
9883 w.mLastRequestedWidth = width;
9884 w.mLastRequestedHeight = height;
9885 w.mLastShownFrame.set(w.mShownFrame);
9886 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009887 if (SHOW_TRANSACTIONS) logSurface(w,
9888 "POS " + w.mShownFrame.left
9889 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009890 w.mSurfaceX = w.mShownFrame.left;
9891 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9893 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009894 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009895 if (!recoveringMemory) {
9896 reclaimSomeSurfaceMemoryLocked(w, "position");
9897 }
9898 }
9899 } else {
9900 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9901 width = w.mShownFrame.width();
9902 height = w.mShownFrame.height();
9903 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009904 }
9905
9906 if (resize) {
9907 if (width < 1) width = 1;
9908 if (height < 1) height = 1;
9909 if (w.mSurface != null) {
9910 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009911 if (SHOW_TRANSACTIONS) logSurface(w,
9912 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009913 + w.mShownFrame.top + " SIZE "
9914 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009915 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009916 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009917 w.mSurfaceW = width;
9918 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009920 w.mSurfaceX = w.mShownFrame.left;
9921 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 w.mSurface.setPosition(w.mShownFrame.left,
9923 w.mShownFrame.top);
9924 } catch (RuntimeException e) {
9925 // If something goes wrong with the surface (such
9926 // as running out of memory), don't take down the
9927 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009928 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 + "size=(" + width + "x" + height
9930 + "), pos=(" + w.mShownFrame.left
9931 + "," + w.mShownFrame.top + ")", e);
9932 if (!recoveringMemory) {
9933 reclaimSomeSurfaceMemoryLocked(w, "size");
9934 }
9935 }
9936 }
9937 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009938 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 w.mContentInsetsChanged =
9940 !w.mLastContentInsets.equals(w.mContentInsets);
9941 w.mVisibleInsetsChanged =
9942 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009943 boolean configChanged =
9944 w.mConfiguration != mCurConfiguration
9945 && (w.mConfiguration == null
9946 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009947 if (DEBUG_CONFIGURATION && configChanged) {
9948 Slog.v(TAG, "Win " + w + " config changed: "
9949 + mCurConfiguration);
9950 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009951 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009952 + ": configChanged=" + configChanged
9953 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009954 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009956 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009957 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009958 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009959 w.mLastFrame.set(w.mFrame);
9960 w.mLastContentInsets.set(w.mContentInsets);
9961 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009962 // If the screen is currently frozen, then keep
9963 // it frozen until this window draws at its new
9964 // orientation.
9965 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009966 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009967 "Resizing while display frozen: " + w);
9968 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009969 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009970 mWindowsFreezingScreen = true;
9971 // XXX should probably keep timeout from
9972 // when we first froze the display.
9973 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9974 mH.sendMessageDelayed(mH.obtainMessage(
9975 H.WINDOW_FREEZE_TIMEOUT), 2000);
9976 }
9977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 // If the orientation is changing, then we need to
9979 // hold off on unfreezing the display until this
9980 // window has been redrawn; to do that, we need
9981 // to go through the process of getting informed
9982 // by the application when it has finished drawing.
9983 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009984 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 "Orientation start waiting for draw in "
9986 + w + ", surface " + w.mSurface);
9987 w.mDrawPending = true;
9988 w.mCommitDrawPending = false;
9989 w.mReadyToShow = false;
9990 if (w.mAppToken != null) {
9991 w.mAppToken.allDrawn = false;
9992 }
9993 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009994 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995 "Resizing window " + w + " to " + w.mFrame);
9996 mResizingWindows.add(w);
9997 } else if (w.mOrientationChanging) {
9998 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009999 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 "Orientation not waiting for draw in "
10001 + w + ", surface " + w.mSurface);
10002 w.mOrientationChanging = false;
10003 }
10004 }
10005 }
10006
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010007 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010008 if (!w.mLastHidden) {
10009 //dump();
10010 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010011 if (SHOW_TRANSACTIONS) logSurface(w,
10012 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010014 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010015 try {
10016 w.mSurface.hide();
10017 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010018 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010019 }
10020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 }
10022 // If we are waiting for this window to handle an
10023 // orientation change, well, it is hidden, so
10024 // doesn't really matter. Note that this does
10025 // introduce a potential glitch if the window
10026 // becomes unhidden before it has drawn for the
10027 // new orientation.
10028 if (w.mOrientationChanging) {
10029 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010030 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010031 "Orientation change skips hidden " + w);
10032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 } else if (w.mLastLayer != w.mAnimLayer
10034 || w.mLastAlpha != w.mShownAlpha
10035 || w.mLastDsDx != w.mDsDx
10036 || w.mLastDtDx != w.mDtDx
10037 || w.mLastDsDy != w.mDsDy
10038 || w.mLastDtDy != w.mDtDy
10039 || w.mLastHScale != w.mHScale
10040 || w.mLastVScale != w.mVScale
10041 || w.mLastHidden) {
10042 displayed = true;
10043 w.mLastAlpha = w.mShownAlpha;
10044 w.mLastLayer = w.mAnimLayer;
10045 w.mLastDsDx = w.mDsDx;
10046 w.mLastDtDx = w.mDtDx;
10047 w.mLastDsDy = w.mDsDy;
10048 w.mLastDtDy = w.mDtDy;
10049 w.mLastHScale = w.mHScale;
10050 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010051 if (SHOW_TRANSACTIONS) logSurface(w,
10052 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010053 + " matrix=[" + (w.mDsDx*w.mHScale)
10054 + "," + (w.mDtDx*w.mVScale)
10055 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010056 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057 if (w.mSurface != null) {
10058 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010059 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010060 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010061 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010062 w.mSurface.setLayer(w.mAnimLayer);
10063 w.mSurface.setMatrix(
10064 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10065 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10066 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010067 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068 if (!recoveringMemory) {
10069 reclaimSomeSurfaceMemoryLocked(w, "update");
10070 }
10071 }
10072 }
10073
10074 if (w.mLastHidden && !w.mDrawPending
10075 && !w.mCommitDrawPending
10076 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010077 if (SHOW_TRANSACTIONS) logSurface(w,
10078 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010079 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010080 + " during relayout");
10081 if (showSurfaceRobustlyLocked(w)) {
10082 w.mHasDrawn = true;
10083 w.mLastHidden = false;
10084 } else {
10085 w.mOrientationChanging = false;
10086 }
10087 }
10088 if (w.mSurface != null) {
10089 w.mToken.hasVisible = true;
10090 }
10091 } else {
10092 displayed = true;
10093 }
10094
10095 if (displayed) {
10096 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010097 if (attrs.width == LayoutParams.MATCH_PARENT
10098 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010099 covered = true;
10100 }
10101 }
10102 if (w.mOrientationChanging) {
10103 if (w.mDrawPending || w.mCommitDrawPending) {
10104 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010105 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 "Orientation continue waiting for draw in " + w);
10107 } else {
10108 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010109 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010110 "Orientation change complete in " + w);
10111 }
10112 }
10113 w.mToken.hasVisible = true;
10114 }
10115 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010116 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 "Orientation change skips hidden " + w);
10118 w.mOrientationChanging = false;
10119 }
10120
10121 final boolean canBeSeen = w.isDisplayedLw();
10122
10123 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10124 focusDisplayed = true;
10125 }
10126
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010127 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010130 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010131 if (w.mSurface != null) {
10132 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10133 holdScreen = w.mSession;
10134 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010135 if (!syswin && w.mAttrs.screenBrightness >= 0
10136 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010137 screenBrightness = w.mAttrs.screenBrightness;
10138 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010139 if (!syswin && w.mAttrs.buttonBrightness >= 0
10140 && buttonBrightness < 0) {
10141 buttonBrightness = w.mAttrs.buttonBrightness;
10142 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010143 if (canBeSeen
10144 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10145 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10146 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010147 syswin = true;
10148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010149 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010150
Dianne Hackborn25994b42009-09-04 14:21:19 -070010151 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10152 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010153 // This window completely covers everything behind it,
10154 // so we want to leave all of them as unblurred (for
10155 // performance reasons).
10156 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010157 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010158 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010159 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010160 obscured = true;
10161 if (mBackgroundFillerSurface == null) {
10162 try {
10163 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010164 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010165 0, dw, dh,
10166 PixelFormat.OPAQUE,
10167 Surface.FX_SURFACE_NORMAL);
10168 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010169 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010170 }
10171 }
10172 try {
10173 mBackgroundFillerSurface.setPosition(0, 0);
10174 mBackgroundFillerSurface.setSize(dw, dh);
10175 // Using the same layer as Dim because they will never be shown at the
10176 // same time.
10177 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10178 mBackgroundFillerSurface.show();
10179 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010180 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010181 }
10182 backgroundFillerShown = true;
10183 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010184 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010185 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010186 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010187 + ": blurring=" + blurring
10188 + " obscured=" + obscured
10189 + " displayed=" + displayed);
10190 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10191 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010192 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010194 if (mDimAnimator == null) {
10195 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010197 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010198 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010200 }
10201 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10202 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010203 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010204 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010205 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010206 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 + mBlurSurface + ": CREATE");
10208 try {
Romain Guy06882f82009-06-10 13:36:04 -070010209 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010210 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010211 -1, 16, 16,
10212 PixelFormat.OPAQUE,
10213 Surface.FX_SURFACE_BLUR);
10214 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010215 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010216 }
10217 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010218 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010219 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10220 + mBlurSurface + ": pos=(0,0) (" +
10221 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010222 mBlurSurface.setPosition(0, 0);
10223 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010224 mBlurSurface.setLayer(w.mAnimLayer-2);
10225 if (!mBlurShown) {
10226 try {
10227 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10228 + mBlurSurface + ": SHOW");
10229 mBlurSurface.show();
10230 } catch (RuntimeException e) {
10231 Slog.w(TAG, "Failure showing blur surface", e);
10232 }
10233 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010234 }
10235 }
10236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237 }
10238 }
10239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010240
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010241 if (obscuredChanged && mWallpaperTarget == w) {
10242 // This is the wallpaper target and its obscured state
10243 // changed... make sure the current wallaper's visibility
10244 // has been updated accordingly.
10245 updateWallpaperVisibilityLocked();
10246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010248
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010249 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10250 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010251 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010252 try {
10253 mBackgroundFillerSurface.hide();
10254 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010255 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010256 }
10257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010258
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010259 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010260 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10261 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010262 }
Romain Guy06882f82009-06-10 13:36:04 -070010263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010264 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010265 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 + ": HIDE");
10267 try {
10268 mBlurSurface.hide();
10269 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010270 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010271 }
10272 mBlurShown = false;
10273 }
10274
Joe Onorato8a9b2202010-02-26 18:56:32 -080010275 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010276 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010277 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 }
10279
Jeff Browne33348b2010-07-15 23:54:05 -070010280 mInputMonitor.updateInputWindowsLw();
10281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010282 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010283
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010284 if (mWatermark != null) {
10285 mWatermark.drawIfNeeded();
10286 }
10287
Joe Onorato8a9b2202010-02-26 18:56:32 -080010288 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 "With display frozen, orientationChangeComplete="
10290 + orientationChangeComplete);
10291 if (orientationChangeComplete) {
10292 if (mWindowsFreezingScreen) {
10293 mWindowsFreezingScreen = false;
10294 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10295 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010296 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 }
Romain Guy06882f82009-06-10 13:36:04 -070010298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 i = mResizingWindows.size();
10300 if (i > 0) {
10301 do {
10302 i--;
10303 WindowState win = mResizingWindows.get(i);
10304 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010305 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10306 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010307 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010308 boolean configChanged =
10309 win.mConfiguration != mCurConfiguration
10310 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010311 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10312 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10313 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010314 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010315 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010316 + " / " + mCurConfiguration + " / 0x"
10317 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010318 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010319 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010320 win.mClient.resized(win.mFrame.width(),
10321 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010322 win.mLastVisibleInsets, win.mDrawPending,
10323 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 win.mContentInsetsChanged = false;
10325 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010326 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 } catch (RemoteException e) {
10328 win.mOrientationChanging = false;
10329 }
10330 } while (i > 0);
10331 mResizingWindows.clear();
10332 }
Romain Guy06882f82009-06-10 13:36:04 -070010333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010334 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010335 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010336 i = mDestroySurface.size();
10337 if (i > 0) {
10338 do {
10339 i--;
10340 WindowState win = mDestroySurface.get(i);
10341 win.mDestroying = false;
10342 if (mInputMethodWindow == win) {
10343 mInputMethodWindow = null;
10344 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010345 if (win == mWallpaperTarget) {
10346 wallpaperDestroyed = true;
10347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010348 win.destroySurfaceLocked();
10349 } while (i > 0);
10350 mDestroySurface.clear();
10351 }
10352
10353 // Time to remove any exiting tokens?
10354 for (i=mExitingTokens.size()-1; i>=0; i--) {
10355 WindowToken token = mExitingTokens.get(i);
10356 if (!token.hasVisible) {
10357 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010358 if (token.windowType == TYPE_WALLPAPER) {
10359 mWallpaperTokens.remove(token);
10360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010361 }
10362 }
10363
10364 // Time to remove any exiting applications?
10365 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10366 AppWindowToken token = mExitingAppTokens.get(i);
10367 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010368 // Make sure there is no animation running on this token,
10369 // so any windows associated with it will be removed as
10370 // soon as their animations are complete
10371 token.animation = null;
10372 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 mAppTokens.remove(token);
10374 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010375 if (mLastEnterAnimToken == token) {
10376 mLastEnterAnimToken = null;
10377 mLastEnterAnimParams = null;
10378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010379 }
10380 }
10381
Dianne Hackborna8f60182009-09-01 19:01:50 -070010382 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010383
Dianne Hackborna8f60182009-09-01 19:01:50 -070010384 if (!animating && mAppTransitionRunning) {
10385 // We have finished the animation of an app transition. To do
10386 // this, we have delayed a lot of operations like showing and
10387 // hiding apps, moving apps in Z-order, etc. The app token list
10388 // reflects the correct Z-order, but the window list may now
10389 // be out of sync with it. So here we will just rebuild the
10390 // entire app window list. Fun!
10391 mAppTransitionRunning = false;
10392 needRelayout = true;
10393 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010394 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010395 // Clear information about apps that were moving.
10396 mToBottomApps.clear();
10397 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010399 if (focusDisplayed) {
10400 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10401 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010402 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010403 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010404 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010405 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010406 requestAnimationLocked(0);
10407 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10409 }
Jeff Browneb857f12010-07-16 10:06:33 -070010410
Jeff Browne33348b2010-07-15 23:54:05 -070010411 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010412
Jeff Brown8e03b752010-06-13 19:16:55 -070010413 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010414 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10415 mPowerManager.setScreenBrightnessOverride(-1);
10416 } else {
10417 mPowerManager.setScreenBrightnessOverride((int)
10418 (screenBrightness * Power.BRIGHTNESS_ON));
10419 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010420 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10421 mPowerManager.setButtonBrightnessOverride(-1);
10422 } else {
10423 mPowerManager.setButtonBrightnessOverride((int)
10424 (buttonBrightness * Power.BRIGHTNESS_ON));
10425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010426 if (holdScreen != mHoldingScreenOn) {
10427 mHoldingScreenOn = holdScreen;
10428 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10429 mH.sendMessage(m);
10430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010431
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010432 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010433 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010434 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10435 LocalPowerManager.BUTTON_EVENT, true);
10436 mTurnOnScreen = false;
10437 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010438
10439 // Check to see if we are now in a state where the screen should
10440 // be enabled, because the window obscured flags have changed.
10441 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010443
10444 /**
10445 * Must be called with the main window manager lock held.
10446 */
10447 void setHoldScreenLocked(boolean holding) {
10448 boolean state = mHoldingScreenWakeLock.isHeld();
10449 if (holding != state) {
10450 if (holding) {
10451 mHoldingScreenWakeLock.acquire();
10452 } else {
10453 mPolicy.screenOnStoppedLw();
10454 mHoldingScreenWakeLock.release();
10455 }
10456 }
10457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010458
10459 void requestAnimationLocked(long delay) {
10460 if (!mAnimationPending) {
10461 mAnimationPending = true;
10462 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10463 }
10464 }
Romain Guy06882f82009-06-10 13:36:04 -070010465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 /**
10467 * Have the surface flinger show a surface, robustly dealing with
10468 * error conditions. In particular, if there is not enough memory
10469 * to show the surface, then we will try to get rid of other surfaces
10470 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010471 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010472 * @return Returns true if the surface was successfully shown.
10473 */
10474 boolean showSurfaceRobustlyLocked(WindowState win) {
10475 try {
10476 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010477 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010479 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010480 if (DEBUG_VISIBILITY) Slog.v(TAG,
10481 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010482 win.mTurnOnScreen = false;
10483 mTurnOnScreen = true;
10484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010485 }
10486 return true;
10487 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010488 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010489 }
Romain Guy06882f82009-06-10 13:36:04 -070010490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 return false;
10494 }
Romain Guy06882f82009-06-10 13:36:04 -070010495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010496 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10497 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010498
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010499 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 if (mForceRemoves == null) {
10503 mForceRemoves = new ArrayList<WindowState>();
10504 }
Romain Guy06882f82009-06-10 13:36:04 -070010505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 long callingIdentity = Binder.clearCallingIdentity();
10507 try {
10508 // There was some problem... first, do a sanity check of the
10509 // window list to make sure we haven't left any dangling surfaces
10510 // around.
10511 int N = mWindows.size();
10512 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010513 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010515 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 if (ws.mSurface != null) {
10517 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010518 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 + ws + " surface=" + ws.mSurface
10520 + " token=" + win.mToken
10521 + " pid=" + ws.mSession.mPid
10522 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010523 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010524 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 ws.mSurface = null;
10526 mForceRemoves.add(ws);
10527 i--;
10528 N--;
10529 leakedSurface = true;
10530 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010531 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 + ws + " surface=" + ws.mSurface
10533 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010534 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010535 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 ws.mSurface = null;
10537 leakedSurface = true;
10538 }
10539 }
10540 }
Romain Guy06882f82009-06-10 13:36:04 -070010541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 boolean killedApps = false;
10543 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010544 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010545 SparseIntArray pidCandidates = new SparseIntArray();
10546 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010547 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 if (ws.mSurface != null) {
10549 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10550 }
10551 }
10552 if (pidCandidates.size() > 0) {
10553 int[] pids = new int[pidCandidates.size()];
10554 for (int i=0; i<pids.length; i++) {
10555 pids[i] = pidCandidates.keyAt(i);
10556 }
10557 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010558 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010559 killedApps = true;
10560 }
10561 } catch (RemoteException e) {
10562 }
10563 }
10564 }
Romain Guy06882f82009-06-10 13:36:04 -070010565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010566 if (leakedSurface || killedApps) {
10567 // We managed to reclaim some memory, so get rid of the trouble
10568 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010569 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010570 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010571 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010572 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 win.mSurface = null;
10574 }
Romain Guy06882f82009-06-10 13:36:04 -070010575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010576 try {
10577 win.mClient.dispatchGetNewSurface();
10578 } catch (RemoteException e) {
10579 }
10580 }
10581 } finally {
10582 Binder.restoreCallingIdentity(callingIdentity);
10583 }
10584 }
Romain Guy06882f82009-06-10 13:36:04 -070010585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010586 private boolean updateFocusedWindowLocked(int mode) {
10587 WindowState newFocus = computeFocusedWindowLocked();
10588 if (mCurrentFocus != newFocus) {
10589 // This check makes sure that we don't already have the focus
10590 // change message pending.
10591 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10592 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010593 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10595 final WindowState oldFocus = mCurrentFocus;
10596 mCurrentFocus = newFocus;
10597 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 final WindowState imWindow = mInputMethodWindow;
10600 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010601 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010602 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010603 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10604 mLayoutNeeded = true;
10605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010606 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10607 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010608 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10609 // Client will do the layout, but we need to assign layers
10610 // for handleNewWindowLocked() below.
10611 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010612 }
10613 }
Jeff Brown349703e2010-06-22 01:27:15 -070010614
10615 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10616 // If we defer assigning layers, then the caller is responsible for
10617 // doing this part.
10618 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 return true;
10621 }
10622 return false;
10623 }
Jeff Brown349703e2010-06-22 01:27:15 -070010624
10625 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010626 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010628
10629 private WindowState computeFocusedWindowLocked() {
10630 WindowState result = null;
10631 WindowState win;
10632
10633 int i = mWindows.size() - 1;
10634 int nextAppIndex = mAppTokens.size()-1;
10635 WindowToken nextApp = nextAppIndex >= 0
10636 ? mAppTokens.get(nextAppIndex) : null;
10637
10638 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010639 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010640
Joe Onorato8a9b2202010-02-26 18:56:32 -080010641 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010642 TAG, "Looking for focus: " + i
10643 + " = " + win
10644 + ", flags=" + win.mAttrs.flags
10645 + ", canReceive=" + win.canReceiveKeys());
10646
10647 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010649 // If this window's application has been removed, just skip it.
10650 if (thisApp != null && thisApp.removed) {
10651 i--;
10652 continue;
10653 }
Romain Guy06882f82009-06-10 13:36:04 -070010654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 // If there is a focused app, don't allow focus to go to any
10656 // windows below it. If this is an application window, step
10657 // through the app tokens until we find its app.
10658 if (thisApp != null && nextApp != null && thisApp != nextApp
10659 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10660 int origAppIndex = nextAppIndex;
10661 while (nextAppIndex > 0) {
10662 if (nextApp == mFocusedApp) {
10663 // Whoops, we are below the focused app... no focus
10664 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010665 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 TAG, "Reached focused app: " + mFocusedApp);
10667 return null;
10668 }
10669 nextAppIndex--;
10670 nextApp = mAppTokens.get(nextAppIndex);
10671 if (nextApp == thisApp) {
10672 break;
10673 }
10674 }
10675 if (thisApp != nextApp) {
10676 // Uh oh, the app token doesn't exist! This shouldn't
10677 // happen, but if it does we can get totally hosed...
10678 // so restart at the original app.
10679 nextAppIndex = origAppIndex;
10680 nextApp = mAppTokens.get(nextAppIndex);
10681 }
10682 }
10683
10684 // Dispatch to this window if it is wants key events.
10685 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010686 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010687 TAG, "Found focus @ " + i + " = " + win);
10688 result = win;
10689 break;
10690 }
10691
10692 i--;
10693 }
10694
10695 return result;
10696 }
10697
10698 private void startFreezingDisplayLocked() {
10699 if (mDisplayFrozen) {
10700 return;
10701 }
Romain Guy06882f82009-06-10 13:36:04 -070010702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010703 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010705 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010706 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010707 if (mFreezeGcPending != 0) {
10708 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010709 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710 mH.removeMessages(H.FORCE_GC);
10711 Runtime.getRuntime().gc();
10712 mFreezeGcPending = now;
10713 }
10714 } else {
10715 mFreezeGcPending = now;
10716 }
Romain Guy06882f82009-06-10 13:36:04 -070010717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010718 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010719
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010720 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010721
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010722 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10723 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010724 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010725 mAppTransitionReady = true;
10726 }
Romain Guy06882f82009-06-10 13:36:04 -070010727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010728 if (PROFILE_ORIENTATION) {
10729 File file = new File("/data/system/frozen");
10730 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10731 }
10732 Surface.freezeDisplay(0);
10733 }
Romain Guy06882f82009-06-10 13:36:04 -070010734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 private void stopFreezingDisplayLocked() {
10736 if (!mDisplayFrozen) {
10737 return;
10738 }
Romain Guy06882f82009-06-10 13:36:04 -070010739
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010740 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10741 return;
10742 }
10743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010744 mDisplayFrozen = false;
10745 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10746 if (PROFILE_ORIENTATION) {
10747 Debug.stopMethodTracing();
10748 }
10749 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010750
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010751 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010752
Christopher Tateb696aee2010-04-02 19:08:30 -070010753 // While the display is frozen we don't re-compute the orientation
10754 // to avoid inconsistent states. However, something interesting
10755 // could have actually changed during that time so re-evaluate it
10756 // now to catch that.
10757 if (updateOrientationFromAppTokensLocked()) {
10758 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10759 }
10760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010761 // A little kludge: a lot could have happened while the
10762 // display was frozen, so now that we are coming back we
10763 // do a gc so that any remote references the system
10764 // processes holds on others can be released if they are
10765 // no longer needed.
10766 mH.removeMessages(H.FORCE_GC);
10767 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10768 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 mScreenFrozenLock.release();
10771 }
Romain Guy06882f82009-06-10 13:36:04 -070010772
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010773 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10774 DisplayMetrics dm) {
10775 if (index < tokens.length) {
10776 String str = tokens[index];
10777 if (str != null && str.length() > 0) {
10778 try {
10779 int val = Integer.parseInt(str);
10780 return val;
10781 } catch (Exception e) {
10782 }
10783 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010784 }
10785 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10786 return defDps;
10787 }
10788 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10789 return val;
10790 }
10791
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010792 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010793 final String[] mTokens;
10794 final String mText;
10795 final Paint mTextPaint;
10796 final int mTextWidth;
10797 final int mTextHeight;
10798 final int mTextAscent;
10799 final int mTextDescent;
10800 final int mDeltaX;
10801 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010802
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010803 Surface mSurface;
10804 int mLastDW;
10805 int mLastDH;
10806 boolean mDrawNeeded;
10807
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010808 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010809 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010810 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010811
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010812 if (false) {
10813 Log.i(TAG, "*********************** WATERMARK");
10814 for (int i=0; i<tokens.length; i++) {
10815 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10816 }
10817 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010818
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010819 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010820
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010821 StringBuilder builder = new StringBuilder(32);
10822 int len = mTokens[0].length();
10823 len = len & ~1;
10824 for (int i=0; i<len; i+=2) {
10825 int c1 = mTokens[0].charAt(i);
10826 int c2 = mTokens[0].charAt(i+1);
10827 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10828 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10829 else c1 -= '0';
10830 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10831 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10832 else c2 -= '0';
10833 builder.append((char)(255-((c1*16)+c2)));
10834 }
10835 mText = builder.toString();
10836 if (false) {
10837 Log.i(TAG, "Final text: " + mText);
10838 }
10839
10840 int fontSize = getPropertyInt(tokens, 1,
10841 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10842
10843 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10844 mTextPaint.setTextSize(fontSize);
10845 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10846
10847 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10848 mTextWidth = (int)mTextPaint.measureText(mText);
10849 mTextAscent = fm.ascent;
10850 mTextDescent = fm.descent;
10851 mTextHeight = fm.descent - fm.ascent;
10852
10853 mDeltaX = getPropertyInt(tokens, 2,
10854 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10855 mDeltaY = getPropertyInt(tokens, 3,
10856 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10857 int shadowColor = getPropertyInt(tokens, 4,
10858 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10859 int color = getPropertyInt(tokens, 5,
10860 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10861 int shadowRadius = getPropertyInt(tokens, 6,
10862 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10863 int shadowDx = getPropertyInt(tokens, 8,
10864 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10865 int shadowDy = getPropertyInt(tokens, 9,
10866 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10867
10868 mTextPaint.setColor(color);
10869 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010870
10871 try {
10872 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010873 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010874 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010875 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010876 mSurface.show();
10877 } catch (OutOfResourcesException e) {
10878 }
10879 }
10880
10881 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010882 if (mLastDW != dw || mLastDH != dh) {
10883 mLastDW = dw;
10884 mLastDH = dh;
10885 mSurface.setSize(dw, dh);
10886 mDrawNeeded = true;
10887 }
10888 }
10889
10890 void drawIfNeeded() {
10891 if (mDrawNeeded) {
10892 final int dw = mLastDW;
10893 final int dh = mLastDH;
10894
10895 mDrawNeeded = false;
10896 Rect dirty = new Rect(0, 0, dw, dh);
10897 Canvas c = null;
10898 try {
10899 c = mSurface.lockCanvas(dirty);
10900 } catch (IllegalArgumentException e) {
10901 } catch (OutOfResourcesException e) {
10902 }
10903 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010904 c.drawColor(0, PorterDuff.Mode.CLEAR);
10905
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010906 int deltaX = mDeltaX;
10907 int deltaY = mDeltaY;
10908
10909 // deltaX shouldn't be close to a round fraction of our
10910 // x step, or else things will line up too much.
10911 int div = (dw+mTextWidth)/deltaX;
10912 int rem = (dw+mTextWidth) - (div*deltaX);
10913 int qdelta = deltaX/4;
10914 if (rem < qdelta || rem > (deltaX-qdelta)) {
10915 deltaX += deltaX/3;
10916 }
10917
10918 int y = -mTextHeight;
10919 int x = -mTextWidth;
10920 while (y < (dh+mTextHeight)) {
10921 c.drawText(mText, x, y, mTextPaint);
10922 x += deltaX;
10923 if (x >= dw) {
10924 x -= (dw+mTextWidth);
10925 y += deltaY;
10926 }
10927 }
10928 mSurface.unlockCanvasAndPost(c);
10929 }
10930 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010931 }
10932 }
10933
10934 void createWatermark() {
10935 if (mWatermark != null) {
10936 return;
10937 }
10938
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010939 File file = new File("/system/etc/setup.conf");
10940 FileInputStream in = null;
10941 try {
10942 in = new FileInputStream(file);
10943 DataInputStream ind = new DataInputStream(in);
10944 String line = ind.readLine();
10945 if (line != null) {
10946 String[] toks = line.split("%");
10947 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010948 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010949 }
10950 }
10951 } catch (FileNotFoundException e) {
10952 } catch (IOException e) {
10953 } finally {
10954 if (in != null) {
10955 try {
10956 in.close();
10957 } catch (IOException e) {
10958 }
10959 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010960 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010961 }
10962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010963 @Override
10964 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10965 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10966 != PackageManager.PERMISSION_GRANTED) {
10967 pw.println("Permission Denial: can't dump WindowManager from from pid="
10968 + Binder.getCallingPid()
10969 + ", uid=" + Binder.getCallingUid());
10970 return;
10971 }
Romain Guy06882f82009-06-10 13:36:04 -070010972
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010973 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010974 pw.println(" ");
10975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010976 synchronized(mWindowMap) {
10977 pw.println("Current Window Manager state:");
10978 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010979 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010980 pw.print(" Window #"); pw.print(i); pw.print(' ');
10981 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010982 w.dump(pw, " ");
10983 }
10984 if (mInputMethodDialogs.size() > 0) {
10985 pw.println(" ");
10986 pw.println(" Input method dialogs:");
10987 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10988 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010989 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010990 }
10991 }
10992 if (mPendingRemove.size() > 0) {
10993 pw.println(" ");
10994 pw.println(" Remove pending for:");
10995 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10996 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010997 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10998 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010999 w.dump(pw, " ");
11000 }
11001 }
11002 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11003 pw.println(" ");
11004 pw.println(" Windows force removing:");
11005 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11006 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011007 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11008 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011009 w.dump(pw, " ");
11010 }
11011 }
11012 if (mDestroySurface.size() > 0) {
11013 pw.println(" ");
11014 pw.println(" Windows waiting to destroy their surface:");
11015 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11016 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011017 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11018 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011019 w.dump(pw, " ");
11020 }
11021 }
11022 if (mLosingFocus.size() > 0) {
11023 pw.println(" ");
11024 pw.println(" Windows losing focus:");
11025 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11026 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011027 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11028 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011029 w.dump(pw, " ");
11030 }
11031 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011032 if (mResizingWindows.size() > 0) {
11033 pw.println(" ");
11034 pw.println(" Windows waiting to resize:");
11035 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11036 WindowState w = mResizingWindows.get(i);
11037 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11038 pw.print(w); pw.println(":");
11039 w.dump(pw, " ");
11040 }
11041 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011042 if (mSessions.size() > 0) {
11043 pw.println(" ");
11044 pw.println(" All active sessions:");
11045 Iterator<Session> it = mSessions.iterator();
11046 while (it.hasNext()) {
11047 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011048 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011049 s.dump(pw, " ");
11050 }
11051 }
11052 if (mTokenMap.size() > 0) {
11053 pw.println(" ");
11054 pw.println(" All tokens:");
11055 Iterator<WindowToken> it = mTokenMap.values().iterator();
11056 while (it.hasNext()) {
11057 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011058 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011059 token.dump(pw, " ");
11060 }
11061 }
11062 if (mTokenList.size() > 0) {
11063 pw.println(" ");
11064 pw.println(" Window token list:");
11065 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011066 pw.print(" #"); pw.print(i); pw.print(": ");
11067 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011068 }
11069 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011070 if (mWallpaperTokens.size() > 0) {
11071 pw.println(" ");
11072 pw.println(" Wallpaper tokens:");
11073 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11074 WindowToken token = mWallpaperTokens.get(i);
11075 pw.print(" Wallpaper #"); pw.print(i);
11076 pw.print(' '); pw.print(token); pw.println(':');
11077 token.dump(pw, " ");
11078 }
11079 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011080 if (mAppTokens.size() > 0) {
11081 pw.println(" ");
11082 pw.println(" Application tokens in Z order:");
11083 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011084 pw.print(" App #"); pw.print(i); pw.print(": ");
11085 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011086 }
11087 }
11088 if (mFinishedStarting.size() > 0) {
11089 pw.println(" ");
11090 pw.println(" Finishing start of application tokens:");
11091 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11092 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011093 pw.print(" Finished Starting #"); pw.print(i);
11094 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011095 token.dump(pw, " ");
11096 }
11097 }
11098 if (mExitingTokens.size() > 0) {
11099 pw.println(" ");
11100 pw.println(" Exiting tokens:");
11101 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11102 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011103 pw.print(" Exiting #"); pw.print(i);
11104 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011105 token.dump(pw, " ");
11106 }
11107 }
11108 if (mExitingAppTokens.size() > 0) {
11109 pw.println(" ");
11110 pw.println(" Exiting application tokens:");
11111 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11112 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011113 pw.print(" Exiting App #"); pw.print(i);
11114 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 token.dump(pw, " ");
11116 }
11117 }
11118 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011119 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11120 pw.print(" mLastFocus="); pw.println(mLastFocus);
11121 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11122 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11123 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011124 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011125 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11126 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11127 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11128 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011129 if (mWindowDetachedWallpaper != null) {
11130 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11131 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011132 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11133 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11134 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011135 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11136 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11137 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11138 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011139 if (mDimAnimator != null) {
11140 mDimAnimator.printTo(pw);
11141 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011142 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011143 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011144 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011145 pw.print(mInputMethodAnimLayerAdjustment);
11146 pw.print(" mWallpaperAnimLayerAdjustment=");
11147 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011148 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11149 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011150 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11151 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011152 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11153 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011154 pw.print(" mRotation="); pw.print(mRotation);
11155 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11156 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11157 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11158 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11159 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11160 pw.print(" mNextAppTransition=0x");
11161 pw.print(Integer.toHexString(mNextAppTransition));
11162 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011163 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011164 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011165 if (mNextAppTransitionPackage != null) {
11166 pw.print(" mNextAppTransitionPackage=");
11167 pw.print(mNextAppTransitionPackage);
11168 pw.print(", mNextAppTransitionEnter=0x");
11169 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11170 pw.print(", mNextAppTransitionExit=0x");
11171 pw.print(Integer.toHexString(mNextAppTransitionExit));
11172 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011173 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11174 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011175 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11176 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11177 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11178 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011179 if (mOpeningApps.size() > 0) {
11180 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11181 }
11182 if (mClosingApps.size() > 0) {
11183 pw.print(" mClosingApps="); pw.println(mClosingApps);
11184 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011185 if (mToTopApps.size() > 0) {
11186 pw.print(" mToTopApps="); pw.println(mToTopApps);
11187 }
11188 if (mToBottomApps.size() > 0) {
11189 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11190 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011191 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11192 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011193 }
11194 }
11195
Jeff Brown349703e2010-06-22 01:27:15 -070011196 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011197 public void monitor() {
11198 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011199 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011200 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011201
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011202 /**
11203 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011204 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011205 */
11206 private static class DimAnimator {
11207 Surface mDimSurface;
11208 boolean mDimShown = false;
11209 float mDimCurrentAlpha;
11210 float mDimTargetAlpha;
11211 float mDimDeltaPerMs;
11212 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011213
11214 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011215
11216 DimAnimator (SurfaceSession session) {
11217 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011218 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011219 + mDimSurface + ": CREATE");
11220 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011221 mDimSurface = new Surface(session, 0,
11222 "DimSurface",
11223 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011224 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011225 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011226 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011227 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011228 }
11229 }
11230 }
11231
11232 /**
11233 * Show the dim surface.
11234 */
11235 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011236 if (!mDimShown) {
11237 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11238 dw + "x" + dh + ")");
11239 mDimShown = true;
11240 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011241 mLastDimWidth = dw;
11242 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011243 mDimSurface.setPosition(0, 0);
11244 mDimSurface.setSize(dw, dh);
11245 mDimSurface.show();
11246 } catch (RuntimeException e) {
11247 Slog.w(TAG, "Failure showing dim surface", e);
11248 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011249 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11250 mLastDimWidth = dw;
11251 mLastDimHeight = dh;
11252 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011253 }
11254 }
11255
11256 /**
11257 * Set's the dim surface's layer and update dim parameters that will be used in
11258 * {@link updateSurface} after all windows are examined.
11259 */
11260 void updateParameters(WindowState w, long currentTime) {
11261 mDimSurface.setLayer(w.mAnimLayer-1);
11262
11263 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011264 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011265 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011266 if (mDimTargetAlpha != target) {
11267 // If the desired dim level has changed, then
11268 // start an animation to it.
11269 mLastDimAnimTime = currentTime;
11270 long duration = (w.mAnimating && w.mAnimation != null)
11271 ? w.mAnimation.computeDurationHint()
11272 : DEFAULT_DIM_DURATION;
11273 if (target > mDimTargetAlpha) {
11274 // This is happening behind the activity UI,
11275 // so we can make it run a little longer to
11276 // give a stronger impression without disrupting
11277 // the user.
11278 duration *= DIM_DURATION_MULTIPLIER;
11279 }
11280 if (duration < 1) {
11281 // Don't divide by zero
11282 duration = 1;
11283 }
11284 mDimTargetAlpha = target;
11285 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11286 }
11287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011288
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011289 /**
11290 * Updating the surface's alpha. Returns true if the animation continues, or returns
11291 * false when the animation is finished and the dim surface is hidden.
11292 */
11293 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11294 if (!dimming) {
11295 if (mDimTargetAlpha != 0) {
11296 mLastDimAnimTime = currentTime;
11297 mDimTargetAlpha = 0;
11298 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11299 }
11300 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011301
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011302 boolean animating = false;
11303 if (mLastDimAnimTime != 0) {
11304 mDimCurrentAlpha += mDimDeltaPerMs
11305 * (currentTime-mLastDimAnimTime);
11306 boolean more = true;
11307 if (displayFrozen) {
11308 // If the display is frozen, there is no reason to animate.
11309 more = false;
11310 } else if (mDimDeltaPerMs > 0) {
11311 if (mDimCurrentAlpha > mDimTargetAlpha) {
11312 more = false;
11313 }
11314 } else if (mDimDeltaPerMs < 0) {
11315 if (mDimCurrentAlpha < mDimTargetAlpha) {
11316 more = false;
11317 }
11318 } else {
11319 more = false;
11320 }
11321
11322 // Do we need to continue animating?
11323 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011324 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011325 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11326 mLastDimAnimTime = currentTime;
11327 mDimSurface.setAlpha(mDimCurrentAlpha);
11328 animating = true;
11329 } else {
11330 mDimCurrentAlpha = mDimTargetAlpha;
11331 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011332 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011333 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11334 mDimSurface.setAlpha(mDimCurrentAlpha);
11335 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011336 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011337 + ": HIDE");
11338 try {
11339 mDimSurface.hide();
11340 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011341 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011342 }
11343 mDimShown = false;
11344 }
11345 }
11346 }
11347 return animating;
11348 }
11349
11350 public void printTo(PrintWriter pw) {
11351 pw.print(" mDimShown="); pw.print(mDimShown);
11352 pw.print(" current="); pw.print(mDimCurrentAlpha);
11353 pw.print(" target="); pw.print(mDimTargetAlpha);
11354 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11355 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11356 }
11357 }
11358
11359 /**
11360 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11361 * This is used for opening/closing transition for apps in compatible mode.
11362 */
11363 private static class FadeInOutAnimation extends Animation {
11364 int mWidth;
11365 boolean mFadeIn;
11366
11367 public FadeInOutAnimation(boolean fadeIn) {
11368 setInterpolator(new AccelerateInterpolator());
11369 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11370 mFadeIn = fadeIn;
11371 }
11372
11373 @Override
11374 protected void applyTransformation(float interpolatedTime, Transformation t) {
11375 float x = interpolatedTime;
11376 if (!mFadeIn) {
11377 x = 1.0f - x; // reverse the interpolation for fade out
11378 }
11379 if (x < 0.5) {
11380 // move the window out of the screen.
11381 t.getMatrix().setTranslate(mWidth, 0);
11382 } else {
11383 t.getMatrix().setTranslate(0, 0);// show
11384 t.setAlpha((x - 0.5f) * 2);
11385 }
11386 }
11387
11388 @Override
11389 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11390 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11391 mWidth = width;
11392 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011393
11394 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011395 public int getZAdjustment() {
11396 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011397 }
11398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011399}