blob: b3ea836bfc86327da76b96d808da71ff39771b4a [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 Hackborn1c24e952010-11-23 00:34:30 -080062import android.content.res.Resources;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070067import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070088import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
90import android.os.SystemProperties;
91import android.os.TokenWatcher;
92import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070093import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070095import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080096import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070098import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700100import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101import android.view.Gravity;
102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
152 static final boolean DEBUG_FOCUS = false;
153 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800154 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800155 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 static final boolean DEBUG_LAYERS = false;
157 static final boolean DEBUG_INPUT = false;
158 static final boolean DEBUG_INPUT_METHOD = false;
159 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700160 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700162 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_APP_TRANSITIONS = false;
164 static final boolean DEBUG_STARTING_WINDOW = false;
165 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700166 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700167 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700169 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 static final boolean PROFILE_ORIENTATION = false;
172 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700173 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 /** How much to multiply the policy's type layer, to reserve room
176 * for multiple windows of the same type and Z-ordering adjustment
177 * with TYPE_LAYER_OFFSET. */
178 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
181 * or below others in the same layer. */
182 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 /** How much to increment the layer for each window, to reserve room
185 * for effect surfaces between them.
186 */
187 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 /** The maximum length we will accept for a loaded animation duration:
190 * this is 10 seconds.
191 */
192 static final int MAX_ANIMATION_DURATION = 10*1000;
193
194 /** Amount of time (in milliseconds) to animate the dim surface from one
195 * value to another, when no window animation is driving it.
196 */
197 static final int DEFAULT_DIM_DURATION = 200;
198
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700199 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
200 * compatible windows.
201 */
202 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
203
Jeff Brown7fbdc842010-06-17 20:52:56 -0700204 // Maximum number of milliseconds to wait for input event injection.
205 // FIXME is this value reasonable?
206 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700207
208 // Default input dispatching timeout in nanoseconds.
209 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 static final int UPDATE_FOCUS_NORMAL = 0;
212 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
213 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
214 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700217 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218
219 /**
220 * Condition waited on by {@link #reenableKeyguard} to know the call to
221 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500222 * This is set to true only if mKeyguardTokenWatcher.acquired() has
223 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500225 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226
Jim Miller284b62e2010-06-08 14:27:42 -0700227 private static final int ALLOW_DISABLE_YES = 1;
228 private static final int ALLOW_DISABLE_NO = 0;
229 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
230 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
231
Mike Lockwood983ee092009-11-22 01:42:24 -0500232 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
233 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700235 if (shouldAllowDisableKeyguard()) {
236 mPolicy.enableKeyguard(false);
237 mKeyguardDisabled = true;
238 } else {
239 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
240 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 }
242 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700243 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 synchronized (mKeyguardTokenWatcher) {
245 mKeyguardDisabled = false;
246 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248 }
249 };
250
Jim Miller284b62e2010-06-08 14:27:42 -0700251 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
252 @Override
253 public void onReceive(Context context, Intent intent) {
254 mPolicy.enableKeyguard(true);
255 synchronized(mKeyguardTokenWatcher) {
256 // lazily evaluate this next time we're asked to disable keyguard
257 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
258 mKeyguardDisabled = false;
259 }
260 }
261 };
262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 final Context mContext;
264
265 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
270
271 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 /**
276 * All currently active sessions with clients.
277 */
278 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * Mapping from an IWindow IBinder to the server's Window object.
282 * This is also used as the lock for all of our state.
283 */
284 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
285
286 /**
287 * Mapping from a token IBinder to a WindowToken object.
288 */
289 final HashMap<IBinder, WindowToken> mTokenMap =
290 new HashMap<IBinder, WindowToken>();
291
292 /**
293 * The same tokens as mTokenMap, stored in a list for efficient iteration
294 * over them.
295 */
296 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 /**
299 * Window tokens that are in the process of exiting, but still
300 * on screen for animations.
301 */
302 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
303
304 /**
305 * Z-ordered (bottom-most first) list of all application tokens, for
306 * controlling the ordering of windows in different applications. This
307 * contains WindowToken objects.
308 */
309 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
310
311 /**
312 * Application tokens that are in the process of exiting, but still
313 * on screen for animations.
314 */
315 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * List of window tokens that have finished starting their application,
319 * and now need to have the policy remove their windows.
320 */
321 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
322
323 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700324 * This was the app token that was used to retrieve the last enter
325 * animation. It will be used for the next exit animation.
326 */
327 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800328
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700329 /**
330 * These were the layout params used to retrieve the last enter animation.
331 * They will be used for the next exit animation.
332 */
333 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800334
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700335 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 * Z-ordered (bottom-most first) list of all Window objects.
337 */
Jeff Browne33348b2010-07-15 23:54:05 -0700338 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339
340 /**
341 * Windows that are being resized. Used so we can tell the client about
342 * the resize after closing the transaction in which we resized the
343 * underlying surface.
344 */
345 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
346
347 /**
348 * Windows whose animations have ended and now must be removed.
349 */
350 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
351
352 /**
353 * Windows whose surface should be destroyed.
354 */
355 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
356
357 /**
358 * Windows that have lost input focus and are waiting for the new
359 * focus window to be displayed before they are told about this.
360 */
361 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
362
363 /**
364 * This is set when we have run out of memory, and will either be an empty
365 * list or contain windows that need to be force removed.
366 */
367 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700372 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 Surface mBlurSurface;
374 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700375 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800376 StrictModeFlash mStrictModeFlash;
Romain Guy06882f82009-06-10 13:36:04 -0700377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 final float[] mTmpFloats = new float[9];
381
382 boolean mSafeMode;
383 boolean mDisplayEnabled = false;
384 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700385 int mInitialDisplayWidth = 0;
386 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 int mRotation = 0;
388 int mRequestedRotation = 0;
389 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700390 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 ArrayList<IRotationWatcher> mRotationWatchers
392 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 boolean mLayoutNeeded = true;
395 boolean mAnimationPending = false;
396 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800397 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 boolean mWindowsFreezingScreen = false;
399 long mFreezeGcPending = 0;
400 int mAppsFreezingScreen = 0;
401
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800402 int mLayoutSeq = 0;
403
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800404 // State while inside of layoutAndPlaceSurfacesLocked().
405 boolean mFocusMayChange;
406
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800407 Configuration mCurConfiguration = new Configuration();
408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 // This is held as long as we have the screen frozen, to give us time to
410 // perform a rotation animation when turning off shows the lock screen which
411 // changes the orientation.
412 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 // State management of app transitions. When we are preparing for a
415 // transition, mNextAppTransition will be the kind of transition to
416 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
417 // mOpeningApps and mClosingApps are the lists of tokens that will be
418 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700419 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700420 String mNextAppTransitionPackage;
421 int mNextAppTransitionEnter;
422 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700424 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 boolean mAppTransitionTimeout = false;
426 boolean mStartingIconInTransition = false;
427 boolean mSkipAppTransitionAnimation = false;
428 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
429 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700430 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
431 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 H mH = new H();
436
437 WindowState mCurrentFocus = null;
438 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 // This just indicates the window the input method is on top of, not
441 // necessarily the window its input is going to.
442 WindowState mInputMethodTarget = null;
443 WindowState mUpcomingInputMethodTarget = null;
444 boolean mInputMethodTargetWaitingAnim;
445 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 WindowState mInputMethodWindow = null;
448 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
449
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700450 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800451
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700452 // If non-null, this is the currently visible window that is associated
453 // with the wallpaper.
454 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700455 // If non-null, we are in the middle of animating from one wallpaper target
456 // to another, and this is the lower one in Z-order.
457 WindowState mLowerWallpaperTarget = null;
458 // If non-null, we are in the middle of animating from one wallpaper target
459 // to another, and this is the higher one in Z-order.
460 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800461 // Window currently running an animation that has requested it be detached
462 // from the wallpaper. This means we need to ensure the wallpaper is
463 // visible behind it in case it animates in a way that would allow it to be
464 // seen.
465 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700466 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700467 float mLastWallpaperX = -1;
468 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800469 float mLastWallpaperXStep = -1;
470 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700471 // This is set when we are waiting for a wallpaper to tell us it is done
472 // changing its scroll position.
473 WindowState mWaitingOnWallpaper;
474 // The last time we had a timeout when waiting for a wallpaper.
475 long mLastWallpaperTimeoutTime;
476 // We give a wallpaper up to 150ms to finish scrolling.
477 static final long WALLPAPER_TIMEOUT = 150;
478 // Time we wait after a timeout before trying to wait again.
479 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 AppWindowToken mFocusedApp = null;
482
483 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 float mWindowAnimationScale = 1.0f;
486 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700487
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700488 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489
490 // Who is holding the screen on.
491 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700492 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700493
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700494 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700497 * Drag/drop state
498 */
499 class DragState {
500 IBinder mToken;
501 Surface mSurface;
502 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700503 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700504 ClipData mData;
505 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700506 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700507 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700508 float mThumbOffsetX, mThumbOffsetY;
509 InputChannel mServerChannel, mClientChannel;
510 WindowState mTargetWindow;
511 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700512 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700513
514 private final Rect tmpRect = new Rect();
515
Chris Tate7b362e42010-11-04 16:02:52 -0700516 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700517 mToken = token;
518 mSurface = surface;
519 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700520 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700521 mNotifiedWindows = new ArrayList<WindowState>();
522 }
523
524 void reset() {
525 if (mSurface != null) {
526 mSurface.destroy();
527 }
528 mSurface = null;
529 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700530 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700531 mToken = null;
532 mData = null;
533 mThumbOffsetX = mThumbOffsetY = 0;
534 mNotifiedWindows = null;
535 }
536
537 void register() {
538 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
539 if (mClientChannel != null) {
540 Slog.e(TAG, "Duplicate register of drag input channel");
541 } else {
542 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
543 mServerChannel = channels[0];
544 mClientChannel = channels[1];
545 mInputManager.registerInputChannel(mServerChannel);
546 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
547 mH.getLooper().getQueue());
548 }
549 }
550
551 void unregister() {
552 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
553 if (mClientChannel == null) {
554 Slog.e(TAG, "Unregister of nonexistent drag input channel");
555 } else {
556 mInputManager.unregisterInputChannel(mServerChannel);
557 InputQueue.unregisterInputChannel(mClientChannel);
558 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700559 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700560 mClientChannel = null;
561 mServerChannel = null;
562 }
563 }
564
Chris Tatea32dcf72010-10-14 12:13:50 -0700565 int getDragLayerLw() {
566 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
567 * TYPE_LAYER_MULTIPLIER
568 + TYPE_LAYER_OFFSET;
569 }
570
Christopher Tatea53146c2010-09-07 11:57:52 -0700571 /* call out to each visible window/session informing it about the drag
572 */
Chris Tateb8203e92010-10-12 14:23:21 -0700573 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700574 // Cache a base-class instance of the clip metadata so that parceling
575 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700576 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700577 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700578 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700579
580 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700581 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700582 }
583
Christopher Tate2c095f32010-10-04 14:13:40 -0700584 final int N = mWindows.size();
585 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700586 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700587 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 }
589
590 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
591 * designated window is potentially a drop recipient. There are race situations
592 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
593 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700594 *
595 * This method clones the 'event' parameter if it's being delivered to the same
596 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700597 */
Chris Tateb478f462010-10-15 16:02:26 -0700598 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
599 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700600 // Don't actually send the event if the drag is supposed to be pinned
601 // to the originating window but 'newWin' is not that window.
602 if (mLocalOnly) {
603 final IBinder winBinder = newWin.mClient.asBinder();
604 if (winBinder != mLocalWin) {
605 if (DEBUG_DRAG) {
606 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
607 }
608 return;
609 }
610 }
611
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700612 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700613 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
614 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700615 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700616 try {
617 newWin.mClient.dispatchDragEvent(event);
618 // track each window that we've notified that the drag is starting
619 mNotifiedWindows.add(newWin);
620 } catch (RemoteException e) {
621 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700622 } finally {
623 // if the callee was local, the dispatch has already recycled the event
624 if (Process.myPid() != newWin.mSession.mPid) {
625 event.recycle();
626 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700627 }
628 }
629 }
630
631 /* helper - construct and send a DRAG_STARTED event only if the window has not
632 * previously been notified, i.e. it became visible after the drag operation
633 * was begun. This is a rare case.
634 */
635 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700636 if (mDragInProgress) {
637 // If we have sent the drag-started, we needn't do so again
638 for (WindowState ws : mNotifiedWindows) {
639 if (ws == newWin) {
640 return;
641 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700642 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700643 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700644 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700645 }
Chris Tateb478f462010-10-15 16:02:26 -0700646 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700647 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700648 }
649
Chris Tated4533f142010-10-19 15:15:08 -0700650 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700651 if (DEBUG_DRAG) {
652 Slog.d(TAG, "broadcasting DRAG_ENDED");
653 }
Chris Tated4533f142010-10-19 15:15:08 -0700654 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
655 0, 0, null, null, mDragResult);
656 for (WindowState ws: mNotifiedWindows) {
657 try {
658 ws.mClient.dispatchDragEvent(evt);
659 } catch (RemoteException e) {
660 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700661 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700662 }
Chris Tated4533f142010-10-19 15:15:08 -0700663 mNotifiedWindows.clear();
664 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700665 evt.recycle();
666 }
667
Chris Tated4533f142010-10-19 15:15:08 -0700668 void endDragLw() {
669 mDragState.broadcastDragEndedLw();
670
671 // stop intercepting input
672 mDragState.unregister();
673 mInputMonitor.updateInputWindowsLw();
674
675 // free our resources and drop all the object references
676 mDragState.reset();
677 mDragState = null;
678 }
679
Christopher Tatea53146c2010-09-07 11:57:52 -0700680 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700681 final int myPid = Process.myPid();
682
683 // Move the surface to the given touch
684 mSurface.openTransaction();
685 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
686 mSurface.closeTransaction();
687
688 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700689 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700690 if (mLocalOnly) {
691 final IBinder touchedBinder = touchedWin.mClient.asBinder();
692 if (touchedBinder != mLocalWin) {
693 // This drag is pinned only to the originating window, but the drag
694 // point is outside that window. Pretend it's over empty space.
695 touchedWin = null;
696 }
697 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700698 try {
699 // have we dragged over a new window?
700 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
701 if (DEBUG_DRAG) {
702 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
703 }
704 // force DRAG_EXITED_EVENT if appropriate
705 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700706 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700707 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700708 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700709 if (myPid != mTargetWindow.mSession.mPid) {
710 evt.recycle();
711 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700712 }
713 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700714 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700715 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
716 }
717 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700718 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700719 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700720 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700721 if (myPid != touchedWin.mSession.mPid) {
722 evt.recycle();
723 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700724 }
725 } catch (RemoteException e) {
726 Slog.w(TAG, "can't send drag notification to windows");
727 }
728 mTargetWindow = touchedWin;
729 }
730
Chris Tated4533f142010-10-19 15:15:08 -0700731 // Tell the drop target about the data. Returns 'true' if we can immediately
732 // dispatch the global drag-ended message, 'false' if we need to wait for a
733 // result from the recipient.
734 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700735 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700736 if (touchedWin == null) {
737 // "drop" outside a valid window -- no recipient to apply a
738 // timeout to, and we can send the drag-ended message immediately.
739 mDragResult = false;
740 return true;
741 }
742
743 if (DEBUG_DRAG) {
744 Slog.d(TAG, "sending DROP to " + touchedWin);
745 }
746 final int myPid = Process.myPid();
747 final IBinder token = touchedWin.mClient.asBinder();
748 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
749 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
750 null, mData, false);
751 try {
752 touchedWin.mClient.dispatchDragEvent(evt);
753
754 // 5 second timeout for this window to respond to the drop
755 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
756 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
757 mH.sendMessageDelayed(msg, 5000);
758 } catch (RemoteException e) {
759 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
760 return true;
761 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700762 if (myPid != touchedWin.mSession.mPid) {
763 evt.recycle();
764 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700765 }
Chris Tated4533f142010-10-19 15:15:08 -0700766 mToken = token;
767 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700768 }
769
770 // Find the visible, touch-deliverable window under the given point
771 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
772 WindowState touchedWin = null;
773 final int x = (int) xf;
774 final int y = (int) yf;
775 final ArrayList<WindowState> windows = mWindows;
776 final int N = windows.size();
777 for (int i = N - 1; i >= 0; i--) {
778 WindowState child = windows.get(i);
779 final int flags = child.mAttrs.flags;
780 if (!child.isVisibleLw()) {
781 // not visible == don't tell about drags
782 continue;
783 }
784 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
785 // not touchable == don't tell about drags
786 continue;
787 }
788 // account for the window's decor etc
789 tmpRect.set(child.mFrame);
790 if (child.mTouchableInsets == ViewTreeObserver
791 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
792 // The point is inside of the window if it is
793 // inside the frame, AND the content part of that
794 // frame that was given by the application.
795 tmpRect.left += child.mGivenContentInsets.left;
796 tmpRect.top += child.mGivenContentInsets.top;
797 tmpRect.right -= child.mGivenContentInsets.right;
798 tmpRect.bottom -= child.mGivenContentInsets.bottom;
799 } else if (child.mTouchableInsets == ViewTreeObserver
800 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
801 // The point is inside of the window if it is
802 // inside the frame, AND the visible part of that
803 // frame that was given by the application.
804 tmpRect.left += child.mGivenVisibleInsets.left;
805 tmpRect.top += child.mGivenVisibleInsets.top;
806 tmpRect.right -= child.mGivenVisibleInsets.right;
807 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
808 }
809 final int touchFlags = flags &
810 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
811 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
812 if (tmpRect.contains(x, y) || touchFlags == 0) {
813 // Found it
814 touchedWin = child;
815 break;
816 }
817 }
818
819 return touchedWin;
820 }
821 }
822
823 DragState mDragState = null;
824 private final InputHandler mDragInputHandler = new BaseInputHandler() {
825 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700826 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
827 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700828 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700829 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
830 && mDragState != null) {
831 boolean endDrag = false;
832 final float newX = event.getRawX();
833 final float newY = event.getRawY();
834
Christopher Tatea53146c2010-09-07 11:57:52 -0700835 switch (event.getAction()) {
836 case MotionEvent.ACTION_DOWN: {
837 if (DEBUG_DRAG) {
838 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
839 }
840 } break;
841
842 case MotionEvent.ACTION_MOVE: {
843 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700844 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700845 mDragState.notifyMoveLw(newX, newY);
846 }
847 } break;
848
849 case MotionEvent.ACTION_UP: {
850 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
851 + newX + "," + newY);
852 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700853 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700854 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700855 } break;
856
857 case MotionEvent.ACTION_CANCEL: {
858 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
859 endDrag = true;
860 } break;
861 }
862
863 if (endDrag) {
864 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
865 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700866 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700867 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700868 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700869 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700870
871 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700872 }
873 } catch (Exception e) {
874 Slog.e(TAG, "Exception caught by drag handleMotion", e);
875 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700876 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700877 }
878 }
879 };
880
881 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 * Whether the UI is currently running in touch mode (not showing
883 * navigational focus because the user is directly pressing the screen).
884 */
885 boolean mInTouchMode = false;
886
887 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700888 private ArrayList<WindowChangeListener> mWindowChangeListeners =
889 new ArrayList<WindowChangeListener>();
890 private boolean mWindowsChanged = false;
891
892 public interface WindowChangeListener {
893 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700894 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896
Dianne Hackbornc485a602009-03-24 22:39:49 -0700897 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700898 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700899
900 // The frame use to limit the size of the app running in compatibility mode.
901 Rect mCompatibleScreenFrame = new Rect();
902 // The surface used to fill the outer rim of the app running in compatibility mode.
903 Surface mBackgroundFillerSurface = null;
904 boolean mBackgroundFillerShown = false;
905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 public static WindowManagerService main(Context context,
907 PowerManagerService pm, boolean haveInputMethods) {
908 WMThread thr = new WMThread(context, pm, haveInputMethods);
909 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 synchronized (thr) {
912 while (thr.mService == null) {
913 try {
914 thr.wait();
915 } catch (InterruptedException e) {
916 }
917 }
918 }
Romain Guy06882f82009-06-10 13:36:04 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 return thr.mService;
921 }
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 static class WMThread extends Thread {
924 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 private final Context mContext;
927 private final PowerManagerService mPM;
928 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 public WMThread(Context context, PowerManagerService pm,
931 boolean haveInputMethods) {
932 super("WindowManager");
933 mContext = context;
934 mPM = pm;
935 mHaveInputMethods = haveInputMethods;
936 }
Romain Guy06882f82009-06-10 13:36:04 -0700937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 public void run() {
939 Looper.prepare();
940 WindowManagerService s = new WindowManagerService(mContext, mPM,
941 mHaveInputMethods);
942 android.os.Process.setThreadPriority(
943 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700944 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 synchronized (this) {
947 mService = s;
948 notifyAll();
949 }
Romain Guy06882f82009-06-10 13:36:04 -0700950
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700951 // For debug builds, log event loop stalls to dropbox for analysis.
952 if (StrictMode.conditionallyEnableDebugLogging()) {
953 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
954 }
955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 Looper.loop();
957 }
958 }
959
960 static class PolicyThread extends Thread {
961 private final WindowManagerPolicy mPolicy;
962 private final WindowManagerService mService;
963 private final Context mContext;
964 private final PowerManagerService mPM;
965 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 public PolicyThread(WindowManagerPolicy policy,
968 WindowManagerService service, Context context,
969 PowerManagerService pm) {
970 super("WindowManagerPolicy");
971 mPolicy = policy;
972 mService = service;
973 mContext = context;
974 mPM = pm;
975 }
Romain Guy06882f82009-06-10 13:36:04 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 public void run() {
978 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800979 WindowManagerPolicyThread.set(this, Looper.myLooper());
980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800982 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 android.os.Process.setThreadPriority(
984 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700985 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 synchronized (this) {
989 mRunning = true;
990 notifyAll();
991 }
Romain Guy06882f82009-06-10 13:36:04 -0700992
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700993 // For debug builds, log event loop stalls to dropbox for analysis.
994 if (StrictMode.conditionallyEnableDebugLogging()) {
995 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
996 }
997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 Looper.loop();
999 }
1000 }
1001
1002 private WindowManagerService(Context context, PowerManagerService pm,
1003 boolean haveInputMethods) {
1004 mContext = context;
1005 mHaveInputMethods = haveInputMethods;
1006 mLimitedAlphaCompositing = context.getResources().getBoolean(
1007 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 mPowerManager = pm;
1010 mPowerManager.setPolicy(mPolicy);
1011 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1012 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1013 "SCREEN_FROZEN");
1014 mScreenFrozenLock.setReferenceCounted(false);
1015
1016 mActivityManager = ActivityManagerNative.getDefault();
1017 mBatteryStats = BatteryStatsService.getService();
1018
1019 // Get persisted window scale setting
1020 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1021 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1022 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1023 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001024
Jim Miller284b62e2010-06-08 14:27:42 -07001025 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1026 IntentFilter filter = new IntentFilter();
1027 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1028 mContext.registerReceiver(mBroadcastReceiver, filter);
1029
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001030 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1031 "KEEP_SCREEN_ON_FLAG");
1032 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033
Jeff Browne33348b2010-07-15 23:54:05 -07001034 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1037 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 synchronized (thr) {
1040 while (!thr.mRunning) {
1041 try {
1042 thr.wait();
1043 } catch (InterruptedException e) {
1044 }
1045 }
1046 }
Romain Guy06882f82009-06-10 13:36:04 -07001047
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001048 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 // Add ourself to the Watchdog monitors.
1051 Watchdog.getInstance().addMonitor(this);
1052 }
1053
1054 @Override
1055 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1056 throws RemoteException {
1057 try {
1058 return super.onTransact(code, data, reply, flags);
1059 } catch (RuntimeException e) {
1060 // The window manager only throws security exceptions, so let's
1061 // log all others.
1062 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001063 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 }
1065 throw e;
1066 }
1067 }
1068
Jeff Browne33348b2010-07-15 23:54:05 -07001069 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 TAG, "Adding window " + window + " at "
1073 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1074 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001075 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 }
1077
Jeff Browne33348b2010-07-15 23:54:05 -07001078 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001080 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 TAG, "Adding window " + window + " at "
1082 + i + " of " + mWindows.size() + " (before " + pos + ")");
1083 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001084 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 }
1086
1087 //This method finds out the index of a window that has the same app token as
1088 //win. used for z ordering the windows in mWindows
1089 private int findIdxBasedOnAppTokens(WindowState win) {
1090 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001091 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 int jmax = localmWindows.size();
1093 if(jmax == 0) {
1094 return -1;
1095 }
1096 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001097 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 if(wentry.mAppToken == win.mAppToken) {
1099 return j;
1100 }
1101 }
1102 return -1;
1103 }
Romain Guy06882f82009-06-10 13:36:04 -07001104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1106 final IWindow client = win.mClient;
1107 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001108 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 final int N = localmWindows.size();
1111 final WindowState attached = win.mAttachedWindow;
1112 int i;
1113 if (attached == null) {
1114 int tokenWindowsPos = token.windows.size();
1115 if (token.appWindowToken != null) {
1116 int index = tokenWindowsPos-1;
1117 if (index >= 0) {
1118 // If this application has existing windows, we
1119 // simply place the new window on top of them... but
1120 // keep the starting window on top.
1121 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1122 // Base windows go behind everything else.
1123 placeWindowBefore(token.windows.get(0), win);
1124 tokenWindowsPos = 0;
1125 } else {
1126 AppWindowToken atoken = win.mAppToken;
1127 if (atoken != null &&
1128 token.windows.get(index) == atoken.startingWindow) {
1129 placeWindowBefore(token.windows.get(index), win);
1130 tokenWindowsPos--;
1131 } else {
1132 int newIdx = findIdxBasedOnAppTokens(win);
1133 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001134 //there is a window above this one associated with the same
1135 //apptoken note that the window could be a floating window
1136 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001138 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001139 TAG, "Adding window " + win + " at "
1140 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001142 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 }
1145 }
1146 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001147 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 TAG, "Figuring out where to add app window "
1149 + client.asBinder() + " (token=" + token + ")");
1150 // Figure out where the window should go, based on the
1151 // order of applications.
1152 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001153 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 for (i=NA-1; i>=0; i--) {
1155 AppWindowToken t = mAppTokens.get(i);
1156 if (t == token) {
1157 i--;
1158 break;
1159 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001160
Dianne Hackborna8f60182009-09-01 19:01:50 -07001161 // We haven't reached the token yet; if this token
1162 // is not going to the bottom and has windows, we can
1163 // use it as an anchor for when we do reach the token.
1164 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 pos = t.windows.get(0);
1166 }
1167 }
1168 // We now know the index into the apps. If we found
1169 // an app window above, that gives us the position; else
1170 // we need to look some more.
1171 if (pos != null) {
1172 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001173 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 if (atoken != null) {
1175 final int NC = atoken.windows.size();
1176 if (NC > 0) {
1177 WindowState bottom = atoken.windows.get(0);
1178 if (bottom.mSubLayer < 0) {
1179 pos = bottom;
1180 }
1181 }
1182 }
1183 placeWindowBefore(pos, win);
1184 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001185 // Continue looking down until we find the first
1186 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 while (i >= 0) {
1188 AppWindowToken t = mAppTokens.get(i);
1189 final int NW = t.windows.size();
1190 if (NW > 0) {
1191 pos = t.windows.get(NW-1);
1192 break;
1193 }
1194 i--;
1195 }
1196 if (pos != null) {
1197 // Move in front of any windows attached to this
1198 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001199 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 if (atoken != null) {
1201 final int NC = atoken.windows.size();
1202 if (NC > 0) {
1203 WindowState top = atoken.windows.get(NC-1);
1204 if (top.mSubLayer >= 0) {
1205 pos = top;
1206 }
1207 }
1208 }
1209 placeWindowAfter(pos, win);
1210 } else {
1211 // Just search for the start of this layer.
1212 final int myLayer = win.mBaseLayer;
1213 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001214 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 if (w.mBaseLayer > myLayer) {
1216 break;
1217 }
1218 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001219 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001220 TAG, "Adding window " + win + " at "
1221 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001223 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 }
1225 }
1226 }
1227 } else {
1228 // Figure out where window should go, based on layer.
1229 final int myLayer = win.mBaseLayer;
1230 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001231 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 i++;
1233 break;
1234 }
1235 }
1236 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001237 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001238 TAG, "Adding window " + win + " at "
1239 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001241 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
1243 if (addToToken) {
1244 token.windows.add(tokenWindowsPos, win);
1245 }
1246
1247 } else {
1248 // Figure out this window's ordering relative to the window
1249 // it is attached to.
1250 final int NA = token.windows.size();
1251 final int sublayer = win.mSubLayer;
1252 int largestSublayer = Integer.MIN_VALUE;
1253 WindowState windowWithLargestSublayer = null;
1254 for (i=0; i<NA; i++) {
1255 WindowState w = token.windows.get(i);
1256 final int wSublayer = w.mSubLayer;
1257 if (wSublayer >= largestSublayer) {
1258 largestSublayer = wSublayer;
1259 windowWithLargestSublayer = w;
1260 }
1261 if (sublayer < 0) {
1262 // For negative sublayers, we go below all windows
1263 // in the same sublayer.
1264 if (wSublayer >= sublayer) {
1265 if (addToToken) {
1266 token.windows.add(i, win);
1267 }
1268 placeWindowBefore(
1269 wSublayer >= 0 ? attached : w, win);
1270 break;
1271 }
1272 } else {
1273 // For positive sublayers, we go above all windows
1274 // in the same sublayer.
1275 if (wSublayer > sublayer) {
1276 if (addToToken) {
1277 token.windows.add(i, win);
1278 }
1279 placeWindowBefore(w, win);
1280 break;
1281 }
1282 }
1283 }
1284 if (i >= NA) {
1285 if (addToToken) {
1286 token.windows.add(win);
1287 }
1288 if (sublayer < 0) {
1289 placeWindowBefore(attached, win);
1290 } else {
1291 placeWindowAfter(largestSublayer >= 0
1292 ? windowWithLargestSublayer
1293 : attached,
1294 win);
1295 }
1296 }
1297 }
Romain Guy06882f82009-06-10 13:36:04 -07001298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 if (win.mAppToken != null && addToToken) {
1300 win.mAppToken.allAppWindows.add(win);
1301 }
1302 }
Romain Guy06882f82009-06-10 13:36:04 -07001303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 static boolean canBeImeTarget(WindowState w) {
1305 final int fl = w.mAttrs.flags
1306 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1307 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1308 return w.isVisibleOrAdding();
1309 }
1310 return false;
1311 }
Romain Guy06882f82009-06-10 13:36:04 -07001312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001314 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 final int N = localmWindows.size();
1316 WindowState w = null;
1317 int i = N;
1318 while (i > 0) {
1319 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001320 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001321
Joe Onorato8a9b2202010-02-26 18:56:32 -08001322 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 // + Integer.toHexString(w.mAttrs.flags));
1324 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001325 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 // Yet more tricksyness! If this window is a "starting"
1328 // window, we do actually want to be on top of it, but
1329 // it is not -really- where input will go. So if the caller
1330 // is not actually looking to move the IME, look down below
1331 // for a real window to target...
1332 if (!willMove
1333 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1334 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001335 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1337 i--;
1338 w = wb;
1339 }
1340 }
1341 break;
1342 }
1343 }
Romain Guy06882f82009-06-10 13:36:04 -07001344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001346
Joe Onorato8a9b2202010-02-26 18:56:32 -08001347 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 if (willMove && w != null) {
1351 final WindowState curTarget = mInputMethodTarget;
1352 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 // Now some fun for dealing with window animations that
1355 // modify the Z order. We need to look at all windows below
1356 // the current target that are in this app, finding the highest
1357 // visible one in layering.
1358 AppWindowToken token = curTarget.mAppToken;
1359 WindowState highestTarget = null;
1360 int highestPos = 0;
1361 if (token.animating || token.animation != null) {
1362 int pos = 0;
1363 pos = localmWindows.indexOf(curTarget);
1364 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001365 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 if (win.mAppToken != token) {
1367 break;
1368 }
1369 if (!win.mRemoved) {
1370 if (highestTarget == null || win.mAnimLayer >
1371 highestTarget.mAnimLayer) {
1372 highestTarget = win;
1373 highestPos = pos;
1374 }
1375 }
1376 pos--;
1377 }
1378 }
Romain Guy06882f82009-06-10 13:36:04 -07001379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001381 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 + mNextAppTransition + " " + highestTarget
1383 + " animating=" + highestTarget.isAnimating()
1384 + " layer=" + highestTarget.mAnimLayer
1385 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001386
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001387 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 // If we are currently setting up for an animation,
1389 // hold everything until we can find out what will happen.
1390 mInputMethodTargetWaitingAnim = true;
1391 mInputMethodTarget = highestTarget;
1392 return highestPos + 1;
1393 } else if (highestTarget.isAnimating() &&
1394 highestTarget.mAnimLayer > w.mAnimLayer) {
1395 // If the window we are currently targeting is involved
1396 // with an animation, and it is on top of the next target
1397 // we will be over, then hold off on moving until
1398 // that is done.
1399 mInputMethodTarget = highestTarget;
1400 return highestPos + 1;
1401 }
1402 }
1403 }
1404 }
Romain Guy06882f82009-06-10 13:36:04 -07001405
Joe Onorato8a9b2202010-02-26 18:56:32 -08001406 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 if (w != null) {
1408 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001409 if (DEBUG_INPUT_METHOD) {
1410 RuntimeException e = null;
1411 if (!HIDE_STACK_CRAWLS) {
1412 e = new RuntimeException();
1413 e.fillInStackTrace();
1414 }
1415 Slog.w(TAG, "Moving IM target from "
1416 + mInputMethodTarget + " to " + w, e);
1417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418 mInputMethodTarget = w;
1419 if (w.mAppToken != null) {
1420 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1421 } else {
1422 setInputMethodAnimLayerAdjustment(0);
1423 }
1424 }
1425 return i+1;
1426 }
1427 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001428 if (DEBUG_INPUT_METHOD) {
1429 RuntimeException e = null;
1430 if (!HIDE_STACK_CRAWLS) {
1431 e = new RuntimeException();
1432 e.fillInStackTrace();
1433 }
1434 Slog.w(TAG, "Moving IM target from "
1435 + mInputMethodTarget + " to null", e);
1436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 mInputMethodTarget = null;
1438 setInputMethodAnimLayerAdjustment(0);
1439 }
1440 return -1;
1441 }
Romain Guy06882f82009-06-10 13:36:04 -07001442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 void addInputMethodWindowToListLocked(WindowState win) {
1444 int pos = findDesiredInputMethodWindowIndexLocked(true);
1445 if (pos >= 0) {
1446 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001447 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001448 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001450 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 moveInputMethodDialogsLocked(pos+1);
1452 return;
1453 }
1454 win.mTargetAppToken = null;
1455 addWindowToListInOrderLocked(win, true);
1456 moveInputMethodDialogsLocked(pos);
1457 }
Romain Guy06882f82009-06-10 13:36:04 -07001458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001460 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 mInputMethodAnimLayerAdjustment = adj;
1462 WindowState imw = mInputMethodWindow;
1463 if (imw != null) {
1464 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001465 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 + " anim layer: " + imw.mAnimLayer);
1467 int wi = imw.mChildWindows.size();
1468 while (wi > 0) {
1469 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001470 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001472 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 + " anim layer: " + cw.mAnimLayer);
1474 }
1475 }
1476 int di = mInputMethodDialogs.size();
1477 while (di > 0) {
1478 di --;
1479 imw = mInputMethodDialogs.get(di);
1480 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001481 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 + " anim layer: " + imw.mAnimLayer);
1483 }
1484 }
Romain Guy06882f82009-06-10 13:36:04 -07001485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1487 int wpos = mWindows.indexOf(win);
1488 if (wpos >= 0) {
1489 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001490 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001492 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 int NC = win.mChildWindows.size();
1494 while (NC > 0) {
1495 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001496 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 int cpos = mWindows.indexOf(cw);
1498 if (cpos >= 0) {
1499 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001500 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001501 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 mWindows.remove(cpos);
1503 }
1504 }
1505 }
1506 return interestingPos;
1507 }
Romain Guy06882f82009-06-10 13:36:04 -07001508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 private void reAddWindowToListInOrderLocked(WindowState win) {
1510 addWindowToListInOrderLocked(win, false);
1511 // This is a hack to get all of the child windows added as well
1512 // at the right position. Child windows should be rare and
1513 // this case should be rare, so it shouldn't be that big a deal.
1514 int wpos = mWindows.indexOf(win);
1515 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001516 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001517 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001519 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 reAddWindowLocked(wpos, win);
1521 }
1522 }
Romain Guy06882f82009-06-10 13:36:04 -07001523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 void logWindowList(String prefix) {
1525 int N = mWindows.size();
1526 while (N > 0) {
1527 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001528 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 }
1530 }
Romain Guy06882f82009-06-10 13:36:04 -07001531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 void moveInputMethodDialogsLocked(int pos) {
1533 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001536 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 for (int i=0; i<N; i++) {
1538 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1539 }
1540 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001541 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 logWindowList(" ");
1543 }
Romain Guy06882f82009-06-10 13:36:04 -07001544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 if (pos >= 0) {
1546 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1547 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001548 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 if (wp == mInputMethodWindow) {
1550 pos++;
1551 }
1552 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001553 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001554 for (int i=0; i<N; i++) {
1555 WindowState win = dialogs.get(i);
1556 win.mTargetAppToken = targetAppToken;
1557 pos = reAddWindowLocked(pos, win);
1558 }
1559 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 logWindowList(" ");
1562 }
1563 return;
1564 }
1565 for (int i=0; i<N; i++) {
1566 WindowState win = dialogs.get(i);
1567 win.mTargetAppToken = null;
1568 reAddWindowToListInOrderLocked(win);
1569 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001570 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 logWindowList(" ");
1572 }
1573 }
1574 }
Romain Guy06882f82009-06-10 13:36:04 -07001575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1577 final WindowState imWin = mInputMethodWindow;
1578 final int DN = mInputMethodDialogs.size();
1579 if (imWin == null && DN == 0) {
1580 return false;
1581 }
Romain Guy06882f82009-06-10 13:36:04 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1584 if (imPos >= 0) {
1585 // In this case, the input method windows are to be placed
1586 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 // First check to see if the input method windows are already
1589 // located here, and contiguous.
1590 final int N = mWindows.size();
1591 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001592 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 // Figure out the actual input method window that should be
1595 // at the bottom of their stack.
1596 WindowState baseImWin = imWin != null
1597 ? imWin : mInputMethodDialogs.get(0);
1598 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001599 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 if (cw.mSubLayer < 0) baseImWin = cw;
1601 }
Romain Guy06882f82009-06-10 13:36:04 -07001602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 if (firstImWin == baseImWin) {
1604 // The windows haven't moved... but are they still contiguous?
1605 // First find the top IM window.
1606 int pos = imPos+1;
1607 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001608 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 break;
1610 }
1611 pos++;
1612 }
1613 pos++;
1614 // Now there should be no more input method windows above.
1615 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001616 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 break;
1618 }
1619 pos++;
1620 }
1621 if (pos >= N) {
1622 // All is good!
1623 return false;
1624 }
1625 }
Romain Guy06882f82009-06-10 13:36:04 -07001626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 if (imWin != null) {
1628 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001629 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 logWindowList(" ");
1631 }
1632 imPos = tmpRemoveWindowLocked(imPos, imWin);
1633 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001634 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 logWindowList(" ");
1636 }
1637 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1638 reAddWindowLocked(imPos, imWin);
1639 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001640 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 logWindowList(" ");
1642 }
1643 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1644 } else {
1645 moveInputMethodDialogsLocked(imPos);
1646 }
Romain Guy06882f82009-06-10 13:36:04 -07001647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 } else {
1649 // In this case, the input method windows go in a fixed layer,
1650 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001653 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 tmpRemoveWindowLocked(0, imWin);
1655 imWin.mTargetAppToken = null;
1656 reAddWindowToListInOrderLocked(imWin);
1657 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001658 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 logWindowList(" ");
1660 }
1661 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1662 } else {
1663 moveInputMethodDialogsLocked(-1);;
1664 }
Romain Guy06882f82009-06-10 13:36:04 -07001665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 }
Romain Guy06882f82009-06-10 13:36:04 -07001667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 if (needAssignLayers) {
1669 assignLayersLocked();
1670 }
Romain Guy06882f82009-06-10 13:36:04 -07001671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 return true;
1673 }
Romain Guy06882f82009-06-10 13:36:04 -07001674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 void adjustInputMethodDialogsLocked() {
1676 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1677 }
Romain Guy06882f82009-06-10 13:36:04 -07001678
Dianne Hackborn25994b42009-09-04 14:21:19 -07001679 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001680 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001681 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1682 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1683 ? wallpaperTarget.mAppToken.animation : null)
1684 + " upper=" + mUpperWallpaperTarget
1685 + " lower=" + mLowerWallpaperTarget);
1686 return (wallpaperTarget != null
1687 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1688 && wallpaperTarget.mAppToken.animation != null)))
1689 || mUpperWallpaperTarget != null
1690 || mLowerWallpaperTarget != null;
1691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001693 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1694 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001695
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001696 int adjustWallpaperWindowsLocked() {
1697 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001698
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001699 final int dw = mDisplay.getWidth();
1700 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001701
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001702 // First find top-most window that has asked to be on top of the
1703 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001704 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001705 int N = localmWindows.size();
1706 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001707 WindowState foundW = null;
1708 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001709 WindowState topCurW = null;
1710 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001711 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001712 int i = N;
1713 while (i > 0) {
1714 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001715 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001716 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1717 if (topCurW == null) {
1718 topCurW = w;
1719 topCurI = i;
1720 }
1721 continue;
1722 }
1723 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001724 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001725 // If this window's app token is hidden and not animating,
1726 // it is of no interest to us.
1727 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001728 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001729 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001730 continue;
1731 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001732 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001733 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001734 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1735 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001736 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001737 && (mWallpaperTarget == w
1738 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001739 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001740 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001741 foundW = w;
1742 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001743 if (w == mWallpaperTarget && ((w.mAppToken != null
1744 && w.mAppToken.animation != null)
1745 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 // The current wallpaper target is animating, so we'll
1747 // look behind it for another possible target and figure
1748 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001749 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001750 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001751 continue;
1752 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001753 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001754 } else if (w == mWindowDetachedWallpaper) {
1755 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001756 }
1757 }
1758
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001759 if (foundW == null && windowDetachedI >= 0) {
1760 if (DEBUG_WALLPAPER) Slog.v(TAG,
1761 "Found animating detached wallpaper activity: #" + i + "=" + w);
1762 foundW = w;
1763 foundI = windowDetachedI;
1764 }
1765
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001766 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001767 // If we are currently waiting for an app transition, and either
1768 // the current target or the next target are involved with it,
1769 // then hold off on doing anything with the wallpaper.
1770 // Note that we are checking here for just whether the target
1771 // is part of an app token... which is potentially overly aggressive
1772 // (the app token may not be involved in the transition), but good
1773 // enough (we'll just wait until whatever transition is pending
1774 // executes).
1775 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001776 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001777 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001778 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001779 }
1780 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001781 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001782 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001783 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001784 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001785 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001786
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001787 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001788 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001789 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001790 + " oldTarget: " + mWallpaperTarget);
1791 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001792
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001793 mLowerWallpaperTarget = null;
1794 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001795
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001796 WindowState oldW = mWallpaperTarget;
1797 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001798
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001799 // Now what is happening... if the current and new targets are
1800 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001801 if (foundW != null && oldW != null) {
1802 boolean oldAnim = oldW.mAnimation != null
1803 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1804 boolean foundAnim = foundW.mAnimation != null
1805 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001808 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001809 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001810 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001811 int oldI = localmWindows.indexOf(oldW);
1812 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 }
1815 if (oldI >= 0) {
1816 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001817 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 + "=" + oldW + "; new#" + foundI
1819 + "=" + foundW);
1820 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001821
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001822 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001823 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001824 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001825 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001826 }
1827 mWallpaperTarget = oldW;
1828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001830 // Now set the upper and lower wallpaper targets
1831 // correctly, and make sure that we are positioning
1832 // the wallpaper below the lower.
1833 if (foundI > oldI) {
1834 // The new target is on top of the old one.
1835 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001836 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001837 }
1838 mUpperWallpaperTarget = foundW;
1839 mLowerWallpaperTarget = oldW;
1840 foundW = oldW;
1841 foundI = oldI;
1842 } else {
1843 // The new target is below the old one.
1844 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 }
1847 mUpperWallpaperTarget = oldW;
1848 mLowerWallpaperTarget = foundW;
1849 }
1850 }
1851 }
1852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001853
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001854 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001855 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001856 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1857 || (mLowerWallpaperTarget.mAppToken != null
1858 && mLowerWallpaperTarget.mAppToken.animation != null);
1859 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1860 || (mUpperWallpaperTarget.mAppToken != null
1861 && mUpperWallpaperTarget.mAppToken.animation != null);
1862 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001863 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 }
1866 mLowerWallpaperTarget = null;
1867 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001868 }
1869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001870
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001871 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001872 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001873 // The window is visible to the compositor... but is it visible
1874 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001875 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001876 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001877
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001878 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001879 // its layer adjustment. Only do this if we are not transfering
1880 // between two wallpaper targets.
1881 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001882 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001883 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001884
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001885 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1886 * TYPE_LAYER_MULTIPLIER
1887 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001888
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001889 // Now w is the window we are supposed to be behind... but we
1890 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001891 // AND any starting window associated with it, AND below the
1892 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001893 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001894 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001895 if (wb.mBaseLayer < maxLayer &&
1896 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001897 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001898 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001899 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001900 // This window is not related to the previous one in any
1901 // interesting way, so stop here.
1902 break;
1903 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001904 foundW = wb;
1905 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001906 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001907 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001908 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001909 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001910
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001911 if (foundW == null && topCurW != null) {
1912 // There is no wallpaper target, so it goes at the bottom.
1913 // We will assume it is the same place as last time, if known.
1914 foundW = topCurW;
1915 foundI = topCurI+1;
1916 } else {
1917 // Okay i is the position immediately above the wallpaper. Look at
1918 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001919 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001921
Dianne Hackborn284ac932009-08-28 10:34:25 -07001922 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001923 if (mWallpaperTarget.mWallpaperX >= 0) {
1924 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001925 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001926 }
1927 if (mWallpaperTarget.mWallpaperY >= 0) {
1928 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001929 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001930 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001932
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001933 // Start stepping backwards from here, ensuring that our wallpaper windows
1934 // are correctly placed.
1935 int curTokenIndex = mWallpaperTokens.size();
1936 while (curTokenIndex > 0) {
1937 curTokenIndex--;
1938 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001939 if (token.hidden == visible) {
1940 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1941 token.hidden = !visible;
1942 // Need to do a layout to ensure the wallpaper now has the
1943 // correct size.
1944 mLayoutNeeded = true;
1945 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001946
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001947 int curWallpaperIndex = token.windows.size();
1948 while (curWallpaperIndex > 0) {
1949 curWallpaperIndex--;
1950 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001951
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001952 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001953 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001954 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001955
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001956 // First, make sure the client has the current visibility
1957 // state.
1958 if (wallpaper.mWallpaperVisible != visible) {
1959 wallpaper.mWallpaperVisible = visible;
1960 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001961 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001962 "Setting visibility of wallpaper " + wallpaper
1963 + ": " + visible);
1964 wallpaper.mClient.dispatchAppVisibility(visible);
1965 } catch (RemoteException e) {
1966 }
1967 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001968
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001969 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001970 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001971 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001972
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001973 // First, if this window is at the current index, then all
1974 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001975 if (wallpaper == foundW) {
1976 foundI--;
1977 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001978 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001979 continue;
1980 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001981
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001982 // The window didn't match... the current wallpaper window,
1983 // wherever it is, is in the wrong place, so make sure it is
1984 // not in the list.
1985 int oldIndex = localmWindows.indexOf(wallpaper);
1986 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001987 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001988 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001989 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001990 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001991 if (oldIndex < foundI) {
1992 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001993 }
1994 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001995
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001996 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001997 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001998 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001999 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002000
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002001 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002002 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002003 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002004 }
2005 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002006
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002007 return changed;
2008 }
2009
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002010 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002012 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002013 mWallpaperAnimLayerAdjustment = adj;
2014 int curTokenIndex = mWallpaperTokens.size();
2015 while (curTokenIndex > 0) {
2016 curTokenIndex--;
2017 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2018 int curWallpaperIndex = token.windows.size();
2019 while (curWallpaperIndex > 0) {
2020 curWallpaperIndex--;
2021 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2022 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002023 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002024 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002025 }
2026 }
2027 }
2028
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002029 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2030 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002031 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002032 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002033 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002034 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002035 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2036 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2037 changed = wallpaperWin.mXOffset != offset;
2038 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002039 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002040 + wallpaperWin + " x: " + offset);
2041 wallpaperWin.mXOffset = offset;
2042 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002043 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002044 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002045 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002046 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002047 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002048
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002049 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002050 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002051 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2052 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2053 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002055 + wallpaperWin + " y: " + offset);
2056 changed = true;
2057 wallpaperWin.mYOffset = offset;
2058 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002059 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002060 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002061 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002062 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002063 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002064
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002065 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002066 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002067 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002068 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2069 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002070 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002071 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002072 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002073 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002074 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2075 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002076 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002077 if (mWaitingOnWallpaper != null) {
2078 long start = SystemClock.uptimeMillis();
2079 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2080 < start) {
2081 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002082 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002083 "Waiting for offset complete...");
2084 mWindowMap.wait(WALLPAPER_TIMEOUT);
2085 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002086 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002087 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002088 if ((start+WALLPAPER_TIMEOUT)
2089 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002090 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002091 + wallpaperWin);
2092 mLastWallpaperTimeoutTime = start;
2093 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002094 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002095 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002096 }
2097 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002098 } catch (RemoteException e) {
2099 }
2100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002101
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002102 return changed;
2103 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002104
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002105 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002106 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002107 if (mWaitingOnWallpaper != null &&
2108 mWaitingOnWallpaper.mClient.asBinder() == window) {
2109 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002110 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002111 }
2112 }
2113 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002114
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002115 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002116 final int dw = mDisplay.getWidth();
2117 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002118
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002119 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002120
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002121 WindowState target = mWallpaperTarget;
2122 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002123 if (target.mWallpaperX >= 0) {
2124 mLastWallpaperX = target.mWallpaperX;
2125 } else if (changingTarget.mWallpaperX >= 0) {
2126 mLastWallpaperX = changingTarget.mWallpaperX;
2127 }
2128 if (target.mWallpaperY >= 0) {
2129 mLastWallpaperY = target.mWallpaperY;
2130 } else if (changingTarget.mWallpaperY >= 0) {
2131 mLastWallpaperY = changingTarget.mWallpaperY;
2132 }
2133 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002134
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002135 int curTokenIndex = mWallpaperTokens.size();
2136 while (curTokenIndex > 0) {
2137 curTokenIndex--;
2138 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2139 int curWallpaperIndex = token.windows.size();
2140 while (curWallpaperIndex > 0) {
2141 curWallpaperIndex--;
2142 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2143 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2144 wallpaper.computeShownFrameLocked();
2145 changed = true;
2146 // We only want to be synchronous with one wallpaper.
2147 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002148 }
2149 }
2150 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002151
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002152 return changed;
2153 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002154
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002155 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002156 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002157 final int dw = mDisplay.getWidth();
2158 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002159
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002160 int curTokenIndex = mWallpaperTokens.size();
2161 while (curTokenIndex > 0) {
2162 curTokenIndex--;
2163 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002164 if (token.hidden == visible) {
2165 token.hidden = !visible;
2166 // Need to do a layout to ensure the wallpaper now has the
2167 // correct size.
2168 mLayoutNeeded = true;
2169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002170
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002171 int curWallpaperIndex = token.windows.size();
2172 while (curWallpaperIndex > 0) {
2173 curWallpaperIndex--;
2174 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2175 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002176 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002177 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002178
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002179 if (wallpaper.mWallpaperVisible != visible) {
2180 wallpaper.mWallpaperVisible = visible;
2181 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002182 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002183 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002184 + ": " + visible);
2185 wallpaper.mClient.dispatchAppVisibility(visible);
2186 } catch (RemoteException e) {
2187 }
2188 }
2189 }
2190 }
2191 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193 public int addWindow(Session session, IWindow client,
2194 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002195 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 int res = mPolicy.checkAddPermission(attrs);
2197 if (res != WindowManagerImpl.ADD_OKAY) {
2198 return res;
2199 }
Romain Guy06882f82009-06-10 13:36:04 -07002200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 boolean reportNewConfig = false;
2202 WindowState attachedWindow = null;
2203 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002204 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002208 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 }
Romain Guy06882f82009-06-10 13:36:04 -07002210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002212 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2214 }
2215
2216 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002217 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002219 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 + attrs.token + ". Aborting.");
2221 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2222 }
2223 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2224 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002225 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 + attrs.token + ". Aborting.");
2227 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2228 }
2229 }
2230
2231 boolean addToken = false;
2232 WindowToken token = mTokenMap.get(attrs.token);
2233 if (token == null) {
2234 if (attrs.type >= FIRST_APPLICATION_WINDOW
2235 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002236 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 + attrs.token + ". Aborting.");
2238 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2239 }
2240 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002241 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 + attrs.token + ". Aborting.");
2243 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2244 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002245 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002246 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002247 + attrs.token + ". Aborting.");
2248 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 token = new WindowToken(attrs.token, -1, false);
2251 addToken = true;
2252 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2253 && attrs.type <= LAST_APPLICATION_WINDOW) {
2254 AppWindowToken atoken = token.appWindowToken;
2255 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002256 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 + token + ". Aborting.");
2258 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2259 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002260 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 + token + ". Aborting.");
2262 return WindowManagerImpl.ADD_APP_EXITING;
2263 }
2264 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2265 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002266 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2268 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2269 }
2270 } else if (attrs.type == TYPE_INPUT_METHOD) {
2271 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002272 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 + attrs.token + ". Aborting.");
2274 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2275 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002276 } else if (attrs.type == TYPE_WALLPAPER) {
2277 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002278 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002279 + attrs.token + ". Aborting.");
2280 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2281 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 }
2283
2284 win = new WindowState(session, client, token,
2285 attachedWindow, attrs, viewVisibility);
2286 if (win.mDeathRecipient == null) {
2287 // Client has apparently died, so there is no reason to
2288 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002289 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 + " that is dead, aborting.");
2291 return WindowManagerImpl.ADD_APP_EXITING;
2292 }
2293
2294 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 res = mPolicy.prepareAddWindowLw(win, attrs);
2297 if (res != WindowManagerImpl.ADD_OKAY) {
2298 return res;
2299 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002300
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002301 if (outInputChannel != null) {
2302 String name = win.makeInputChannelName();
2303 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2304 win.mInputChannel = inputChannels[0];
2305 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2306
2307 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002308 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309
2310 // From now on, no exceptions or errors allowed!
2311
2312 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002313
Dianne Hackborn5132b372010-07-29 12:51:35 -07002314 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 if (addToken) {
2317 mTokenMap.put(attrs.token, token);
2318 mTokenList.add(token);
2319 }
2320 win.attach();
2321 mWindowMap.put(client.asBinder(), win);
2322
2323 if (attrs.type == TYPE_APPLICATION_STARTING &&
2324 token.appWindowToken != null) {
2325 token.appWindowToken.startingWindow = win;
2326 }
2327
2328 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 if (attrs.type == TYPE_INPUT_METHOD) {
2331 mInputMethodWindow = win;
2332 addInputMethodWindowToListLocked(win);
2333 imMayMove = false;
2334 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2335 mInputMethodDialogs.add(win);
2336 addWindowToListInOrderLocked(win, true);
2337 adjustInputMethodDialogsLocked();
2338 imMayMove = false;
2339 } else {
2340 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002341 if (attrs.type == TYPE_WALLPAPER) {
2342 mLastWallpaperTimeoutTime = 0;
2343 adjustWallpaperWindowsLocked();
2344 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002345 adjustWallpaperWindowsLocked();
2346 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 }
Romain Guy06882f82009-06-10 13:36:04 -07002348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002351 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 if (mInTouchMode) {
2354 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2355 }
2356 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2357 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2358 }
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002360 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002362 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2363 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 imMayMove = false;
2365 }
2366 }
Romain Guy06882f82009-06-10 13:36:04 -07002367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002369 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 }
Romain Guy06882f82009-06-10 13:36:04 -07002371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 assignLayersLocked();
2373 // Don't do layout here, the window must call
2374 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 //dump();
2377
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002378 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002379 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002380 }
Jeff Brown349703e2010-06-22 01:27:15 -07002381
Joe Onorato8a9b2202010-02-26 18:56:32 -08002382 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 TAG, "New client " + client.asBinder()
2384 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002385
2386 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2387 reportNewConfig = true;
2388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 }
2390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 if (reportNewConfig) {
2392 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 return res;
2398 }
Romain Guy06882f82009-06-10 13:36:04 -07002399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 public void removeWindow(Session session, IWindow client) {
2401 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002402 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 if (win == null) {
2404 return;
2405 }
2406 removeWindowLocked(session, win);
2407 }
2408 }
Romain Guy06882f82009-06-10 13:36:04 -07002409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 public void removeWindowLocked(Session session, WindowState win) {
2411
Joe Onorato8a9b2202010-02-26 18:56:32 -08002412 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 TAG, "Remove " + win + " client="
2414 + Integer.toHexString(System.identityHashCode(
2415 win.mClient.asBinder()))
2416 + ", surface=" + win.mSurface);
2417
2418 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002419
2420 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002421
Joe Onorato8a9b2202010-02-26 18:56:32 -08002422 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2424 + " mExiting=" + win.mExiting
2425 + " isAnimating=" + win.isAnimating()
2426 + " app-animation="
2427 + (win.mAppToken != null ? win.mAppToken.animation : null)
2428 + " inPendingTransaction="
2429 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2430 + " mDisplayFrozen=" + mDisplayFrozen);
2431 // Visibility of the removed window. Will be used later to update orientation later on.
2432 boolean wasVisible = false;
2433 // First, see if we need to run an animation. If we do, we have
2434 // to hold off on removing the window until the animation is done.
2435 // If the display is frozen, just remove immediately, since the
2436 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002437 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 // If we are not currently running the exit animation, we
2439 // need to see about starting one.
2440 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2443 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2444 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2445 }
2446 // Try starting an animation.
2447 if (applyAnimationLocked(win, transit, false)) {
2448 win.mExiting = true;
2449 }
2450 }
2451 if (win.mExiting || win.isAnimating()) {
2452 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002453 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002454 win.mExiting = true;
2455 win.mRemoveOnExit = true;
2456 mLayoutNeeded = true;
2457 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2458 performLayoutAndPlaceSurfacesLocked();
2459 if (win.mAppToken != null) {
2460 win.mAppToken.updateReportedVisibilityLocked();
2461 }
2462 //dump();
2463 Binder.restoreCallingIdentity(origId);
2464 return;
2465 }
2466 }
2467
2468 removeWindowInnerLocked(session, win);
2469 // Removing a visible window will effect the computed orientation
2470 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002471 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002472 != mForcedAppOrientation
2473 && updateOrientationFromAppTokensLocked()) {
2474 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 }
2476 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2477 Binder.restoreCallingIdentity(origId);
2478 }
Romain Guy06882f82009-06-10 13:36:04 -07002479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 if (mInputMethodTarget == win) {
2484 moveInputMethodWindowsIfNeededLocked(false);
2485 }
Romain Guy06882f82009-06-10 13:36:04 -07002486
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002487 if (false) {
2488 RuntimeException e = new RuntimeException("here");
2489 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002490 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002491 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 mPolicy.removeWindowLw(win);
2494 win.removeLocked();
2495
2496 mWindowMap.remove(win.mClient.asBinder());
2497 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002498 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002499 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500
2501 if (mInputMethodWindow == win) {
2502 mInputMethodWindow = null;
2503 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2504 mInputMethodDialogs.remove(win);
2505 }
Romain Guy06882f82009-06-10 13:36:04 -07002506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 final WindowToken token = win.mToken;
2508 final AppWindowToken atoken = win.mAppToken;
2509 token.windows.remove(win);
2510 if (atoken != null) {
2511 atoken.allAppWindows.remove(win);
2512 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002513 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 TAG, "**** Removing window " + win + ": count="
2515 + token.windows.size());
2516 if (token.windows.size() == 0) {
2517 if (!token.explicit) {
2518 mTokenMap.remove(token.token);
2519 mTokenList.remove(token);
2520 } else if (atoken != null) {
2521 atoken.firstWindowDrawn = false;
2522 }
2523 }
2524
2525 if (atoken != null) {
2526 if (atoken.startingWindow == win) {
2527 atoken.startingWindow = null;
2528 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2529 // If this is the last window and we had requested a starting
2530 // transition window, well there is no point now.
2531 atoken.startingData = null;
2532 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2533 // If this is the last window except for a starting transition
2534 // window, we need to get rid of the starting transition.
2535 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002536 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 + ": no more real windows");
2538 }
2539 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2540 mH.sendMessage(m);
2541 }
2542 }
Romain Guy06882f82009-06-10 13:36:04 -07002543
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002544 if (win.mAttrs.type == TYPE_WALLPAPER) {
2545 mLastWallpaperTimeoutTime = 0;
2546 adjustWallpaperWindowsLocked();
2547 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002548 adjustWallpaperWindowsLocked();
2549 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 if (!mInLayout) {
2552 assignLayersLocked();
2553 mLayoutNeeded = true;
2554 performLayoutAndPlaceSurfacesLocked();
2555 if (win.mAppToken != null) {
2556 win.mAppToken.updateReportedVisibilityLocked();
2557 }
2558 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002559
2560 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 }
2562
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002563 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2564 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2565 + ": " + msg + " / " + w.mAttrs.getTitle();
2566 if (where != null) {
2567 Slog.i(TAG, str, where);
2568 } else {
2569 Slog.i(TAG, str);
2570 }
2571 }
2572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2574 long origId = Binder.clearCallingIdentity();
2575 try {
2576 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002577 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002579 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 Surface.openTransaction();
2581 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002582 if (SHOW_TRANSACTIONS) logSurface(w,
2583 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584 w.mSurface.setTransparentRegionHint(region);
2585 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 Surface.closeTransaction();
2588 }
2589 }
2590 }
2591 } finally {
2592 Binder.restoreCallingIdentity(origId);
2593 }
2594 }
2595
2596 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002597 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 Rect visibleInsets) {
2599 long origId = Binder.clearCallingIdentity();
2600 try {
2601 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002602 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 if (w != null) {
2604 w.mGivenInsetsPending = false;
2605 w.mGivenContentInsets.set(contentInsets);
2606 w.mGivenVisibleInsets.set(visibleInsets);
2607 w.mTouchableInsets = touchableInsets;
2608 mLayoutNeeded = true;
2609 performLayoutAndPlaceSurfacesLocked();
2610 }
2611 }
2612 } finally {
2613 Binder.restoreCallingIdentity(origId);
2614 }
2615 }
Romain Guy06882f82009-06-10 13:36:04 -07002616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 public void getWindowDisplayFrame(Session session, IWindow client,
2618 Rect outDisplayFrame) {
2619 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002620 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 if (win == null) {
2622 outDisplayFrame.setEmpty();
2623 return;
2624 }
2625 outDisplayFrame.set(win.mDisplayFrame);
2626 }
2627 }
2628
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002629 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2630 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002631 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2632 window.mWallpaperX = x;
2633 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002634 window.mWallpaperXStep = xStep;
2635 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002636 if (updateWallpaperOffsetLocked(window, true)) {
2637 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002638 }
2639 }
2640 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002641
Dianne Hackborn75804932009-10-20 20:15:20 -07002642 void wallpaperCommandComplete(IBinder window, Bundle result) {
2643 synchronized (mWindowMap) {
2644 if (mWaitingOnWallpaper != null &&
2645 mWaitingOnWallpaper.mClient.asBinder() == window) {
2646 mWaitingOnWallpaper = null;
2647 mWindowMap.notifyAll();
2648 }
2649 }
2650 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002651
Dianne Hackborn75804932009-10-20 20:15:20 -07002652 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2653 String action, int x, int y, int z, Bundle extras, boolean sync) {
2654 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2655 || window == mUpperWallpaperTarget) {
2656 boolean doWait = sync;
2657 int curTokenIndex = mWallpaperTokens.size();
2658 while (curTokenIndex > 0) {
2659 curTokenIndex--;
2660 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2661 int curWallpaperIndex = token.windows.size();
2662 while (curWallpaperIndex > 0) {
2663 curWallpaperIndex--;
2664 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2665 try {
2666 wallpaper.mClient.dispatchWallpaperCommand(action,
2667 x, y, z, extras, sync);
2668 // We only want to be synchronous with one wallpaper.
2669 sync = false;
2670 } catch (RemoteException e) {
2671 }
2672 }
2673 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002674
Dianne Hackborn75804932009-10-20 20:15:20 -07002675 if (doWait) {
2676 // XXX Need to wait for result.
2677 }
2678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002679
Dianne Hackborn75804932009-10-20 20:15:20 -07002680 return null;
2681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 public int relayoutWindow(Session session, IWindow client,
2684 WindowManager.LayoutParams attrs, int requestedWidth,
2685 int requestedHeight, int viewVisibility, boolean insetsPending,
2686 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002687 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 boolean displayed = false;
2689 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002690 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002694 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 if (win == null) {
2696 return 0;
2697 }
2698 win.mRequestedWidth = requestedWidth;
2699 win.mRequestedHeight = requestedHeight;
2700
2701 if (attrs != null) {
2702 mPolicy.adjustWindowParamsLw(attrs);
2703 }
Romain Guy06882f82009-06-10 13:36:04 -07002704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 int attrChanges = 0;
2706 int flagChanges = 0;
2707 if (attrs != null) {
2708 flagChanges = win.mAttrs.flags ^= attrs.flags;
2709 attrChanges = win.mAttrs.copyFrom(attrs);
2710 }
2711
Joe Onorato8a9b2202010-02-26 18:56:32 -08002712 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713
2714 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2715 win.mAlpha = attrs.alpha;
2716 }
2717
2718 final boolean scaledWindow =
2719 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2720
2721 if (scaledWindow) {
2722 // requested{Width|Height} Surface's physical size
2723 // attrs.{width|height} Size on screen
2724 win.mHScale = (attrs.width != requestedWidth) ?
2725 (attrs.width / (float)requestedWidth) : 1.0f;
2726 win.mVScale = (attrs.height != requestedHeight) ?
2727 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002728 } else {
2729 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 }
2731
2732 boolean imMayMove = (flagChanges&(
2733 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2734 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002736 boolean focusMayChange = win.mViewVisibility != viewVisibility
2737 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2738 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002739
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002740 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2741 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 win.mRelayoutCalled = true;
2744 final int oldVisibility = win.mViewVisibility;
2745 win.mViewVisibility = viewVisibility;
2746 if (viewVisibility == View.VISIBLE &&
2747 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2748 displayed = !win.isVisibleLw();
2749 if (win.mExiting) {
2750 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002751 if (win.mAnimation != null) {
2752 win.mAnimation.cancel();
2753 win.mAnimation = null;
2754 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 }
2756 if (win.mDestroying) {
2757 win.mDestroying = false;
2758 mDestroySurface.remove(win);
2759 }
2760 if (oldVisibility == View.GONE) {
2761 win.mEnterAnimationPending = true;
2762 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002763 if (displayed) {
2764 if (win.mSurface != null && !win.mDrawPending
2765 && !win.mCommitDrawPending && !mDisplayFrozen
2766 && mPolicy.isScreenOn()) {
2767 applyEnterAnimationLocked(win);
2768 }
2769 if ((win.mAttrs.flags
2770 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2771 if (DEBUG_VISIBILITY) Slog.v(TAG,
2772 "Relayout window turning screen on: " + win);
2773 win.mTurnOnScreen = true;
2774 }
2775 int diff = 0;
2776 if (win.mConfiguration != mCurConfiguration
2777 && (win.mConfiguration == null
2778 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2779 win.mConfiguration = mCurConfiguration;
2780 if (DEBUG_CONFIGURATION) {
2781 Slog.i(TAG, "Window " + win + " visible with new config: "
2782 + win.mConfiguration + " / 0x"
2783 + Integer.toHexString(diff));
2784 }
2785 outConfig.setTo(mCurConfiguration);
2786 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002787 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2789 // To change the format, we need to re-build the surface.
2790 win.destroySurfaceLocked();
2791 displayed = true;
2792 }
2793 try {
2794 Surface surface = win.createSurfaceLocked();
2795 if (surface != null) {
2796 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002797 win.mReportDestroySurface = false;
2798 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002799 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002800 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002802 // For some reason there isn't a surface. Clear the
2803 // caller's object so they see the same state.
2804 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 }
2806 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002807 mInputMonitor.updateInputWindowsLw();
2808
Joe Onorato8a9b2202010-02-26 18:56:32 -08002809 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002810 + client + " (" + win.mAttrs.getTitle() + ")",
2811 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 Binder.restoreCallingIdentity(origId);
2813 return 0;
2814 }
2815 if (displayed) {
2816 focusMayChange = true;
2817 }
2818 if (win.mAttrs.type == TYPE_INPUT_METHOD
2819 && mInputMethodWindow == null) {
2820 mInputMethodWindow = win;
2821 imMayMove = true;
2822 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002823 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2824 && win.mAppToken != null
2825 && win.mAppToken.startingWindow != null) {
2826 // Special handling of starting window over the base
2827 // window of the app: propagate lock screen flags to it,
2828 // to provide the correct semantics while starting.
2829 final int mask =
2830 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002831 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2832 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002833 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2834 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 } else {
2837 win.mEnterAnimationPending = false;
2838 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002839 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002840 + ": mExiting=" + win.mExiting
2841 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 // If we are not currently running the exit animation, we
2843 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002844 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 // Try starting an animation; if there isn't one, we
2846 // can destroy the surface right away.
2847 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2848 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2849 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2850 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002851 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002853 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 } else if (win.isAnimating()) {
2856 // Currently in a hide animation... turn this into
2857 // an exit.
2858 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002859 } else if (win == mWallpaperTarget) {
2860 // If the wallpaper is currently behind this
2861 // window, we need to change both of them inside
2862 // of a transaction to avoid artifacts.
2863 win.mExiting = true;
2864 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 } else {
2866 if (mInputMethodWindow == win) {
2867 mInputMethodWindow = null;
2868 }
2869 win.destroySurfaceLocked();
2870 }
2871 }
2872 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002873
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002874 if (win.mSurface == null || (win.getAttrs().flags
2875 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2876 || win.mSurfacePendingDestroy) {
2877 // We are being called from a local process, which
2878 // means outSurface holds its current surface. Ensure the
2879 // surface object is cleared, but we don't want it actually
2880 // destroyed at this point.
2881 win.mSurfacePendingDestroy = false;
2882 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002883 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002884 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002885 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002886 "Keeping surface, will report destroy: " + win);
2887 win.mReportDestroySurface = true;
2888 outSurface.copyFrom(win.mSurface);
2889 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 }
2891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 if (focusMayChange) {
2893 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2894 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 imMayMove = false;
2896 }
2897 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2898 }
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002900 // updateFocusedWindowLocked() already assigned layers so we only need to
2901 // reassign them at this point if the IM window state gets shuffled
2902 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002905 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2906 // Little hack here -- we -should- be able to rely on the
2907 // function to return true if the IME has moved and needs
2908 // its layer recomputed. However, if the IME was hidden
2909 // and isn't actually moved in the list, its layer may be
2910 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 assignLayers = true;
2912 }
2913 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002914 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002915 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002916 assignLayers = true;
2917 }
2918 }
Romain Guy06882f82009-06-10 13:36:04 -07002919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 mLayoutNeeded = true;
2921 win.mGivenInsetsPending = insetsPending;
2922 if (assignLayers) {
2923 assignLayersLocked();
2924 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002925 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002927 if (displayed && win.mIsWallpaper) {
2928 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002929 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 if (win.mAppToken != null) {
2932 win.mAppToken.updateReportedVisibilityLocked();
2933 }
2934 outFrame.set(win.mFrame);
2935 outContentInsets.set(win.mContentInsets);
2936 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002937 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002939 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 + ", requestedHeight=" + requestedHeight
2941 + ", viewVisibility=" + viewVisibility
2942 + "\nRelayout returning frame=" + outFrame
2943 + ", surface=" + outSurface);
2944
Joe Onorato8a9b2202010-02-26 18:56:32 -08002945 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2947
2948 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002949
2950 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 }
2952
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002953 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 sendNewConfiguration();
2955 }
Romain Guy06882f82009-06-10 13:36:04 -07002956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2960 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2961 }
2962
2963 public void finishDrawingWindow(Session session, IWindow client) {
2964 final long origId = Binder.clearCallingIdentity();
2965 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002966 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002968 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2969 adjustWallpaperWindowsLocked();
2970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 mLayoutNeeded = true;
2972 performLayoutAndPlaceSurfacesLocked();
2973 }
2974 }
2975 Binder.restoreCallingIdentity(origId);
2976 }
2977
2978 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002979 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 + (lp != null ? lp.packageName : null)
2981 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2982 if (lp != null && lp.windowAnimations != 0) {
2983 // If this is a system resource, don't try to load it from the
2984 // application resources. It is nice to avoid loading application
2985 // resources if we can.
2986 String packageName = lp.packageName != null ? lp.packageName : "android";
2987 int resId = lp.windowAnimations;
2988 if ((resId&0xFF000000) == 0x01000000) {
2989 packageName = "android";
2990 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002991 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 + packageName);
2993 return AttributeCache.instance().get(packageName, resId,
2994 com.android.internal.R.styleable.WindowAnimation);
2995 }
2996 return null;
2997 }
Romain Guy06882f82009-06-10 13:36:04 -07002998
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002999 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003000 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003001 + packageName + " resId=0x" + Integer.toHexString(resId));
3002 if (packageName != null) {
3003 if ((resId&0xFF000000) == 0x01000000) {
3004 packageName = "android";
3005 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003006 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003007 + packageName);
3008 return AttributeCache.instance().get(packageName, resId,
3009 com.android.internal.R.styleable.WindowAnimation);
3010 }
3011 return null;
3012 }
3013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 private void applyEnterAnimationLocked(WindowState win) {
3015 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3016 if (win.mEnterAnimationPending) {
3017 win.mEnterAnimationPending = false;
3018 transit = WindowManagerPolicy.TRANSIT_ENTER;
3019 }
3020
3021 applyAnimationLocked(win, transit, true);
3022 }
3023
3024 private boolean applyAnimationLocked(WindowState win,
3025 int transit, boolean isEntrance) {
3026 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3027 // If we are trying to apply an animation, but already running
3028 // an animation of the same type, then just leave that one alone.
3029 return true;
3030 }
Romain Guy06882f82009-06-10 13:36:04 -07003031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 // Only apply an animation if the display isn't frozen. If it is
3033 // frozen, there is no reason to animate and it can cause strange
3034 // artifacts when we unfreeze the display if some different animation
3035 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003036 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003037 int anim = mPolicy.selectAnimationLw(win, transit);
3038 int attr = -1;
3039 Animation a = null;
3040 if (anim != 0) {
3041 a = AnimationUtils.loadAnimation(mContext, anim);
3042 } else {
3043 switch (transit) {
3044 case WindowManagerPolicy.TRANSIT_ENTER:
3045 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3046 break;
3047 case WindowManagerPolicy.TRANSIT_EXIT:
3048 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3049 break;
3050 case WindowManagerPolicy.TRANSIT_SHOW:
3051 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3052 break;
3053 case WindowManagerPolicy.TRANSIT_HIDE:
3054 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3055 break;
3056 }
3057 if (attr >= 0) {
3058 a = loadAnimation(win.mAttrs, attr);
3059 }
3060 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003061 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003062 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3063 + " mAnimation=" + win.mAnimation
3064 + " isEntrance=" + isEntrance);
3065 if (a != null) {
3066 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003067 RuntimeException e = null;
3068 if (!HIDE_STACK_CRAWLS) {
3069 e = new RuntimeException();
3070 e.fillInStackTrace();
3071 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003072 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 }
3074 win.setAnimation(a);
3075 win.mAnimationIsEntrance = isEntrance;
3076 }
3077 } else {
3078 win.clearAnimation();
3079 }
3080
3081 return win.mAnimation != null;
3082 }
3083
3084 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3085 int anim = 0;
3086 Context context = mContext;
3087 if (animAttr >= 0) {
3088 AttributeCache.Entry ent = getCachedAnimations(lp);
3089 if (ent != null) {
3090 context = ent.context;
3091 anim = ent.array.getResourceId(animAttr, 0);
3092 }
3093 }
3094 if (anim != 0) {
3095 return AnimationUtils.loadAnimation(context, anim);
3096 }
3097 return null;
3098 }
Romain Guy06882f82009-06-10 13:36:04 -07003099
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003100 private Animation loadAnimation(String packageName, int resId) {
3101 int anim = 0;
3102 Context context = mContext;
3103 if (resId >= 0) {
3104 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3105 if (ent != null) {
3106 context = ent.context;
3107 anim = resId;
3108 }
3109 }
3110 if (anim != 0) {
3111 return AnimationUtils.loadAnimation(context, anim);
3112 }
3113 return null;
3114 }
3115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003116 private boolean applyAnimationLocked(AppWindowToken wtoken,
3117 WindowManager.LayoutParams lp, int transit, boolean enter) {
3118 // Only apply an animation if the display isn't frozen. If it is
3119 // frozen, there is no reason to animate and it can cause strange
3120 // artifacts when we unfreeze the display if some different animation
3121 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003122 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003123 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003124 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003125 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003126 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003127 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003128 } else if (mNextAppTransitionPackage != null) {
3129 a = loadAnimation(mNextAppTransitionPackage, enter ?
3130 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003131 } else {
3132 int animAttr = 0;
3133 switch (transit) {
3134 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3135 animAttr = enter
3136 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3137 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3138 break;
3139 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3140 animAttr = enter
3141 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3142 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3143 break;
3144 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3145 animAttr = enter
3146 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3147 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3148 break;
3149 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3150 animAttr = enter
3151 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3152 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3153 break;
3154 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3155 animAttr = enter
3156 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3157 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3158 break;
3159 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3160 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003161 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003162 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3163 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003164 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003165 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003166 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3167 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003168 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003169 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003170 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003171 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3172 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3173 break;
3174 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3175 animAttr = enter
3176 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3177 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3178 break;
3179 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3180 animAttr = enter
3181 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3182 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003183 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003184 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003185 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003186 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003187 + " anim=" + a
3188 + " animAttr=0x" + Integer.toHexString(animAttr)
3189 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 if (a != null) {
3192 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003193 RuntimeException e = null;
3194 if (!HIDE_STACK_CRAWLS) {
3195 e = new RuntimeException();
3196 e.fillInStackTrace();
3197 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003198 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 }
3200 wtoken.setAnimation(a);
3201 }
3202 } else {
3203 wtoken.clearAnimation();
3204 }
3205
3206 return wtoken.animation != null;
3207 }
3208
3209 // -------------------------------------------------------------
3210 // Application Window Tokens
3211 // -------------------------------------------------------------
3212
3213 public void validateAppTokens(List tokens) {
3214 int v = tokens.size()-1;
3215 int m = mAppTokens.size()-1;
3216 while (v >= 0 && m >= 0) {
3217 AppWindowToken wtoken = mAppTokens.get(m);
3218 if (wtoken.removed) {
3219 m--;
3220 continue;
3221 }
3222 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003223 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3225 }
3226 v--;
3227 m--;
3228 }
3229 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003230 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 v--;
3232 }
3233 while (m >= 0) {
3234 AppWindowToken wtoken = mAppTokens.get(m);
3235 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003236 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 }
3238 m--;
3239 }
3240 }
3241
3242 boolean checkCallingPermission(String permission, String func) {
3243 // Quick check: if the calling permission is me, it's all okay.
3244 if (Binder.getCallingPid() == Process.myPid()) {
3245 return true;
3246 }
Romain Guy06882f82009-06-10 13:36:04 -07003247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 if (mContext.checkCallingPermission(permission)
3249 == PackageManager.PERMISSION_GRANTED) {
3250 return true;
3251 }
3252 String msg = "Permission Denial: " + func + " from pid="
3253 + Binder.getCallingPid()
3254 + ", uid=" + Binder.getCallingUid()
3255 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003256 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 return false;
3258 }
Romain Guy06882f82009-06-10 13:36:04 -07003259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 AppWindowToken findAppWindowToken(IBinder token) {
3261 WindowToken wtoken = mTokenMap.get(token);
3262 if (wtoken == null) {
3263 return null;
3264 }
3265 return wtoken.appWindowToken;
3266 }
Romain Guy06882f82009-06-10 13:36:04 -07003267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 public void addWindowToken(IBinder token, int type) {
3269 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3270 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003271 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 }
Romain Guy06882f82009-06-10 13:36:04 -07003273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 synchronized(mWindowMap) {
3275 WindowToken wtoken = mTokenMap.get(token);
3276 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003277 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 return;
3279 }
3280 wtoken = new WindowToken(token, type, true);
3281 mTokenMap.put(token, wtoken);
3282 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003283 if (type == TYPE_WALLPAPER) {
3284 mWallpaperTokens.add(wtoken);
3285 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 }
3287 }
Romain Guy06882f82009-06-10 13:36:04 -07003288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 public void removeWindowToken(IBinder token) {
3290 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3291 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003292 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 }
3294
3295 final long origId = Binder.clearCallingIdentity();
3296 synchronized(mWindowMap) {
3297 WindowToken wtoken = mTokenMap.remove(token);
3298 mTokenList.remove(wtoken);
3299 if (wtoken != null) {
3300 boolean delayed = false;
3301 if (!wtoken.hidden) {
3302 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 final int N = wtoken.windows.size();
3305 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 for (int i=0; i<N; i++) {
3308 WindowState win = wtoken.windows.get(i);
3309
3310 if (win.isAnimating()) {
3311 delayed = true;
3312 }
Romain Guy06882f82009-06-10 13:36:04 -07003313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003314 if (win.isVisibleNow()) {
3315 applyAnimationLocked(win,
3316 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 changed = true;
3318 }
3319 }
3320
3321 if (changed) {
3322 mLayoutNeeded = true;
3323 performLayoutAndPlaceSurfacesLocked();
3324 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3325 }
Romain Guy06882f82009-06-10 13:36:04 -07003326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 if (delayed) {
3328 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003329 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3330 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 }
3332 }
Romain Guy06882f82009-06-10 13:36:04 -07003333
Jeff Brownc5ed5912010-07-14 18:48:53 -07003334 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003336 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 }
3338 }
3339 Binder.restoreCallingIdentity(origId);
3340 }
3341
3342 public void addAppToken(int addPos, IApplicationToken token,
3343 int groupId, int requestedOrientation, boolean fullscreen) {
3344 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3345 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003346 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 }
Jeff Brown349703e2010-06-22 01:27:15 -07003348
3349 // Get the dispatching timeout here while we are not holding any locks so that it
3350 // can be cached by the AppWindowToken. The timeout value is used later by the
3351 // input dispatcher in code that does hold locks. If we did not cache the value
3352 // here we would run the chance of introducing a deadlock between the window manager
3353 // (which holds locks while updating the input dispatcher state) and the activity manager
3354 // (which holds locks while querying the application token).
3355 long inputDispatchingTimeoutNanos;
3356 try {
3357 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3358 } catch (RemoteException ex) {
3359 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3360 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3361 }
Romain Guy06882f82009-06-10 13:36:04 -07003362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 synchronized(mWindowMap) {
3364 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3365 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003366 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 return;
3368 }
3369 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003370 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 wtoken.groupId = groupId;
3372 wtoken.appFullscreen = fullscreen;
3373 wtoken.requestedOrientation = requestedOrientation;
3374 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003375 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 mTokenMap.put(token.asBinder(), wtoken);
3377 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 // Application tokens start out hidden.
3380 wtoken.hidden = true;
3381 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 //dump();
3384 }
3385 }
Romain Guy06882f82009-06-10 13:36:04 -07003386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 public void setAppGroupId(IBinder token, int groupId) {
3388 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3389 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003390 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 }
3392
3393 synchronized(mWindowMap) {
3394 AppWindowToken wtoken = findAppWindowToken(token);
3395 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003396 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 return;
3398 }
3399 wtoken.groupId = groupId;
3400 }
3401 }
Romain Guy06882f82009-06-10 13:36:04 -07003402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 public int getOrientationFromWindowsLocked() {
3404 int pos = mWindows.size() - 1;
3405 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003406 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 pos--;
3408 if (wtoken.mAppToken != null) {
3409 // We hit an application window. so the orientation will be determined by the
3410 // app window. No point in continuing further.
3411 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3412 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003413 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 continue;
3415 }
3416 int req = wtoken.mAttrs.screenOrientation;
3417 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3418 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3419 continue;
3420 } else {
3421 return req;
3422 }
3423 }
3424 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3425 }
Romain Guy06882f82009-06-10 13:36:04 -07003426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003427 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003428 int pos = mAppTokens.size() - 1;
3429 int curGroup = 0;
3430 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3431 boolean findingBehind = false;
3432 boolean haveGroup = false;
3433 boolean lastFullscreen = false;
3434 while (pos >= 0) {
3435 AppWindowToken wtoken = mAppTokens.get(pos);
3436 pos--;
3437 // if we're about to tear down this window and not seek for
3438 // the behind activity, don't use it for orientation
3439 if (!findingBehind
3440 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3441 continue;
3442 }
3443
3444 if (!haveGroup) {
3445 // We ignore any hidden applications on the top.
3446 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003447 continue;
3448 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003449 haveGroup = true;
3450 curGroup = wtoken.groupId;
3451 lastOrientation = wtoken.requestedOrientation;
3452 } else if (curGroup != wtoken.groupId) {
3453 // If we have hit a new application group, and the bottom
3454 // of the previous group didn't explicitly say to use
3455 // the orientation behind it, and the last app was
3456 // full screen, then we'll stick with the
3457 // user's orientation.
3458 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3459 && lastFullscreen) {
3460 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003462 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003463 int or = wtoken.requestedOrientation;
3464 // If this application is fullscreen, and didn't explicitly say
3465 // to use the orientation behind it, then just take whatever
3466 // orientation it has and ignores whatever is under it.
3467 lastFullscreen = wtoken.appFullscreen;
3468 if (lastFullscreen
3469 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3470 return or;
3471 }
3472 // If this application has requested an explicit orientation,
3473 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003474 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3475 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003476 return or;
3477 }
3478 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3479 }
3480 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 }
Romain Guy06882f82009-06-10 13:36:04 -07003482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003484 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003485 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3486 "updateOrientationFromAppTokens()")) {
3487 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3488 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003489
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003490 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003491 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003492
3493 synchronized(mWindowMap) {
3494 if (updateOrientationFromAppTokensLocked()) {
3495 if (freezeThisOneIfNeeded != null) {
3496 AppWindowToken wtoken = findAppWindowToken(
3497 freezeThisOneIfNeeded);
3498 if (wtoken != null) {
3499 startAppFreezingScreenLocked(wtoken,
3500 ActivityInfo.CONFIG_ORIENTATION);
3501 }
3502 }
3503 config = computeNewConfigurationLocked();
3504
3505 } else if (currentConfig != null) {
3506 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003507 // state mismatches the activity manager's, update it,
3508 // disregarding font scale, which should remain set to
3509 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003510 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003511 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003512 if (computeNewConfigurationLocked(mTempConfiguration)) {
3513 if (currentConfig.diff(mTempConfiguration) != 0) {
3514 mWaitingForConfig = true;
3515 mLayoutNeeded = true;
3516 startFreezingDisplayLocked();
3517 config = new Configuration(mTempConfiguration);
3518 }
3519 }
3520 }
3521 }
3522
Dianne Hackborncfaef692009-06-15 14:24:44 -07003523 Binder.restoreCallingIdentity(ident);
3524 return config;
3525 }
3526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003528 * Determine the new desired orientation of the display, returning
3529 * a non-null new Configuration if it has changed from the current
3530 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3531 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3532 * SCREEN. This will typically be done for you if you call
3533 * sendNewConfiguration().
3534 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 * The orientation is computed from non-application windows first. If none of
3536 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003537 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3539 * android.os.IBinder)
3540 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003541 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003542 if (mDisplayFrozen) {
3543 // If the display is frozen, some activities may be in the middle
3544 // of restarting, and thus have removed their old window. If the
3545 // window has the flag to hide the lock screen, then the lock screen
3546 // can re-appear and inflict its own orientation on us. Keep the
3547 // orientation stable until this all settles down.
3548 return false;
3549 }
3550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003551 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 long ident = Binder.clearCallingIdentity();
3553 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003554 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 mForcedAppOrientation = req;
3558 //send a message to Policy indicating orientation change to take
3559 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003560 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003561 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3562 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3563 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 }
3565 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003566
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003567 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 } finally {
3569 Binder.restoreCallingIdentity(ident);
3570 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 }
Romain Guy06882f82009-06-10 13:36:04 -07003572
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003573 int computeForcedAppOrientationLocked() {
3574 int req = getOrientationFromWindowsLocked();
3575 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3576 req = getOrientationFromAppTokensLocked();
3577 }
3578 return req;
3579 }
Romain Guy06882f82009-06-10 13:36:04 -07003580
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003581 public void setNewConfiguration(Configuration config) {
3582 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3583 "setNewConfiguration()")) {
3584 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3585 }
3586
3587 synchronized(mWindowMap) {
3588 mCurConfiguration = new Configuration(config);
3589 mWaitingForConfig = false;
3590 performLayoutAndPlaceSurfacesLocked();
3591 }
3592 }
3593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3595 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3596 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003597 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 }
Romain Guy06882f82009-06-10 13:36:04 -07003599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 synchronized(mWindowMap) {
3601 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3602 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003603 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 return;
3605 }
Romain Guy06882f82009-06-10 13:36:04 -07003606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 wtoken.requestedOrientation = requestedOrientation;
3608 }
3609 }
Romain Guy06882f82009-06-10 13:36:04 -07003610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 public int getAppOrientation(IApplicationToken token) {
3612 synchronized(mWindowMap) {
3613 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3614 if (wtoken == null) {
3615 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3616 }
Romain Guy06882f82009-06-10 13:36:04 -07003617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 return wtoken.requestedOrientation;
3619 }
3620 }
Romain Guy06882f82009-06-10 13:36:04 -07003621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3623 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3624 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003625 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 }
3627
3628 synchronized(mWindowMap) {
3629 boolean changed = false;
3630 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003631 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 changed = mFocusedApp != null;
3633 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003634 if (changed) {
3635 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 } else {
3638 AppWindowToken newFocus = findAppWindowToken(token);
3639 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003640 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 return;
3642 }
3643 changed = mFocusedApp != newFocus;
3644 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003645 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003646 if (changed) {
3647 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 }
3650
3651 if (moveFocusNow && changed) {
3652 final long origId = Binder.clearCallingIdentity();
3653 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3654 Binder.restoreCallingIdentity(origId);
3655 }
3656 }
3657 }
3658
3659 public void prepareAppTransition(int transit) {
3660 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3661 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003662 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 }
Romain Guy06882f82009-06-10 13:36:04 -07003664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003666 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 TAG, "Prepare app transition: transit=" + transit
3668 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003669 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003670 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3671 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003673 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3674 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3675 // Opening a new task always supersedes a close for the anim.
3676 mNextAppTransition = transit;
3677 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3678 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3679 // Opening a new activity always supersedes a close for the anim.
3680 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 }
3682 mAppTransitionReady = false;
3683 mAppTransitionTimeout = false;
3684 mStartingIconInTransition = false;
3685 mSkipAppTransitionAnimation = false;
3686 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3687 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3688 5000);
3689 }
3690 }
3691 }
3692
3693 public int getPendingAppTransition() {
3694 return mNextAppTransition;
3695 }
Romain Guy06882f82009-06-10 13:36:04 -07003696
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003697 public void overridePendingAppTransition(String packageName,
3698 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003699 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003700 mNextAppTransitionPackage = packageName;
3701 mNextAppTransitionEnter = enterAnim;
3702 mNextAppTransitionExit = exitAnim;
3703 }
3704 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 public void executeAppTransition() {
3707 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3708 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003709 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 }
Romain Guy06882f82009-06-10 13:36:04 -07003711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003713 if (DEBUG_APP_TRANSITIONS) {
3714 RuntimeException e = new RuntimeException("here");
3715 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003716 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003717 + mNextAppTransition, e);
3718 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003719 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 mAppTransitionReady = true;
3721 final long origId = Binder.clearCallingIdentity();
3722 performLayoutAndPlaceSurfacesLocked();
3723 Binder.restoreCallingIdentity(origId);
3724 }
3725 }
3726 }
3727
3728 public void setAppStartingWindow(IBinder token, String pkg,
3729 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003730 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3732 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003733 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 }
3735
3736 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003737 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3739 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 AppWindowToken wtoken = findAppWindowToken(token);
3742 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003743 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 return;
3745 }
3746
3747 // If the display is frozen, we won't do anything until the
3748 // actual window is displayed so there is no reason to put in
3749 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003750 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 return;
3752 }
Romain Guy06882f82009-06-10 13:36:04 -07003753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 if (wtoken.startingData != null) {
3755 return;
3756 }
Romain Guy06882f82009-06-10 13:36:04 -07003757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 if (transferFrom != null) {
3759 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3760 if (ttoken != null) {
3761 WindowState startingWindow = ttoken.startingWindow;
3762 if (startingWindow != null) {
3763 if (mStartingIconInTransition) {
3764 // In this case, the starting icon has already
3765 // been displayed, so start letting windows get
3766 // shown immediately without any more transitions.
3767 mSkipAppTransitionAnimation = true;
3768 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003769 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 "Moving existing starting from " + ttoken
3771 + " to " + wtoken);
3772 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 // Transfer the starting window over to the new
3775 // token.
3776 wtoken.startingData = ttoken.startingData;
3777 wtoken.startingView = ttoken.startingView;
3778 wtoken.startingWindow = startingWindow;
3779 ttoken.startingData = null;
3780 ttoken.startingView = null;
3781 ttoken.startingWindow = null;
3782 ttoken.startingMoved = true;
3783 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003784 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003785 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003786 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003787 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003789 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 ttoken.windows.remove(startingWindow);
3791 ttoken.allAppWindows.remove(startingWindow);
3792 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 // Propagate other interesting state between the
3795 // tokens. If the old token is displayed, we should
3796 // immediately force the new one to be displayed. If
3797 // it is animating, we need to move that animation to
3798 // the new one.
3799 if (ttoken.allDrawn) {
3800 wtoken.allDrawn = true;
3801 }
3802 if (ttoken.firstWindowDrawn) {
3803 wtoken.firstWindowDrawn = true;
3804 }
3805 if (!ttoken.hidden) {
3806 wtoken.hidden = false;
3807 wtoken.hiddenRequested = false;
3808 wtoken.willBeHidden = false;
3809 }
3810 if (wtoken.clientHidden != ttoken.clientHidden) {
3811 wtoken.clientHidden = ttoken.clientHidden;
3812 wtoken.sendAppVisibilityToClients();
3813 }
3814 if (ttoken.animation != null) {
3815 wtoken.animation = ttoken.animation;
3816 wtoken.animating = ttoken.animating;
3817 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3818 ttoken.animation = null;
3819 ttoken.animLayerAdjustment = 0;
3820 wtoken.updateLayers();
3821 ttoken.updateLayers();
3822 }
Romain Guy06882f82009-06-10 13:36:04 -07003823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 mLayoutNeeded = true;
3826 performLayoutAndPlaceSurfacesLocked();
3827 Binder.restoreCallingIdentity(origId);
3828 return;
3829 } else if (ttoken.startingData != null) {
3830 // The previous app was getting ready to show a
3831 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003832 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 "Moving pending starting from " + ttoken
3834 + " to " + wtoken);
3835 wtoken.startingData = ttoken.startingData;
3836 ttoken.startingData = null;
3837 ttoken.startingMoved = true;
3838 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3839 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3840 // want to process the message ASAP, before any other queued
3841 // messages.
3842 mH.sendMessageAtFrontOfQueue(m);
3843 return;
3844 }
3845 }
3846 }
3847
3848 // There is no existing starting window, and the caller doesn't
3849 // want us to create one, so that's it!
3850 if (!createIfNeeded) {
3851 return;
3852 }
Romain Guy06882f82009-06-10 13:36:04 -07003853
Dianne Hackborn284ac932009-08-28 10:34:25 -07003854 // If this is a translucent or wallpaper window, then don't
3855 // show a starting window -- the current effect (a full-screen
3856 // opaque starting window that fades away to the real contents
3857 // when it is ready) does not work for this.
3858 if (theme != 0) {
3859 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3860 com.android.internal.R.styleable.Window);
3861 if (ent.array.getBoolean(
3862 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3863 return;
3864 }
3865 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003866 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3867 return;
3868 }
3869 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003870 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3871 return;
3872 }
3873 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 mStartingIconInTransition = true;
3876 wtoken.startingData = new StartingData(
3877 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003878 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3880 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3881 // want to process the message ASAP, before any other queued
3882 // messages.
3883 mH.sendMessageAtFrontOfQueue(m);
3884 }
3885 }
3886
3887 public void setAppWillBeHidden(IBinder token) {
3888 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3889 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003890 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003891 }
3892
3893 AppWindowToken wtoken;
3894
3895 synchronized(mWindowMap) {
3896 wtoken = findAppWindowToken(token);
3897 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003898 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 -08003899 return;
3900 }
3901 wtoken.willBeHidden = true;
3902 }
3903 }
Romain Guy06882f82009-06-10 13:36:04 -07003904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3906 boolean visible, int transit, boolean performLayout) {
3907 boolean delayed = false;
3908
3909 if (wtoken.clientHidden == visible) {
3910 wtoken.clientHidden = !visible;
3911 wtoken.sendAppVisibilityToClients();
3912 }
Romain Guy06882f82009-06-10 13:36:04 -07003913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 wtoken.willBeHidden = false;
3915 if (wtoken.hidden == visible) {
3916 final int N = wtoken.allAppWindows.size();
3917 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003918 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3920 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003923
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003924 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 if (wtoken.animation == sDummyAnimation) {
3926 wtoken.animation = null;
3927 }
3928 applyAnimationLocked(wtoken, lp, transit, visible);
3929 changed = true;
3930 if (wtoken.animation != null) {
3931 delayed = runningAppAnimation = true;
3932 }
3933 }
Romain Guy06882f82009-06-10 13:36:04 -07003934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003935 for (int i=0; i<N; i++) {
3936 WindowState win = wtoken.allAppWindows.get(i);
3937 if (win == wtoken.startingWindow) {
3938 continue;
3939 }
3940
3941 if (win.isAnimating()) {
3942 delayed = true;
3943 }
Romain Guy06882f82009-06-10 13:36:04 -07003944
Joe Onorato8a9b2202010-02-26 18:56:32 -08003945 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 //win.dump(" ");
3947 if (visible) {
3948 if (!win.isVisibleNow()) {
3949 if (!runningAppAnimation) {
3950 applyAnimationLocked(win,
3951 WindowManagerPolicy.TRANSIT_ENTER, true);
3952 }
3953 changed = true;
3954 }
3955 } else if (win.isVisibleNow()) {
3956 if (!runningAppAnimation) {
3957 applyAnimationLocked(win,
3958 WindowManagerPolicy.TRANSIT_EXIT, false);
3959 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 changed = true;
3961 }
3962 }
3963
3964 wtoken.hidden = wtoken.hiddenRequested = !visible;
3965 if (!visible) {
3966 unsetAppFreezingScreenLocked(wtoken, true, true);
3967 } else {
3968 // If we are being set visible, and the starting window is
3969 // not yet displayed, then make sure it doesn't get displayed.
3970 WindowState swin = wtoken.startingWindow;
3971 if (swin != null && (swin.mDrawPending
3972 || swin.mCommitDrawPending)) {
3973 swin.mPolicyVisibility = false;
3974 swin.mPolicyVisibilityAfterAnim = false;
3975 }
3976 }
Romain Guy06882f82009-06-10 13:36:04 -07003977
Joe Onorato8a9b2202010-02-26 18:56:32 -08003978 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003979 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3980 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003981
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003982 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003984 if (performLayout) {
3985 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3986 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003987 } else {
3988 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003989 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 }
3991 }
3992
3993 if (wtoken.animation != null) {
3994 delayed = true;
3995 }
Romain Guy06882f82009-06-10 13:36:04 -07003996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 return delayed;
3998 }
3999
4000 public void setAppVisibility(IBinder token, boolean visible) {
4001 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4002 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004003 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 }
4005
4006 AppWindowToken wtoken;
4007
4008 synchronized(mWindowMap) {
4009 wtoken = findAppWindowToken(token);
4010 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004011 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 return;
4013 }
4014
4015 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004016 RuntimeException e = null;
4017 if (!HIDE_STACK_CRAWLS) {
4018 e = new RuntimeException();
4019 e.fillInStackTrace();
4020 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004021 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004022 + "): mNextAppTransition=" + mNextAppTransition
4023 + " hidden=" + wtoken.hidden
4024 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4025 }
Romain Guy06882f82009-06-10 13:36:04 -07004026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004027 // If we are preparing an app transition, then delay changing
4028 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004029 if (!mDisplayFrozen && mPolicy.isScreenOn()
4030 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 // Already in requested state, don't do anything more.
4032 if (wtoken.hiddenRequested != visible) {
4033 return;
4034 }
4035 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004036
Joe Onorato8a9b2202010-02-26 18:56:32 -08004037 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004038 TAG, "Setting dummy animation on: " + wtoken);
4039 wtoken.setDummyAnimation();
4040 mOpeningApps.remove(wtoken);
4041 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004042 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004043 wtoken.inPendingTransaction = true;
4044 if (visible) {
4045 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004046 wtoken.startingDisplayed = false;
4047 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004048
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004049 // If the token is currently hidden (should be the
4050 // common case), then we need to set up to wait for
4051 // its windows to be ready.
4052 if (wtoken.hidden) {
4053 wtoken.allDrawn = false;
4054 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004055
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004056 if (wtoken.clientHidden) {
4057 // In the case where we are making an app visible
4058 // but holding off for a transition, we still need
4059 // to tell the client to make its windows visible so
4060 // they get drawn. Otherwise, we will wait on
4061 // performing the transition until all windows have
4062 // been drawn, they never will be, and we are sad.
4063 wtoken.clientHidden = false;
4064 wtoken.sendAppVisibilityToClients();
4065 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 }
4067 } else {
4068 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004069
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004070 // If the token is currently visible (should be the
4071 // common case), then set up to wait for it to be hidden.
4072 if (!wtoken.hidden) {
4073 wtoken.waitingToHide = true;
4074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 }
4076 return;
4077 }
Romain Guy06882f82009-06-10 13:36:04 -07004078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004080 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 wtoken.updateReportedVisibilityLocked();
4082 Binder.restoreCallingIdentity(origId);
4083 }
4084 }
4085
4086 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4087 boolean unfreezeSurfaceNow, boolean force) {
4088 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004089 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 + " force=" + force);
4091 final int N = wtoken.allAppWindows.size();
4092 boolean unfrozeWindows = false;
4093 for (int i=0; i<N; i++) {
4094 WindowState w = wtoken.allAppWindows.get(i);
4095 if (w.mAppFreezing) {
4096 w.mAppFreezing = false;
4097 if (w.mSurface != null && !w.mOrientationChanging) {
4098 w.mOrientationChanging = true;
4099 }
4100 unfrozeWindows = true;
4101 }
4102 }
4103 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004104 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004105 wtoken.freezingScreen = false;
4106 mAppsFreezingScreen--;
4107 }
4108 if (unfreezeSurfaceNow) {
4109 if (unfrozeWindows) {
4110 mLayoutNeeded = true;
4111 performLayoutAndPlaceSurfacesLocked();
4112 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004113 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 }
4115 }
4116 }
Romain Guy06882f82009-06-10 13:36:04 -07004117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004118 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4119 int configChanges) {
4120 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004121 RuntimeException e = null;
4122 if (!HIDE_STACK_CRAWLS) {
4123 e = new RuntimeException();
4124 e.fillInStackTrace();
4125 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004126 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 + ": hidden=" + wtoken.hidden + " freezing="
4128 + wtoken.freezingScreen, e);
4129 }
4130 if (!wtoken.hiddenRequested) {
4131 if (!wtoken.freezingScreen) {
4132 wtoken.freezingScreen = true;
4133 mAppsFreezingScreen++;
4134 if (mAppsFreezingScreen == 1) {
4135 startFreezingDisplayLocked();
4136 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4137 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4138 5000);
4139 }
4140 }
4141 final int N = wtoken.allAppWindows.size();
4142 for (int i=0; i<N; i++) {
4143 WindowState w = wtoken.allAppWindows.get(i);
4144 w.mAppFreezing = true;
4145 }
4146 }
4147 }
Romain Guy06882f82009-06-10 13:36:04 -07004148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 public void startAppFreezingScreen(IBinder token, int configChanges) {
4150 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4151 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004152 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 }
4154
4155 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004156 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004157 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 return;
4159 }
Romain Guy06882f82009-06-10 13:36:04 -07004160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 AppWindowToken wtoken = findAppWindowToken(token);
4162 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004163 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 return;
4165 }
4166 final long origId = Binder.clearCallingIdentity();
4167 startAppFreezingScreenLocked(wtoken, configChanges);
4168 Binder.restoreCallingIdentity(origId);
4169 }
4170 }
Romain Guy06882f82009-06-10 13:36:04 -07004171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 public void stopAppFreezingScreen(IBinder token, boolean force) {
4173 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4174 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004175 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 }
4177
4178 synchronized(mWindowMap) {
4179 AppWindowToken wtoken = findAppWindowToken(token);
4180 if (wtoken == null || wtoken.appToken == null) {
4181 return;
4182 }
4183 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004184 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4186 unsetAppFreezingScreenLocked(wtoken, true, force);
4187 Binder.restoreCallingIdentity(origId);
4188 }
4189 }
Romain Guy06882f82009-06-10 13:36:04 -07004190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191 public void removeAppToken(IBinder token) {
4192 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4193 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004194 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004195 }
4196
4197 AppWindowToken wtoken = null;
4198 AppWindowToken startingToken = null;
4199 boolean delayed = false;
4200
4201 final long origId = Binder.clearCallingIdentity();
4202 synchronized(mWindowMap) {
4203 WindowToken basewtoken = mTokenMap.remove(token);
4204 mTokenList.remove(basewtoken);
4205 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004206 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004207 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 wtoken.inPendingTransaction = false;
4209 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004210 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 if (mClosingApps.contains(wtoken)) {
4212 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004213 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004214 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004215 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 delayed = true;
4217 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004218 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 TAG, "Removing app " + wtoken + " delayed=" + delayed
4220 + " animation=" + wtoken.animation
4221 + " animating=" + wtoken.animating);
4222 if (delayed) {
4223 // set the token aside because it has an active animation to be finished
4224 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004225 } else {
4226 // Make sure there is no animation running on this token,
4227 // so any windows associated with it will be removed as
4228 // soon as their animations are complete
4229 wtoken.animation = null;
4230 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004231 }
4232 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004233 if (mLastEnterAnimToken == wtoken) {
4234 mLastEnterAnimToken = null;
4235 mLastEnterAnimParams = null;
4236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 wtoken.removed = true;
4238 if (wtoken.startingData != null) {
4239 startingToken = wtoken;
4240 }
4241 unsetAppFreezingScreenLocked(wtoken, true, true);
4242 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004243 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 mFocusedApp = null;
4245 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004246 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 }
4248 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004249 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 }
Romain Guy06882f82009-06-10 13:36:04 -07004251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 if (!delayed && wtoken != null) {
4253 wtoken.updateReportedVisibilityLocked();
4254 }
4255 }
4256 Binder.restoreCallingIdentity(origId);
4257
4258 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004259 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 + startingToken + ": app token removed");
4261 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4262 mH.sendMessage(m);
4263 }
4264 }
4265
4266 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4267 final int NW = token.windows.size();
4268 for (int i=0; i<NW; i++) {
4269 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004270 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004272 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 int j = win.mChildWindows.size();
4274 while (j > 0) {
4275 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004276 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004277 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004278 "Tmp removing child window " + cwin);
4279 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 }
4281 }
4282 return NW > 0;
4283 }
4284
4285 void dumpAppTokensLocked() {
4286 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004287 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 }
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 void dumpWindowsLocked() {
4292 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004293 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 }
4295 }
Romain Guy06882f82009-06-10 13:36:04 -07004296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 private int findWindowOffsetLocked(int tokenPos) {
4298 final int NW = mWindows.size();
4299
4300 if (tokenPos >= mAppTokens.size()) {
4301 int i = NW;
4302 while (i > 0) {
4303 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004304 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 if (win.getAppToken() != null) {
4306 return i+1;
4307 }
4308 }
4309 }
4310
4311 while (tokenPos > 0) {
4312 // Find the first app token below the new position that has
4313 // a window displayed.
4314 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004315 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004317 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004318 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004319 "Skipping token -- currently sending to bottom");
4320 tokenPos--;
4321 continue;
4322 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 int i = wtoken.windows.size();
4324 while (i > 0) {
4325 i--;
4326 WindowState win = wtoken.windows.get(i);
4327 int j = win.mChildWindows.size();
4328 while (j > 0) {
4329 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004330 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004331 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 for (int pos=NW-1; pos>=0; pos--) {
4333 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004334 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 "Found child win @" + (pos+1));
4336 return pos+1;
4337 }
4338 }
4339 }
4340 }
4341 for (int pos=NW-1; pos>=0; pos--) {
4342 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004343 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 return pos+1;
4345 }
4346 }
4347 }
4348 tokenPos--;
4349 }
4350
4351 return 0;
4352 }
4353
4354 private final int reAddWindowLocked(int index, WindowState win) {
4355 final int NCW = win.mChildWindows.size();
4356 boolean added = false;
4357 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004358 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004360 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004361 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 mWindows.add(index, win);
4363 index++;
4364 added = true;
4365 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004366 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004367 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 mWindows.add(index, cwin);
4369 index++;
4370 }
4371 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004372 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004373 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004374 mWindows.add(index, win);
4375 index++;
4376 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004377 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 return index;
4379 }
Romain Guy06882f82009-06-10 13:36:04 -07004380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4382 final int NW = token.windows.size();
4383 for (int i=0; i<NW; i++) {
4384 index = reAddWindowLocked(index, token.windows.get(i));
4385 }
4386 return index;
4387 }
4388
4389 public void moveAppToken(int index, IBinder token) {
4390 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4391 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004392 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004393 }
4394
4395 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004396 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004397 if (DEBUG_REORDER) dumpAppTokensLocked();
4398 final AppWindowToken wtoken = findAppWindowToken(token);
4399 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004400 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 + token + " (" + wtoken + ")");
4402 return;
4403 }
4404 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004405 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004409 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 if (DEBUG_REORDER) dumpWindowsLocked();
4411 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004412 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 if (DEBUG_REORDER) dumpWindowsLocked();
4414 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004415 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 if (DEBUG_REORDER) dumpWindowsLocked();
4417 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 mLayoutNeeded = true;
4419 performLayoutAndPlaceSurfacesLocked();
4420 }
4421 Binder.restoreCallingIdentity(origId);
4422 }
4423 }
4424
4425 private void removeAppTokensLocked(List<IBinder> tokens) {
4426 // XXX This should be done more efficiently!
4427 // (take advantage of the fact that both lists should be
4428 // ordered in the same way.)
4429 int N = tokens.size();
4430 for (int i=0; i<N; i++) {
4431 IBinder token = tokens.get(i);
4432 final AppWindowToken wtoken = findAppWindowToken(token);
4433 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004434 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 + token + " (" + wtoken + ")");
4436 i--;
4437 N--;
4438 }
4439 }
4440 }
4441
Dianne Hackborna8f60182009-09-01 19:01:50 -07004442 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4443 boolean updateFocusAndLayout) {
4444 // First remove all of the windows from the list.
4445 tmpRemoveAppWindowsLocked(wtoken);
4446
4447 // Where to start adding?
4448 int pos = findWindowOffsetLocked(tokenPos);
4449
4450 // And now add them back at the correct place.
4451 pos = reAddAppWindowsLocked(pos, wtoken);
4452
4453 if (updateFocusAndLayout) {
4454 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4455 assignLayersLocked();
4456 }
4457 mLayoutNeeded = true;
4458 performLayoutAndPlaceSurfacesLocked();
4459 }
4460 }
4461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4463 // First remove all of the windows from the list.
4464 final int N = tokens.size();
4465 int i;
4466 for (i=0; i<N; i++) {
4467 WindowToken token = mTokenMap.get(tokens.get(i));
4468 if (token != null) {
4469 tmpRemoveAppWindowsLocked(token);
4470 }
4471 }
4472
4473 // Where to start adding?
4474 int pos = findWindowOffsetLocked(tokenPos);
4475
4476 // And now add them back at the correct place.
4477 for (i=0; i<N; i++) {
4478 WindowToken token = mTokenMap.get(tokens.get(i));
4479 if (token != null) {
4480 pos = reAddAppWindowsLocked(pos, token);
4481 }
4482 }
4483
Dianne Hackborna8f60182009-09-01 19:01:50 -07004484 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4485 assignLayersLocked();
4486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 mLayoutNeeded = true;
4488 performLayoutAndPlaceSurfacesLocked();
4489
4490 //dump();
4491 }
4492
4493 public void moveAppTokensToTop(List<IBinder> tokens) {
4494 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4495 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004496 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 }
4498
4499 final long origId = Binder.clearCallingIdentity();
4500 synchronized(mWindowMap) {
4501 removeAppTokensLocked(tokens);
4502 final int N = tokens.size();
4503 for (int i=0; i<N; i++) {
4504 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4505 if (wt != null) {
4506 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004507 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004508 mToTopApps.remove(wt);
4509 mToBottomApps.remove(wt);
4510 mToTopApps.add(wt);
4511 wt.sendingToBottom = false;
4512 wt.sendingToTop = true;
4513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 }
4515 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004516
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004517 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004518 moveAppWindowsLocked(tokens, mAppTokens.size());
4519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 }
4521 Binder.restoreCallingIdentity(origId);
4522 }
4523
4524 public void moveAppTokensToBottom(List<IBinder> tokens) {
4525 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4526 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004527 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 }
4529
4530 final long origId = Binder.clearCallingIdentity();
4531 synchronized(mWindowMap) {
4532 removeAppTokensLocked(tokens);
4533 final int N = tokens.size();
4534 int pos = 0;
4535 for (int i=0; i<N; i++) {
4536 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4537 if (wt != null) {
4538 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004539 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004540 mToTopApps.remove(wt);
4541 mToBottomApps.remove(wt);
4542 mToBottomApps.add(i, wt);
4543 wt.sendingToTop = false;
4544 wt.sendingToBottom = true;
4545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004546 pos++;
4547 }
4548 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004549
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004550 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004551 moveAppWindowsLocked(tokens, 0);
4552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004553 }
4554 Binder.restoreCallingIdentity(origId);
4555 }
4556
4557 // -------------------------------------------------------------
4558 // Misc IWindowSession methods
4559 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004560
Jim Miller284b62e2010-06-08 14:27:42 -07004561 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004562 {
Jim Miller284b62e2010-06-08 14:27:42 -07004563 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4564 // called before DevicePolicyManagerService has started.
4565 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4566 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4567 Context.DEVICE_POLICY_SERVICE);
4568 if (dpm != null) {
4569 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4570 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4571 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4572 }
Jim Millerd6b57052010-06-07 17:52:42 -07004573 }
Jim Miller284b62e2010-06-08 14:27:42 -07004574 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004575 }
4576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004577 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004578 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 != PackageManager.PERMISSION_GRANTED) {
4580 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4581 }
Jim Millerd6b57052010-06-07 17:52:42 -07004582
Jim Miller284b62e2010-06-08 14:27:42 -07004583 synchronized (mKeyguardTokenWatcher) {
4584 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 }
4587
4588 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004589 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004590 != PackageManager.PERMISSION_GRANTED) {
4591 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593
Jim Miller284b62e2010-06-08 14:27:42 -07004594 synchronized (mKeyguardTokenWatcher) {
4595 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004596
Jim Miller284b62e2010-06-08 14:27:42 -07004597 if (!mKeyguardTokenWatcher.isAcquired()) {
4598 // If we are the last one to reenable the keyguard wait until
4599 // we have actually finished reenabling until returning.
4600 // It is possible that reenableKeyguard() can be called before
4601 // the previous disableKeyguard() is handled, in which case
4602 // neither mKeyguardTokenWatcher.acquired() or released() would
4603 // be called. In that case mKeyguardDisabled will be false here
4604 // and we have nothing to wait for.
4605 while (mKeyguardDisabled) {
4606 try {
4607 mKeyguardTokenWatcher.wait();
4608 } catch (InterruptedException e) {
4609 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004610 }
4611 }
4612 }
4613 }
4614 }
4615
4616 /**
4617 * @see android.app.KeyguardManager#exitKeyguardSecurely
4618 */
4619 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004620 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 != PackageManager.PERMISSION_GRANTED) {
4622 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4623 }
4624 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4625 public void onKeyguardExitResult(boolean success) {
4626 try {
4627 callback.onKeyguardExitResult(success);
4628 } catch (RemoteException e) {
4629 // Client has died, we don't care.
4630 }
4631 }
4632 });
4633 }
4634
4635 public boolean inKeyguardRestrictedInputMode() {
4636 return mPolicy.inKeyguardRestrictedKeyInputMode();
4637 }
Romain Guy06882f82009-06-10 13:36:04 -07004638
Dianne Hackbornffa42482009-09-23 22:20:11 -07004639 public void closeSystemDialogs(String reason) {
4640 synchronized(mWindowMap) {
4641 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004642 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004643 if (w.mSurface != null) {
4644 try {
4645 w.mClient.closeSystemDialogs(reason);
4646 } catch (RemoteException e) {
4647 }
4648 }
4649 }
4650 }
4651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 static float fixScale(float scale) {
4654 if (scale < 0) scale = 0;
4655 else if (scale > 20) scale = 20;
4656 return Math.abs(scale);
4657 }
Romain Guy06882f82009-06-10 13:36:04 -07004658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 public void setAnimationScale(int which, float scale) {
4660 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4661 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004662 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004663 }
4664
4665 if (scale < 0) scale = 0;
4666 else if (scale > 20) scale = 20;
4667 scale = Math.abs(scale);
4668 switch (which) {
4669 case 0: mWindowAnimationScale = fixScale(scale); break;
4670 case 1: mTransitionAnimationScale = fixScale(scale); break;
4671 }
Romain Guy06882f82009-06-10 13:36:04 -07004672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004673 // Persist setting
4674 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4675 }
Romain Guy06882f82009-06-10 13:36:04 -07004676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004677 public void setAnimationScales(float[] scales) {
4678 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4679 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004680 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 }
4682
4683 if (scales != null) {
4684 if (scales.length >= 1) {
4685 mWindowAnimationScale = fixScale(scales[0]);
4686 }
4687 if (scales.length >= 2) {
4688 mTransitionAnimationScale = fixScale(scales[1]);
4689 }
4690 }
Romain Guy06882f82009-06-10 13:36:04 -07004691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004692 // Persist setting
4693 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4694 }
Romain Guy06882f82009-06-10 13:36:04 -07004695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 public float getAnimationScale(int which) {
4697 switch (which) {
4698 case 0: return mWindowAnimationScale;
4699 case 1: return mTransitionAnimationScale;
4700 }
4701 return 0;
4702 }
Romain Guy06882f82009-06-10 13:36:04 -07004703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004704 public float[] getAnimationScales() {
4705 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4706 }
Romain Guy06882f82009-06-10 13:36:04 -07004707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004708 public int getSwitchState(int sw) {
4709 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4710 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004711 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004713 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 }
Romain Guy06882f82009-06-10 13:36:04 -07004715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 public int getSwitchStateForDevice(int devid, int sw) {
4717 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4718 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004719 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004721 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 }
Romain Guy06882f82009-06-10 13:36:04 -07004723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 public int getScancodeState(int sw) {
4725 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4726 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004727 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004729 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004730 }
Romain Guy06882f82009-06-10 13:36:04 -07004731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 public int getScancodeStateForDevice(int devid, int sw) {
4733 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4734 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004735 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004736 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004737 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 }
Romain Guy06882f82009-06-10 13:36:04 -07004739
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004740 public int getTrackballScancodeState(int sw) {
4741 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4742 "getTrackballScancodeState()")) {
4743 throw new SecurityException("Requires READ_INPUT_STATE permission");
4744 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004745 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004746 }
4747
4748 public int getDPadScancodeState(int sw) {
4749 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4750 "getDPadScancodeState()")) {
4751 throw new SecurityException("Requires READ_INPUT_STATE permission");
4752 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004753 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004754 }
4755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 public int getKeycodeState(int sw) {
4757 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4758 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004759 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004760 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004761 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004762 }
Romain Guy06882f82009-06-10 13:36:04 -07004763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 public int getKeycodeStateForDevice(int devid, int sw) {
4765 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4766 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004767 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004769 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 }
Romain Guy06882f82009-06-10 13:36:04 -07004771
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004772 public int getTrackballKeycodeState(int sw) {
4773 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4774 "getTrackballKeycodeState()")) {
4775 throw new SecurityException("Requires READ_INPUT_STATE permission");
4776 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004777 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004778 }
4779
4780 public int getDPadKeycodeState(int sw) {
4781 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4782 "getDPadKeycodeState()")) {
4783 throw new SecurityException("Requires READ_INPUT_STATE permission");
4784 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004785 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004786 }
Jeff Browna41ca772010-08-11 14:46:32 -07004787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004789 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 }
Romain Guy06882f82009-06-10 13:36:04 -07004791
Jeff Browna41ca772010-08-11 14:46:32 -07004792 public InputChannel monitorInput(String inputChannelName) {
4793 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4794 "monitorInput()")) {
4795 throw new SecurityException("Requires READ_INPUT_STATE permission");
4796 }
4797 return mInputManager.monitorInput(inputChannelName);
4798 }
4799
Jeff Brown8d608662010-08-30 03:02:23 -07004800 public InputDevice getInputDevice(int deviceId) {
4801 return mInputManager.getInputDevice(deviceId);
4802 }
4803
4804 public int[] getInputDeviceIds() {
4805 return mInputManager.getInputDeviceIds();
4806 }
4807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 public void enableScreenAfterBoot() {
4809 synchronized(mWindowMap) {
4810 if (mSystemBooted) {
4811 return;
4812 }
4813 mSystemBooted = true;
4814 }
Romain Guy06882f82009-06-10 13:36:04 -07004815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 performEnableScreen();
4817 }
Romain Guy06882f82009-06-10 13:36:04 -07004818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004819 public void enableScreenIfNeededLocked() {
4820 if (mDisplayEnabled) {
4821 return;
4822 }
4823 if (!mSystemBooted) {
4824 return;
4825 }
4826 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4827 }
Romain Guy06882f82009-06-10 13:36:04 -07004828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 public void performEnableScreen() {
4830 synchronized(mWindowMap) {
4831 if (mDisplayEnabled) {
4832 return;
4833 }
4834 if (!mSystemBooted) {
4835 return;
4836 }
Romain Guy06882f82009-06-10 13:36:04 -07004837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004838 // Don't enable the screen until all existing windows
4839 // have been drawn.
4840 final int N = mWindows.size();
4841 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004842 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004843 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004844 return;
4845 }
4846 }
Romain Guy06882f82009-06-10 13:36:04 -07004847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 mDisplayEnabled = true;
4849 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004850 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004851 StringWriter sw = new StringWriter();
4852 PrintWriter pw = new PrintWriter(sw);
4853 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004854 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 }
4856 try {
4857 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4858 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004859 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 Parcel data = Parcel.obtain();
4861 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4862 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4863 data, null, 0);
4864 data.recycle();
4865 }
4866 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004867 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004868 }
4869 }
Romain Guy06882f82009-06-10 13:36:04 -07004870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004874 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4875 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 }
Romain Guy06882f82009-06-10 13:36:04 -07004877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004878 public void setInTouchMode(boolean mode) {
4879 synchronized(mWindowMap) {
4880 mInTouchMode = mode;
4881 }
4882 }
4883
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004884 // TODO: more accounting of which pid(s) turned it on, keep count,
4885 // only allow disables from pids which have count on, etc.
4886 public void showStrictModeViolation(boolean on) {
4887 int pid = Binder.getCallingPid();
4888 synchronized(mWindowMap) {
4889 // Ignoring requests to enable the red border from clients
4890 // which aren't on screen. (e.g. Broadcast Receivers in
4891 // the background..)
4892 if (on) {
4893 boolean isVisible = false;
4894 for (WindowState ws : mWindows) {
4895 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4896 isVisible = true;
4897 break;
4898 }
4899 }
4900 if (!isVisible) {
4901 return;
4902 }
4903 }
4904
4905 Surface.openTransaction();
4906 if (mStrictModeFlash == null) {
4907 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4908 }
4909 mStrictModeFlash.setVisibility(on);
4910 Surface.closeTransaction();
4911 }
4912 }
4913
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004914 public void freezeRotation() {
4915 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4916 "setRotation()")) {
4917 throw new SecurityException("Requires SET_ORIENTATION permission");
4918 }
4919
4920 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4921 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4922 }
4923
4924 public void thawRotation() {
4925 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4926 "setRotation()")) {
4927 throw new SecurityException("Requires SET_ORIENTATION permission");
4928 }
4929
4930 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4931 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4932 }
4933
Romain Guy06882f82009-06-10 13:36:04 -07004934 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004935 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004937 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004938 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 }
4940
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004941 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 }
Romain Guy06882f82009-06-10 13:36:04 -07004943
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004944 public void setRotationUnchecked(int rotation,
4945 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004946 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 long origId = Binder.clearCallingIdentity();
4950 boolean changed;
4951 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004952 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 }
Romain Guy06882f82009-06-10 13:36:04 -07004954
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004955 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004956 sendNewConfiguration();
4957 }
Romain Guy06882f82009-06-10 13:36:04 -07004958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 Binder.restoreCallingIdentity(origId);
4960 }
Romain Guy06882f82009-06-10 13:36:04 -07004961
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004962 /**
4963 * Apply a new rotation to the screen, respecting the requests of
4964 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4965 * re-evaluate the desired rotation.
4966 *
4967 * Returns null if the rotation has been changed. In this case YOU
4968 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4969 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004970 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004971 boolean changed;
4972 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4973 rotation = mRequestedRotation;
4974 } else {
4975 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004976 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004977 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004978 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004979 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004981 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004984 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004985 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004986 "Rotation changed to " + rotation
4987 + " from " + mRotation
4988 + " (forceApp=" + mForcedAppOrientation
4989 + ", req=" + mRequestedRotation + ")");
4990 mRotation = rotation;
4991 mWindowsFreezingScreen = true;
4992 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4993 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4994 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004995 mWaitingForConfig = true;
4996 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004997 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004998 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004999 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005000 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07005001 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005002 }
5003 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005004 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005005 if (w.mSurface != null) {
5006 w.mOrientationChanging = true;
5007 }
5008 }
5009 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5010 try {
5011 mRotationWatchers.get(i).onRotationChanged(rotation);
5012 } catch (RemoteException e) {
5013 }
5014 }
5015 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005017 return changed;
5018 }
Romain Guy06882f82009-06-10 13:36:04 -07005019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005020 public int getRotation() {
5021 return mRotation;
5022 }
5023
5024 public int watchRotation(IRotationWatcher watcher) {
5025 final IBinder watcherBinder = watcher.asBinder();
5026 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5027 public void binderDied() {
5028 synchronized (mWindowMap) {
5029 for (int i=0; i<mRotationWatchers.size(); i++) {
5030 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005031 IRotationWatcher removed = mRotationWatchers.remove(i);
5032 if (removed != null) {
5033 removed.asBinder().unlinkToDeath(this, 0);
5034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 i--;
5036 }
5037 }
5038 }
5039 }
5040 };
Romain Guy06882f82009-06-10 13:36:04 -07005041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005042 synchronized (mWindowMap) {
5043 try {
5044 watcher.asBinder().linkToDeath(dr, 0);
5045 mRotationWatchers.add(watcher);
5046 } catch (RemoteException e) {
5047 // Client died, no cleanup needed.
5048 }
Romain Guy06882f82009-06-10 13:36:04 -07005049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005050 return mRotation;
5051 }
5052 }
5053
5054 /**
5055 * Starts the view server on the specified port.
5056 *
5057 * @param port The port to listener to.
5058 *
5059 * @return True if the server was successfully started, false otherwise.
5060 *
5061 * @see com.android.server.ViewServer
5062 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5063 */
5064 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005065 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005066 return false;
5067 }
5068
5069 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5070 return false;
5071 }
5072
5073 if (port < 1024) {
5074 return false;
5075 }
5076
5077 if (mViewServer != null) {
5078 if (!mViewServer.isRunning()) {
5079 try {
5080 return mViewServer.start();
5081 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005082 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005083 }
5084 }
5085 return false;
5086 }
5087
5088 try {
5089 mViewServer = new ViewServer(this, port);
5090 return mViewServer.start();
5091 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005092 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005093 }
5094 return false;
5095 }
5096
Romain Guy06882f82009-06-10 13:36:04 -07005097 private boolean isSystemSecure() {
5098 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5099 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5100 }
5101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005102 /**
5103 * Stops the view server if it exists.
5104 *
5105 * @return True if the server stopped, false if it wasn't started or
5106 * couldn't be stopped.
5107 *
5108 * @see com.android.server.ViewServer
5109 */
5110 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005111 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005112 return false;
5113 }
5114
5115 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5116 return false;
5117 }
5118
5119 if (mViewServer != null) {
5120 return mViewServer.stop();
5121 }
5122 return false;
5123 }
5124
5125 /**
5126 * Indicates whether the view server is running.
5127 *
5128 * @return True if the server is running, false otherwise.
5129 *
5130 * @see com.android.server.ViewServer
5131 */
5132 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005133 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 return false;
5135 }
5136
5137 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5138 return false;
5139 }
5140
5141 return mViewServer != null && mViewServer.isRunning();
5142 }
5143
5144 /**
5145 * Lists all availble windows in the system. The listing is written in the
5146 * specified Socket's output stream with the following syntax:
5147 * windowHashCodeInHexadecimal windowName
5148 * Each line of the ouput represents a different window.
5149 *
5150 * @param client The remote client to send the listing to.
5151 * @return False if an error occured, true otherwise.
5152 */
5153 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005154 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005155 return false;
5156 }
5157
5158 boolean result = true;
5159
Jeff Browne33348b2010-07-15 23:54:05 -07005160 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005161 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005162 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005163 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005164 }
5165
5166 BufferedWriter out = null;
5167
5168 // Any uncaught exception will crash the system process
5169 try {
5170 OutputStream clientStream = client.getOutputStream();
5171 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5172
5173 final int count = windows.length;
5174 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005175 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005176 out.write(Integer.toHexString(System.identityHashCode(w)));
5177 out.write(' ');
5178 out.append(w.mAttrs.getTitle());
5179 out.write('\n');
5180 }
5181
5182 out.write("DONE.\n");
5183 out.flush();
5184 } catch (Exception e) {
5185 result = false;
5186 } finally {
5187 if (out != null) {
5188 try {
5189 out.close();
5190 } catch (IOException e) {
5191 result = false;
5192 }
5193 }
5194 }
5195
5196 return result;
5197 }
5198
5199 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005200 * Returns the focused window in the following format:
5201 * windowHashCodeInHexadecimal windowName
5202 *
5203 * @param client The remote client to send the listing to.
5204 * @return False if an error occurred, true otherwise.
5205 */
5206 boolean viewServerGetFocusedWindow(Socket client) {
5207 if (isSystemSecure()) {
5208 return false;
5209 }
5210
5211 boolean result = true;
5212
5213 WindowState focusedWindow = getFocusedWindow();
5214
5215 BufferedWriter out = null;
5216
5217 // Any uncaught exception will crash the system process
5218 try {
5219 OutputStream clientStream = client.getOutputStream();
5220 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5221
5222 if(focusedWindow != null) {
5223 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5224 out.write(' ');
5225 out.append(focusedWindow.mAttrs.getTitle());
5226 }
5227 out.write('\n');
5228 out.flush();
5229 } catch (Exception e) {
5230 result = false;
5231 } finally {
5232 if (out != null) {
5233 try {
5234 out.close();
5235 } catch (IOException e) {
5236 result = false;
5237 }
5238 }
5239 }
5240
5241 return result;
5242 }
5243
5244 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 * Sends a command to a target window. The result of the command, if any, will be
5246 * written in the output stream of the specified socket.
5247 *
5248 * The parameters must follow this syntax:
5249 * windowHashcode extra
5250 *
5251 * Where XX is the length in characeters of the windowTitle.
5252 *
5253 * The first parameter is the target window. The window with the specified hashcode
5254 * will be the target. If no target can be found, nothing happens. The extra parameters
5255 * will be delivered to the target window and as parameters to the command itself.
5256 *
5257 * @param client The remote client to sent the result, if any, to.
5258 * @param command The command to execute.
5259 * @param parameters The command parameters.
5260 *
5261 * @return True if the command was successfully delivered, false otherwise. This does
5262 * not indicate whether the command itself was successful.
5263 */
5264 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005265 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 return false;
5267 }
5268
5269 boolean success = true;
5270 Parcel data = null;
5271 Parcel reply = null;
5272
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005273 BufferedWriter out = null;
5274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005275 // Any uncaught exception will crash the system process
5276 try {
5277 // Find the hashcode of the window
5278 int index = parameters.indexOf(' ');
5279 if (index == -1) {
5280 index = parameters.length();
5281 }
5282 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005283 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284
5285 // Extract the command's parameter after the window description
5286 if (index < parameters.length()) {
5287 parameters = parameters.substring(index + 1);
5288 } else {
5289 parameters = "";
5290 }
5291
5292 final WindowManagerService.WindowState window = findWindow(hashCode);
5293 if (window == null) {
5294 return false;
5295 }
5296
5297 data = Parcel.obtain();
5298 data.writeInterfaceToken("android.view.IWindow");
5299 data.writeString(command);
5300 data.writeString(parameters);
5301 data.writeInt(1);
5302 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5303
5304 reply = Parcel.obtain();
5305
5306 final IBinder binder = window.mClient.asBinder();
5307 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5308 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5309
5310 reply.readException();
5311
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005312 if (!client.isOutputShutdown()) {
5313 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5314 out.write("DONE\n");
5315 out.flush();
5316 }
5317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005318 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005319 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005320 success = false;
5321 } finally {
5322 if (data != null) {
5323 data.recycle();
5324 }
5325 if (reply != null) {
5326 reply.recycle();
5327 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005328 if (out != null) {
5329 try {
5330 out.close();
5331 } catch (IOException e) {
5332
5333 }
5334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005335 }
5336
5337 return success;
5338 }
5339
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005340 public void addWindowChangeListener(WindowChangeListener listener) {
5341 synchronized(mWindowMap) {
5342 mWindowChangeListeners.add(listener);
5343 }
5344 }
5345
5346 public void removeWindowChangeListener(WindowChangeListener listener) {
5347 synchronized(mWindowMap) {
5348 mWindowChangeListeners.remove(listener);
5349 }
5350 }
5351
5352 private void notifyWindowsChanged() {
5353 WindowChangeListener[] windowChangeListeners;
5354 synchronized(mWindowMap) {
5355 if(mWindowChangeListeners.isEmpty()) {
5356 return;
5357 }
5358 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5359 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5360 }
5361 int N = windowChangeListeners.length;
5362 for(int i = 0; i < N; i++) {
5363 windowChangeListeners[i].windowsChanged();
5364 }
5365 }
5366
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005367 private void notifyFocusChanged() {
5368 WindowChangeListener[] windowChangeListeners;
5369 synchronized(mWindowMap) {
5370 if(mWindowChangeListeners.isEmpty()) {
5371 return;
5372 }
5373 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5374 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5375 }
5376 int N = windowChangeListeners.length;
5377 for(int i = 0; i < N; i++) {
5378 windowChangeListeners[i].focusChanged();
5379 }
5380 }
5381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 private WindowState findWindow(int hashCode) {
5383 if (hashCode == -1) {
5384 return getFocusedWindow();
5385 }
5386
5387 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005388 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005389 final int count = windows.size();
5390
5391 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005392 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 if (System.identityHashCode(w) == hashCode) {
5394 return w;
5395 }
5396 }
5397 }
5398
5399 return null;
5400 }
5401
5402 /*
5403 * Instruct the Activity Manager to fetch the current configuration and broadcast
5404 * that to config-changed listeners if appropriate.
5405 */
5406 void sendNewConfiguration() {
5407 try {
5408 mActivityManager.updateConfiguration(null);
5409 } catch (RemoteException e) {
5410 }
5411 }
Romain Guy06882f82009-06-10 13:36:04 -07005412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005413 public Configuration computeNewConfiguration() {
5414 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005415 return computeNewConfigurationLocked();
5416 }
5417 }
Romain Guy06882f82009-06-10 13:36:04 -07005418
Dianne Hackbornc485a602009-03-24 22:39:49 -07005419 Configuration computeNewConfigurationLocked() {
5420 Configuration config = new Configuration();
5421 if (!computeNewConfigurationLocked(config)) {
5422 return null;
5423 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005424 return config;
5425 }
Romain Guy06882f82009-06-10 13:36:04 -07005426
Dianne Hackbornc485a602009-03-24 22:39:49 -07005427 boolean computeNewConfigurationLocked(Configuration config) {
5428 if (mDisplay == null) {
5429 return false;
5430 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005431
5432 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005433
5434 // Use the effective "visual" dimensions based on current rotation
5435 final boolean rotated = (mRotation == Surface.ROTATION_90
5436 || mRotation == Surface.ROTATION_270);
5437 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5438 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5439
Dianne Hackbornc485a602009-03-24 22:39:49 -07005440 int orientation = Configuration.ORIENTATION_SQUARE;
5441 if (dw < dh) {
5442 orientation = Configuration.ORIENTATION_PORTRAIT;
5443 } else if (dw > dh) {
5444 orientation = Configuration.ORIENTATION_LANDSCAPE;
5445 }
5446 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005447
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005448 DisplayMetrics dm = new DisplayMetrics();
5449 mDisplay.getMetrics(dm);
5450 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5451
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005452 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005453 // Note we only do this once because at this point we don't
5454 // expect the screen to change in this way at runtime, and want
5455 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005456 int longSize = dw;
5457 int shortSize = dh;
5458 if (longSize < shortSize) {
5459 int tmp = longSize;
5460 longSize = shortSize;
5461 shortSize = tmp;
5462 }
5463 longSize = (int)(longSize/dm.density);
5464 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005465
Dianne Hackborn723738c2009-06-25 19:48:04 -07005466 // These semi-magic numbers define our compatibility modes for
5467 // applications with different screens. Don't change unless you
5468 // make sure to test lots and lots of apps!
5469 if (longSize < 470) {
5470 // This is shorter than an HVGA normal density screen (which
5471 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005472 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5473 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005474 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005475 // What size is this screen screen?
5476 if (longSize >= 800 && shortSize >= 600) {
5477 // SVGA or larger screens at medium density are the point
5478 // at which we consider it to be an extra large screen.
5479 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005480 } else if (longSize >= 530 && shortSize >= 400) {
5481 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005482 // at which we consider it to be a large screen.
5483 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5484 } else {
5485 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005486
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005487 // If this screen is wider than normal HVGA, or taller
5488 // than FWVGA, then for old apps we want to run in size
5489 // compatibility mode.
5490 if (shortSize > 321 || longSize > 570) {
5491 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5492 }
5493 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005494
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005495 // Is this a long screen?
5496 if (((longSize*3)/5) >= (shortSize-1)) {
5497 // Anything wider than WVGA (5:3) is considering to be long.
5498 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5499 } else {
5500 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5501 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005502 }
5503 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005504 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005505
Dianne Hackbornc485a602009-03-24 22:39:49 -07005506 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5507 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5508 mPolicy.adjustConfigurationLw(config);
5509 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005510 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005511
5512 // -------------------------------------------------------------
5513 // Drag and drop
5514 // -------------------------------------------------------------
5515
5516 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5517 boolean localOnly, int width, int height, Surface outSurface) {
5518 if (DEBUG_DRAG) {
5519 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5520 + " local=" + localOnly + " win=" + window
5521 + " asbinder=" + window.asBinder());
5522 }
5523
5524 final int callerPid = Binder.getCallingPid();
5525 final long origId = Binder.clearCallingIdentity();
5526 IBinder token = null;
5527
5528 try {
5529 synchronized (mWindowMap) {
5530 try {
5531 // !!! TODO: fail if the given window does not currently have touch focus?
5532
5533 if (mDragState == null) {
5534 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5535 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5536 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005537 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005538 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005539 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005540 mDragState.mSurface = surface;
5541 mDragState.mLocalOnly = localOnly;
5542 token = mDragState.mToken = new Binder();
5543
5544 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005545 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5546 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005547 mH.sendMessageDelayed(msg, 5000);
5548 } else {
5549 Slog.w(TAG, "Drag already in progress");
5550 }
5551 } catch (Surface.OutOfResourcesException e) {
5552 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5553 if (mDragState != null) {
5554 mDragState.reset();
5555 mDragState = null;
5556 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005557 }
5558 }
5559 } finally {
5560 Binder.restoreCallingIdentity(origId);
5561 }
5562
5563 return token;
5564 }
5565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005566 // -------------------------------------------------------------
5567 // Input Events and Focus Management
5568 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005569
Jeff Brown349703e2010-06-22 01:27:15 -07005570 InputMonitor mInputMonitor = new InputMonitor();
5571
5572 /* Tracks the progress of input dispatch and ensures that input dispatch state
5573 * is kept in sync with changes in window focus, visibility, registration, and
5574 * other relevant Window Manager state transitions. */
5575 final class InputMonitor {
5576 // Current window with input focus for keys and other non-touch events. May be null.
5577 private WindowState mInputFocus;
5578
5579 // When true, prevents input dispatch from proceeding until set to false again.
5580 private boolean mInputDispatchFrozen;
5581
5582 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5583 private boolean mInputDispatchEnabled = true;
5584
5585 // Temporary list of windows information to provide to the input dispatcher.
5586 private InputWindowList mTempInputWindows = new InputWindowList();
5587
5588 // Temporary input application object to provide to the input dispatcher.
5589 private InputApplication mTempInputApplication = new InputApplication();
5590
5591 /* Notifies the window manager about a broken input channel.
5592 *
5593 * Called by the InputManager.
5594 */
5595 public void notifyInputChannelBroken(InputChannel inputChannel) {
5596 synchronized (mWindowMap) {
5597 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5598 if (windowState == null) {
5599 return; // irrelevant
5600 }
5601
5602 Slog.i(TAG, "WINDOW DIED " + windowState);
5603 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005604 }
5605 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005606
Jeff Brown519e0242010-09-15 15:18:56 -07005607 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005608 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005609 *
5610 * Called by the InputManager.
5611 */
Jeff Brown519e0242010-09-15 15:18:56 -07005612 public long notifyANR(Object token, InputChannel inputChannel) {
5613 AppWindowToken appWindowToken = null;
5614 if (inputChannel != null) {
5615 synchronized (mWindowMap) {
5616 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5617 if (windowState != null) {
5618 Slog.i(TAG, "Input event dispatching timed out sending to "
5619 + windowState.mAttrs.getTitle());
5620 appWindowToken = windowState.mAppToken;
5621 }
Jeff Brown349703e2010-06-22 01:27:15 -07005622 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005623 }
5624
Jeff Brown519e0242010-09-15 15:18:56 -07005625 if (appWindowToken == null && token != null) {
5626 appWindowToken = (AppWindowToken) token;
5627 Slog.i(TAG, "Input event dispatching timed out sending to application "
5628 + appWindowToken.stringName);
5629 }
Jeff Brown349703e2010-06-22 01:27:15 -07005630
Jeff Brown519e0242010-09-15 15:18:56 -07005631 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005632 try {
5633 // Notify the activity manager about the timeout and let it decide whether
5634 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005635 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005636 if (! abort) {
5637 // The activity manager declined to abort dispatching.
5638 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005639 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005640 }
Jeff Brown349703e2010-06-22 01:27:15 -07005641 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005642 }
5643 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005644 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005645 }
5646
Jeff Brown349703e2010-06-22 01:27:15 -07005647 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5648 synchronized (mWindowMap) {
5649 return getWindowStateForInputChannelLocked(inputChannel);
5650 }
5651 }
5652
5653 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5654 int windowCount = mWindows.size();
5655 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005656 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005657 if (windowState.mInputChannel == inputChannel) {
5658 return windowState;
5659 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005660 }
5661
Jeff Brown349703e2010-06-22 01:27:15 -07005662 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005663 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005664
Chris Tatea32dcf72010-10-14 12:13:50 -07005665 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005666 final InputWindow inputWindow = windowList.add();
5667 inputWindow.inputChannel = mDragState.mServerChannel;
5668 inputWindow.name = "drag";
5669 inputWindow.layoutParamsFlags = 0;
5670 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5671 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5672 inputWindow.visible = true;
5673 inputWindow.canReceiveKeys = false;
5674 inputWindow.hasFocus = true;
5675 inputWindow.hasWallpaper = false;
5676 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005677 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005678 inputWindow.ownerPid = Process.myPid();
5679 inputWindow.ownerUid = Process.myUid();
5680
5681 // The drag window covers the entire display
5682 inputWindow.frameLeft = 0;
5683 inputWindow.frameTop = 0;
5684 inputWindow.frameRight = mDisplay.getWidth();
5685 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005686
Christopher Tatea53146c2010-09-07 11:57:52 -07005687 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5688 inputWindow.visibleFrameTop = inputWindow.frameTop;
5689 inputWindow.visibleFrameRight = inputWindow.frameRight;
5690 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5691
5692 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5693 inputWindow.touchableAreaTop = inputWindow.frameTop;
5694 inputWindow.touchableAreaRight = inputWindow.frameRight;
5695 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5696 }
5697
Jeff Brown349703e2010-06-22 01:27:15 -07005698 /* Updates the cached window information provided to the input dispatcher. */
5699 public void updateInputWindowsLw() {
5700 // Populate the input window list with information about all of the windows that
5701 // could potentially receive input.
5702 // As an optimization, we could try to prune the list of windows but this turns
5703 // out to be difficult because only the native code knows for sure which window
5704 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005705 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005706
5707 // If there's a drag in flight, provide a pseudowindow to catch drag input
5708 final boolean inDrag = (mDragState != null);
5709 if (inDrag) {
5710 if (DEBUG_DRAG) {
5711 Log.d(TAG, "Inserting drag window");
5712 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005713 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005714 }
5715
Jeff Brown7fbdc842010-06-17 20:52:56 -07005716 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005717 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005718 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005719 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005720 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005721 continue;
5722 }
5723
Jeff Brown349703e2010-06-22 01:27:15 -07005724 final int flags = child.mAttrs.flags;
5725 final int type = child.mAttrs.type;
5726
5727 final boolean hasFocus = (child == mInputFocus);
5728 final boolean isVisible = child.isVisibleLw();
5729 final boolean hasWallpaper = (child == mWallpaperTarget)
5730 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005731
5732 // If there's a drag in progress and 'child' is a potential drop target,
5733 // make sure it's been told about the drag
5734 if (inDrag && isVisible) {
5735 mDragState.sendDragStartedIfNeededLw(child);
5736 }
5737
Jeff Brown349703e2010-06-22 01:27:15 -07005738 // Add a window to our list of input windows.
5739 final InputWindow inputWindow = mTempInputWindows.add();
5740 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005741 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005742 inputWindow.layoutParamsFlags = flags;
5743 inputWindow.layoutParamsType = type;
5744 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5745 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005746 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005747 inputWindow.hasFocus = hasFocus;
5748 inputWindow.hasWallpaper = hasWallpaper;
5749 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005750 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005751 inputWindow.ownerPid = child.mSession.mPid;
5752 inputWindow.ownerUid = child.mSession.mUid;
5753
5754 final Rect frame = child.mFrame;
5755 inputWindow.frameLeft = frame.left;
5756 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005757 inputWindow.frameRight = frame.right;
5758 inputWindow.frameBottom = frame.bottom;
5759
5760 final Rect visibleFrame = child.mVisibleFrame;
5761 inputWindow.visibleFrameLeft = visibleFrame.left;
5762 inputWindow.visibleFrameTop = visibleFrame.top;
5763 inputWindow.visibleFrameRight = visibleFrame.right;
5764 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005765
5766 switch (child.mTouchableInsets) {
5767 default:
5768 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5769 inputWindow.touchableAreaLeft = frame.left;
5770 inputWindow.touchableAreaTop = frame.top;
5771 inputWindow.touchableAreaRight = frame.right;
5772 inputWindow.touchableAreaBottom = frame.bottom;
5773 break;
5774
5775 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5776 Rect inset = child.mGivenContentInsets;
5777 inputWindow.touchableAreaLeft = frame.left + inset.left;
5778 inputWindow.touchableAreaTop = frame.top + inset.top;
5779 inputWindow.touchableAreaRight = frame.right - inset.right;
5780 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5781 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005782 }
Jeff Brown349703e2010-06-22 01:27:15 -07005783
5784 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5785 Rect inset = child.mGivenVisibleInsets;
5786 inputWindow.touchableAreaLeft = frame.left + inset.left;
5787 inputWindow.touchableAreaTop = frame.top + inset.top;
5788 inputWindow.touchableAreaRight = frame.right - inset.right;
5789 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005790 break;
5791 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005792 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005793 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005794
Jeff Brown349703e2010-06-22 01:27:15 -07005795 // Send windows to native code.
5796 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005797
Jeff Brown349703e2010-06-22 01:27:15 -07005798 // Clear the list in preparation for the next round.
5799 // Also avoids keeping InputChannel objects referenced unnecessarily.
5800 mTempInputWindows.clear();
5801 }
5802
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005803 /* Notifies that the lid switch changed state. */
5804 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5805 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5806 }
5807
Jeff Brown349703e2010-06-22 01:27:15 -07005808 /* Provides an opportunity for the window manager policy to intercept early key
5809 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005810 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5811 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5812 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5813 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005814 }
5815
5816 /* Provides an opportunity for the window manager policy to process a key before
5817 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005818 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005819 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005820 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005821 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005822 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005823 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005824 }
5825
Jeff Brown3915bb82010-11-05 15:02:16 -07005826 /* Provides an opportunity for the window manager policy to process a key that
5827 * the application did not handle. */
5828 public boolean dispatchUnhandledKey(InputChannel focus,
5829 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
5830 int policyFlags) {
5831 WindowState windowState = getWindowStateForInputChannel(focus);
5832 return mPolicy.dispatchUnhandledKey(windowState, action, flags,
5833 keyCode, scanCode, metaState, repeatCount, policyFlags);
5834 }
5835
Jeff Brown349703e2010-06-22 01:27:15 -07005836 /* Called when the current input focus changes.
5837 * Layer assignment is assumed to be complete by the time this is called.
5838 */
5839 public void setInputFocusLw(WindowState newWindow) {
5840 if (DEBUG_INPUT) {
5841 Slog.d(TAG, "Input focus has changed to " + newWindow);
5842 }
5843
5844 if (newWindow != mInputFocus) {
5845 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005846 // Displaying a window implicitly causes dispatching to be unpaused.
5847 // This is to protect against bugs if someone pauses dispatching but
5848 // forgets to resume.
5849 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005850 }
Jeff Brown349703e2010-06-22 01:27:15 -07005851
5852 mInputFocus = newWindow;
5853 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005854 }
5855 }
5856
Jeff Brown349703e2010-06-22 01:27:15 -07005857 public void setFocusedAppLw(AppWindowToken newApp) {
5858 // Focused app has changed.
5859 if (newApp == null) {
5860 mInputManager.setFocusedApplication(null);
5861 } else {
5862 mTempInputApplication.name = newApp.toString();
5863 mTempInputApplication.dispatchingTimeoutNanos =
5864 newApp.inputDispatchingTimeoutNanos;
5865 mTempInputApplication.token = newApp;
5866
5867 mInputManager.setFocusedApplication(mTempInputApplication);
5868 }
5869 }
5870
Jeff Brown349703e2010-06-22 01:27:15 -07005871 public void pauseDispatchingLw(WindowToken window) {
5872 if (! window.paused) {
5873 if (DEBUG_INPUT) {
5874 Slog.v(TAG, "Pausing WindowToken " + window);
5875 }
5876
5877 window.paused = true;
5878 updateInputWindowsLw();
5879 }
5880 }
5881
5882 public void resumeDispatchingLw(WindowToken window) {
5883 if (window.paused) {
5884 if (DEBUG_INPUT) {
5885 Slog.v(TAG, "Resuming WindowToken " + window);
5886 }
5887
5888 window.paused = false;
5889 updateInputWindowsLw();
5890 }
5891 }
5892
5893 public void freezeInputDispatchingLw() {
5894 if (! mInputDispatchFrozen) {
5895 if (DEBUG_INPUT) {
5896 Slog.v(TAG, "Freezing input dispatching");
5897 }
5898
5899 mInputDispatchFrozen = true;
5900 updateInputDispatchModeLw();
5901 }
5902 }
5903
5904 public void thawInputDispatchingLw() {
5905 if (mInputDispatchFrozen) {
5906 if (DEBUG_INPUT) {
5907 Slog.v(TAG, "Thawing input dispatching");
5908 }
5909
5910 mInputDispatchFrozen = false;
5911 updateInputDispatchModeLw();
5912 }
5913 }
5914
5915 public void setEventDispatchingLw(boolean enabled) {
5916 if (mInputDispatchEnabled != enabled) {
5917 if (DEBUG_INPUT) {
5918 Slog.v(TAG, "Setting event dispatching to " + enabled);
5919 }
5920
5921 mInputDispatchEnabled = enabled;
5922 updateInputDispatchModeLw();
5923 }
5924 }
5925
5926 private void updateInputDispatchModeLw() {
5927 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5928 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005929 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005931 public void pauseKeyDispatching(IBinder _token) {
5932 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5933 "pauseKeyDispatching()")) {
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) {
5938 WindowToken token = mTokenMap.get(_token);
5939 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005940 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 }
5942 }
5943 }
5944
5945 public void resumeKeyDispatching(IBinder _token) {
5946 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5947 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005948 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005949 }
5950
5951 synchronized (mWindowMap) {
5952 WindowToken token = mTokenMap.get(_token);
5953 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005954 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005955 }
5956 }
5957 }
5958
5959 public void setEventDispatching(boolean enabled) {
5960 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5961 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005962 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 }
5964
5965 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005966 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005967 }
5968 }
Romain Guy06882f82009-06-10 13:36:04 -07005969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005970 /**
5971 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005972 * Even when sync is false, this method may block while waiting for current
5973 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005974 *
5975 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005976 * {@link SystemClock#uptimeMillis()} as the timebase.)
5977 * @param sync If true, wait for the event to be completed before returning to the caller.
5978 * @return Returns true if event was dispatched, false if it was dropped for any reason
5979 */
5980 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5981 long downTime = ev.getDownTime();
5982 long eventTime = ev.getEventTime();
5983
5984 int action = ev.getAction();
5985 int code = ev.getKeyCode();
5986 int repeatCount = ev.getRepeatCount();
5987 int metaState = ev.getMetaState();
5988 int deviceId = ev.getDeviceId();
5989 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005990 int source = ev.getSource();
5991
5992 if (source == InputDevice.SOURCE_UNKNOWN) {
5993 source = InputDevice.SOURCE_KEYBOARD;
5994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005995
5996 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5997 if (downTime == 0) downTime = eventTime;
5998
5999 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07006000 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006002 final int pid = Binder.getCallingPid();
6003 final int uid = Binder.getCallingUid();
6004 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006005
Jeff Brownbbda99d2010-07-28 15:48:59 -07006006 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6007 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6008 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6009 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006010
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006011 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006012 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006013 }
6014
6015 /**
6016 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006017 * Even when sync is false, this method may block while waiting for current
6018 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006019 *
6020 * @param ev A motion event describing the pointer (touch) action. (As noted in
6021 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006022 * {@link SystemClock#uptimeMillis()} as the timebase.)
6023 * @param sync If true, wait for the event to be completed before returning to the caller.
6024 * @return Returns true if event was dispatched, false if it was dropped for any reason
6025 */
6026 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006027 final int pid = Binder.getCallingPid();
6028 final int uid = Binder.getCallingUid();
6029 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006030
Jeff Brownc5ed5912010-07-14 18:48:53 -07006031 MotionEvent newEvent = MotionEvent.obtain(ev);
6032 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6033 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6034 }
6035
Jeff Brownbbda99d2010-07-28 15:48:59 -07006036 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6037 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6038 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6039 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006040
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006041 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006042 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006043 }
Romain Guy06882f82009-06-10 13:36:04 -07006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 /**
6046 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006047 * Even when sync is false, this method may block while waiting for current
6048 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006049 *
6050 * @param ev A motion event describing the trackball action. (As noted in
6051 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006052 * {@link SystemClock#uptimeMillis()} as the timebase.)
6053 * @param sync If true, wait for the event to be completed before returning to the caller.
6054 * @return Returns true if event was dispatched, false if it was dropped for any reason
6055 */
6056 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006057 final int pid = Binder.getCallingPid();
6058 final int uid = Binder.getCallingUid();
6059 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006060
Jeff Brownc5ed5912010-07-14 18:48:53 -07006061 MotionEvent newEvent = MotionEvent.obtain(ev);
6062 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6063 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6064 }
6065
Jeff Brownbbda99d2010-07-28 15:48:59 -07006066 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6067 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6068 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6069 INJECTION_TIMEOUT_MILLIS);
6070
6071 Binder.restoreCallingIdentity(ident);
6072 return reportInjectionResult(result);
6073 }
6074
6075 /**
6076 * Inject an input event into the UI without waiting for dispatch to commence.
6077 * This variant is useful for fire-and-forget input event injection. It does not
6078 * block any longer than it takes to enqueue the input event.
6079 *
6080 * @param ev An input event. (Be sure to set the input source correctly.)
6081 * @return Returns true if event was dispatched, false if it was dropped for any reason
6082 */
6083 public boolean injectInputEventNoWait(InputEvent ev) {
6084 final int pid = Binder.getCallingPid();
6085 final int uid = Binder.getCallingUid();
6086 final long ident = Binder.clearCallingIdentity();
6087
6088 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6089 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6090 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006091
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006092 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006093 return reportInjectionResult(result);
6094 }
6095
6096 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006097 switch (result) {
6098 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6099 Slog.w(TAG, "Input event injection permission denied.");
6100 throw new SecurityException(
6101 "Injecting to another application requires INJECT_EVENTS permission");
6102 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006103 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006104 return true;
6105 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6106 Slog.w(TAG, "Input event injection timed out.");
6107 return false;
6108 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6109 default:
6110 Slog.w(TAG, "Input event injection failed.");
6111 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 }
Romain Guy06882f82009-06-10 13:36:04 -07006114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006115 private WindowState getFocusedWindow() {
6116 synchronized (mWindowMap) {
6117 return getFocusedWindowLocked();
6118 }
6119 }
6120
6121 private WindowState getFocusedWindowLocked() {
6122 return mCurrentFocus;
6123 }
Romain Guy06882f82009-06-10 13:36:04 -07006124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 public boolean detectSafeMode() {
6126 mSafeMode = mPolicy.detectSafeMode();
6127 return mSafeMode;
6128 }
Romain Guy06882f82009-06-10 13:36:04 -07006129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006130 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006131 synchronized(mWindowMap) {
6132 if (mDisplay != null) {
6133 throw new IllegalStateException("Display already initialized");
6134 }
6135 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6136 mDisplay = wm.getDefaultDisplay();
6137 mInitialDisplayWidth = mDisplay.getWidth();
6138 mInitialDisplayHeight = mDisplay.getHeight();
6139 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6140 }
6141
6142 try {
6143 mActivityManager.updateConfiguration(null);
6144 } catch (RemoteException e) {
6145 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006146
6147 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006148 }
6149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 // -------------------------------------------------------------
6151 // Client Session State
6152 // -------------------------------------------------------------
6153
6154 private final class Session extends IWindowSession.Stub
6155 implements IBinder.DeathRecipient {
6156 final IInputMethodClient mClient;
6157 final IInputContext mInputContext;
6158 final int mUid;
6159 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006160 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006161 SurfaceSession mSurfaceSession;
6162 int mNumWindow = 0;
6163 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006165 public Session(IInputMethodClient client, IInputContext inputContext) {
6166 mClient = client;
6167 mInputContext = inputContext;
6168 mUid = Binder.getCallingUid();
6169 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006170 StringBuilder sb = new StringBuilder();
6171 sb.append("Session{");
6172 sb.append(Integer.toHexString(System.identityHashCode(this)));
6173 sb.append(" uid ");
6174 sb.append(mUid);
6175 sb.append("}");
6176 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006178 synchronized (mWindowMap) {
6179 if (mInputMethodManager == null && mHaveInputMethods) {
6180 IBinder b = ServiceManager.getService(
6181 Context.INPUT_METHOD_SERVICE);
6182 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6183 }
6184 }
6185 long ident = Binder.clearCallingIdentity();
6186 try {
6187 // Note: it is safe to call in to the input method manager
6188 // here because we are not holding our lock.
6189 if (mInputMethodManager != null) {
6190 mInputMethodManager.addClient(client, inputContext,
6191 mUid, mPid);
6192 } else {
6193 client.setUsingInputMethod(false);
6194 }
6195 client.asBinder().linkToDeath(this, 0);
6196 } catch (RemoteException e) {
6197 // The caller has died, so we can just forget about this.
6198 try {
6199 if (mInputMethodManager != null) {
6200 mInputMethodManager.removeClient(client);
6201 }
6202 } catch (RemoteException ee) {
6203 }
6204 } finally {
6205 Binder.restoreCallingIdentity(ident);
6206 }
6207 }
Romain Guy06882f82009-06-10 13:36:04 -07006208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 @Override
6210 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6211 throws RemoteException {
6212 try {
6213 return super.onTransact(code, data, reply, flags);
6214 } catch (RuntimeException e) {
6215 // Log all 'real' exceptions thrown to the caller
6216 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006217 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 }
6219 throw e;
6220 }
6221 }
6222
6223 public void binderDied() {
6224 // Note: it is safe to call in to the input method manager
6225 // here because we are not holding our lock.
6226 try {
6227 if (mInputMethodManager != null) {
6228 mInputMethodManager.removeClient(mClient);
6229 }
6230 } catch (RemoteException e) {
6231 }
6232 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006233 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006234 mClientDead = true;
6235 killSessionLocked();
6236 }
6237 }
6238
6239 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006240 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6241 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6242 outInputChannel);
6243 }
6244
6245 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006246 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006247 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006248 }
Romain Guy06882f82009-06-10 13:36:04 -07006249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 public void remove(IWindow window) {
6251 removeWindow(this, window);
6252 }
Romain Guy06882f82009-06-10 13:36:04 -07006253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6255 int requestedWidth, int requestedHeight, int viewFlags,
6256 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006257 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006258 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6259 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006260 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006261 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006262 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6263 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 }
Romain Guy06882f82009-06-10 13:36:04 -07006265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 public void setTransparentRegion(IWindow window, Region region) {
6267 setTransparentRegionWindow(this, window, region);
6268 }
Romain Guy06882f82009-06-10 13:36:04 -07006269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270 public void setInsets(IWindow window, int touchableInsets,
6271 Rect contentInsets, Rect visibleInsets) {
6272 setInsetsWindow(this, window, touchableInsets, contentInsets,
6273 visibleInsets);
6274 }
Romain Guy06882f82009-06-10 13:36:04 -07006275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006276 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6277 getWindowDisplayFrame(this, window, outDisplayFrame);
6278 }
Romain Guy06882f82009-06-10 13:36:04 -07006279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006280 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006281 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 TAG, "IWindow finishDrawing called for " + window);
6283 finishDrawingWindow(this, window);
6284 }
6285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006286 public void setInTouchMode(boolean mode) {
6287 synchronized(mWindowMap) {
6288 mInTouchMode = mode;
6289 }
6290 }
6291
6292 public boolean getInTouchMode() {
6293 synchronized(mWindowMap) {
6294 return mInTouchMode;
6295 }
6296 }
6297
6298 public boolean performHapticFeedback(IWindow window, int effectId,
6299 boolean always) {
6300 synchronized(mWindowMap) {
6301 long ident = Binder.clearCallingIdentity();
6302 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006303 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006304 windowForClientLocked(this, window, true),
6305 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 } finally {
6307 Binder.restoreCallingIdentity(ident);
6308 }
6309 }
6310 }
Romain Guy06882f82009-06-10 13:36:04 -07006311
Christopher Tatea53146c2010-09-07 11:57:52 -07006312 /* Drag/drop */
6313 public IBinder prepareDrag(IWindow window, boolean localOnly,
6314 int width, int height, Surface outSurface) {
6315 return prepareDragSurface(window, mSurfaceSession, localOnly,
6316 width, height, outSurface);
6317 }
6318
6319 public boolean performDrag(IWindow window, IBinder dragToken,
6320 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6321 ClipData data) {
6322 if (DEBUG_DRAG) {
6323 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6324 }
6325
6326 synchronized (mWindowMap) {
6327 if (mDragState == null) {
6328 Slog.w(TAG, "No drag prepared");
6329 throw new IllegalStateException("performDrag() without prepareDrag()");
6330 }
6331
6332 if (dragToken != mDragState.mToken) {
6333 Slog.w(TAG, "Performing mismatched drag");
6334 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6335 }
6336
6337 WindowState callingWin = windowForClientLocked(null, window, false);
6338 if (callingWin == null) {
6339 Slog.w(TAG, "Bad requesting window " + window);
6340 return false; // !!! TODO: throw here?
6341 }
6342
6343 // !!! TODO: if input is not still focused on the initiating window, fail
6344 // the drag initiation (e.g. an alarm window popped up just as the application
6345 // called performDrag()
6346
6347 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6348
Christopher Tate2c095f32010-10-04 14:13:40 -07006349 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6350 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006351
Chris Tateb478f462010-10-15 16:02:26 -07006352 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6353 // the actual drag event dispatch stuff in the dragstate
6354
Christopher Tatea53146c2010-09-07 11:57:52 -07006355 mDragState.register();
6356 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006357 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6358 mDragState.mServerChannel)) {
6359 Slog.e(TAG, "Unable to transfer touch focus");
6360 mDragState.unregister();
6361 mDragState = null;
6362 mInputMonitor.updateInputWindowsLw();
6363 return false;
6364 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006365
6366 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006367 mDragState.mCurrentX = touchX;
6368 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006369 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006370
6371 // remember the thumb offsets for later
6372 mDragState.mThumbOffsetX = thumbCenterX;
6373 mDragState.mThumbOffsetY = thumbCenterY;
6374
6375 // Make the surface visible at the proper location
6376 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006377 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006378 try {
6379 surface.setPosition((int)(touchX - thumbCenterX),
6380 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006381 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006382 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006383 surface.show();
6384 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006385 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006386 }
6387 }
6388
6389 return true; // success!
6390 }
6391
Chris Tated4533f142010-10-19 15:15:08 -07006392 public void reportDropResult(IWindow window, boolean consumed) {
6393 IBinder token = window.asBinder();
6394 if (DEBUG_DRAG) {
6395 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6396 }
6397
6398 synchronized (mWindowMap) {
6399 if (mDragState.mToken != token) {
6400 Slog.w(TAG, "Invalid drop-result claim by " + window);
6401 throw new IllegalStateException("reportDropResult() by non-recipient");
6402 }
6403
6404 // The right window has responded, even if it's no longer around,
6405 // so be sure to halt the timeout even if the later WindowState
6406 // lookup fails.
6407 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6408
6409 WindowState callingWin = windowForClientLocked(null, window, false);
6410 if (callingWin == null) {
6411 Slog.w(TAG, "Bad result-reporting window " + window);
6412 return; // !!! TODO: throw here?
6413 }
6414
6415 mDragState.mDragResult = consumed;
6416 mDragState.endDragLw();
6417 }
6418 }
6419
Christopher Tatea53146c2010-09-07 11:57:52 -07006420 public void dragRecipientEntered(IWindow window) {
6421 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006422 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006423 }
6424 }
6425
6426 public void dragRecipientExited(IWindow window) {
6427 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006428 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006429 }
6430 }
6431
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006432 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006433 synchronized(mWindowMap) {
6434 long ident = Binder.clearCallingIdentity();
6435 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006436 setWindowWallpaperPositionLocked(
6437 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006438 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006439 } finally {
6440 Binder.restoreCallingIdentity(ident);
6441 }
6442 }
6443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006444
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006445 public void wallpaperOffsetsComplete(IBinder window) {
6446 WindowManagerService.this.wallpaperOffsetsComplete(window);
6447 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006448
Dianne Hackborn75804932009-10-20 20:15:20 -07006449 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6450 int z, Bundle extras, boolean sync) {
6451 synchronized(mWindowMap) {
6452 long ident = Binder.clearCallingIdentity();
6453 try {
6454 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006455 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006456 action, x, y, z, extras, sync);
6457 } finally {
6458 Binder.restoreCallingIdentity(ident);
6459 }
6460 }
6461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006462
Dianne Hackborn75804932009-10-20 20:15:20 -07006463 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6464 WindowManagerService.this.wallpaperCommandComplete(window, result);
6465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 void windowAddedLocked() {
6468 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006469 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 TAG, "First window added to " + this + ", creating SurfaceSession");
6471 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006472 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006473 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 mSessions.add(this);
6475 }
6476 mNumWindow++;
6477 }
6478
6479 void windowRemovedLocked() {
6480 mNumWindow--;
6481 killSessionLocked();
6482 }
Romain Guy06882f82009-06-10 13:36:04 -07006483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006484 void killSessionLocked() {
6485 if (mNumWindow <= 0 && mClientDead) {
6486 mSessions.remove(this);
6487 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006488 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 TAG, "Last window removed from " + this
6490 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006491 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006492 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 try {
6494 mSurfaceSession.kill();
6495 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006496 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006497 + mSurfaceSession + " in session " + this
6498 + ": " + e.toString());
6499 }
6500 mSurfaceSession = null;
6501 }
6502 }
6503 }
Romain Guy06882f82009-06-10 13:36:04 -07006504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006506 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6507 pw.print(" mClientDead="); pw.print(mClientDead);
6508 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006509 }
6510
6511 @Override
6512 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006513 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 }
6515 }
6516
6517 // -------------------------------------------------------------
6518 // Client Window State
6519 // -------------------------------------------------------------
6520
6521 private final class WindowState implements WindowManagerPolicy.WindowState {
6522 final Session mSession;
6523 final IWindow mClient;
6524 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006525 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006526 AppWindowToken mAppToken;
6527 AppWindowToken mTargetAppToken;
6528 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6529 final DeathRecipient mDeathRecipient;
6530 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006531 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006532 final int mBaseLayer;
6533 final int mSubLayer;
6534 final boolean mLayoutAttached;
6535 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006536 final boolean mIsWallpaper;
6537 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 int mViewVisibility;
6539 boolean mPolicyVisibility = true;
6540 boolean mPolicyVisibilityAfterAnim = true;
6541 boolean mAppFreezing;
6542 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006543 boolean mReportDestroySurface;
6544 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006545 boolean mAttachedHidden; // is our parent window hidden?
6546 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006547 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 int mRequestedWidth;
6549 int mRequestedHeight;
6550 int mLastRequestedWidth;
6551 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006552 int mLayer;
6553 int mAnimLayer;
6554 int mLastLayer;
6555 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006556 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006557 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006559 int mLayoutSeq = -1;
6560
6561 Configuration mConfiguration = null;
6562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 // Actual frame shown on-screen (may be modified by animation)
6564 final Rect mShownFrame = new Rect();
6565 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006568 * Set when we have changed the size of the surface, to know that
6569 * we must tell them application to resize (and thus redraw itself).
6570 */
6571 boolean mSurfaceResized;
6572
6573 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 * Insets that determine the actually visible area
6575 */
6576 final Rect mVisibleInsets = new Rect();
6577 final Rect mLastVisibleInsets = new Rect();
6578 boolean mVisibleInsetsChanged;
6579
6580 /**
6581 * Insets that are covered by system windows
6582 */
6583 final Rect mContentInsets = new Rect();
6584 final Rect mLastContentInsets = new Rect();
6585 boolean mContentInsetsChanged;
6586
6587 /**
6588 * Set to true if we are waiting for this window to receive its
6589 * given internal insets before laying out other windows based on it.
6590 */
6591 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 /**
6594 * These are the content insets that were given during layout for
6595 * this window, to be applied to windows behind it.
6596 */
6597 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 /**
6600 * These are the visible insets that were given during layout for
6601 * this window, to be applied to windows behind it.
6602 */
6603 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 /**
6606 * Flag indicating whether the touchable region should be adjusted by
6607 * the visible insets; if false the area outside the visible insets is
6608 * NOT touchable, so we must use those to adjust the frame during hit
6609 * tests.
6610 */
6611 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 // Current transformation being applied.
6614 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6615 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6616 float mHScale=1, mVScale=1;
6617 float mLastHScale=1, mLastVScale=1;
6618 final Matrix mTmpMatrix = new Matrix();
6619
6620 // "Real" frame that the application sees.
6621 final Rect mFrame = new Rect();
6622 final Rect mLastFrame = new Rect();
6623
6624 final Rect mContainingFrame = new Rect();
6625 final Rect mDisplayFrame = new Rect();
6626 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006627 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 final Rect mVisibleFrame = new Rect();
6629
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006630 boolean mContentChanged;
6631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006632 float mShownAlpha = 1;
6633 float mAlpha = 1;
6634 float mLastAlpha = 1;
6635
6636 // Set to true if, when the window gets displayed, it should perform
6637 // an enter animation.
6638 boolean mEnterAnimationPending;
6639
6640 // Currently running animation.
6641 boolean mAnimating;
6642 boolean mLocalAnimating;
6643 Animation mAnimation;
6644 boolean mAnimationIsEntrance;
6645 boolean mHasTransformation;
6646 boolean mHasLocalTransformation;
6647 final Transformation mTransformation = new Transformation();
6648
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006649 // If a window showing a wallpaper: the requested offset for the
6650 // wallpaper; if a wallpaper window: the currently applied offset.
6651 float mWallpaperX = -1;
6652 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006653
6654 // If a window showing a wallpaper: what fraction of the offset
6655 // range corresponds to a full virtual screen.
6656 float mWallpaperXStep = -1;
6657 float mWallpaperYStep = -1;
6658
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006659 // Wallpaper windows: pixels offset based on above variables.
6660 int mXOffset;
6661 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006663 // This is set after IWindowSession.relayout() has been called at
6664 // least once for the window. It allows us to detect the situation
6665 // where we don't yet have a surface, but should have one soon, so
6666 // we can give the window focus before waiting for the relayout.
6667 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006669 // This is set after the Surface has been created but before the
6670 // window has been drawn. During this time the surface is hidden.
6671 boolean mDrawPending;
6672
6673 // This is set after the window has finished drawing for the first
6674 // time but before its surface is shown. The surface will be
6675 // displayed when the next layout is run.
6676 boolean mCommitDrawPending;
6677
6678 // This is set during the time after the window's drawing has been
6679 // committed, and before its surface is actually shown. It is used
6680 // to delay showing the surface until all windows in a token are ready
6681 // to be shown.
6682 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006684 // Set when the window has been shown in the screen the first time.
6685 boolean mHasDrawn;
6686
6687 // Currently running an exit animation?
6688 boolean mExiting;
6689
6690 // Currently on the mDestroySurface list?
6691 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006693 // Completely remove from window manager after exit animation?
6694 boolean mRemoveOnExit;
6695
6696 // Set when the orientation is changing and this window has not yet
6697 // been updated for the new orientation.
6698 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006700 // Is this window now (or just being) removed?
6701 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006702
Dianne Hackborn16064f92010-03-25 00:47:24 -07006703 // For debugging, this is the last information given to the surface flinger.
6704 boolean mSurfaceShown;
6705 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6706 int mSurfaceLayer;
6707 float mSurfaceAlpha;
6708
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006709 // Input channel
6710 InputChannel mInputChannel;
6711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 WindowState(Session s, IWindow c, WindowToken token,
6713 WindowState attachedWindow, WindowManager.LayoutParams a,
6714 int viewVisibility) {
6715 mSession = s;
6716 mClient = c;
6717 mToken = token;
6718 mAttrs.copyFrom(a);
6719 mViewVisibility = viewVisibility;
6720 DeathRecipient deathRecipient = new DeathRecipient();
6721 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006722 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006723 TAG, "Window " + this + " client=" + c.asBinder()
6724 + " token=" + token + " (" + mAttrs.token + ")");
6725 try {
6726 c.asBinder().linkToDeath(deathRecipient, 0);
6727 } catch (RemoteException e) {
6728 mDeathRecipient = null;
6729 mAttachedWindow = null;
6730 mLayoutAttached = false;
6731 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006732 mIsWallpaper = false;
6733 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 mBaseLayer = 0;
6735 mSubLayer = 0;
6736 return;
6737 }
6738 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6741 mAttrs.type <= LAST_SUB_WINDOW)) {
6742 // The multiplier here is to reserve space for multiple
6743 // windows in the same type layer.
6744 mBaseLayer = mPolicy.windowTypeToLayerLw(
6745 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6746 + TYPE_LAYER_OFFSET;
6747 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6748 mAttachedWindow = attachedWindow;
6749 mAttachedWindow.mChildWindows.add(this);
6750 mLayoutAttached = mAttrs.type !=
6751 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6752 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6753 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006754 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6755 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006756 } else {
6757 // The multiplier here is to reserve space for multiple
6758 // windows in the same type layer.
6759 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6760 * TYPE_LAYER_MULTIPLIER
6761 + TYPE_LAYER_OFFSET;
6762 mSubLayer = 0;
6763 mAttachedWindow = null;
6764 mLayoutAttached = false;
6765 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6766 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006767 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6768 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 }
6770
6771 WindowState appWin = this;
6772 while (appWin.mAttachedWindow != null) {
6773 appWin = mAttachedWindow;
6774 }
6775 WindowToken appToken = appWin.mToken;
6776 while (appToken.appWindowToken == null) {
6777 WindowToken parent = mTokenMap.get(appToken.token);
6778 if (parent == null || appToken == parent) {
6779 break;
6780 }
6781 appToken = parent;
6782 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006783 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 mAppToken = appToken.appWindowToken;
6785
6786 mSurface = null;
6787 mRequestedWidth = 0;
6788 mRequestedHeight = 0;
6789 mLastRequestedWidth = 0;
6790 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006791 mXOffset = 0;
6792 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006793 mLayer = 0;
6794 mAnimLayer = 0;
6795 mLastLayer = 0;
6796 }
6797
6798 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006799 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 TAG, "Attaching " + this + " token=" + mToken
6801 + ", list=" + mToken.windows);
6802 mSession.windowAddedLocked();
6803 }
6804
6805 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6806 mHaveFrame = true;
6807
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006808 final Rect container = mContainingFrame;
6809 container.set(pf);
6810
6811 final Rect display = mDisplayFrame;
6812 display.set(df);
6813
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006814 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006815 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006816 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6817 display.intersect(mCompatibleScreenFrame);
6818 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006819 }
6820
6821 final int pw = container.right - container.left;
6822 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823
6824 int w,h;
6825 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6826 w = mAttrs.width < 0 ? pw : mAttrs.width;
6827 h = mAttrs.height< 0 ? ph : mAttrs.height;
6828 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006829 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6830 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 }
Romain Guy06882f82009-06-10 13:36:04 -07006832
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006833 if (!mParentFrame.equals(pf)) {
6834 mParentFrame.set(pf);
6835 mContentChanged = true;
6836 }
6837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 final Rect content = mContentFrame;
6839 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 final Rect visible = mVisibleFrame;
6842 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006845 final int fw = frame.width();
6846 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6849 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6850
6851 Gravity.apply(mAttrs.gravity, w, h, container,
6852 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6853 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6854
6855 //System.out.println("Out: " + mFrame);
6856
6857 // Now make sure the window fits in the overall display.
6858 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 // Make sure the content and visible frames are inside of the
6861 // final window frame.
6862 if (content.left < frame.left) content.left = frame.left;
6863 if (content.top < frame.top) content.top = frame.top;
6864 if (content.right > frame.right) content.right = frame.right;
6865 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6866 if (visible.left < frame.left) visible.left = frame.left;
6867 if (visible.top < frame.top) visible.top = frame.top;
6868 if (visible.right > frame.right) visible.right = frame.right;
6869 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 final Rect contentInsets = mContentInsets;
6872 contentInsets.left = content.left-frame.left;
6873 contentInsets.top = content.top-frame.top;
6874 contentInsets.right = frame.right-content.right;
6875 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 final Rect visibleInsets = mVisibleInsets;
6878 visibleInsets.left = visible.left-frame.left;
6879 visibleInsets.top = visible.top-frame.top;
6880 visibleInsets.right = frame.right-visible.right;
6881 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006882
Dianne Hackborn284ac932009-08-28 10:34:25 -07006883 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6884 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006885 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006886 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006888 if (localLOGV) {
6889 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6890 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006891 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006892 + mRequestedWidth + ", mRequestedheight="
6893 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6894 + "): frame=" + mFrame.toShortString()
6895 + " ci=" + contentInsets.toShortString()
6896 + " vi=" + visibleInsets.toShortString());
6897 //}
6898 }
6899 }
Romain Guy06882f82009-06-10 13:36:04 -07006900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 public Rect getFrameLw() {
6902 return mFrame;
6903 }
6904
6905 public Rect getShownFrameLw() {
6906 return mShownFrame;
6907 }
6908
6909 public Rect getDisplayFrameLw() {
6910 return mDisplayFrame;
6911 }
6912
6913 public Rect getContentFrameLw() {
6914 return mContentFrame;
6915 }
6916
6917 public Rect getVisibleFrameLw() {
6918 return mVisibleFrame;
6919 }
6920
6921 public boolean getGivenInsetsPendingLw() {
6922 return mGivenInsetsPending;
6923 }
6924
6925 public Rect getGivenContentInsetsLw() {
6926 return mGivenContentInsets;
6927 }
Romain Guy06882f82009-06-10 13:36:04 -07006928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006929 public Rect getGivenVisibleInsetsLw() {
6930 return mGivenVisibleInsets;
6931 }
Romain Guy06882f82009-06-10 13:36:04 -07006932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006933 public WindowManager.LayoutParams getAttrs() {
6934 return mAttrs;
6935 }
6936
6937 public int getSurfaceLayer() {
6938 return mLayer;
6939 }
Romain Guy06882f82009-06-10 13:36:04 -07006940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 public IApplicationToken getAppToken() {
6942 return mAppToken != null ? mAppToken.appToken : null;
6943 }
Jeff Brown349703e2010-06-22 01:27:15 -07006944
6945 public long getInputDispatchingTimeoutNanos() {
6946 return mAppToken != null
6947 ? mAppToken.inputDispatchingTimeoutNanos
6948 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6949 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950
6951 public boolean hasAppShownWindows() {
6952 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6953 }
6954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006956 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 TAG, "Setting animation in " + this + ": " + anim);
6958 mAnimating = false;
6959 mLocalAnimating = false;
6960 mAnimation = anim;
6961 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6962 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6963 }
6964
6965 public void clearAnimation() {
6966 if (mAnimation != null) {
6967 mAnimating = true;
6968 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07006969 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006970 mAnimation = null;
6971 }
6972 }
Romain Guy06882f82009-06-10 13:36:04 -07006973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 Surface createSurfaceLocked() {
6975 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006976 mReportDestroySurface = false;
6977 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 mDrawPending = true;
6979 mCommitDrawPending = false;
6980 mReadyToShow = false;
6981 if (mAppToken != null) {
6982 mAppToken.allDrawn = false;
6983 }
6984
6985 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006986 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006987 flags |= Surface.PUSH_BUFFERS;
6988 }
6989
6990 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6991 flags |= Surface.SECURE;
6992 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006993 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006994 TAG, "Creating surface in session "
6995 + mSession.mSurfaceSession + " window " + this
6996 + " w=" + mFrame.width()
6997 + " h=" + mFrame.height() + " format="
6998 + mAttrs.format + " flags=" + flags);
6999
7000 int w = mFrame.width();
7001 int h = mFrame.height();
7002 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7003 // for a scaled surface, we always want the requested
7004 // size.
7005 w = mRequestedWidth;
7006 h = mRequestedHeight;
7007 }
7008
Romain Guy9825ec62009-10-01 00:58:09 -07007009 // Something is wrong and SurfaceFlinger will not like this,
7010 // try to revert to sane values
7011 if (w <= 0) w = 1;
7012 if (h <= 0) h = 1;
7013
Dianne Hackborn16064f92010-03-25 00:47:24 -07007014 mSurfaceShown = false;
7015 mSurfaceLayer = 0;
7016 mSurfaceAlpha = 1;
7017 mSurfaceX = 0;
7018 mSurfaceY = 0;
7019 mSurfaceW = w;
7020 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007021 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007022 final boolean isHwAccelerated = (mAttrs.flags &
7023 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7024 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7025 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7026 flags |= Surface.OPAQUE;
7027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007028 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007029 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007030 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007031 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007032 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007033 + mSurface + " IN SESSION "
7034 + mSession.mSurfaceSession
7035 + ": pid=" + mSession.mPid + " format="
7036 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007037 + Integer.toHexString(flags)
7038 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007039 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007040 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007041 reclaimSomeSurfaceMemoryLocked(this, "create");
7042 return null;
7043 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007044 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 return null;
7046 }
Romain Guy06882f82009-06-10 13:36:04 -07007047
Joe Onorato8a9b2202010-02-26 18:56:32 -08007048 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 TAG, "Got surface: " + mSurface
7050 + ", set left=" + mFrame.left + " top=" + mFrame.top
7051 + ", animLayer=" + mAnimLayer);
7052 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007053 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007054 if (SHOW_TRANSACTIONS) logSurface(this,
7055 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7056 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7057 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007058 }
7059 Surface.openTransaction();
7060 try {
7061 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007062 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007063 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007064 mSurface.setPosition(mSurfaceX, mSurfaceY);
7065 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007066 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007067 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 mSurface.hide();
7069 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007070 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007071 mSurface.setFlags(Surface.SURFACE_DITHER,
7072 Surface.SURFACE_DITHER);
7073 }
7074 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007075 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007076 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7077 }
7078 mLastHidden = true;
7079 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007080 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 Surface.closeTransaction();
7082 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007083 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 TAG, "Created surface " + this);
7085 }
7086 return mSurface;
7087 }
Romain Guy06882f82009-06-10 13:36:04 -07007088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007089 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 if (mAppToken != null && this == mAppToken.startingWindow) {
7091 mAppToken.startingDisplayed = false;
7092 }
Romain Guy06882f82009-06-10 13:36:04 -07007093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007095 mDrawPending = false;
7096 mCommitDrawPending = false;
7097 mReadyToShow = false;
7098
7099 int i = mChildWindows.size();
7100 while (i > 0) {
7101 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007102 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007103 c.mAttachedHidden = true;
7104 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007105
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007106 if (mReportDestroySurface) {
7107 mReportDestroySurface = false;
7108 mSurfacePendingDestroy = true;
7109 try {
7110 mClient.dispatchGetNewSurface();
7111 // We'll really destroy on the next time around.
7112 return;
7113 } catch (RemoteException e) {
7114 }
7115 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007117 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007118 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007119 RuntimeException e = null;
7120 if (!HIDE_STACK_CRAWLS) {
7121 e = new RuntimeException();
7122 e.fillInStackTrace();
7123 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007124 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007125 + mSurface + ", session " + mSession, e);
7126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007127 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007128 RuntimeException e = null;
7129 if (!HIDE_STACK_CRAWLS) {
7130 e = new RuntimeException();
7131 e.fillInStackTrace();
7132 }
7133 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007134 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007135 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007137 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007138 + " surface " + mSurface + " session " + mSession
7139 + ": " + e.toString());
7140 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007141
Dianne Hackborn16064f92010-03-25 00:47:24 -07007142 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007143 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007144 }
7145 }
7146
7147 boolean finishDrawingLocked() {
7148 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007149 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 TAG, "finishDrawingLocked: " + mSurface);
7151 mCommitDrawPending = true;
7152 mDrawPending = false;
7153 return true;
7154 }
7155 return false;
7156 }
7157
7158 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007159 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007160 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007161 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007162 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007163 }
7164 mCommitDrawPending = false;
7165 mReadyToShow = true;
7166 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7167 final AppWindowToken atoken = mAppToken;
7168 if (atoken == null || atoken.allDrawn || starting) {
7169 performShowLocked();
7170 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007171 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172 }
7173
7174 // This must be called while inside a transaction.
7175 boolean performShowLocked() {
7176 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007177 RuntimeException e = null;
7178 if (!HIDE_STACK_CRAWLS) {
7179 e = new RuntimeException();
7180 e.fillInStackTrace();
7181 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007182 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007183 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7184 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7185 }
7186 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007187 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7188 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007189 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007190 + " during animation: policyVis=" + mPolicyVisibility
7191 + " attHidden=" + mAttachedHidden
7192 + " tok.hiddenRequested="
7193 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007194 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 + (mAppToken != null ? mAppToken.hidden : false)
7196 + " animating=" + mAnimating
7197 + " tok animating="
7198 + (mAppToken != null ? mAppToken.animating : false));
7199 if (!showSurfaceRobustlyLocked(this)) {
7200 return false;
7201 }
7202 mLastAlpha = -1;
7203 mHasDrawn = true;
7204 mLastHidden = false;
7205 mReadyToShow = false;
7206 enableScreenIfNeededLocked();
7207
7208 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 int i = mChildWindows.size();
7211 while (i > 0) {
7212 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007213 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007214 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007216 if (c.mSurface != null) {
7217 c.performShowLocked();
7218 // It hadn't been shown, which means layout not
7219 // performed on it, so now we want to make sure to
7220 // do a layout. If called from within the transaction
7221 // loop, this will cause it to restart with a new
7222 // layout.
7223 mLayoutNeeded = true;
7224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225 }
7226 }
Romain Guy06882f82009-06-10 13:36:04 -07007227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 if (mAttrs.type != TYPE_APPLICATION_STARTING
7229 && mAppToken != null) {
7230 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007231
Dianne Hackborn248b1882009-09-16 16:46:44 -07007232 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007233 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007234 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007236 // If this initial window is animating, stop it -- we
7237 // will do an animation to reveal it from behind the
7238 // starting window, so there is no need for it to also
7239 // be doing its own stuff.
7240 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007241 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007242 mAnimation = null;
7243 // Make sure we clean up the animation.
7244 mAnimating = true;
7245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007246 mFinishedStarting.add(mAppToken);
7247 mH.sendEmptyMessage(H.FINISHED_STARTING);
7248 }
7249 mAppToken.updateReportedVisibilityLocked();
7250 }
7251 }
7252 return true;
7253 }
Romain Guy06882f82009-06-10 13:36:04 -07007254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 // This must be called while inside a transaction. Returns true if
7256 // there is more animation to run.
7257 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007258 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7262 mHasTransformation = true;
7263 mHasLocalTransformation = true;
7264 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007265 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266 TAG, "Starting animation in " + this +
7267 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7268 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7269 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7270 mAnimation.setStartTime(currentTime);
7271 mLocalAnimating = true;
7272 mAnimating = true;
7273 }
7274 mTransformation.clear();
7275 final boolean more = mAnimation.getTransformation(
7276 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007277 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 TAG, "Stepped animation in " + this +
7279 ": more=" + more + ", xform=" + mTransformation);
7280 if (more) {
7281 // we're not done!
7282 return true;
7283 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007284 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007285 TAG, "Finished animation in " + this +
7286 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007287
7288 if (mAnimation != null) {
7289 mAnimation.cancel();
7290 mAnimation = null;
7291 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 //WindowManagerService.this.dump();
7293 }
7294 mHasLocalTransformation = false;
7295 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007296 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007297 // When our app token is animating, we kind-of pretend like
7298 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7299 // part of this check means that we will only do this if
7300 // our window is not currently exiting, or it is not
7301 // locally animating itself. The idea being that one that
7302 // is exiting and doing a local animation should be removed
7303 // once that animation is done.
7304 mAnimating = true;
7305 mHasTransformation = true;
7306 mTransformation.clear();
7307 return false;
7308 } else if (mHasTransformation) {
7309 // Little trick to get through the path below to act like
7310 // we have finished an animation.
7311 mAnimating = true;
7312 } else if (isAnimating()) {
7313 mAnimating = true;
7314 }
7315 } else if (mAnimation != null) {
7316 // If the display is frozen, and there is a pending animation,
7317 // clear it and make sure we run the cleanup code.
7318 mAnimating = true;
7319 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007320 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 mAnimation = null;
7322 }
Romain Guy06882f82009-06-10 13:36:04 -07007323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007324 if (!mAnimating && !mLocalAnimating) {
7325 return false;
7326 }
7327
Joe Onorato8a9b2202010-02-26 18:56:32 -08007328 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 TAG, "Animation done in " + this + ": exiting=" + mExiting
7330 + ", reportedVisible="
7331 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007333 mAnimating = false;
7334 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007335 if (mAnimation != null) {
7336 mAnimation.cancel();
7337 mAnimation = null;
7338 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 mAnimLayer = mLayer;
7340 if (mIsImWindow) {
7341 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007342 } else if (mIsWallpaper) {
7343 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007345 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 + " anim layer: " + mAnimLayer);
7347 mHasTransformation = false;
7348 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007349 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7350 if (DEBUG_VISIBILITY) {
7351 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7352 + mPolicyVisibilityAfterAnim);
7353 }
7354 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7355 if (!mPolicyVisibility) {
7356 if (mCurrentFocus == this) {
7357 mFocusMayChange = true;
7358 }
7359 // Window is no longer visible -- make sure if we were waiting
7360 // for it to be displayed before enabling the display, that
7361 // we allow the display to be enabled now.
7362 enableScreenIfNeededLocked();
7363 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 mTransformation.clear();
7366 if (mHasDrawn
7367 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7368 && mAppToken != null
7369 && mAppToken.firstWindowDrawn
7370 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007371 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 + mToken + ": first real window done animating");
7373 mFinishedStarting.add(mAppToken);
7374 mH.sendEmptyMessage(H.FINISHED_STARTING);
7375 }
Romain Guy06882f82009-06-10 13:36:04 -07007376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007377 finishExit();
7378
7379 if (mAppToken != null) {
7380 mAppToken.updateReportedVisibilityLocked();
7381 }
7382
7383 return false;
7384 }
7385
7386 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007387 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 TAG, "finishExit in " + this
7389 + ": exiting=" + mExiting
7390 + " remove=" + mRemoveOnExit
7391 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007393 final int N = mChildWindows.size();
7394 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007395 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 }
Romain Guy06882f82009-06-10 13:36:04 -07007397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007398 if (!mExiting) {
7399 return;
7400 }
Romain Guy06882f82009-06-10 13:36:04 -07007401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 if (isWindowAnimating()) {
7403 return;
7404 }
7405
Joe Onorato8a9b2202010-02-26 18:56:32 -08007406 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 TAG, "Exit animation finished in " + this
7408 + ": remove=" + mRemoveOnExit);
7409 if (mSurface != null) {
7410 mDestroySurface.add(this);
7411 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007412 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007413 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 try {
7415 mSurface.hide();
7416 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007417 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 }
7419 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007420 }
7421 mExiting = false;
7422 if (mRemoveOnExit) {
7423 mPendingRemove.add(this);
7424 mRemoveOnExit = false;
7425 }
7426 }
Romain Guy06882f82009-06-10 13:36:04 -07007427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7429 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7430 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7431 if (dtdx < -.000001f || dtdx > .000001f) return false;
7432 if (dsdy < -.000001f || dsdy > .000001f) return false;
7433 return true;
7434 }
Romain Guy06882f82009-06-10 13:36:04 -07007435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 void computeShownFrameLocked() {
7437 final boolean selfTransformation = mHasLocalTransformation;
7438 Transformation attachedTransformation =
7439 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7440 ? mAttachedWindow.mTransformation : null;
7441 Transformation appTransformation =
7442 (mAppToken != null && mAppToken.hasTransformation)
7443 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007444
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007445 // Wallpapers are animated based on the "real" window they
7446 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007447 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007448 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007449 if (mWallpaperTarget.mHasLocalTransformation &&
7450 mWallpaperTarget.mAnimation != null &&
7451 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007452 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007453 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007454 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007455 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007456 }
7457 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007458 mWallpaperTarget.mAppToken.hasTransformation &&
7459 mWallpaperTarget.mAppToken.animation != null &&
7460 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007461 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007462 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007463 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007464 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007465 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007466 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007468 if (selfTransformation || attachedTransformation != null
7469 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007470 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007471 final Rect frame = mFrame;
7472 final float tmpFloats[] = mTmpFloats;
7473 final Matrix tmpMatrix = mTmpMatrix;
7474
7475 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007476 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007478 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007480 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007482 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 }
7484 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007485 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 }
7487
7488 // "convert" it into SurfaceFlinger's format
7489 // (a 2x2 matrix + an offset)
7490 // Here we must not transform the position of the surface
7491 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007492 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 tmpMatrix.getValues(tmpFloats);
7495 mDsDx = tmpFloats[Matrix.MSCALE_X];
7496 mDtDx = tmpFloats[Matrix.MSKEW_X];
7497 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7498 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007499 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7500 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 int w = frame.width();
7502 int h = frame.height();
7503 mShownFrame.set(x, y, x+w, y+h);
7504
7505 // Now set the alpha... but because our current hardware
7506 // can't do alpha transformation on a non-opaque surface,
7507 // turn it off if we are running an animation that is also
7508 // transforming since it is more important to have that
7509 // animation be smooth.
7510 mShownAlpha = mAlpha;
7511 if (!mLimitedAlphaCompositing
7512 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7513 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7514 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007515 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 if (selfTransformation) {
7517 mShownAlpha *= mTransformation.getAlpha();
7518 }
7519 if (attachedTransformation != null) {
7520 mShownAlpha *= attachedTransformation.getAlpha();
7521 }
7522 if (appTransformation != null) {
7523 mShownAlpha *= appTransformation.getAlpha();
7524 }
7525 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007526 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 }
Romain Guy06882f82009-06-10 13:36:04 -07007528
Joe Onorato8a9b2202010-02-26 18:56:32 -08007529 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 TAG, "Continuing animation in " + this +
7531 ": " + mShownFrame +
7532 ", alpha=" + mTransformation.getAlpha());
7533 return;
7534 }
Romain Guy06882f82009-06-10 13:36:04 -07007535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007537 if (mXOffset != 0 || mYOffset != 0) {
7538 mShownFrame.offset(mXOffset, mYOffset);
7539 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 mShownAlpha = mAlpha;
7541 mDsDx = 1;
7542 mDtDx = 0;
7543 mDsDy = 0;
7544 mDtDy = 1;
7545 }
Romain Guy06882f82009-06-10 13:36:04 -07007546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 /**
7548 * Is this window visible? It is not visible if there is no
7549 * surface, or we are in the process of running an exit animation
7550 * that will remove the surface, or its app token has been hidden.
7551 */
7552 public boolean isVisibleLw() {
7553 final AppWindowToken atoken = mAppToken;
7554 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7555 && (atoken == null || !atoken.hiddenRequested)
7556 && !mExiting && !mDestroying;
7557 }
7558
7559 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007560 * Like {@link #isVisibleLw}, but also counts a window that is currently
7561 * "hidden" behind the keyguard as visible. This allows us to apply
7562 * things like window flags that impact the keyguard.
7563 * XXX I am starting to think we need to have ANOTHER visibility flag
7564 * for this "hidden behind keyguard" state rather than overloading
7565 * mPolicyVisibility. Ungh.
7566 */
7567 public boolean isVisibleOrBehindKeyguardLw() {
7568 final AppWindowToken atoken = mAppToken;
7569 return mSurface != null && !mAttachedHidden
7570 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007571 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007572 && !mExiting && !mDestroying;
7573 }
7574
7575 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 * Is this window visible, ignoring its app token? It is not visible
7577 * if there is no surface, or we are in the process of running an exit animation
7578 * that will remove the surface.
7579 */
7580 public boolean isWinVisibleLw() {
7581 final AppWindowToken atoken = mAppToken;
7582 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7583 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7584 && !mExiting && !mDestroying;
7585 }
7586
7587 /**
7588 * The same as isVisible(), but follows the current hidden state of
7589 * the associated app token, not the pending requested hidden state.
7590 */
7591 boolean isVisibleNow() {
7592 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007593 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 }
7595
7596 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007597 * Can this window possibly be a drag/drop target? The test here is
7598 * a combination of the above "visible now" with the check that the
7599 * Input Manager uses when discarding windows from input consideration.
7600 */
7601 boolean isPotentialDragTarget() {
7602 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7603 }
7604
7605 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 * Same as isVisible(), but we also count it as visible between the
7607 * call to IWindowSession.add() and the first relayout().
7608 */
7609 boolean isVisibleOrAdding() {
7610 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007611 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7613 && mPolicyVisibility && !mAttachedHidden
7614 && (atoken == null || !atoken.hiddenRequested)
7615 && !mExiting && !mDestroying;
7616 }
7617
7618 /**
7619 * Is this window currently on-screen? It is on-screen either if it
7620 * is visible or it is currently running an animation before no longer
7621 * being visible.
7622 */
7623 boolean isOnScreen() {
7624 final AppWindowToken atoken = mAppToken;
7625 if (atoken != null) {
7626 return mSurface != null && mPolicyVisibility && !mDestroying
7627 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007628 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 } else {
7630 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007631 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 }
7633 }
Romain Guy06882f82009-06-10 13:36:04 -07007634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007635 /**
7636 * Like isOnScreen(), but we don't return true if the window is part
7637 * of a transition that has not yet been started.
7638 */
7639 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007640 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007641 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007642 return false;
7643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007645 final boolean animating = atoken != null
7646 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007648 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7649 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007650 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 }
7652
7653 /** Is the window or its container currently animating? */
7654 boolean isAnimating() {
7655 final WindowState attached = mAttachedWindow;
7656 final AppWindowToken atoken = mAppToken;
7657 return mAnimation != null
7658 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007659 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 (atoken.animation != null
7661 || atoken.inPendingTransaction));
7662 }
7663
7664 /** Is this window currently animating? */
7665 boolean isWindowAnimating() {
7666 return mAnimation != null;
7667 }
7668
7669 /**
7670 * Like isOnScreen, but returns false if the surface hasn't yet
7671 * been drawn.
7672 */
7673 public boolean isDisplayedLw() {
7674 final AppWindowToken atoken = mAppToken;
7675 return mSurface != null && mPolicyVisibility && !mDestroying
7676 && !mDrawPending && !mCommitDrawPending
7677 && ((!mAttachedHidden &&
7678 (atoken == null || !atoken.hiddenRequested))
7679 || mAnimating);
7680 }
7681
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007682 /**
7683 * Returns true if the window has a surface that it has drawn a
7684 * complete UI in to.
7685 */
7686 public boolean isDrawnLw() {
7687 final AppWindowToken atoken = mAppToken;
7688 return mSurface != null && !mDestroying
7689 && !mDrawPending && !mCommitDrawPending;
7690 }
7691
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007692 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007693 * Return true if the window is opaque and fully drawn. This indicates
7694 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007695 */
7696 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007697 return (mAttrs.format == PixelFormat.OPAQUE
7698 || mAttrs.type == TYPE_WALLPAPER)
7699 && mSurface != null && mAnimation == null
7700 && (mAppToken == null || mAppToken.animation == null)
7701 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007702 }
7703
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007704 /**
7705 * Return whether this window is wanting to have a translation
7706 * animation applied to it for an in-progress move. (Only makes
7707 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7708 */
7709 boolean shouldAnimateMove() {
7710 return mContentChanged && !mAnimating && !mLastHidden && !mDisplayFrozen
7711 && (mFrame.top != mLastFrame.top
7712 || mFrame.left != mLastFrame.left)
7713 && (mAttachedWindow == null
7714 || (mAttachedWindow.mAnimation == null
7715 && !mAttachedWindow.shouldAnimateMove()))
7716 && mPolicy.isScreenOn();
7717 }
7718
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007719 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7720 return
7721 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007722 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7723 // only if it's visible
7724 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007725 // and only if the application fills the compatible screen
7726 mFrame.left <= mCompatibleScreenFrame.left &&
7727 mFrame.top <= mCompatibleScreenFrame.top &&
7728 mFrame.right >= mCompatibleScreenFrame.right &&
7729 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007730 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007731 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007732 }
7733
7734 boolean isFullscreen(int screenWidth, int screenHeight) {
7735 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007736 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 }
7738
7739 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007740 disposeInputChannel();
7741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007742 if (mAttachedWindow != null) {
7743 mAttachedWindow.mChildWindows.remove(this);
7744 }
7745 destroySurfaceLocked();
7746 mSession.windowRemovedLocked();
7747 try {
7748 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7749 } catch (RuntimeException e) {
7750 // Ignore if it has already been removed (usually because
7751 // we are doing this as part of processing a death note.)
7752 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007753 }
7754
7755 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007756 if (mInputChannel != null) {
7757 mInputManager.unregisterInputChannel(mInputChannel);
7758
7759 mInputChannel.dispose();
7760 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 }
7763
7764 private class DeathRecipient implements IBinder.DeathRecipient {
7765 public void binderDied() {
7766 try {
7767 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007768 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007769 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 if (win != null) {
7771 removeWindowLocked(mSession, win);
7772 }
7773 }
7774 } catch (IllegalArgumentException ex) {
7775 // This will happen if the window has already been
7776 // removed.
7777 }
7778 }
7779 }
7780
7781 /** Returns true if this window desires key events. */
7782 public final boolean canReceiveKeys() {
7783 return isVisibleOrAdding()
7784 && (mViewVisibility == View.VISIBLE)
7785 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7786 }
7787
7788 public boolean hasDrawnLw() {
7789 return mHasDrawn;
7790 }
7791
7792 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007793 return showLw(doAnimation, true);
7794 }
7795
7796 boolean showLw(boolean doAnimation, boolean requestAnim) {
7797 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7798 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007800 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007801 if (doAnimation) {
7802 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7803 + mPolicyVisibility + " mAnimation=" + mAnimation);
7804 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7805 doAnimation = false;
7806 } else if (mPolicyVisibility && mAnimation == null) {
7807 // Check for the case where we are currently visible and
7808 // not animating; we do not want to do animation at such a
7809 // point to become visible when we already are.
7810 doAnimation = false;
7811 }
7812 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007813 mPolicyVisibility = true;
7814 mPolicyVisibilityAfterAnim = true;
7815 if (doAnimation) {
7816 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7817 }
7818 if (requestAnim) {
7819 requestAnimationLocked(0);
7820 }
7821 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007822 }
7823
7824 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007825 return hideLw(doAnimation, true);
7826 }
7827
7828 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007829 if (doAnimation) {
7830 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7831 doAnimation = false;
7832 }
7833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007834 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7835 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007836 if (!current) {
7837 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007839 if (doAnimation) {
7840 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7841 if (mAnimation == null) {
7842 doAnimation = false;
7843 }
7844 }
7845 if (doAnimation) {
7846 mPolicyVisibilityAfterAnim = false;
7847 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007848 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007849 mPolicyVisibilityAfterAnim = false;
7850 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007851 // Window is no longer visible -- make sure if we were waiting
7852 // for it to be displayed before enabling the display, that
7853 // we allow the display to be enabled now.
7854 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007855 if (mCurrentFocus == this) {
7856 mFocusMayChange = true;
7857 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007858 }
7859 if (requestAnim) {
7860 requestAnimationLocked(0);
7861 }
7862 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007863 }
7864
7865 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007866 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7867 pw.print(" mClient="); pw.println(mClient.asBinder());
7868 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7869 if (mAttachedWindow != null || mLayoutAttached) {
7870 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7871 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7872 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007873 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7874 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7875 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007876 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7877 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007878 }
7879 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7880 pw.print(" mSubLayer="); pw.print(mSubLayer);
7881 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7882 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7883 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7884 pw.print("="); pw.print(mAnimLayer);
7885 pw.print(" mLastLayer="); pw.println(mLastLayer);
7886 if (mSurface != null) {
7887 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007888 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7889 pw.print(" layer="); pw.print(mSurfaceLayer);
7890 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7891 pw.print(" rect=("); pw.print(mSurfaceX);
7892 pw.print(","); pw.print(mSurfaceY);
7893 pw.print(") "); pw.print(mSurfaceW);
7894 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007895 }
7896 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7897 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7898 if (mAppToken != null) {
7899 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7900 }
7901 if (mTargetAppToken != null) {
7902 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7903 }
7904 pw.print(prefix); pw.print("mViewVisibility=0x");
7905 pw.print(Integer.toHexString(mViewVisibility));
7906 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007907 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7908 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007909 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7910 pw.print(prefix); pw.print("mPolicyVisibility=");
7911 pw.print(mPolicyVisibility);
7912 pw.print(" mPolicyVisibilityAfterAnim=");
7913 pw.print(mPolicyVisibilityAfterAnim);
7914 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7915 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007916 if (!mRelayoutCalled) {
7917 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7918 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007919 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007920 pw.print(" h="); pw.print(mRequestedHeight);
7921 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007922 if (mXOffset != 0 || mYOffset != 0) {
7923 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7924 pw.print(" y="); pw.println(mYOffset);
7925 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007926 pw.print(prefix); pw.print("mGivenContentInsets=");
7927 mGivenContentInsets.printShortString(pw);
7928 pw.print(" mGivenVisibleInsets=");
7929 mGivenVisibleInsets.printShortString(pw);
7930 pw.println();
7931 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7932 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7933 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7934 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007935 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007936 pw.print(prefix); pw.print("mShownFrame=");
7937 mShownFrame.printShortString(pw);
7938 pw.print(" last="); mLastShownFrame.printShortString(pw);
7939 pw.println();
7940 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7941 pw.print(" last="); mLastFrame.printShortString(pw);
7942 pw.println();
7943 pw.print(prefix); pw.print("mContainingFrame=");
7944 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007945 pw.print(" mParentFrame=");
7946 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007947 pw.print(" mDisplayFrame=");
7948 mDisplayFrame.printShortString(pw);
7949 pw.println();
7950 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7951 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7952 pw.println();
7953 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7954 pw.print(" last="); mLastContentInsets.printShortString(pw);
7955 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7956 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7957 pw.println();
7958 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7959 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7960 pw.print(" mAlpha="); pw.print(mAlpha);
7961 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7962 }
7963 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7964 || mAnimation != null) {
7965 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7966 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7967 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7968 pw.print(" mAnimation="); pw.println(mAnimation);
7969 }
7970 if (mHasTransformation || mHasLocalTransformation) {
7971 pw.print(prefix); pw.print("XForm: has=");
7972 pw.print(mHasTransformation);
7973 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7974 pw.print(" "); mTransformation.printShortString(pw);
7975 pw.println();
7976 }
7977 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7978 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7979 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7980 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7981 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7982 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7983 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7984 pw.print(" mDestroying="); pw.print(mDestroying);
7985 pw.print(" mRemoved="); pw.println(mRemoved);
7986 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007987 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007988 pw.print(prefix); pw.print("mOrientationChanging=");
7989 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007990 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7991 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007992 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007993 if (mHScale != 1 || mVScale != 1) {
7994 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7995 pw.print(" mVScale="); pw.println(mVScale);
7996 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007997 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007998 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7999 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8000 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008001 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8002 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8003 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008005 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008006
8007 String makeInputChannelName() {
8008 return Integer.toHexString(System.identityHashCode(this))
8009 + " " + mAttrs.getTitle();
8010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011
8012 @Override
8013 public String toString() {
8014 return "Window{"
8015 + Integer.toHexString(System.identityHashCode(this))
8016 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8017 }
8018 }
Romain Guy06882f82009-06-10 13:36:04 -07008019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008020 // -------------------------------------------------------------
8021 // Window Token State
8022 // -------------------------------------------------------------
8023
8024 class WindowToken {
8025 // The actual token.
8026 final IBinder token;
8027
8028 // The type of window this token is for, as per WindowManager.LayoutParams.
8029 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008031 // Set if this token was explicitly added by a client, so should
8032 // not be removed when all windows are removed.
8033 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008034
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008035 // For printing.
8036 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 // If this is an AppWindowToken, this is non-null.
8039 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008041 // All of the windows associated with this token.
8042 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8043
8044 // Is key dispatching paused for this token?
8045 boolean paused = false;
8046
8047 // Should this token's windows be hidden?
8048 boolean hidden;
8049
8050 // Temporary for finding which tokens no longer have visible windows.
8051 boolean hasVisible;
8052
Dianne Hackborna8f60182009-09-01 19:01:50 -07008053 // Set to true when this token is in a pending transaction where it
8054 // will be shown.
8055 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008056
Dianne Hackborna8f60182009-09-01 19:01:50 -07008057 // Set to true when this token is in a pending transaction where it
8058 // will be hidden.
8059 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008060
Dianne Hackborna8f60182009-09-01 19:01:50 -07008061 // Set to true when this token is in a pending transaction where its
8062 // windows will be put to the bottom of the list.
8063 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008064
Dianne Hackborna8f60182009-09-01 19:01:50 -07008065 // Set to true when this token is in a pending transaction where its
8066 // windows will be put to the top of the list.
8067 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 WindowToken(IBinder _token, int type, boolean _explicit) {
8070 token = _token;
8071 windowType = type;
8072 explicit = _explicit;
8073 }
8074
8075 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008076 pw.print(prefix); pw.print("token="); pw.println(token);
8077 pw.print(prefix); pw.print("windows="); pw.println(windows);
8078 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8079 pw.print(" hidden="); pw.print(hidden);
8080 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008081 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8082 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8083 pw.print(" waitingToHide="); pw.print(waitingToHide);
8084 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8085 pw.print(" sendingToTop="); pw.println(sendingToTop);
8086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008087 }
8088
8089 @Override
8090 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008091 if (stringName == null) {
8092 StringBuilder sb = new StringBuilder();
8093 sb.append("WindowToken{");
8094 sb.append(Integer.toHexString(System.identityHashCode(this)));
8095 sb.append(" token="); sb.append(token); sb.append('}');
8096 stringName = sb.toString();
8097 }
8098 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 }
8100 };
8101
8102 class AppWindowToken extends WindowToken {
8103 // Non-null only for application tokens.
8104 final IApplicationToken appToken;
8105
8106 // All of the windows and child windows that are included in this
8107 // application token. Note this list is NOT sorted!
8108 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8109
8110 int groupId = -1;
8111 boolean appFullscreen;
8112 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008113
8114 // The input dispatching timeout for this application token in nanoseconds.
8115 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008117 // These are used for determining when all windows associated with
8118 // an activity have been drawn, so they can be made visible together
8119 // at the same time.
8120 int lastTransactionSequence = mTransactionSequence-1;
8121 int numInterestingWindows;
8122 int numDrawnWindows;
8123 boolean inPendingTransaction;
8124 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008126 // Is this token going to be hidden in a little while? If so, it
8127 // won't be taken into account for setting the screen orientation.
8128 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 // Is this window's surface needed? This is almost like hidden, except
8131 // it will sometimes be true a little earlier: when the token has
8132 // been shown, but is still waiting for its app transition to execute
8133 // before making its windows shown.
8134 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008136 // Have we told the window clients to hide themselves?
8137 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008139 // Last visibility state we reported to the app token.
8140 boolean reportedVisible;
8141
8142 // Set to true when the token has been removed from the window mgr.
8143 boolean removed;
8144
8145 // Have we been asked to have this token keep the screen frozen?
8146 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 boolean animating;
8149 Animation animation;
8150 boolean hasTransformation;
8151 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008153 // Offset to the window of all layers in the token, for use by
8154 // AppWindowToken animations.
8155 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008157 // Information about an application starting window if displayed.
8158 StartingData startingData;
8159 WindowState startingWindow;
8160 View startingView;
8161 boolean startingDisplayed;
8162 boolean startingMoved;
8163 boolean firstWindowDrawn;
8164
8165 AppWindowToken(IApplicationToken _token) {
8166 super(_token.asBinder(),
8167 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8168 appWindowToken = this;
8169 appToken = _token;
8170 }
Romain Guy06882f82009-06-10 13:36:04 -07008171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008172 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008173 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008174 TAG, "Setting animation in " + this + ": " + anim);
8175 animation = anim;
8176 animating = false;
8177 anim.restrictDuration(MAX_ANIMATION_DURATION);
8178 anim.scaleCurrentDuration(mTransitionAnimationScale);
8179 int zorder = anim.getZAdjustment();
8180 int adj = 0;
8181 if (zorder == Animation.ZORDER_TOP) {
8182 adj = TYPE_LAYER_OFFSET;
8183 } else if (zorder == Animation.ZORDER_BOTTOM) {
8184 adj = -TYPE_LAYER_OFFSET;
8185 }
Romain Guy06882f82009-06-10 13:36:04 -07008186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008187 if (animLayerAdjustment != adj) {
8188 animLayerAdjustment = adj;
8189 updateLayers();
8190 }
8191 }
Romain Guy06882f82009-06-10 13:36:04 -07008192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008193 public void setDummyAnimation() {
8194 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008195 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008196 TAG, "Setting dummy animation in " + this);
8197 animation = sDummyAnimation;
8198 }
8199 }
8200
8201 public void clearAnimation() {
8202 if (animation != null) {
8203 animation = null;
8204 animating = true;
8205 }
8206 }
Romain Guy06882f82009-06-10 13:36:04 -07008207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008208 void updateLayers() {
8209 final int N = allAppWindows.size();
8210 final int adj = animLayerAdjustment;
8211 for (int i=0; i<N; i++) {
8212 WindowState w = allAppWindows.get(i);
8213 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008214 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008215 + w.mAnimLayer);
8216 if (w == mInputMethodTarget) {
8217 setInputMethodAnimLayerAdjustment(adj);
8218 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008219 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008220 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008222 }
8223 }
Romain Guy06882f82009-06-10 13:36:04 -07008224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 void sendAppVisibilityToClients() {
8226 final int N = allAppWindows.size();
8227 for (int i=0; i<N; i++) {
8228 WindowState win = allAppWindows.get(i);
8229 if (win == startingWindow && clientHidden) {
8230 // Don't hide the starting window.
8231 continue;
8232 }
8233 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008234 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008235 "Setting visibility of " + win + ": " + (!clientHidden));
8236 win.mClient.dispatchAppVisibility(!clientHidden);
8237 } catch (RemoteException e) {
8238 }
8239 }
8240 }
Romain Guy06882f82009-06-10 13:36:04 -07008241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008242 void showAllWindowsLocked() {
8243 final int NW = allAppWindows.size();
8244 for (int i=0; i<NW; i++) {
8245 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008246 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008247 "performing show on: " + w);
8248 w.performShowLocked();
8249 }
8250 }
Romain Guy06882f82009-06-10 13:36:04 -07008251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008252 // This must be called while inside a transaction.
8253 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008254 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008255 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008257 if (animation == sDummyAnimation) {
8258 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008259 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008260 // when it is really time to animate, this will be set to
8261 // a real animation and the next call will execute normally.
8262 return false;
8263 }
Romain Guy06882f82009-06-10 13:36:04 -07008264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008265 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8266 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008267 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 TAG, "Starting animation in " + this +
8269 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8270 + " scale=" + mTransitionAnimationScale
8271 + " allDrawn=" + allDrawn + " animating=" + animating);
8272 animation.initialize(dw, dh, dw, dh);
8273 animation.setStartTime(currentTime);
8274 animating = true;
8275 }
8276 transformation.clear();
8277 final boolean more = animation.getTransformation(
8278 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008279 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008280 TAG, "Stepped animation in " + this +
8281 ": more=" + more + ", xform=" + transformation);
8282 if (more) {
8283 // we're done!
8284 hasTransformation = true;
8285 return true;
8286 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008287 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 TAG, "Finished animation in " + this +
8289 " @ " + currentTime);
8290 animation = null;
8291 }
8292 } else if (animation != null) {
8293 // If the display is frozen, and there is a pending animation,
8294 // clear it and make sure we run the cleanup code.
8295 animating = true;
8296 animation = null;
8297 }
8298
8299 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008301 if (!animating) {
8302 return false;
8303 }
8304
8305 clearAnimation();
8306 animating = false;
8307 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8308 moveInputMethodWindowsIfNeededLocked(true);
8309 }
Romain Guy06882f82009-06-10 13:36:04 -07008310
Joe Onorato8a9b2202010-02-26 18:56:32 -08008311 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008312 TAG, "Animation done in " + this
8313 + ": reportedVisible=" + reportedVisible);
8314
8315 transformation.clear();
8316 if (animLayerAdjustment != 0) {
8317 animLayerAdjustment = 0;
8318 updateLayers();
8319 }
Romain Guy06882f82009-06-10 13:36:04 -07008320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 final int N = windows.size();
8322 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008323 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008324 }
8325 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008327 return false;
8328 }
8329
8330 void updateReportedVisibilityLocked() {
8331 if (appToken == null) {
8332 return;
8333 }
Romain Guy06882f82009-06-10 13:36:04 -07008334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008335 int numInteresting = 0;
8336 int numVisible = 0;
8337 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008338
Joe Onorato8a9b2202010-02-26 18:56:32 -08008339 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 final int N = allAppWindows.size();
8341 for (int i=0; i<N; i++) {
8342 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008343 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008344 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008345 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8346 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008347 continue;
8348 }
8349 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008350 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008351 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008352 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008353 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008354 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008355 + " pv=" + win.mPolicyVisibility
8356 + " dp=" + win.mDrawPending
8357 + " cdp=" + win.mCommitDrawPending
8358 + " ah=" + win.mAttachedHidden
8359 + " th="
8360 + (win.mAppToken != null
8361 ? win.mAppToken.hiddenRequested : false)
8362 + " a=" + win.mAnimating);
8363 }
8364 }
8365 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008366 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008367 if (!win.isAnimating()) {
8368 numVisible++;
8369 }
8370 nowGone = false;
8371 } else if (win.isAnimating()) {
8372 nowGone = false;
8373 }
8374 }
Romain Guy06882f82009-06-10 13:36:04 -07008375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008376 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008377 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008378 + numInteresting + " visible=" + numVisible);
8379 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008380 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008381 TAG, "Visibility changed in " + this
8382 + ": vis=" + nowVisible);
8383 reportedVisible = nowVisible;
8384 Message m = mH.obtainMessage(
8385 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8386 nowVisible ? 1 : 0,
8387 nowGone ? 1 : 0,
8388 this);
8389 mH.sendMessage(m);
8390 }
8391 }
Romain Guy06882f82009-06-10 13:36:04 -07008392
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008393 WindowState findMainWindow() {
8394 int j = windows.size();
8395 while (j > 0) {
8396 j--;
8397 WindowState win = windows.get(j);
8398 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8399 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8400 return win;
8401 }
8402 }
8403 return null;
8404 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 void dump(PrintWriter pw, String prefix) {
8407 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008408 if (appToken != null) {
8409 pw.print(prefix); pw.println("app=true");
8410 }
8411 if (allAppWindows.size() > 0) {
8412 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8413 }
8414 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008415 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008416 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8417 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8418 pw.print(" clientHidden="); pw.print(clientHidden);
8419 pw.print(" willBeHidden="); pw.print(willBeHidden);
8420 pw.print(" reportedVisible="); pw.println(reportedVisible);
8421 if (paused || freezingScreen) {
8422 pw.print(prefix); pw.print("paused="); pw.print(paused);
8423 pw.print(" freezingScreen="); pw.println(freezingScreen);
8424 }
8425 if (numInterestingWindows != 0 || numDrawnWindows != 0
8426 || inPendingTransaction || allDrawn) {
8427 pw.print(prefix); pw.print("numInterestingWindows=");
8428 pw.print(numInterestingWindows);
8429 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8430 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8431 pw.print(" allDrawn="); pw.println(allDrawn);
8432 }
8433 if (animating || animation != null) {
8434 pw.print(prefix); pw.print("animating="); pw.print(animating);
8435 pw.print(" animation="); pw.println(animation);
8436 }
8437 if (animLayerAdjustment != 0) {
8438 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8439 }
8440 if (hasTransformation) {
8441 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8442 pw.print(" transformation="); transformation.printShortString(pw);
8443 pw.println();
8444 }
8445 if (startingData != null || removed || firstWindowDrawn) {
8446 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8447 pw.print(" removed="); pw.print(removed);
8448 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8449 }
8450 if (startingWindow != null || startingView != null
8451 || startingDisplayed || startingMoved) {
8452 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8453 pw.print(" startingView="); pw.print(startingView);
8454 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8455 pw.print(" startingMoved"); pw.println(startingMoved);
8456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008457 }
8458
8459 @Override
8460 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008461 if (stringName == null) {
8462 StringBuilder sb = new StringBuilder();
8463 sb.append("AppWindowToken{");
8464 sb.append(Integer.toHexString(System.identityHashCode(this)));
8465 sb.append(" token="); sb.append(token); sb.append('}');
8466 stringName = sb.toString();
8467 }
8468 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 }
8470 }
Romain Guy06882f82009-06-10 13:36:04 -07008471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008472 // -------------------------------------------------------------
8473 // DummyAnimation
8474 // -------------------------------------------------------------
8475
8476 // This is an animation that does nothing: it just immediately finishes
8477 // itself every time it is called. It is used as a stub animation in cases
8478 // where we want to synchronize multiple things that may be animating.
8479 static final class DummyAnimation extends Animation {
8480 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8481 return false;
8482 }
8483 }
8484 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 // -------------------------------------------------------------
8487 // Async Handler
8488 // -------------------------------------------------------------
8489
8490 static final class StartingData {
8491 final String pkg;
8492 final int theme;
8493 final CharSequence nonLocalizedLabel;
8494 final int labelRes;
8495 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008496 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008499 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008500 pkg = _pkg;
8501 theme = _theme;
8502 nonLocalizedLabel = _nonLocalizedLabel;
8503 labelRes = _labelRes;
8504 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008505 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 }
8507 }
8508
8509 private final class H extends Handler {
8510 public static final int REPORT_FOCUS_CHANGE = 2;
8511 public static final int REPORT_LOSING_FOCUS = 3;
8512 public static final int ANIMATE = 4;
8513 public static final int ADD_STARTING = 5;
8514 public static final int REMOVE_STARTING = 6;
8515 public static final int FINISHED_STARTING = 7;
8516 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008517 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8518 public static final int HOLD_SCREEN_CHANGED = 12;
8519 public static final int APP_TRANSITION_TIMEOUT = 13;
8520 public static final int PERSIST_ANIMATION_SCALE = 14;
8521 public static final int FORCE_GC = 15;
8522 public static final int ENABLE_SCREEN = 16;
8523 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008524 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008525 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008526 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008527 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 public H() {
8532 }
Romain Guy06882f82009-06-10 13:36:04 -07008533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 @Override
8535 public void handleMessage(Message msg) {
8536 switch (msg.what) {
8537 case REPORT_FOCUS_CHANGE: {
8538 WindowState lastFocus;
8539 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 synchronized(mWindowMap) {
8542 lastFocus = mLastFocus;
8543 newFocus = mCurrentFocus;
8544 if (lastFocus == newFocus) {
8545 // Focus is not changing, so nothing to do.
8546 return;
8547 }
8548 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008549 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008550 // + " to " + newFocus);
8551 if (newFocus != null && lastFocus != null
8552 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008553 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008554 mLosingFocus.add(lastFocus);
8555 lastFocus = null;
8556 }
8557 }
8558
8559 if (lastFocus != newFocus) {
8560 //System.out.println("Changing focus from " + lastFocus
8561 // + " to " + newFocus);
8562 if (newFocus != null) {
8563 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008564 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008565 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8566 } catch (RemoteException e) {
8567 // Ignore if process has died.
8568 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008569 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 }
8571
8572 if (lastFocus != null) {
8573 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008574 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8576 } catch (RemoteException e) {
8577 // Ignore if process has died.
8578 }
8579 }
8580 }
8581 } break;
8582
8583 case REPORT_LOSING_FOCUS: {
8584 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 synchronized(mWindowMap) {
8587 losers = mLosingFocus;
8588 mLosingFocus = new ArrayList<WindowState>();
8589 }
8590
8591 final int N = losers.size();
8592 for (int i=0; i<N; i++) {
8593 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008594 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008595 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8596 } catch (RemoteException e) {
8597 // Ignore if process has died.
8598 }
8599 }
8600 } break;
8601
8602 case ANIMATE: {
8603 synchronized(mWindowMap) {
8604 mAnimationPending = false;
8605 performLayoutAndPlaceSurfacesLocked();
8606 }
8607 } break;
8608
8609 case ADD_STARTING: {
8610 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8611 final StartingData sd = wtoken.startingData;
8612
8613 if (sd == null) {
8614 // Animation has been canceled... do nothing.
8615 return;
8616 }
Romain Guy06882f82009-06-10 13:36:04 -07008617
Joe Onorato8a9b2202010-02-26 18:56:32 -08008618 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621 View view = null;
8622 try {
8623 view = mPolicy.addStartingWindow(
8624 wtoken.token, sd.pkg,
8625 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008626 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008628 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 }
8630
8631 if (view != null) {
8632 boolean abort = false;
8633
8634 synchronized(mWindowMap) {
8635 if (wtoken.removed || wtoken.startingData == null) {
8636 // If the window was successfully added, then
8637 // we need to remove it.
8638 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008639 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 "Aborted starting " + wtoken
8641 + ": removed=" + wtoken.removed
8642 + " startingData=" + wtoken.startingData);
8643 wtoken.startingWindow = null;
8644 wtoken.startingData = null;
8645 abort = true;
8646 }
8647 } else {
8648 wtoken.startingView = view;
8649 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008650 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008651 "Added starting " + wtoken
8652 + ": startingWindow="
8653 + wtoken.startingWindow + " startingView="
8654 + wtoken.startingView);
8655 }
8656
8657 if (abort) {
8658 try {
8659 mPolicy.removeStartingWindow(wtoken.token, view);
8660 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008661 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008662 }
8663 }
8664 }
8665 } break;
8666
8667 case REMOVE_STARTING: {
8668 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8669 IBinder token = null;
8670 View view = null;
8671 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008672 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 + wtoken + ": startingWindow="
8674 + wtoken.startingWindow + " startingView="
8675 + wtoken.startingView);
8676 if (wtoken.startingWindow != null) {
8677 view = wtoken.startingView;
8678 token = wtoken.token;
8679 wtoken.startingData = null;
8680 wtoken.startingView = null;
8681 wtoken.startingWindow = null;
8682 }
8683 }
8684 if (view != null) {
8685 try {
8686 mPolicy.removeStartingWindow(token, view);
8687 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008688 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008689 }
8690 }
8691 } break;
8692
8693 case FINISHED_STARTING: {
8694 IBinder token = null;
8695 View view = null;
8696 while (true) {
8697 synchronized (mWindowMap) {
8698 final int N = mFinishedStarting.size();
8699 if (N <= 0) {
8700 break;
8701 }
8702 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8703
Joe Onorato8a9b2202010-02-26 18:56:32 -08008704 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008705 "Finished starting " + wtoken
8706 + ": startingWindow=" + wtoken.startingWindow
8707 + " startingView=" + wtoken.startingView);
8708
8709 if (wtoken.startingWindow == null) {
8710 continue;
8711 }
8712
8713 view = wtoken.startingView;
8714 token = wtoken.token;
8715 wtoken.startingData = null;
8716 wtoken.startingView = null;
8717 wtoken.startingWindow = null;
8718 }
8719
8720 try {
8721 mPolicy.removeStartingWindow(token, view);
8722 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008723 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 }
8725 }
8726 } break;
8727
8728 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8729 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8730
8731 boolean nowVisible = msg.arg1 != 0;
8732 boolean nowGone = msg.arg2 != 0;
8733
8734 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008735 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008736 TAG, "Reporting visible in " + wtoken
8737 + " visible=" + nowVisible
8738 + " gone=" + nowGone);
8739 if (nowVisible) {
8740 wtoken.appToken.windowsVisible();
8741 } else {
8742 wtoken.appToken.windowsGone();
8743 }
8744 } catch (RemoteException ex) {
8745 }
8746 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008748 case WINDOW_FREEZE_TIMEOUT: {
8749 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008750 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008751 int i = mWindows.size();
8752 while (i > 0) {
8753 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008754 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008755 if (w.mOrientationChanging) {
8756 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008757 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 }
8759 }
8760 performLayoutAndPlaceSurfacesLocked();
8761 }
8762 break;
8763 }
Romain Guy06882f82009-06-10 13:36:04 -07008764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008765 case HOLD_SCREEN_CHANGED: {
8766 Session oldHold;
8767 Session newHold;
8768 synchronized (mWindowMap) {
8769 oldHold = mLastReportedHold;
8770 newHold = (Session)msg.obj;
8771 mLastReportedHold = newHold;
8772 }
Romain Guy06882f82009-06-10 13:36:04 -07008773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008774 if (oldHold != newHold) {
8775 try {
8776 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008777 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008778 "window",
8779 BatteryStats.WAKE_TYPE_WINDOW);
8780 }
8781 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008782 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 "window",
8784 BatteryStats.WAKE_TYPE_WINDOW);
8785 }
8786 } catch (RemoteException e) {
8787 }
8788 }
8789 break;
8790 }
Romain Guy06882f82009-06-10 13:36:04 -07008791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 case APP_TRANSITION_TIMEOUT: {
8793 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008794 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008795 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 "*** APP TRANSITION TIMEOUT");
8797 mAppTransitionReady = true;
8798 mAppTransitionTimeout = true;
8799 performLayoutAndPlaceSurfacesLocked();
8800 }
8801 }
8802 break;
8803 }
Romain Guy06882f82009-06-10 13:36:04 -07008804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008805 case PERSIST_ANIMATION_SCALE: {
8806 Settings.System.putFloat(mContext.getContentResolver(),
8807 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8808 Settings.System.putFloat(mContext.getContentResolver(),
8809 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8810 break;
8811 }
Romain Guy06882f82009-06-10 13:36:04 -07008812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813 case FORCE_GC: {
8814 synchronized(mWindowMap) {
8815 if (mAnimationPending) {
8816 // If we are animating, don't do the gc now but
8817 // delay a bit so we don't interrupt the animation.
8818 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8819 2000);
8820 return;
8821 }
8822 // If we are currently rotating the display, it will
8823 // schedule a new message when done.
8824 if (mDisplayFrozen) {
8825 return;
8826 }
8827 mFreezeGcPending = 0;
8828 }
8829 Runtime.getRuntime().gc();
8830 break;
8831 }
Romain Guy06882f82009-06-10 13:36:04 -07008832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008833 case ENABLE_SCREEN: {
8834 performEnableScreen();
8835 break;
8836 }
Romain Guy06882f82009-06-10 13:36:04 -07008837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008838 case APP_FREEZE_TIMEOUT: {
8839 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008840 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008841 int i = mAppTokens.size();
8842 while (i > 0) {
8843 i--;
8844 AppWindowToken tok = mAppTokens.get(i);
8845 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008846 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008847 unsetAppFreezingScreenLocked(tok, true, true);
8848 }
8849 }
8850 }
8851 break;
8852 }
Romain Guy06882f82009-06-10 13:36:04 -07008853
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008854 case SEND_NEW_CONFIGURATION: {
8855 removeMessages(SEND_NEW_CONFIGURATION);
8856 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008857 break;
8858 }
Romain Guy06882f82009-06-10 13:36:04 -07008859
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008860 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008861 if (mWindowsChanged) {
8862 synchronized (mWindowMap) {
8863 mWindowsChanged = false;
8864 }
8865 notifyWindowsChanged();
8866 }
8867 break;
8868 }
8869
Christopher Tatea53146c2010-09-07 11:57:52 -07008870 case DRAG_START_TIMEOUT: {
8871 IBinder win = (IBinder)msg.obj;
8872 if (DEBUG_DRAG) {
8873 Slog.w(TAG, "Timeout starting drag by win " + win);
8874 }
8875 synchronized (mWindowMap) {
8876 // !!! TODO: ANR the app that has failed to start the drag in time
8877 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008878 mDragState.unregister();
8879 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008880 mDragState.reset();
8881 mDragState = null;
8882 }
8883 }
Chris Tated4533f142010-10-19 15:15:08 -07008884 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008885 }
8886
Chris Tated4533f142010-10-19 15:15:08 -07008887 case DRAG_END_TIMEOUT: {
8888 IBinder win = (IBinder)msg.obj;
8889 if (DEBUG_DRAG) {
8890 Slog.w(TAG, "Timeout ending drag to win " + win);
8891 }
8892 synchronized (mWindowMap) {
8893 // !!! TODO: ANR the drag-receiving app
8894 mDragState.mDragResult = false;
8895 mDragState.endDragLw();
8896 }
8897 break;
8898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008899 }
8900 }
8901 }
8902
8903 // -------------------------------------------------------------
8904 // IWindowManager API
8905 // -------------------------------------------------------------
8906
8907 public IWindowSession openSession(IInputMethodClient client,
8908 IInputContext inputContext) {
8909 if (client == null) throw new IllegalArgumentException("null client");
8910 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008911 Session session = new Session(client, inputContext);
8912 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008913 }
8914
8915 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8916 synchronized (mWindowMap) {
8917 // The focus for the client is the window immediately below
8918 // where we would place the input method window.
8919 int idx = findDesiredInputMethodWindowIndexLocked(false);
8920 WindowState imFocus;
8921 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008922 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008923 if (imFocus != null) {
8924 if (imFocus.mSession.mClient != null &&
8925 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8926 return true;
8927 }
8928 }
8929 }
8930 }
8931 return false;
8932 }
Romain Guy06882f82009-06-10 13:36:04 -07008933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008934 // -------------------------------------------------------------
8935 // Internals
8936 // -------------------------------------------------------------
8937
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008938 final WindowState windowForClientLocked(Session session, IWindow client,
8939 boolean throwOnError) {
8940 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008941 }
Romain Guy06882f82009-06-10 13:36:04 -07008942
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008943 final WindowState windowForClientLocked(Session session, IBinder client,
8944 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008946 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008947 TAG, "Looking up client " + client + ": " + win);
8948 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008949 RuntimeException ex = new IllegalArgumentException(
8950 "Requested window " + client + " does not exist");
8951 if (throwOnError) {
8952 throw ex;
8953 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008954 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008955 return null;
8956 }
8957 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008958 RuntimeException ex = new IllegalArgumentException(
8959 "Requested window " + client + " is in session " +
8960 win.mSession + ", not " + session);
8961 if (throwOnError) {
8962 throw ex;
8963 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008964 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008965 return null;
8966 }
8967
8968 return win;
8969 }
8970
Dianne Hackborna8f60182009-09-01 19:01:50 -07008971 final void rebuildAppWindowListLocked() {
8972 int NW = mWindows.size();
8973 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008974 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008975 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008976
Dianne Hackborna8f60182009-09-01 19:01:50 -07008977 // First remove all existing app windows.
8978 i=0;
8979 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008980 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008981 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008982 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008983 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008984 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008985 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008986 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008987 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008988 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008989 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8990 && lastWallpaper == i-1) {
8991 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008992 }
8993 i++;
8994 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008995
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008996 // The wallpaper window(s) typically live at the bottom of the stack,
8997 // so skip them before adding app tokens.
8998 lastWallpaper++;
8999 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009000
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009001 // First add all of the exiting app tokens... these are no longer
9002 // in the main app list, but still have windows shown. We put them
9003 // in the back because now that the animation is over we no longer
9004 // will care about them.
9005 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009006 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009007 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9008 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009009
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009010 // And add in the still active app tokens in Z order.
9011 NT = mAppTokens.size();
9012 for (int j=0; j<NT; j++) {
9013 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009014 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009015
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009016 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009017 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009018 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009019 + " windows but added " + i);
9020 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009021 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009023 private final void assignLayersLocked() {
9024 int N = mWindows.size();
9025 int curBaseLayer = 0;
9026 int curLayer = 0;
9027 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009028
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009029 if (DEBUG_LAYERS) {
9030 RuntimeException here = new RuntimeException("here");
9031 here.fillInStackTrace();
9032 Log.v(TAG, "Assigning layers", here);
9033 }
9034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009036 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009037 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9038 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009039 curLayer += WINDOW_LAYER_MULTIPLIER;
9040 w.mLayer = curLayer;
9041 } else {
9042 curBaseLayer = curLayer = w.mBaseLayer;
9043 w.mLayer = curLayer;
9044 }
9045 if (w.mTargetAppToken != null) {
9046 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9047 } else if (w.mAppToken != null) {
9048 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9049 } else {
9050 w.mAnimLayer = w.mLayer;
9051 }
9052 if (w.mIsImWindow) {
9053 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009054 } else if (w.mIsWallpaper) {
9055 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009057 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058 + w.mAnimLayer);
9059 //System.out.println(
9060 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9061 }
9062 }
9063
9064 private boolean mInLayout = false;
9065 private final void performLayoutAndPlaceSurfacesLocked() {
9066 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009067 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009068 throw new RuntimeException("Recursive call!");
9069 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009070 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009071 return;
9072 }
9073
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009074 if (mWaitingForConfig) {
9075 // Our configuration has changed (most likely rotation), but we
9076 // don't yet have the complete configuration to report to
9077 // applications. Don't do any window layout until we have it.
9078 return;
9079 }
9080
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009081 if (mDisplay == null) {
9082 // Not yet initialized, nothing to do.
9083 return;
9084 }
9085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009086 boolean recoveringMemory = false;
9087 if (mForceRemoves != null) {
9088 recoveringMemory = true;
9089 // Wait a little it for things to settle down, and off we go.
9090 for (int i=0; i<mForceRemoves.size(); i++) {
9091 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009092 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009093 removeWindowInnerLocked(ws.mSession, ws);
9094 }
9095 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009096 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009097 Object tmp = new Object();
9098 synchronized (tmp) {
9099 try {
9100 tmp.wait(250);
9101 } catch (InterruptedException e) {
9102 }
9103 }
9104 }
Romain Guy06882f82009-06-10 13:36:04 -07009105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009106 mInLayout = true;
9107 try {
9108 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009110 int i = mPendingRemove.size()-1;
9111 if (i >= 0) {
9112 while (i >= 0) {
9113 WindowState w = mPendingRemove.get(i);
9114 removeWindowInnerLocked(w.mSession, w);
9115 i--;
9116 }
9117 mPendingRemove.clear();
9118
9119 mInLayout = false;
9120 assignLayersLocked();
9121 mLayoutNeeded = true;
9122 performLayoutAndPlaceSurfacesLocked();
9123
9124 } else {
9125 mInLayout = false;
9126 if (mLayoutNeeded) {
9127 requestAnimationLocked(0);
9128 }
9129 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009130 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009131 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9132 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009134 } catch (RuntimeException e) {
9135 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009136 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009137 }
9138 }
9139
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009140 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009141 if (!mLayoutNeeded) {
9142 return 0;
9143 }
9144
9145 mLayoutNeeded = false;
9146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009147 final int dw = mDisplay.getWidth();
9148 final int dh = mDisplay.getHeight();
9149
9150 final int N = mWindows.size();
9151 int i;
9152
Joe Onorato8a9b2202010-02-26 18:56:32 -08009153 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009154 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9155
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009156 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009157
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009158 int seq = mLayoutSeq+1;
9159 if (seq < 0) seq = 0;
9160 mLayoutSeq = seq;
9161
9162 // First perform layout of any root windows (not attached
9163 // to another window).
9164 int topAttached = -1;
9165 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009166 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009167
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009168 // Don't do layout of a window if it is not visible, or
9169 // soon won't be visible, to avoid wasting time and funky
9170 // changes while a window is animating away.
9171 final AppWindowToken atoken = win.mAppToken;
9172 final boolean gone = win.mViewVisibility == View.GONE
9173 || !win.mRelayoutCalled
9174 || win.mRootToken.hidden
9175 || (atoken != null && atoken.hiddenRequested)
9176 || win.mAttachedHidden
9177 || win.mExiting || win.mDestroying;
9178
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009179 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9180 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009181 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9182 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009183 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009184 + win.mViewVisibility + " mRelayoutCalled="
9185 + win.mRelayoutCalled + " hidden="
9186 + win.mRootToken.hidden + " hiddenRequested="
9187 + (atoken != null && atoken.hiddenRequested)
9188 + " mAttachedHidden=" + win.mAttachedHidden);
9189 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009190
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009191 // If this view is GONE, then skip it -- keep the current
9192 // frame, and let the caller know so they can ignore it
9193 // if they want. (We do the normal layout for INVISIBLE
9194 // windows, since that means "perform layout as normal,
9195 // just don't display").
9196 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009197 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009198 if (initial) {
9199 win.mContentChanged = false;
9200 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009201 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9202 win.mLayoutSeq = seq;
9203 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9204 + win.mFrame + " mContainingFrame="
9205 + win.mContainingFrame + " mDisplayFrame="
9206 + win.mDisplayFrame);
9207 } else {
9208 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009209 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009212
9213 // Now perform layout of attached windows, which usually
9214 // depend on the position of the window they are attached to.
9215 // XXX does not deal with windows that are attached to windows
9216 // that are themselves attached.
9217 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009218 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009219
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009220 if (win.mLayoutAttached) {
9221 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9222 + " mHaveFrame=" + win.mHaveFrame
9223 + " mViewVisibility=" + win.mViewVisibility
9224 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009225 // If this view is GONE, then skip it -- keep the current
9226 // frame, and let the caller know so they can ignore it
9227 // if they want. (We do the normal layout for INVISIBLE
9228 // windows, since that means "perform layout as normal,
9229 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009230 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9231 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009232 if (initial) {
9233 win.mContentChanged = false;
9234 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009235 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9236 win.mLayoutSeq = seq;
9237 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9238 + win.mFrame + " mContainingFrame="
9239 + win.mContainingFrame + " mDisplayFrame="
9240 + win.mDisplayFrame);
9241 }
9242 }
9243 }
Jeff Brown349703e2010-06-22 01:27:15 -07009244
9245 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009246 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009247
9248 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 }
Romain Guy06882f82009-06-10 13:36:04 -07009250
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009251 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009252 private final void performLayoutAndPlaceSurfacesLockedInner(
9253 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009254 if (mDisplay == null) {
9255 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9256 return;
9257 }
9258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009259 final long currentTime = SystemClock.uptimeMillis();
9260 final int dw = mDisplay.getWidth();
9261 final int dh = mDisplay.getHeight();
9262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009263 int i;
9264
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009265 if (mFocusMayChange) {
9266 mFocusMayChange = false;
9267 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9268 }
9269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 // Initialize state of exiting tokens.
9271 for (i=mExitingTokens.size()-1; i>=0; i--) {
9272 mExitingTokens.get(i).hasVisible = false;
9273 }
9274
9275 // Initialize state of exiting applications.
9276 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9277 mExitingAppTokens.get(i).hasVisible = false;
9278 }
9279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280 boolean orientationChangeComplete = true;
9281 Session holdScreen = null;
9282 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009283 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009284 boolean focusDisplayed = false;
9285 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009286 boolean createWatermark = false;
9287
9288 if (mFxSession == null) {
9289 mFxSession = new SurfaceSession();
9290 createWatermark = true;
9291 }
9292
9293 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009294
9295 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009296
9297 if (createWatermark) {
9298 createWatermark();
9299 }
9300 if (mWatermark != null) {
9301 mWatermark.positionSurface(dw, dh);
9302 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009303 if (mStrictModeFlash != null) {
9304 mStrictModeFlash.positionSurface(dw, dh);
9305 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009307 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009308 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009309 int repeats = 0;
9310 int changes = 0;
9311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009313 repeats++;
9314 if (repeats > 6) {
9315 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9316 mLayoutNeeded = false;
9317 break;
9318 }
9319
9320 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9321 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9322 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9323 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9324 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9325 assignLayersLocked();
9326 mLayoutNeeded = true;
9327 }
9328 }
9329 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9330 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9331 if (updateOrientationFromAppTokensLocked()) {
9332 mLayoutNeeded = true;
9333 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9334 }
9335 }
9336 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9337 mLayoutNeeded = true;
9338 }
9339 }
9340
9341 // FIRST LOOP: Perform a layout, if needed.
9342 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009343 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009344 if (changes != 0) {
9345 continue;
9346 }
9347 } else {
9348 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9349 changes = 0;
9350 }
9351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 final int transactionSequence = ++mTransactionSequence;
9353
9354 // Update animations of all applications, including those
9355 // associated with exiting/removed apps
9356 boolean tokensAnimating = false;
9357 final int NAT = mAppTokens.size();
9358 for (i=0; i<NAT; i++) {
9359 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9360 tokensAnimating = true;
9361 }
9362 }
9363 final int NEAT = mExitingAppTokens.size();
9364 for (i=0; i<NEAT; i++) {
9365 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9366 tokensAnimating = true;
9367 }
9368 }
9369
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009370 // SECOND LOOP: Execute animations and update visibility of windows.
9371
Joe Onorato8a9b2202010-02-26 18:56:32 -08009372 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009373 + transactionSequence + " tokensAnimating="
9374 + tokensAnimating);
9375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009376 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009377
9378 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009379 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009380 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009381 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382
9383 mPolicy.beginAnimationLw(dw, dh);
9384
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009385 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009387 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009388 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009389
9390 final WindowManager.LayoutParams attrs = w.mAttrs;
9391
9392 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009393 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009394 if (w.commitFinishDrawingLocked(currentTime)) {
9395 if ((w.mAttrs.flags
9396 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009397 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009398 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009399 wallpaperMayChange = true;
9400 }
9401 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009402
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009403 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009404
9405 int animDw = dw;
9406 int animDh = dh;
9407
9408 // If the window has moved due to its containing
9409 // content frame changing, then we'd like to animate
9410 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009411 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009412 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009413 // Frame has moved, containing content frame
9414 // has also moved, and we're not currently animating...
9415 // let's do something.
9416 Animation a = AnimationUtils.loadAnimation(mContext,
9417 com.android.internal.R.anim.window_move_from_decor);
9418 w.setAnimation(a);
9419 animDw = w.mLastFrame.left - w.mFrame.left;
9420 animDh = w.mLastFrame.top - w.mFrame.top;
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009421 w.mContentChanged = false;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009422 }
9423
9424 // Execute animation.
9425 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9426 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009427
9428 // If this window is animating, make a note that we have
9429 // an animating window and take care of a request to run
9430 // a detached wallpaper animation.
9431 if (nowAnimating) {
9432 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9433 windowDetachedWallpaper = w;
9434 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009435 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009436 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009437
9438 // If this window's app token is running a detached wallpaper
9439 // animation, make a note so we can ensure the wallpaper is
9440 // displayed behind it.
9441 if (w.mAppToken != null && w.mAppToken.animation != null
9442 && w.mAppToken.animation.getDetachWallpaper()) {
9443 windowDetachedWallpaper = w;
9444 }
9445
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009446 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9447 wallpaperMayChange = true;
9448 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009449
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009450 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009451 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009452 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009453 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009454 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009455 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009456 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009457 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9458 forceHiding = true;
9459 }
9460 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9461 boolean changed;
9462 if (forceHiding) {
9463 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009464 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9465 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009466 } else {
9467 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009468 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9469 "Now policy shown: " + w);
9470 if (changed) {
9471 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009472 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009473 // Assume we will need to animate. If
9474 // we don't (because the wallpaper will
9475 // stay with the lock screen), then we will
9476 // clean up later.
9477 Animation a = mPolicy.createForceHideEnterAnimation();
9478 if (a != null) {
9479 w.setAnimation(a);
9480 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009481 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009482 if (mCurrentFocus == null ||
9483 mCurrentFocus.mLayer < w.mLayer) {
9484 // We are showing on to of the current
9485 // focus, so re-evaluate focus to make
9486 // sure it is correct.
9487 mFocusMayChange = true;
9488 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009489 }
9490 }
9491 if (changed && (attrs.flags
9492 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9493 wallpaperMayChange = true;
9494 }
9495 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 mPolicy.animatingWindowLw(w, attrs);
9498 }
9499
9500 final AppWindowToken atoken = w.mAppToken;
9501 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9502 if (atoken.lastTransactionSequence != transactionSequence) {
9503 atoken.lastTransactionSequence = transactionSequence;
9504 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9505 atoken.startingDisplayed = false;
9506 }
9507 if ((w.isOnScreen() || w.mAttrs.type
9508 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9509 && !w.mExiting && !w.mDestroying) {
9510 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009511 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009512 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009513 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009514 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009515 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 + " pv=" + w.mPolicyVisibility
9517 + " dp=" + w.mDrawPending
9518 + " cdp=" + w.mCommitDrawPending
9519 + " ah=" + w.mAttachedHidden
9520 + " th=" + atoken.hiddenRequested
9521 + " a=" + w.mAnimating);
9522 }
9523 }
9524 if (w != atoken.startingWindow) {
9525 if (!atoken.freezingScreen || !w.mAppFreezing) {
9526 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009527 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009528 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009529 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009530 "tokenMayBeDrawn: " + atoken
9531 + " freezingScreen=" + atoken.freezingScreen
9532 + " mAppFreezing=" + w.mAppFreezing);
9533 tokenMayBeDrawn = true;
9534 }
9535 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009536 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009537 atoken.startingDisplayed = true;
9538 }
9539 }
9540 } else if (w.mReadyToShow) {
9541 w.performShowLocked();
9542 }
9543 }
9544
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009545 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009546
9547 if (tokenMayBeDrawn) {
9548 // See if any windows have been drawn, so they (and others
9549 // associated with them) can now be shown.
9550 final int NT = mTokenList.size();
9551 for (i=0; i<NT; i++) {
9552 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9553 if (wtoken == null) {
9554 continue;
9555 }
9556 if (wtoken.freezingScreen) {
9557 int numInteresting = wtoken.numInterestingWindows;
9558 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009559 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 "allDrawn: " + wtoken
9561 + " interesting=" + numInteresting
9562 + " drawn=" + wtoken.numDrawnWindows);
9563 wtoken.showAllWindowsLocked();
9564 unsetAppFreezingScreenLocked(wtoken, false, true);
9565 orientationChangeComplete = true;
9566 }
9567 } else if (!wtoken.allDrawn) {
9568 int numInteresting = wtoken.numInterestingWindows;
9569 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009570 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009571 "allDrawn: " + wtoken
9572 + " interesting=" + numInteresting
9573 + " drawn=" + wtoken.numDrawnWindows);
9574 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009575 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009576
9577 // We can now show all of the drawn windows!
9578 if (!mOpeningApps.contains(wtoken)) {
9579 wtoken.showAllWindowsLocked();
9580 }
9581 }
9582 }
9583 }
9584 }
9585
9586 // If we are ready to perform an app transition, check through
9587 // all of the app tokens to be shown and see if they are ready
9588 // to go.
9589 if (mAppTransitionReady) {
9590 int NN = mOpeningApps.size();
9591 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009592 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 "Checking " + NN + " opening apps (frozen="
9594 + mDisplayFrozen + " timeout="
9595 + mAppTransitionTimeout + ")...");
9596 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9597 // If the display isn't frozen, wait to do anything until
9598 // all of the apps are ready. Otherwise just go because
9599 // we'll unfreeze the display when everyone is ready.
9600 for (i=0; i<NN && goodToGo; i++) {
9601 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009602 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 "Check opening app" + wtoken + ": allDrawn="
9604 + wtoken.allDrawn + " startingDisplayed="
9605 + wtoken.startingDisplayed);
9606 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9607 && !wtoken.startingMoved) {
9608 goodToGo = false;
9609 }
9610 }
9611 }
9612 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009613 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009614 int transit = mNextAppTransition;
9615 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009616 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009617 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009618 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009619 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009620 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009621 mAppTransitionTimeout = false;
9622 mStartingIconInTransition = false;
9623 mSkipAppTransitionAnimation = false;
9624
9625 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9626
Dianne Hackborna8f60182009-09-01 19:01:50 -07009627 // If there are applications waiting to come to the
9628 // top of the stack, now is the time to move their windows.
9629 // (Note that we don't do apps going to the bottom
9630 // here -- we want to keep their windows in the old
9631 // Z-order until the animation completes.)
9632 if (mToTopApps.size() > 0) {
9633 NN = mAppTokens.size();
9634 for (i=0; i<NN; i++) {
9635 AppWindowToken wtoken = mAppTokens.get(i);
9636 if (wtoken.sendingToTop) {
9637 wtoken.sendingToTop = false;
9638 moveAppWindowsLocked(wtoken, NN, false);
9639 }
9640 }
9641 mToTopApps.clear();
9642 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009643
Dianne Hackborn25994b42009-09-04 14:21:19 -07009644 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009645
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009646 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009647 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009648
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009649 // The top-most window will supply the layout params,
9650 // and we will determine it below.
9651 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009652 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009653 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009654
Joe Onorato8a9b2202010-02-26 18:56:32 -08009655 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009656 "New wallpaper target=" + mWallpaperTarget
9657 + ", lower target=" + mLowerWallpaperTarget
9658 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009659 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009660 // Do a first pass through the tokens for two
9661 // things:
9662 // (1) Determine if both the closing and opening
9663 // app token sets are wallpaper targets, in which
9664 // case special animations are needed
9665 // (since the wallpaper needs to stay static
9666 // behind them).
9667 // (2) Find the layout params of the top-most
9668 // application window in the tokens, which is
9669 // what will control the animation theme.
9670 final int NC = mClosingApps.size();
9671 NN = NC + mOpeningApps.size();
9672 for (i=0; i<NN; i++) {
9673 AppWindowToken wtoken;
9674 int mode;
9675 if (i < NC) {
9676 wtoken = mClosingApps.get(i);
9677 mode = 1;
9678 } else {
9679 wtoken = mOpeningApps.get(i-NC);
9680 mode = 2;
9681 }
9682 if (mLowerWallpaperTarget != null) {
9683 if (mLowerWallpaperTarget.mAppToken == wtoken
9684 || mUpperWallpaperTarget.mAppToken == wtoken) {
9685 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009686 }
9687 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009688 if (wtoken.appFullscreen) {
9689 WindowState ws = wtoken.findMainWindow();
9690 if (ws != null) {
9691 // If this is a compatibility mode
9692 // window, we will always use its anim.
9693 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9694 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009695 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009696 bestAnimLayer = Integer.MAX_VALUE;
9697 } else if (ws.mLayer > bestAnimLayer) {
9698 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009699 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009700 bestAnimLayer = ws.mLayer;
9701 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009702 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009703 }
9704 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009705
Dianne Hackborn25994b42009-09-04 14:21:19 -07009706 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009707 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009708 "Wallpaper animation!");
9709 switch (transit) {
9710 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9711 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9712 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9713 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9714 break;
9715 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9716 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9717 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9718 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9719 break;
9720 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009721 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009722 "New transit: " + transit);
9723 } else if (oldWallpaper != null) {
9724 // We are transitioning from an activity with
9725 // a wallpaper to one without.
9726 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009727 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009728 "New transit away from wallpaper: " + transit);
9729 } else if (mWallpaperTarget != null) {
9730 // We are transitioning from an activity without
9731 // a wallpaper to now showing the wallpaper
9732 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009733 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009734 "New transit into wallpaper: " + transit);
9735 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009736
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009737 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9738 mLastEnterAnimToken = animToken;
9739 mLastEnterAnimParams = animLp;
9740 } else if (mLastEnterAnimParams != null) {
9741 animLp = mLastEnterAnimParams;
9742 mLastEnterAnimToken = null;
9743 mLastEnterAnimParams = null;
9744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009745
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009746 // If all closing windows are obscured, then there is
9747 // no need to do an animation. This is the case, for
9748 // example, when this transition is being done behind
9749 // the lock screen.
9750 if (!mPolicy.allowAppAnimationsLw()) {
9751 animLp = null;
9752 }
9753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009754 NN = mOpeningApps.size();
9755 for (i=0; i<NN; i++) {
9756 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009757 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 "Now opening app" + wtoken);
9759 wtoken.reportedVisible = false;
9760 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009761 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009762 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009763 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009764 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 wtoken.showAllWindowsLocked();
9766 }
9767 NN = mClosingApps.size();
9768 for (i=0; i<NN; i++) {
9769 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009770 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009771 "Now closing app" + wtoken);
9772 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009773 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009774 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009776 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777 // Force the allDrawn flag, because we want to start
9778 // this guy's animations regardless of whether it's
9779 // gotten drawn.
9780 wtoken.allDrawn = true;
9781 }
9782
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009783 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009785 mOpeningApps.clear();
9786 mClosingApps.clear();
9787
9788 // This has changed the visibility of windows, so perform
9789 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009790 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009792 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9793 assignLayersLocked();
9794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009796 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009797 }
9798 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009799
Dianne Hackborn16064f92010-03-25 00:47:24 -07009800 int adjResult = 0;
9801
Dianne Hackborna8f60182009-09-01 19:01:50 -07009802 if (!animating && mAppTransitionRunning) {
9803 // We have finished the animation of an app transition. To do
9804 // this, we have delayed a lot of operations like showing and
9805 // hiding apps, moving apps in Z-order, etc. The app token list
9806 // reflects the correct Z-order, but the window list may now
9807 // be out of sync with it. So here we will just rebuild the
9808 // entire app window list. Fun!
9809 mAppTransitionRunning = false;
9810 // Clear information about apps that were moving.
9811 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009812
Dianne Hackborna8f60182009-09-01 19:01:50 -07009813 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009814 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009815 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009816 moveInputMethodWindowsIfNeededLocked(false);
9817 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009818 // Since the window list has been rebuilt, focus might
9819 // have to be recomputed since the actual order of windows
9820 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009821 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009823
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009824 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009825 // At this point, there was a window with a wallpaper that
9826 // was force hiding other windows behind it, but now it
9827 // is going away. This may be simple -- just animate
9828 // away the wallpaper and its window -- or it may be
9829 // hard -- the wallpaper now needs to be shown behind
9830 // something that was hidden.
9831 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009832 if (mLowerWallpaperTarget != null
9833 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009834 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009835 "wallpaperForceHiding changed with lower="
9836 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009837 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009838 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9839 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9840 if (mLowerWallpaperTarget.mAppToken.hidden) {
9841 // The lower target has become hidden before we
9842 // actually started the animation... let's completely
9843 // re-evaluate everything.
9844 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009845 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009846 }
9847 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009848 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009849 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009850 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009851 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009852 + " NEW: " + mWallpaperTarget
9853 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009854 if (mLowerWallpaperTarget == null) {
9855 // Whoops, we don't need a special wallpaper animation.
9856 // Clear them out.
9857 forceHiding = false;
9858 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009859 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009860 if (w.mSurface != null) {
9861 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009862 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009863 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009864 forceHiding = true;
9865 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9866 if (!w.mAnimating) {
9867 // We set the animation above so it
9868 // is not yet running.
9869 w.clearAnimation();
9870 }
9871 }
9872 }
9873 }
9874 }
9875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009876
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009877 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
9878 if (DEBUG_WALLPAPER) Slog.v(TAG,
9879 "Detached wallpaper changed from " + mWindowDetachedWallpaper
9880 + windowDetachedWallpaper);
9881 mWindowDetachedWallpaper = windowDetachedWallpaper;
9882 wallpaperMayChange = true;
9883 }
9884
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009885 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009886 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009887 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009888 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009889 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009890
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009891 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009892 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009893 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009894 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009895 assignLayersLocked();
9896 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009897 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009898 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009899 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009900 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009901
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009902 if (mFocusMayChange) {
9903 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009904 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009905 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009906 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009907 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009908 }
9909
9910 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009911 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009912 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009913
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009914 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9915 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009916
Jeff Browne33348b2010-07-15 23:54:05 -07009917 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009918 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919
9920 // THIRD LOOP: Update the surfaces of all windows.
9921
9922 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9923
9924 boolean obscured = false;
9925 boolean blurring = false;
9926 boolean dimming = false;
9927 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009928 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009929 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009931 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009934 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009935
9936 boolean displayed = false;
9937 final WindowManager.LayoutParams attrs = w.mAttrs;
9938 final int attrFlags = attrs.flags;
9939
9940 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009941 // XXX NOTE: The logic here could be improved. We have
9942 // the decision about whether to resize a window separated
9943 // from whether to hide the surface. This can cause us to
9944 // resize a surface even if we are going to hide it. You
9945 // can see this by (1) holding device in landscape mode on
9946 // home screen; (2) tapping browser icon (device will rotate
9947 // to landscape; (3) tap home. The wallpaper will be resized
9948 // in step 2 but then immediately hidden, causing us to
9949 // have to resize and then redraw it again in step 3. It
9950 // would be nice to figure out how to avoid this, but it is
9951 // difficult because we do need to resize surfaces in some
9952 // cases while they are hidden such as when first showing a
9953 // window.
9954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009956 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009957 TAG, "Placing surface #" + i + " " + w.mSurface
9958 + ": new=" + w.mShownFrame + ", old="
9959 + w.mLastShownFrame);
9960
9961 boolean resize;
9962 int width, height;
9963 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9964 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9965 w.mLastRequestedHeight != w.mRequestedHeight;
9966 // for a scaled surface, we just want to use
9967 // the requested size.
9968 width = w.mRequestedWidth;
9969 height = w.mRequestedHeight;
9970 w.mLastRequestedWidth = width;
9971 w.mLastRequestedHeight = height;
9972 w.mLastShownFrame.set(w.mShownFrame);
9973 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009974 if (SHOW_TRANSACTIONS) logSurface(w,
9975 "POS " + w.mShownFrame.left
9976 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009977 w.mSurfaceX = w.mShownFrame.left;
9978 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009979 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9980 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009981 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009982 if (!recoveringMemory) {
9983 reclaimSomeSurfaceMemoryLocked(w, "position");
9984 }
9985 }
9986 } else {
9987 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9988 width = w.mShownFrame.width();
9989 height = w.mShownFrame.height();
9990 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009991 }
9992
9993 if (resize) {
9994 if (width < 1) width = 1;
9995 if (height < 1) height = 1;
9996 if (w.mSurface != null) {
9997 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009998 if (SHOW_TRANSACTIONS) logSurface(w,
9999 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010000 + w.mShownFrame.top + " SIZE "
10001 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010002 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010003 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010004 w.mSurfaceW = width;
10005 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010007 w.mSurfaceX = w.mShownFrame.left;
10008 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 w.mSurface.setPosition(w.mShownFrame.left,
10010 w.mShownFrame.top);
10011 } catch (RuntimeException e) {
10012 // If something goes wrong with the surface (such
10013 // as running out of memory), don't take down the
10014 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010015 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010016 + "size=(" + width + "x" + height
10017 + "), pos=(" + w.mShownFrame.left
10018 + "," + w.mShownFrame.top + ")", e);
10019 if (!recoveringMemory) {
10020 reclaimSomeSurfaceMemoryLocked(w, "size");
10021 }
10022 }
10023 }
10024 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010025 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010026 w.mContentInsetsChanged =
10027 !w.mLastContentInsets.equals(w.mContentInsets);
10028 w.mVisibleInsetsChanged =
10029 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010030 boolean configChanged =
10031 w.mConfiguration != mCurConfiguration
10032 && (w.mConfiguration == null
10033 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010034 if (DEBUG_CONFIGURATION && configChanged) {
10035 Slog.v(TAG, "Win " + w + " config changed: "
10036 + mCurConfiguration);
10037 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010038 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010039 + ": configChanged=" + configChanged
10040 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010041 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010042 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010043 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010044 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010045 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 w.mLastFrame.set(w.mFrame);
10047 w.mLastContentInsets.set(w.mContentInsets);
10048 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010049 // If the screen is currently frozen, then keep
10050 // it frozen until this window draws at its new
10051 // orientation.
10052 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010053 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010054 "Resizing while display frozen: " + w);
10055 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010056 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010057 mWindowsFreezingScreen = true;
10058 // XXX should probably keep timeout from
10059 // when we first froze the display.
10060 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10061 mH.sendMessageDelayed(mH.obtainMessage(
10062 H.WINDOW_FREEZE_TIMEOUT), 2000);
10063 }
10064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010065 // If the orientation is changing, then we need to
10066 // hold off on unfreezing the display until this
10067 // window has been redrawn; to do that, we need
10068 // to go through the process of getting informed
10069 // by the application when it has finished drawing.
10070 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010071 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010072 "Orientation start waiting for draw in "
10073 + w + ", surface " + w.mSurface);
10074 w.mDrawPending = true;
10075 w.mCommitDrawPending = false;
10076 w.mReadyToShow = false;
10077 if (w.mAppToken != null) {
10078 w.mAppToken.allDrawn = false;
10079 }
10080 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010081 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010082 "Resizing window " + w + " to " + w.mFrame);
10083 mResizingWindows.add(w);
10084 } else if (w.mOrientationChanging) {
10085 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010086 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 "Orientation not waiting for draw in "
10088 + w + ", surface " + w.mSurface);
10089 w.mOrientationChanging = false;
10090 }
10091 }
10092 }
10093
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010094 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010095 if (!w.mLastHidden) {
10096 //dump();
10097 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010098 if (SHOW_TRANSACTIONS) logSurface(w,
10099 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010100 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010101 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010102 try {
10103 w.mSurface.hide();
10104 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010105 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 }
10107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010108 }
10109 // If we are waiting for this window to handle an
10110 // orientation change, well, it is hidden, so
10111 // doesn't really matter. Note that this does
10112 // introduce a potential glitch if the window
10113 // becomes unhidden before it has drawn for the
10114 // new orientation.
10115 if (w.mOrientationChanging) {
10116 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010117 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 "Orientation change skips hidden " + w);
10119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010120 } else if (w.mLastLayer != w.mAnimLayer
10121 || w.mLastAlpha != w.mShownAlpha
10122 || w.mLastDsDx != w.mDsDx
10123 || w.mLastDtDx != w.mDtDx
10124 || w.mLastDsDy != w.mDsDy
10125 || w.mLastDtDy != w.mDtDy
10126 || w.mLastHScale != w.mHScale
10127 || w.mLastVScale != w.mVScale
10128 || w.mLastHidden) {
10129 displayed = true;
10130 w.mLastAlpha = w.mShownAlpha;
10131 w.mLastLayer = w.mAnimLayer;
10132 w.mLastDsDx = w.mDsDx;
10133 w.mLastDtDx = w.mDtDx;
10134 w.mLastDsDy = w.mDsDy;
10135 w.mLastDtDy = w.mDtDy;
10136 w.mLastHScale = w.mHScale;
10137 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010138 if (SHOW_TRANSACTIONS) logSurface(w,
10139 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010140 + " matrix=[" + (w.mDsDx*w.mHScale)
10141 + "," + (w.mDtDx*w.mVScale)
10142 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010143 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 if (w.mSurface != null) {
10145 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010146 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010147 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010148 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010149 w.mSurface.setLayer(w.mAnimLayer);
10150 w.mSurface.setMatrix(
10151 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10152 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10153 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010154 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010155 if (!recoveringMemory) {
10156 reclaimSomeSurfaceMemoryLocked(w, "update");
10157 }
10158 }
10159 }
10160
10161 if (w.mLastHidden && !w.mDrawPending
10162 && !w.mCommitDrawPending
10163 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010164 if (SHOW_TRANSACTIONS) logSurface(w,
10165 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010166 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010167 + " during relayout");
10168 if (showSurfaceRobustlyLocked(w)) {
10169 w.mHasDrawn = true;
10170 w.mLastHidden = false;
10171 } else {
10172 w.mOrientationChanging = false;
10173 }
10174 }
10175 if (w.mSurface != null) {
10176 w.mToken.hasVisible = true;
10177 }
10178 } else {
10179 displayed = true;
10180 }
10181
10182 if (displayed) {
10183 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010184 if (attrs.width == LayoutParams.MATCH_PARENT
10185 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010186 covered = true;
10187 }
10188 }
10189 if (w.mOrientationChanging) {
10190 if (w.mDrawPending || w.mCommitDrawPending) {
10191 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010192 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 "Orientation continue waiting for draw in " + w);
10194 } else {
10195 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010196 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010197 "Orientation change complete in " + w);
10198 }
10199 }
10200 w.mToken.hasVisible = true;
10201 }
10202 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010203 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010204 "Orientation change skips hidden " + w);
10205 w.mOrientationChanging = false;
10206 }
10207
10208 final boolean canBeSeen = w.isDisplayedLw();
10209
10210 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10211 focusDisplayed = true;
10212 }
10213
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010214 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010216 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010217 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010218 if (w.mSurface != null) {
10219 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10220 holdScreen = w.mSession;
10221 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010222 if (!syswin && w.mAttrs.screenBrightness >= 0
10223 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010224 screenBrightness = w.mAttrs.screenBrightness;
10225 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010226 if (!syswin && w.mAttrs.buttonBrightness >= 0
10227 && buttonBrightness < 0) {
10228 buttonBrightness = w.mAttrs.buttonBrightness;
10229 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010230 if (canBeSeen
10231 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10232 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10233 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010234 syswin = true;
10235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010236 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010237
Dianne Hackborn25994b42009-09-04 14:21:19 -070010238 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10239 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010240 // This window completely covers everything behind it,
10241 // so we want to leave all of them as unblurred (for
10242 // performance reasons).
10243 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010244 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010245 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010246 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010247 obscured = true;
10248 if (mBackgroundFillerSurface == null) {
10249 try {
10250 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010251 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010252 0, dw, dh,
10253 PixelFormat.OPAQUE,
10254 Surface.FX_SURFACE_NORMAL);
10255 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010256 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010257 }
10258 }
10259 try {
10260 mBackgroundFillerSurface.setPosition(0, 0);
10261 mBackgroundFillerSurface.setSize(dw, dh);
10262 // Using the same layer as Dim because they will never be shown at the
10263 // same time.
10264 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10265 mBackgroundFillerSurface.show();
10266 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010267 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010268 }
10269 backgroundFillerShown = true;
10270 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010271 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010273 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010274 + ": blurring=" + blurring
10275 + " obscured=" + obscured
10276 + " displayed=" + displayed);
10277 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10278 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010279 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010281 if (mDimAnimator == null) {
10282 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010284 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010285 mDimAnimator.updateParameters(mContext.getResources(),
10286 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010287 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 }
10289 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10290 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010291 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010292 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010294 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 + mBlurSurface + ": CREATE");
10296 try {
Romain Guy06882f82009-06-10 13:36:04 -070010297 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010298 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 -1, 16, 16,
10300 PixelFormat.OPAQUE,
10301 Surface.FX_SURFACE_BLUR);
10302 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010303 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 }
10305 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010307 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10308 + mBlurSurface + ": pos=(0,0) (" +
10309 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010310 mBlurSurface.setPosition(0, 0);
10311 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010312 mBlurSurface.setLayer(w.mAnimLayer-2);
10313 if (!mBlurShown) {
10314 try {
10315 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10316 + mBlurSurface + ": SHOW");
10317 mBlurSurface.show();
10318 } catch (RuntimeException e) {
10319 Slog.w(TAG, "Failure showing blur surface", e);
10320 }
10321 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010322 }
10323 }
10324 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010325 }
10326 }
10327 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010328
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010329 if (obscuredChanged && mWallpaperTarget == w) {
10330 // This is the wallpaper target and its obscured state
10331 // changed... make sure the current wallaper's visibility
10332 // has been updated accordingly.
10333 updateWallpaperVisibilityLocked();
10334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010336
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010337 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10338 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010339 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010340 try {
10341 mBackgroundFillerSurface.hide();
10342 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010343 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010344 }
10345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010347 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010348 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10349 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010350 }
Romain Guy06882f82009-06-10 13:36:04 -070010351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010352 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010353 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354 + ": HIDE");
10355 try {
10356 mBlurSurface.hide();
10357 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010358 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 }
10360 mBlurShown = false;
10361 }
10362
Joe Onorato8a9b2202010-02-26 18:56:32 -080010363 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010365 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010366 }
10367
Jeff Browne33348b2010-07-15 23:54:05 -070010368 mInputMonitor.updateInputWindowsLw();
10369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010370 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010371
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010372 if (mWatermark != null) {
10373 mWatermark.drawIfNeeded();
10374 }
10375
Joe Onorato8a9b2202010-02-26 18:56:32 -080010376 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010377 "With display frozen, orientationChangeComplete="
10378 + orientationChangeComplete);
10379 if (orientationChangeComplete) {
10380 if (mWindowsFreezingScreen) {
10381 mWindowsFreezingScreen = false;
10382 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10383 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010384 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 }
Romain Guy06882f82009-06-10 13:36:04 -070010386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 i = mResizingWindows.size();
10388 if (i > 0) {
10389 do {
10390 i--;
10391 WindowState win = mResizingWindows.get(i);
10392 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010393 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10394 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010395 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010396 boolean configChanged =
10397 win.mConfiguration != mCurConfiguration
10398 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010399 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10400 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10401 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010402 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010403 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010404 + " / " + mCurConfiguration + " / 0x"
10405 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010406 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010407 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408 win.mClient.resized(win.mFrame.width(),
10409 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010410 win.mLastVisibleInsets, win.mDrawPending,
10411 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 win.mContentInsetsChanged = false;
10413 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010414 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010415 } catch (RemoteException e) {
10416 win.mOrientationChanging = false;
10417 }
10418 } while (i > 0);
10419 mResizingWindows.clear();
10420 }
Romain Guy06882f82009-06-10 13:36:04 -070010421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010422 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010423 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424 i = mDestroySurface.size();
10425 if (i > 0) {
10426 do {
10427 i--;
10428 WindowState win = mDestroySurface.get(i);
10429 win.mDestroying = false;
10430 if (mInputMethodWindow == win) {
10431 mInputMethodWindow = null;
10432 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010433 if (win == mWallpaperTarget) {
10434 wallpaperDestroyed = true;
10435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010436 win.destroySurfaceLocked();
10437 } while (i > 0);
10438 mDestroySurface.clear();
10439 }
10440
10441 // Time to remove any exiting tokens?
10442 for (i=mExitingTokens.size()-1; i>=0; i--) {
10443 WindowToken token = mExitingTokens.get(i);
10444 if (!token.hasVisible) {
10445 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010446 if (token.windowType == TYPE_WALLPAPER) {
10447 mWallpaperTokens.remove(token);
10448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010449 }
10450 }
10451
10452 // Time to remove any exiting applications?
10453 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10454 AppWindowToken token = mExitingAppTokens.get(i);
10455 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010456 // Make sure there is no animation running on this token,
10457 // so any windows associated with it will be removed as
10458 // soon as their animations are complete
10459 token.animation = null;
10460 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 mAppTokens.remove(token);
10462 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010463 if (mLastEnterAnimToken == token) {
10464 mLastEnterAnimToken = null;
10465 mLastEnterAnimParams = null;
10466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467 }
10468 }
10469
Dianne Hackborna8f60182009-09-01 19:01:50 -070010470 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010471
Dianne Hackborna8f60182009-09-01 19:01:50 -070010472 if (!animating && mAppTransitionRunning) {
10473 // We have finished the animation of an app transition. To do
10474 // this, we have delayed a lot of operations like showing and
10475 // hiding apps, moving apps in Z-order, etc. The app token list
10476 // reflects the correct Z-order, but the window list may now
10477 // be out of sync with it. So here we will just rebuild the
10478 // entire app window list. Fun!
10479 mAppTransitionRunning = false;
10480 needRelayout = true;
10481 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010482 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010483 // Clear information about apps that were moving.
10484 mToBottomApps.clear();
10485 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010487 if (focusDisplayed) {
10488 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10489 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010490 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010491 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010492 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010493 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010494 requestAnimationLocked(0);
10495 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010496 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10497 }
Jeff Browneb857f12010-07-16 10:06:33 -070010498
Jeff Browne33348b2010-07-15 23:54:05 -070010499 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010500
Jeff Brown8e03b752010-06-13 19:16:55 -070010501 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10503 mPowerManager.setScreenBrightnessOverride(-1);
10504 } else {
10505 mPowerManager.setScreenBrightnessOverride((int)
10506 (screenBrightness * Power.BRIGHTNESS_ON));
10507 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010508 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10509 mPowerManager.setButtonBrightnessOverride(-1);
10510 } else {
10511 mPowerManager.setButtonBrightnessOverride((int)
10512 (buttonBrightness * Power.BRIGHTNESS_ON));
10513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 if (holdScreen != mHoldingScreenOn) {
10515 mHoldingScreenOn = holdScreen;
10516 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10517 mH.sendMessage(m);
10518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010519
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010520 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010521 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010522 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10523 LocalPowerManager.BUTTON_EVENT, true);
10524 mTurnOnScreen = false;
10525 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010526
10527 // Check to see if we are now in a state where the screen should
10528 // be enabled, because the window obscured flags have changed.
10529 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010530 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010531
10532 /**
10533 * Must be called with the main window manager lock held.
10534 */
10535 void setHoldScreenLocked(boolean holding) {
10536 boolean state = mHoldingScreenWakeLock.isHeld();
10537 if (holding != state) {
10538 if (holding) {
10539 mHoldingScreenWakeLock.acquire();
10540 } else {
10541 mPolicy.screenOnStoppedLw();
10542 mHoldingScreenWakeLock.release();
10543 }
10544 }
10545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010546
10547 void requestAnimationLocked(long delay) {
10548 if (!mAnimationPending) {
10549 mAnimationPending = true;
10550 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10551 }
10552 }
Romain Guy06882f82009-06-10 13:36:04 -070010553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010554 /**
10555 * Have the surface flinger show a surface, robustly dealing with
10556 * error conditions. In particular, if there is not enough memory
10557 * to show the surface, then we will try to get rid of other surfaces
10558 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010559 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010560 * @return Returns true if the surface was successfully shown.
10561 */
10562 boolean showSurfaceRobustlyLocked(WindowState win) {
10563 try {
10564 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010565 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010566 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010567 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010568 if (DEBUG_VISIBILITY) Slog.v(TAG,
10569 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010570 win.mTurnOnScreen = false;
10571 mTurnOnScreen = true;
10572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 }
10574 return true;
10575 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010576 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010577 }
Romain Guy06882f82009-06-10 13:36:04 -070010578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 return false;
10582 }
Romain Guy06882f82009-06-10 13:36:04 -070010583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10585 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010586
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010587 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590 if (mForceRemoves == null) {
10591 mForceRemoves = new ArrayList<WindowState>();
10592 }
Romain Guy06882f82009-06-10 13:36:04 -070010593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 long callingIdentity = Binder.clearCallingIdentity();
10595 try {
10596 // There was some problem... first, do a sanity check of the
10597 // window list to make sure we haven't left any dangling surfaces
10598 // around.
10599 int N = mWindows.size();
10600 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010601 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010602 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010603 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010604 if (ws.mSurface != null) {
10605 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010606 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 + ws + " surface=" + ws.mSurface
10608 + " token=" + win.mToken
10609 + " pid=" + ws.mSession.mPid
10610 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010611 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010612 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010613 ws.mSurface = null;
10614 mForceRemoves.add(ws);
10615 i--;
10616 N--;
10617 leakedSurface = true;
10618 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010619 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 + ws + " surface=" + ws.mSurface
10621 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010622 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010623 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010624 ws.mSurface = null;
10625 leakedSurface = true;
10626 }
10627 }
10628 }
Romain Guy06882f82009-06-10 13:36:04 -070010629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010630 boolean killedApps = false;
10631 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010632 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010633 SparseIntArray pidCandidates = new SparseIntArray();
10634 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010635 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010636 if (ws.mSurface != null) {
10637 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10638 }
10639 }
10640 if (pidCandidates.size() > 0) {
10641 int[] pids = new int[pidCandidates.size()];
10642 for (int i=0; i<pids.length; i++) {
10643 pids[i] = pidCandidates.keyAt(i);
10644 }
10645 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010646 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 killedApps = true;
10648 }
10649 } catch (RemoteException e) {
10650 }
10651 }
10652 }
Romain Guy06882f82009-06-10 13:36:04 -070010653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010654 if (leakedSurface || killedApps) {
10655 // We managed to reclaim some memory, so get rid of the trouble
10656 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010657 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010658 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010659 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010660 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010661 win.mSurface = null;
10662 }
Romain Guy06882f82009-06-10 13:36:04 -070010663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 try {
10665 win.mClient.dispatchGetNewSurface();
10666 } catch (RemoteException e) {
10667 }
10668 }
10669 } finally {
10670 Binder.restoreCallingIdentity(callingIdentity);
10671 }
10672 }
Romain Guy06882f82009-06-10 13:36:04 -070010673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010674 private boolean updateFocusedWindowLocked(int mode) {
10675 WindowState newFocus = computeFocusedWindowLocked();
10676 if (mCurrentFocus != newFocus) {
10677 // This check makes sure that we don't already have the focus
10678 // change message pending.
10679 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10680 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010681 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010682 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10683 final WindowState oldFocus = mCurrentFocus;
10684 mCurrentFocus = newFocus;
10685 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010687 final WindowState imWindow = mInputMethodWindow;
10688 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010689 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010690 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010691 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10692 mLayoutNeeded = true;
10693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010694 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010695 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010696 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10697 // Client will do the layout, but we need to assign layers
10698 // for handleNewWindowLocked() below.
10699 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010700 }
10701 }
Jeff Brown349703e2010-06-22 01:27:15 -070010702
10703 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10704 // If we defer assigning layers, then the caller is responsible for
10705 // doing this part.
10706 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010708 return true;
10709 }
10710 return false;
10711 }
Jeff Brown349703e2010-06-22 01:27:15 -070010712
10713 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010714 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010715 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010716
10717 private WindowState computeFocusedWindowLocked() {
10718 WindowState result = null;
10719 WindowState win;
10720
10721 int i = mWindows.size() - 1;
10722 int nextAppIndex = mAppTokens.size()-1;
10723 WindowToken nextApp = nextAppIndex >= 0
10724 ? mAppTokens.get(nextAppIndex) : null;
10725
10726 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010727 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010728
Joe Onorato8a9b2202010-02-26 18:56:32 -080010729 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010730 TAG, "Looking for focus: " + i
10731 + " = " + win
10732 + ", flags=" + win.mAttrs.flags
10733 + ", canReceive=" + win.canReceiveKeys());
10734
10735 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010737 // If this window's application has been removed, just skip it.
10738 if (thisApp != null && thisApp.removed) {
10739 i--;
10740 continue;
10741 }
Romain Guy06882f82009-06-10 13:36:04 -070010742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010743 // If there is a focused app, don't allow focus to go to any
10744 // windows below it. If this is an application window, step
10745 // through the app tokens until we find its app.
10746 if (thisApp != null && nextApp != null && thisApp != nextApp
10747 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10748 int origAppIndex = nextAppIndex;
10749 while (nextAppIndex > 0) {
10750 if (nextApp == mFocusedApp) {
10751 // Whoops, we are below the focused app... no focus
10752 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010753 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010754 TAG, "Reached focused app: " + mFocusedApp);
10755 return null;
10756 }
10757 nextAppIndex--;
10758 nextApp = mAppTokens.get(nextAppIndex);
10759 if (nextApp == thisApp) {
10760 break;
10761 }
10762 }
10763 if (thisApp != nextApp) {
10764 // Uh oh, the app token doesn't exist! This shouldn't
10765 // happen, but if it does we can get totally hosed...
10766 // so restart at the original app.
10767 nextAppIndex = origAppIndex;
10768 nextApp = mAppTokens.get(nextAppIndex);
10769 }
10770 }
10771
10772 // Dispatch to this window if it is wants key events.
10773 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010774 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 TAG, "Found focus @ " + i + " = " + win);
10776 result = win;
10777 break;
10778 }
10779
10780 i--;
10781 }
10782
10783 return result;
10784 }
10785
10786 private void startFreezingDisplayLocked() {
10787 if (mDisplayFrozen) {
10788 return;
10789 }
Romain Guy06882f82009-06-10 13:36:04 -070010790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010791 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010794 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010795 if (mFreezeGcPending != 0) {
10796 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010797 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010798 mH.removeMessages(H.FORCE_GC);
10799 Runtime.getRuntime().gc();
10800 mFreezeGcPending = now;
10801 }
10802 } else {
10803 mFreezeGcPending = now;
10804 }
Romain Guy06882f82009-06-10 13:36:04 -070010805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010807
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010808 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010809
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010810 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10811 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010812 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 mAppTransitionReady = true;
10814 }
Romain Guy06882f82009-06-10 13:36:04 -070010815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010816 if (PROFILE_ORIENTATION) {
10817 File file = new File("/data/system/frozen");
10818 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10819 }
10820 Surface.freezeDisplay(0);
10821 }
Romain Guy06882f82009-06-10 13:36:04 -070010822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010823 private void stopFreezingDisplayLocked() {
10824 if (!mDisplayFrozen) {
10825 return;
10826 }
Romain Guy06882f82009-06-10 13:36:04 -070010827
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010828 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10829 return;
10830 }
10831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010832 mDisplayFrozen = false;
10833 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10834 if (PROFILE_ORIENTATION) {
10835 Debug.stopMethodTracing();
10836 }
10837 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010838
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010839 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010840
Christopher Tateb696aee2010-04-02 19:08:30 -070010841 // While the display is frozen we don't re-compute the orientation
10842 // to avoid inconsistent states. However, something interesting
10843 // could have actually changed during that time so re-evaluate it
10844 // now to catch that.
10845 if (updateOrientationFromAppTokensLocked()) {
10846 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10847 }
10848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 // A little kludge: a lot could have happened while the
10850 // display was frozen, so now that we are coming back we
10851 // do a gc so that any remote references the system
10852 // processes holds on others can be released if they are
10853 // no longer needed.
10854 mH.removeMessages(H.FORCE_GC);
10855 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10856 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010858 mScreenFrozenLock.release();
10859 }
Romain Guy06882f82009-06-10 13:36:04 -070010860
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010861 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10862 DisplayMetrics dm) {
10863 if (index < tokens.length) {
10864 String str = tokens[index];
10865 if (str != null && str.length() > 0) {
10866 try {
10867 int val = Integer.parseInt(str);
10868 return val;
10869 } catch (Exception e) {
10870 }
10871 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010872 }
10873 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10874 return defDps;
10875 }
10876 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10877 return val;
10878 }
10879
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010880 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010881 final String[] mTokens;
10882 final String mText;
10883 final Paint mTextPaint;
10884 final int mTextWidth;
10885 final int mTextHeight;
10886 final int mTextAscent;
10887 final int mTextDescent;
10888 final int mDeltaX;
10889 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010890
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010891 Surface mSurface;
10892 int mLastDW;
10893 int mLastDH;
10894 boolean mDrawNeeded;
10895
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010896 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010897 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010898 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010899
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010900 if (false) {
10901 Log.i(TAG, "*********************** WATERMARK");
10902 for (int i=0; i<tokens.length; i++) {
10903 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10904 }
10905 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010906
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010907 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010908
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010909 StringBuilder builder = new StringBuilder(32);
10910 int len = mTokens[0].length();
10911 len = len & ~1;
10912 for (int i=0; i<len; i+=2) {
10913 int c1 = mTokens[0].charAt(i);
10914 int c2 = mTokens[0].charAt(i+1);
10915 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10916 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10917 else c1 -= '0';
10918 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10919 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10920 else c2 -= '0';
10921 builder.append((char)(255-((c1*16)+c2)));
10922 }
10923 mText = builder.toString();
10924 if (false) {
10925 Log.i(TAG, "Final text: " + mText);
10926 }
10927
10928 int fontSize = getPropertyInt(tokens, 1,
10929 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10930
10931 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10932 mTextPaint.setTextSize(fontSize);
10933 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10934
10935 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10936 mTextWidth = (int)mTextPaint.measureText(mText);
10937 mTextAscent = fm.ascent;
10938 mTextDescent = fm.descent;
10939 mTextHeight = fm.descent - fm.ascent;
10940
10941 mDeltaX = getPropertyInt(tokens, 2,
10942 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10943 mDeltaY = getPropertyInt(tokens, 3,
10944 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10945 int shadowColor = getPropertyInt(tokens, 4,
10946 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10947 int color = getPropertyInt(tokens, 5,
10948 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10949 int shadowRadius = getPropertyInt(tokens, 6,
10950 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10951 int shadowDx = getPropertyInt(tokens, 8,
10952 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10953 int shadowDy = getPropertyInt(tokens, 9,
10954 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10955
10956 mTextPaint.setColor(color);
10957 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010958
10959 try {
10960 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010961 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010962 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010963 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010964 mSurface.show();
10965 } catch (OutOfResourcesException e) {
10966 }
10967 }
10968
10969 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010970 if (mLastDW != dw || mLastDH != dh) {
10971 mLastDW = dw;
10972 mLastDH = dh;
10973 mSurface.setSize(dw, dh);
10974 mDrawNeeded = true;
10975 }
10976 }
10977
10978 void drawIfNeeded() {
10979 if (mDrawNeeded) {
10980 final int dw = mLastDW;
10981 final int dh = mLastDH;
10982
10983 mDrawNeeded = false;
10984 Rect dirty = new Rect(0, 0, dw, dh);
10985 Canvas c = null;
10986 try {
10987 c = mSurface.lockCanvas(dirty);
10988 } catch (IllegalArgumentException e) {
10989 } catch (OutOfResourcesException e) {
10990 }
10991 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010992 c.drawColor(0, PorterDuff.Mode.CLEAR);
10993
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010994 int deltaX = mDeltaX;
10995 int deltaY = mDeltaY;
10996
10997 // deltaX shouldn't be close to a round fraction of our
10998 // x step, or else things will line up too much.
10999 int div = (dw+mTextWidth)/deltaX;
11000 int rem = (dw+mTextWidth) - (div*deltaX);
11001 int qdelta = deltaX/4;
11002 if (rem < qdelta || rem > (deltaX-qdelta)) {
11003 deltaX += deltaX/3;
11004 }
11005
11006 int y = -mTextHeight;
11007 int x = -mTextWidth;
11008 while (y < (dh+mTextHeight)) {
11009 c.drawText(mText, x, y, mTextPaint);
11010 x += deltaX;
11011 if (x >= dw) {
11012 x -= (dw+mTextWidth);
11013 y += deltaY;
11014 }
11015 }
11016 mSurface.unlockCanvasAndPost(c);
11017 }
11018 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011019 }
11020 }
11021
11022 void createWatermark() {
11023 if (mWatermark != null) {
11024 return;
11025 }
11026
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011027 File file = new File("/system/etc/setup.conf");
11028 FileInputStream in = null;
11029 try {
11030 in = new FileInputStream(file);
11031 DataInputStream ind = new DataInputStream(in);
11032 String line = ind.readLine();
11033 if (line != null) {
11034 String[] toks = line.split("%");
11035 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011036 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011037 }
11038 }
11039 } catch (FileNotFoundException e) {
11040 } catch (IOException e) {
11041 } finally {
11042 if (in != null) {
11043 try {
11044 in.close();
11045 } catch (IOException e) {
11046 }
11047 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011048 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011049 }
11050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011051 @Override
11052 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11053 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11054 != PackageManager.PERMISSION_GRANTED) {
11055 pw.println("Permission Denial: can't dump WindowManager from from pid="
11056 + Binder.getCallingPid()
11057 + ", uid=" + Binder.getCallingUid());
11058 return;
11059 }
Romain Guy06882f82009-06-10 13:36:04 -070011060
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011061 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011062 pw.println(" ");
11063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011064 synchronized(mWindowMap) {
11065 pw.println("Current Window Manager state:");
11066 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011067 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011068 pw.print(" Window #"); pw.print(i); pw.print(' ');
11069 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011070 w.dump(pw, " ");
11071 }
11072 if (mInputMethodDialogs.size() > 0) {
11073 pw.println(" ");
11074 pw.println(" Input method dialogs:");
11075 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11076 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011077 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011078 }
11079 }
11080 if (mPendingRemove.size() > 0) {
11081 pw.println(" ");
11082 pw.println(" Remove pending for:");
11083 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11084 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011085 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11086 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011087 w.dump(pw, " ");
11088 }
11089 }
11090 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11091 pw.println(" ");
11092 pw.println(" Windows force removing:");
11093 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11094 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011095 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11096 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011097 w.dump(pw, " ");
11098 }
11099 }
11100 if (mDestroySurface.size() > 0) {
11101 pw.println(" ");
11102 pw.println(" Windows waiting to destroy their surface:");
11103 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11104 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011105 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11106 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011107 w.dump(pw, " ");
11108 }
11109 }
11110 if (mLosingFocus.size() > 0) {
11111 pw.println(" ");
11112 pw.println(" Windows losing focus:");
11113 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11114 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011115 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11116 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011117 w.dump(pw, " ");
11118 }
11119 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011120 if (mResizingWindows.size() > 0) {
11121 pw.println(" ");
11122 pw.println(" Windows waiting to resize:");
11123 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11124 WindowState w = mResizingWindows.get(i);
11125 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11126 pw.print(w); pw.println(":");
11127 w.dump(pw, " ");
11128 }
11129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011130 if (mSessions.size() > 0) {
11131 pw.println(" ");
11132 pw.println(" All active sessions:");
11133 Iterator<Session> it = mSessions.iterator();
11134 while (it.hasNext()) {
11135 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011136 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011137 s.dump(pw, " ");
11138 }
11139 }
11140 if (mTokenMap.size() > 0) {
11141 pw.println(" ");
11142 pw.println(" All tokens:");
11143 Iterator<WindowToken> it = mTokenMap.values().iterator();
11144 while (it.hasNext()) {
11145 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011146 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011147 token.dump(pw, " ");
11148 }
11149 }
11150 if (mTokenList.size() > 0) {
11151 pw.println(" ");
11152 pw.println(" Window token list:");
11153 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011154 pw.print(" #"); pw.print(i); pw.print(": ");
11155 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011156 }
11157 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011158 if (mWallpaperTokens.size() > 0) {
11159 pw.println(" ");
11160 pw.println(" Wallpaper tokens:");
11161 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11162 WindowToken token = mWallpaperTokens.get(i);
11163 pw.print(" Wallpaper #"); pw.print(i);
11164 pw.print(' '); pw.print(token); pw.println(':');
11165 token.dump(pw, " ");
11166 }
11167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011168 if (mAppTokens.size() > 0) {
11169 pw.println(" ");
11170 pw.println(" Application tokens in Z order:");
11171 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011172 pw.print(" App #"); pw.print(i); pw.print(": ");
11173 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011174 }
11175 }
11176 if (mFinishedStarting.size() > 0) {
11177 pw.println(" ");
11178 pw.println(" Finishing start of application tokens:");
11179 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11180 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011181 pw.print(" Finished Starting #"); pw.print(i);
11182 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011183 token.dump(pw, " ");
11184 }
11185 }
11186 if (mExitingTokens.size() > 0) {
11187 pw.println(" ");
11188 pw.println(" Exiting tokens:");
11189 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11190 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011191 pw.print(" Exiting #"); pw.print(i);
11192 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011193 token.dump(pw, " ");
11194 }
11195 }
11196 if (mExitingAppTokens.size() > 0) {
11197 pw.println(" ");
11198 pw.println(" Exiting application tokens:");
11199 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11200 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011201 pw.print(" Exiting App #"); pw.print(i);
11202 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011203 token.dump(pw, " ");
11204 }
11205 }
11206 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011207 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11208 pw.print(" mLastFocus="); pw.println(mLastFocus);
11209 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11210 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11211 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011212 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011213 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11214 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11215 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11216 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011217 if (mWindowDetachedWallpaper != null) {
11218 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11219 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011220 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11221 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11222 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011223 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11224 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11225 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11226 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011227 if (mDimAnimator != null) {
11228 mDimAnimator.printTo(pw);
11229 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011230 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011231 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011232 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011233 pw.print(mInputMethodAnimLayerAdjustment);
11234 pw.print(" mWallpaperAnimLayerAdjustment=");
11235 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011236 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11237 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011238 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11239 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011240 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11241 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011242 pw.print(" mRotation="); pw.print(mRotation);
11243 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11244 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11245 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11246 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11247 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11248 pw.print(" mNextAppTransition=0x");
11249 pw.print(Integer.toHexString(mNextAppTransition));
11250 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011251 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011252 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011253 if (mNextAppTransitionPackage != null) {
11254 pw.print(" mNextAppTransitionPackage=");
11255 pw.print(mNextAppTransitionPackage);
11256 pw.print(", mNextAppTransitionEnter=0x");
11257 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11258 pw.print(", mNextAppTransitionExit=0x");
11259 pw.print(Integer.toHexString(mNextAppTransitionExit));
11260 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011261 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11262 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011263 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11264 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11265 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11266 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011267 if (mOpeningApps.size() > 0) {
11268 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11269 }
11270 if (mClosingApps.size() > 0) {
11271 pw.print(" mClosingApps="); pw.println(mClosingApps);
11272 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011273 if (mToTopApps.size() > 0) {
11274 pw.print(" mToTopApps="); pw.println(mToTopApps);
11275 }
11276 if (mToBottomApps.size() > 0) {
11277 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11278 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011279 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11280 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011281 }
11282 }
11283
Jeff Brown349703e2010-06-22 01:27:15 -070011284 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011285 public void monitor() {
11286 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011287 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011289
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011290 /**
11291 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011292 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011293 */
11294 private static class DimAnimator {
11295 Surface mDimSurface;
11296 boolean mDimShown = false;
11297 float mDimCurrentAlpha;
11298 float mDimTargetAlpha;
11299 float mDimDeltaPerMs;
11300 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011301
11302 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011303
11304 DimAnimator (SurfaceSession session) {
11305 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011306 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011307 + mDimSurface + ": CREATE");
11308 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011309 mDimSurface = new Surface(session, 0,
11310 "DimSurface",
11311 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011312 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011313 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011314 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011315 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011316 }
11317 }
11318 }
11319
11320 /**
11321 * Show the dim surface.
11322 */
11323 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011324 if (!mDimShown) {
11325 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11326 dw + "x" + dh + ")");
11327 mDimShown = true;
11328 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011329 mLastDimWidth = dw;
11330 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011331 mDimSurface.setPosition(0, 0);
11332 mDimSurface.setSize(dw, dh);
11333 mDimSurface.show();
11334 } catch (RuntimeException e) {
11335 Slog.w(TAG, "Failure showing dim surface", e);
11336 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011337 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11338 mLastDimWidth = dw;
11339 mLastDimHeight = dh;
11340 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011341 }
11342 }
11343
11344 /**
11345 * Set's the dim surface's layer and update dim parameters that will be used in
11346 * {@link updateSurface} after all windows are examined.
11347 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011348 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011349 mDimSurface.setLayer(w.mAnimLayer-1);
11350
11351 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011352 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011353 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011354 if (mDimTargetAlpha != target) {
11355 // If the desired dim level has changed, then
11356 // start an animation to it.
11357 mLastDimAnimTime = currentTime;
11358 long duration = (w.mAnimating && w.mAnimation != null)
11359 ? w.mAnimation.computeDurationHint()
11360 : DEFAULT_DIM_DURATION;
11361 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011362 TypedValue tv = new TypedValue();
11363 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11364 tv, true);
11365 if (tv.type == TypedValue.TYPE_FRACTION) {
11366 duration = (long)tv.getFraction((float)duration, (float)duration);
11367 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11368 && tv.type <= TypedValue.TYPE_LAST_INT) {
11369 duration = tv.data;
11370 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011371 }
11372 if (duration < 1) {
11373 // Don't divide by zero
11374 duration = 1;
11375 }
11376 mDimTargetAlpha = target;
11377 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11378 }
11379 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011380
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011381 /**
11382 * Updating the surface's alpha. Returns true if the animation continues, or returns
11383 * false when the animation is finished and the dim surface is hidden.
11384 */
11385 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11386 if (!dimming) {
11387 if (mDimTargetAlpha != 0) {
11388 mLastDimAnimTime = currentTime;
11389 mDimTargetAlpha = 0;
11390 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11391 }
11392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011393
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011394 boolean animating = false;
11395 if (mLastDimAnimTime != 0) {
11396 mDimCurrentAlpha += mDimDeltaPerMs
11397 * (currentTime-mLastDimAnimTime);
11398 boolean more = true;
11399 if (displayFrozen) {
11400 // If the display is frozen, there is no reason to animate.
11401 more = false;
11402 } else if (mDimDeltaPerMs > 0) {
11403 if (mDimCurrentAlpha > mDimTargetAlpha) {
11404 more = false;
11405 }
11406 } else if (mDimDeltaPerMs < 0) {
11407 if (mDimCurrentAlpha < mDimTargetAlpha) {
11408 more = false;
11409 }
11410 } else {
11411 more = false;
11412 }
11413
11414 // Do we need to continue animating?
11415 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011416 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011417 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11418 mLastDimAnimTime = currentTime;
11419 mDimSurface.setAlpha(mDimCurrentAlpha);
11420 animating = true;
11421 } else {
11422 mDimCurrentAlpha = mDimTargetAlpha;
11423 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011424 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011425 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11426 mDimSurface.setAlpha(mDimCurrentAlpha);
11427 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011428 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011429 + ": HIDE");
11430 try {
11431 mDimSurface.hide();
11432 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011433 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011434 }
11435 mDimShown = false;
11436 }
11437 }
11438 }
11439 return animating;
11440 }
11441
11442 public void printTo(PrintWriter pw) {
11443 pw.print(" mDimShown="); pw.print(mDimShown);
11444 pw.print(" current="); pw.print(mDimCurrentAlpha);
11445 pw.print(" target="); pw.print(mDimTargetAlpha);
11446 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11447 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11448 }
11449 }
11450
11451 /**
11452 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11453 * This is used for opening/closing transition for apps in compatible mode.
11454 */
11455 private static class FadeInOutAnimation extends Animation {
11456 int mWidth;
11457 boolean mFadeIn;
11458
11459 public FadeInOutAnimation(boolean fadeIn) {
11460 setInterpolator(new AccelerateInterpolator());
11461 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11462 mFadeIn = fadeIn;
11463 }
11464
11465 @Override
11466 protected void applyTransformation(float interpolatedTime, Transformation t) {
11467 float x = interpolatedTime;
11468 if (!mFadeIn) {
11469 x = 1.0f - x; // reverse the interpolation for fade out
11470 }
11471 if (x < 0.5) {
11472 // move the window out of the screen.
11473 t.getMatrix().setTranslate(mWidth, 0);
11474 } else {
11475 t.getMatrix().setTranslate(0, 0);// show
11476 t.setAlpha((x - 0.5f) * 2);
11477 }
11478 }
11479
11480 @Override
11481 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11482 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11483 mWidth = width;
11484 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011485
11486 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011487 public int getZAdjustment() {
11488 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011489 }
11490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011491}