blob: 90cdb4b89c21d6907d5be431aa455e3f0d0ad6e0 [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;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070068import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.graphics.Rect;
70import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070071import android.graphics.Typeface;
72import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.BatteryStats;
74import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070075import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.Debug;
77import android.os.Handler;
78import android.os.IBinder;
79import android.os.LocalPowerManager;
80import android.os.Looper;
81import android.os.Message;
82import android.os.Parcel;
83import android.os.ParcelFileDescriptor;
84import android.os.Power;
85import android.os.PowerManager;
86import android.os.Process;
87import android.os.RemoteException;
88import android.os.ServiceManager;
89import 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;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700102import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103import android.view.IApplicationToken;
104import android.view.IOnKeyguardExitResult;
105import android.view.IRotationWatcher;
106import android.view.IWindow;
107import android.view.IWindowManager;
108import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700109import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700111import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700112import android.view.InputHandler;
113import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.KeyEvent;
115import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.Surface;
117import android.view.SurfaceSession;
118import android.view.View;
119import android.view.ViewTreeObserver;
120import android.view.WindowManager;
121import android.view.WindowManagerImpl;
122import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700123import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700125import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import android.view.animation.Animation;
127import android.view.animation.AnimationUtils;
128import android.view.animation.Transformation;
129
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700132import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133import java.io.File;
134import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700135import java.io.FileInputStream;
136import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137import java.io.IOException;
138import java.io.OutputStream;
139import java.io.OutputStreamWriter;
140import java.io.PrintWriter;
141import java.io.StringWriter;
142import java.net.Socket;
143import java.util.ArrayList;
144import java.util.HashMap;
145import java.util.HashSet;
146import java.util.Iterator;
147import java.util.List;
148
149/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700150public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700151 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final String TAG = "WindowManager";
153 static final boolean DEBUG = false;
154 static final boolean DEBUG_FOCUS = false;
155 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800156 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800157 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean DEBUG_LAYERS = false;
159 static final boolean DEBUG_INPUT = false;
160 static final boolean DEBUG_INPUT_METHOD = false;
161 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700162 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700164 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean DEBUG_APP_TRANSITIONS = false;
166 static final boolean DEBUG_STARTING_WINDOW = false;
167 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700168 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700169 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700171 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 static final boolean PROFILE_ORIENTATION = false;
174 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700175 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to multiply the policy's type layer, to reserve room
178 * for multiple windows of the same type and Z-ordering adjustment
179 * with TYPE_LAYER_OFFSET. */
180 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
183 * or below others in the same layer. */
184 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** How much to increment the layer for each window, to reserve room
187 * for effect surfaces between them.
188 */
189 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** The maximum length we will accept for a loaded animation duration:
192 * this is 10 seconds.
193 */
194 static final int MAX_ANIMATION_DURATION = 10*1000;
195
196 /** Amount of time (in milliseconds) to animate the dim surface from one
197 * value to another, when no window animation is driving it.
198 */
199 static final int DEFAULT_DIM_DURATION = 200;
200
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700201 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
202 * compatible windows.
203 */
204 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 /** Adjustment to time to perform a dim, to make it more dramatic.
207 */
208 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700209
210 // Maximum number of milliseconds to wait for input event injection.
211 // FIXME is this value reasonable?
212 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700213
214 // Default input dispatching timeout in nanoseconds.
215 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 static final int UPDATE_FOCUS_NORMAL = 0;
218 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
219 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
220 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700223 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
225 /**
226 * Condition waited on by {@link #reenableKeyguard} to know the call to
227 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500228 * This is set to true only if mKeyguardTokenWatcher.acquired() has
229 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500231 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232
Jim Miller284b62e2010-06-08 14:27:42 -0700233 private static final int ALLOW_DISABLE_YES = 1;
234 private static final int ALLOW_DISABLE_NO = 0;
235 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
236 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
237
Mike Lockwood983ee092009-11-22 01:42:24 -0500238 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
239 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700241 if (shouldAllowDisableKeyguard()) {
242 mPolicy.enableKeyguard(false);
243 mKeyguardDisabled = true;
244 } else {
245 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700249 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500250 synchronized (mKeyguardTokenWatcher) {
251 mKeyguardDisabled = false;
252 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 }
255 };
256
Jim Miller284b62e2010-06-08 14:27:42 -0700257 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
258 @Override
259 public void onReceive(Context context, Intent intent) {
260 mPolicy.enableKeyguard(true);
261 synchronized(mKeyguardTokenWatcher) {
262 // lazily evaluate this next time we're asked to disable keyguard
263 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
264 mKeyguardDisabled = false;
265 }
266 }
267 };
268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 final Context mContext;
270
271 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
276
277 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 /**
282 * All currently active sessions with clients.
283 */
284 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /**
287 * Mapping from an IWindow IBinder to the server's Window object.
288 * This is also used as the lock for all of our state.
289 */
290 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
291
292 /**
293 * Mapping from a token IBinder to a WindowToken object.
294 */
295 final HashMap<IBinder, WindowToken> mTokenMap =
296 new HashMap<IBinder, WindowToken>();
297
298 /**
299 * The same tokens as mTokenMap, stored in a list for efficient iteration
300 * over them.
301 */
302 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 /**
305 * Window tokens that are in the process of exiting, but still
306 * on screen for animations.
307 */
308 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
309
310 /**
311 * Z-ordered (bottom-most first) list of all application tokens, for
312 * controlling the ordering of windows in different applications. This
313 * contains WindowToken objects.
314 */
315 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * Application tokens that are in the process of exiting, but still
319 * on screen for animations.
320 */
321 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
322
323 /**
324 * List of window tokens that have finished starting their application,
325 * and now need to have the policy remove their windows.
326 */
327 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
328
329 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700330 * This was the app token that was used to retrieve the last enter
331 * animation. It will be used for the next exit animation.
332 */
333 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800334
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700335 /**
336 * These were the layout params used to retrieve the last enter animation.
337 * They will be used for the next exit animation.
338 */
339 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800340
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700341 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 * Z-ordered (bottom-most first) list of all Window objects.
343 */
Jeff Browne33348b2010-07-15 23:54:05 -0700344 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345
346 /**
347 * Windows that are being resized. Used so we can tell the client about
348 * the resize after closing the transaction in which we resized the
349 * underlying surface.
350 */
351 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
352
353 /**
354 * Windows whose animations have ended and now must be removed.
355 */
356 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
357
358 /**
359 * Windows whose surface should be destroyed.
360 */
361 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
362
363 /**
364 * Windows that have lost input focus and are waiting for the new
365 * focus window to be displayed before they are told about this.
366 */
367 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
368
369 /**
370 * This is set when we have run out of memory, and will either be an empty
371 * list or contain windows that need to be force removed.
372 */
373 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700378 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 Surface mBlurSurface;
380 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700381 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 final float[] mTmpFloats = new float[9];
386
387 boolean mSafeMode;
388 boolean mDisplayEnabled = false;
389 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700390 int mInitialDisplayWidth = 0;
391 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 int mRotation = 0;
393 int mRequestedRotation = 0;
394 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700395 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 ArrayList<IRotationWatcher> mRotationWatchers
397 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 boolean mLayoutNeeded = true;
400 boolean mAnimationPending = false;
401 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800402 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 boolean mWindowsFreezingScreen = false;
404 long mFreezeGcPending = 0;
405 int mAppsFreezingScreen = 0;
406
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800407 int mLayoutSeq = 0;
408
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800409 // State while inside of layoutAndPlaceSurfacesLocked().
410 boolean mFocusMayChange;
411
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800412 Configuration mCurConfiguration = new Configuration();
413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 // This is held as long as we have the screen frozen, to give us time to
415 // perform a rotation animation when turning off shows the lock screen which
416 // changes the orientation.
417 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 // State management of app transitions. When we are preparing for a
420 // transition, mNextAppTransition will be the kind of transition to
421 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
422 // mOpeningApps and mClosingApps are the lists of tokens that will be
423 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700424 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700425 String mNextAppTransitionPackage;
426 int mNextAppTransitionEnter;
427 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700429 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 boolean mAppTransitionTimeout = false;
431 boolean mStartingIconInTransition = false;
432 boolean mSkipAppTransitionAnimation = false;
433 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
434 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700435 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
436 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 H mH = new H();
441
442 WindowState mCurrentFocus = null;
443 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 // This just indicates the window the input method is on top of, not
446 // necessarily the window its input is going to.
447 WindowState mInputMethodTarget = null;
448 WindowState mUpcomingInputMethodTarget = null;
449 boolean mInputMethodTargetWaitingAnim;
450 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 WindowState mInputMethodWindow = null;
453 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
454
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700455 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800456
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 // If non-null, this is the currently visible window that is associated
458 // with the wallpaper.
459 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the lower one in Z-order.
462 WindowState mLowerWallpaperTarget = null;
463 // If non-null, we are in the middle of animating from one wallpaper target
464 // to another, and this is the higher one in Z-order.
465 WindowState mUpperWallpaperTarget = 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 Brown46b9ac02010-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 Brown46b9ac02010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-10-19 15:15:08 -0700663 mNotifiedWindows.clear();
664 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700665 evt.recycle();
666 }
667
Chris Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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
826 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
827 boolean endDrag = false;
828 final float newX = event.getRawX();
829 final float newY = event.getRawY();
830
831 try {
832 if (mDragState != null) {
833 switch (event.getAction()) {
834 case MotionEvent.ACTION_DOWN: {
835 if (DEBUG_DRAG) {
836 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
837 }
838 } break;
839
840 case MotionEvent.ACTION_MOVE: {
841 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700842 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700843 mDragState.notifyMoveLw(newX, newY);
844 }
845 } break;
846
847 case MotionEvent.ACTION_UP: {
848 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
849 + newX + "," + newY);
850 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700851 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700852 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700853 } break;
854
855 case MotionEvent.ACTION_CANCEL: {
856 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
857 endDrag = true;
858 } break;
859 }
860
861 if (endDrag) {
862 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
863 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700864 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700865 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700866 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700867 }
868 }
869 } catch (Exception e) {
870 Slog.e(TAG, "Exception caught by drag handleMotion", e);
871 } finally {
872 finishedCallback.run();
873 }
874 }
875 };
876
877 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 * Whether the UI is currently running in touch mode (not showing
879 * navigational focus because the user is directly pressing the screen).
880 */
881 boolean mInTouchMode = false;
882
883 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700884 private ArrayList<WindowChangeListener> mWindowChangeListeners =
885 new ArrayList<WindowChangeListener>();
886 private boolean mWindowsChanged = false;
887
888 public interface WindowChangeListener {
889 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700890 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892
Dianne Hackbornc485a602009-03-24 22:39:49 -0700893 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700894 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700895
896 // The frame use to limit the size of the app running in compatibility mode.
897 Rect mCompatibleScreenFrame = new Rect();
898 // The surface used to fill the outer rim of the app running in compatibility mode.
899 Surface mBackgroundFillerSurface = null;
900 boolean mBackgroundFillerShown = false;
901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 public static WindowManagerService main(Context context,
903 PowerManagerService pm, boolean haveInputMethods) {
904 WMThread thr = new WMThread(context, pm, haveInputMethods);
905 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 synchronized (thr) {
908 while (thr.mService == null) {
909 try {
910 thr.wait();
911 } catch (InterruptedException e) {
912 }
913 }
914 }
Romain Guy06882f82009-06-10 13:36:04 -0700915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 return thr.mService;
917 }
Romain Guy06882f82009-06-10 13:36:04 -0700918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 static class WMThread extends Thread {
920 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 private final Context mContext;
923 private final PowerManagerService mPM;
924 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 public WMThread(Context context, PowerManagerService pm,
927 boolean haveInputMethods) {
928 super("WindowManager");
929 mContext = context;
930 mPM = pm;
931 mHaveInputMethods = haveInputMethods;
932 }
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 public void run() {
935 Looper.prepare();
936 WindowManagerService s = new WindowManagerService(mContext, mPM,
937 mHaveInputMethods);
938 android.os.Process.setThreadPriority(
939 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700940 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 synchronized (this) {
943 mService = s;
944 notifyAll();
945 }
Romain Guy06882f82009-06-10 13:36:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 Looper.loop();
948 }
949 }
950
951 static class PolicyThread extends Thread {
952 private final WindowManagerPolicy mPolicy;
953 private final WindowManagerService mService;
954 private final Context mContext;
955 private final PowerManagerService mPM;
956 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 public PolicyThread(WindowManagerPolicy policy,
959 WindowManagerService service, Context context,
960 PowerManagerService pm) {
961 super("WindowManagerPolicy");
962 mPolicy = policy;
963 mService = service;
964 mContext = context;
965 mPM = pm;
966 }
Romain Guy06882f82009-06-10 13:36:04 -0700967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 public void run() {
969 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800970 WindowManagerPolicyThread.set(this, Looper.myLooper());
971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800973 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 android.os.Process.setThreadPriority(
975 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700976 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 synchronized (this) {
980 mRunning = true;
981 notifyAll();
982 }
Romain Guy06882f82009-06-10 13:36:04 -0700983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 Looper.loop();
985 }
986 }
987
988 private WindowManagerService(Context context, PowerManagerService pm,
989 boolean haveInputMethods) {
990 mContext = context;
991 mHaveInputMethods = haveInputMethods;
992 mLimitedAlphaCompositing = context.getResources().getBoolean(
993 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 mPowerManager = pm;
996 mPowerManager.setPolicy(mPolicy);
997 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
998 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
999 "SCREEN_FROZEN");
1000 mScreenFrozenLock.setReferenceCounted(false);
1001
1002 mActivityManager = ActivityManagerNative.getDefault();
1003 mBatteryStats = BatteryStatsService.getService();
1004
1005 // Get persisted window scale setting
1006 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1007 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1008 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1009 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001010
Jim Miller284b62e2010-06-08 14:27:42 -07001011 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1012 IntentFilter filter = new IntentFilter();
1013 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1014 mContext.registerReceiver(mBroadcastReceiver, filter);
1015
Jeff Brown46b9ac02010-04-22 18:58:52 -07001016 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1017 "KEEP_SCREEN_ON_FLAG");
1018 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019
Jeff Browne33348b2010-07-15 23:54:05 -07001020 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1023 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 synchronized (thr) {
1026 while (!thr.mRunning) {
1027 try {
1028 thr.wait();
1029 } catch (InterruptedException e) {
1030 }
1031 }
1032 }
Romain Guy06882f82009-06-10 13:36:04 -07001033
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001034 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 // Add ourself to the Watchdog monitors.
1037 Watchdog.getInstance().addMonitor(this);
1038 }
1039
1040 @Override
1041 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1042 throws RemoteException {
1043 try {
1044 return super.onTransact(code, data, reply, flags);
1045 } catch (RuntimeException e) {
1046 // The window manager only throws security exceptions, so let's
1047 // log all others.
1048 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001049 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 }
1051 throw e;
1052 }
1053 }
1054
Jeff Browne33348b2010-07-15 23:54:05 -07001055 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001057 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 TAG, "Adding window " + window + " at "
1059 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1060 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001061 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 }
1063
Jeff Browne33348b2010-07-15 23:54:05 -07001064 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 TAG, "Adding window " + window + " at "
1068 + i + " of " + mWindows.size() + " (before " + pos + ")");
1069 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001070 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 }
1072
1073 //This method finds out the index of a window that has the same app token as
1074 //win. used for z ordering the windows in mWindows
1075 private int findIdxBasedOnAppTokens(WindowState win) {
1076 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001077 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 int jmax = localmWindows.size();
1079 if(jmax == 0) {
1080 return -1;
1081 }
1082 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001083 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 if(wentry.mAppToken == win.mAppToken) {
1085 return j;
1086 }
1087 }
1088 return -1;
1089 }
Romain Guy06882f82009-06-10 13:36:04 -07001090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1092 final IWindow client = win.mClient;
1093 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001094 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 final int N = localmWindows.size();
1097 final WindowState attached = win.mAttachedWindow;
1098 int i;
1099 if (attached == null) {
1100 int tokenWindowsPos = token.windows.size();
1101 if (token.appWindowToken != null) {
1102 int index = tokenWindowsPos-1;
1103 if (index >= 0) {
1104 // If this application has existing windows, we
1105 // simply place the new window on top of them... but
1106 // keep the starting window on top.
1107 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1108 // Base windows go behind everything else.
1109 placeWindowBefore(token.windows.get(0), win);
1110 tokenWindowsPos = 0;
1111 } else {
1112 AppWindowToken atoken = win.mAppToken;
1113 if (atoken != null &&
1114 token.windows.get(index) == atoken.startingWindow) {
1115 placeWindowBefore(token.windows.get(index), win);
1116 tokenWindowsPos--;
1117 } else {
1118 int newIdx = findIdxBasedOnAppTokens(win);
1119 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001120 //there is a window above this one associated with the same
1121 //apptoken note that the window could be a floating window
1122 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001124 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001125 TAG, "Adding window " + win + " at "
1126 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001128 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 }
1131 }
1132 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001133 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 TAG, "Figuring out where to add app window "
1135 + client.asBinder() + " (token=" + token + ")");
1136 // Figure out where the window should go, based on the
1137 // order of applications.
1138 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001139 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 for (i=NA-1; i>=0; i--) {
1141 AppWindowToken t = mAppTokens.get(i);
1142 if (t == token) {
1143 i--;
1144 break;
1145 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001146
Dianne Hackborna8f60182009-09-01 19:01:50 -07001147 // We haven't reached the token yet; if this token
1148 // is not going to the bottom and has windows, we can
1149 // use it as an anchor for when we do reach the token.
1150 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 pos = t.windows.get(0);
1152 }
1153 }
1154 // We now know the index into the apps. If we found
1155 // an app window above, that gives us the position; else
1156 // we need to look some more.
1157 if (pos != null) {
1158 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001159 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 if (atoken != null) {
1161 final int NC = atoken.windows.size();
1162 if (NC > 0) {
1163 WindowState bottom = atoken.windows.get(0);
1164 if (bottom.mSubLayer < 0) {
1165 pos = bottom;
1166 }
1167 }
1168 }
1169 placeWindowBefore(pos, win);
1170 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001171 // Continue looking down until we find the first
1172 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 while (i >= 0) {
1174 AppWindowToken t = mAppTokens.get(i);
1175 final int NW = t.windows.size();
1176 if (NW > 0) {
1177 pos = t.windows.get(NW-1);
1178 break;
1179 }
1180 i--;
1181 }
1182 if (pos != null) {
1183 // Move in front of any windows attached to this
1184 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001185 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 if (atoken != null) {
1187 final int NC = atoken.windows.size();
1188 if (NC > 0) {
1189 WindowState top = atoken.windows.get(NC-1);
1190 if (top.mSubLayer >= 0) {
1191 pos = top;
1192 }
1193 }
1194 }
1195 placeWindowAfter(pos, win);
1196 } else {
1197 // Just search for the start of this layer.
1198 final int myLayer = win.mBaseLayer;
1199 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001200 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 if (w.mBaseLayer > myLayer) {
1202 break;
1203 }
1204 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001205 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001206 TAG, "Adding window " + win + " at "
1207 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001209 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 }
1211 }
1212 }
1213 } else {
1214 // Figure out where window should go, based on layer.
1215 final int myLayer = win.mBaseLayer;
1216 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001217 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 i++;
1219 break;
1220 }
1221 }
1222 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001223 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001224 TAG, "Adding window " + win + " at "
1225 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001227 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 }
1229 if (addToToken) {
1230 token.windows.add(tokenWindowsPos, win);
1231 }
1232
1233 } else {
1234 // Figure out this window's ordering relative to the window
1235 // it is attached to.
1236 final int NA = token.windows.size();
1237 final int sublayer = win.mSubLayer;
1238 int largestSublayer = Integer.MIN_VALUE;
1239 WindowState windowWithLargestSublayer = null;
1240 for (i=0; i<NA; i++) {
1241 WindowState w = token.windows.get(i);
1242 final int wSublayer = w.mSubLayer;
1243 if (wSublayer >= largestSublayer) {
1244 largestSublayer = wSublayer;
1245 windowWithLargestSublayer = w;
1246 }
1247 if (sublayer < 0) {
1248 // For negative sublayers, we go below all windows
1249 // in the same sublayer.
1250 if (wSublayer >= sublayer) {
1251 if (addToToken) {
1252 token.windows.add(i, win);
1253 }
1254 placeWindowBefore(
1255 wSublayer >= 0 ? attached : w, win);
1256 break;
1257 }
1258 } else {
1259 // For positive sublayers, we go above all windows
1260 // in the same sublayer.
1261 if (wSublayer > sublayer) {
1262 if (addToToken) {
1263 token.windows.add(i, win);
1264 }
1265 placeWindowBefore(w, win);
1266 break;
1267 }
1268 }
1269 }
1270 if (i >= NA) {
1271 if (addToToken) {
1272 token.windows.add(win);
1273 }
1274 if (sublayer < 0) {
1275 placeWindowBefore(attached, win);
1276 } else {
1277 placeWindowAfter(largestSublayer >= 0
1278 ? windowWithLargestSublayer
1279 : attached,
1280 win);
1281 }
1282 }
1283 }
Romain Guy06882f82009-06-10 13:36:04 -07001284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 if (win.mAppToken != null && addToToken) {
1286 win.mAppToken.allAppWindows.add(win);
1287 }
1288 }
Romain Guy06882f82009-06-10 13:36:04 -07001289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 static boolean canBeImeTarget(WindowState w) {
1291 final int fl = w.mAttrs.flags
1292 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1293 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1294 return w.isVisibleOrAdding();
1295 }
1296 return false;
1297 }
Romain Guy06882f82009-06-10 13:36:04 -07001298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001300 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 final int N = localmWindows.size();
1302 WindowState w = null;
1303 int i = N;
1304 while (i > 0) {
1305 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001306 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001307
Joe Onorato8a9b2202010-02-26 18:56:32 -08001308 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 // + Integer.toHexString(w.mAttrs.flags));
1310 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001311 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 // Yet more tricksyness! If this window is a "starting"
1314 // window, we do actually want to be on top of it, but
1315 // it is not -really- where input will go. So if the caller
1316 // is not actually looking to move the IME, look down below
1317 // for a real window to target...
1318 if (!willMove
1319 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1320 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001321 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1323 i--;
1324 w = wb;
1325 }
1326 }
1327 break;
1328 }
1329 }
Romain Guy06882f82009-06-10 13:36:04 -07001330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001332
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 if (willMove && w != null) {
1337 final WindowState curTarget = mInputMethodTarget;
1338 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 // Now some fun for dealing with window animations that
1341 // modify the Z order. We need to look at all windows below
1342 // the current target that are in this app, finding the highest
1343 // visible one in layering.
1344 AppWindowToken token = curTarget.mAppToken;
1345 WindowState highestTarget = null;
1346 int highestPos = 0;
1347 if (token.animating || token.animation != null) {
1348 int pos = 0;
1349 pos = localmWindows.indexOf(curTarget);
1350 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001351 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 if (win.mAppToken != token) {
1353 break;
1354 }
1355 if (!win.mRemoved) {
1356 if (highestTarget == null || win.mAnimLayer >
1357 highestTarget.mAnimLayer) {
1358 highestTarget = win;
1359 highestPos = pos;
1360 }
1361 }
1362 pos--;
1363 }
1364 }
Romain Guy06882f82009-06-10 13:36:04 -07001365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001367 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 + mNextAppTransition + " " + highestTarget
1369 + " animating=" + highestTarget.isAnimating()
1370 + " layer=" + highestTarget.mAnimLayer
1371 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001372
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001373 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 // If we are currently setting up for an animation,
1375 // hold everything until we can find out what will happen.
1376 mInputMethodTargetWaitingAnim = true;
1377 mInputMethodTarget = highestTarget;
1378 return highestPos + 1;
1379 } else if (highestTarget.isAnimating() &&
1380 highestTarget.mAnimLayer > w.mAnimLayer) {
1381 // If the window we are currently targeting is involved
1382 // with an animation, and it is on top of the next target
1383 // we will be over, then hold off on moving until
1384 // that is done.
1385 mInputMethodTarget = highestTarget;
1386 return highestPos + 1;
1387 }
1388 }
1389 }
1390 }
Romain Guy06882f82009-06-10 13:36:04 -07001391
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 if (w != null) {
1394 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001395 if (DEBUG_INPUT_METHOD) {
1396 RuntimeException e = null;
1397 if (!HIDE_STACK_CRAWLS) {
1398 e = new RuntimeException();
1399 e.fillInStackTrace();
1400 }
1401 Slog.w(TAG, "Moving IM target from "
1402 + mInputMethodTarget + " to " + w, e);
1403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 mInputMethodTarget = w;
1405 if (w.mAppToken != null) {
1406 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1407 } else {
1408 setInputMethodAnimLayerAdjustment(0);
1409 }
1410 }
1411 return i+1;
1412 }
1413 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001414 if (DEBUG_INPUT_METHOD) {
1415 RuntimeException e = null;
1416 if (!HIDE_STACK_CRAWLS) {
1417 e = new RuntimeException();
1418 e.fillInStackTrace();
1419 }
1420 Slog.w(TAG, "Moving IM target from "
1421 + mInputMethodTarget + " to null", e);
1422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 mInputMethodTarget = null;
1424 setInputMethodAnimLayerAdjustment(0);
1425 }
1426 return -1;
1427 }
Romain Guy06882f82009-06-10 13:36:04 -07001428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 void addInputMethodWindowToListLocked(WindowState win) {
1430 int pos = findDesiredInputMethodWindowIndexLocked(true);
1431 if (pos >= 0) {
1432 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001434 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001436 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 moveInputMethodDialogsLocked(pos+1);
1438 return;
1439 }
1440 win.mTargetAppToken = null;
1441 addWindowToListInOrderLocked(win, true);
1442 moveInputMethodDialogsLocked(pos);
1443 }
Romain Guy06882f82009-06-10 13:36:04 -07001444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001446 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 mInputMethodAnimLayerAdjustment = adj;
1448 WindowState imw = mInputMethodWindow;
1449 if (imw != null) {
1450 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 + " anim layer: " + imw.mAnimLayer);
1453 int wi = imw.mChildWindows.size();
1454 while (wi > 0) {
1455 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001456 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001458 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 + " anim layer: " + cw.mAnimLayer);
1460 }
1461 }
1462 int di = mInputMethodDialogs.size();
1463 while (di > 0) {
1464 di --;
1465 imw = mInputMethodDialogs.get(di);
1466 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 + " anim layer: " + imw.mAnimLayer);
1469 }
1470 }
Romain Guy06882f82009-06-10 13:36:04 -07001471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1473 int wpos = mWindows.indexOf(win);
1474 if (wpos >= 0) {
1475 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001476 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001478 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 int NC = win.mChildWindows.size();
1480 while (NC > 0) {
1481 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001482 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 int cpos = mWindows.indexOf(cw);
1484 if (cpos >= 0) {
1485 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001486 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001487 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 mWindows.remove(cpos);
1489 }
1490 }
1491 }
1492 return interestingPos;
1493 }
Romain Guy06882f82009-06-10 13:36:04 -07001494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 private void reAddWindowToListInOrderLocked(WindowState win) {
1496 addWindowToListInOrderLocked(win, false);
1497 // This is a hack to get all of the child windows added as well
1498 // at the right position. Child windows should be rare and
1499 // this case should be rare, so it shouldn't be that big a deal.
1500 int wpos = mWindows.indexOf(win);
1501 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001503 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001505 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 reAddWindowLocked(wpos, win);
1507 }
1508 }
Romain Guy06882f82009-06-10 13:36:04 -07001509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 void logWindowList(String prefix) {
1511 int N = mWindows.size();
1512 while (N > 0) {
1513 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001514 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 }
1516 }
Romain Guy06882f82009-06-10 13:36:04 -07001517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 void moveInputMethodDialogsLocked(int pos) {
1519 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001522 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 for (int i=0; i<N; i++) {
1524 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1525 }
1526 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001527 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 logWindowList(" ");
1529 }
Romain Guy06882f82009-06-10 13:36:04 -07001530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 if (pos >= 0) {
1532 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1533 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001534 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 if (wp == mInputMethodWindow) {
1536 pos++;
1537 }
1538 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001539 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 for (int i=0; i<N; i++) {
1541 WindowState win = dialogs.get(i);
1542 win.mTargetAppToken = targetAppToken;
1543 pos = reAddWindowLocked(pos, win);
1544 }
1545 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001546 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 logWindowList(" ");
1548 }
1549 return;
1550 }
1551 for (int i=0; i<N; i++) {
1552 WindowState win = dialogs.get(i);
1553 win.mTargetAppToken = null;
1554 reAddWindowToListInOrderLocked(win);
1555 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001556 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 logWindowList(" ");
1558 }
1559 }
1560 }
Romain Guy06882f82009-06-10 13:36:04 -07001561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1563 final WindowState imWin = mInputMethodWindow;
1564 final int DN = mInputMethodDialogs.size();
1565 if (imWin == null && DN == 0) {
1566 return false;
1567 }
Romain Guy06882f82009-06-10 13:36:04 -07001568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1570 if (imPos >= 0) {
1571 // In this case, the input method windows are to be placed
1572 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 // First check to see if the input method windows are already
1575 // located here, and contiguous.
1576 final int N = mWindows.size();
1577 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001578 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 // Figure out the actual input method window that should be
1581 // at the bottom of their stack.
1582 WindowState baseImWin = imWin != null
1583 ? imWin : mInputMethodDialogs.get(0);
1584 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001585 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 if (cw.mSubLayer < 0) baseImWin = cw;
1587 }
Romain Guy06882f82009-06-10 13:36:04 -07001588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 if (firstImWin == baseImWin) {
1590 // The windows haven't moved... but are they still contiguous?
1591 // First find the top IM window.
1592 int pos = imPos+1;
1593 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001594 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 break;
1596 }
1597 pos++;
1598 }
1599 pos++;
1600 // Now there should be no more input method windows above.
1601 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001602 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 break;
1604 }
1605 pos++;
1606 }
1607 if (pos >= N) {
1608 // All is good!
1609 return false;
1610 }
1611 }
Romain Guy06882f82009-06-10 13:36:04 -07001612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 if (imWin != null) {
1614 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001615 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 logWindowList(" ");
1617 }
1618 imPos = tmpRemoveWindowLocked(imPos, imWin);
1619 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001620 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 logWindowList(" ");
1622 }
1623 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1624 reAddWindowLocked(imPos, imWin);
1625 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 logWindowList(" ");
1628 }
1629 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1630 } else {
1631 moveInputMethodDialogsLocked(imPos);
1632 }
Romain Guy06882f82009-06-10 13:36:04 -07001633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 } else {
1635 // In this case, the input method windows go in a fixed layer,
1636 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001639 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 tmpRemoveWindowLocked(0, imWin);
1641 imWin.mTargetAppToken = null;
1642 reAddWindowToListInOrderLocked(imWin);
1643 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001644 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 logWindowList(" ");
1646 }
1647 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1648 } else {
1649 moveInputMethodDialogsLocked(-1);;
1650 }
Romain Guy06882f82009-06-10 13:36:04 -07001651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 }
Romain Guy06882f82009-06-10 13:36:04 -07001653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 if (needAssignLayers) {
1655 assignLayersLocked();
1656 }
Romain Guy06882f82009-06-10 13:36:04 -07001657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001658 return true;
1659 }
Romain Guy06882f82009-06-10 13:36:04 -07001660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 void adjustInputMethodDialogsLocked() {
1662 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1663 }
Romain Guy06882f82009-06-10 13:36:04 -07001664
Dianne Hackborn25994b42009-09-04 14:21:19 -07001665 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001666 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001667 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1668 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1669 ? wallpaperTarget.mAppToken.animation : null)
1670 + " upper=" + mUpperWallpaperTarget
1671 + " lower=" + mLowerWallpaperTarget);
1672 return (wallpaperTarget != null
1673 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1674 && wallpaperTarget.mAppToken.animation != null)))
1675 || mUpperWallpaperTarget != null
1676 || mLowerWallpaperTarget != null;
1677 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001678
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001679 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1680 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001681
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001682 int adjustWallpaperWindowsLocked() {
1683 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001684
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001685 final int dw = mDisplay.getWidth();
1686 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001687
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001688 // First find top-most window that has asked to be on top of the
1689 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001690 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001691 int N = localmWindows.size();
1692 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001693 WindowState foundW = null;
1694 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001695 WindowState topCurW = null;
1696 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001697 int i = N;
1698 while (i > 0) {
1699 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001700 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001701 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1702 if (topCurW == null) {
1703 topCurW = w;
1704 topCurI = i;
1705 }
1706 continue;
1707 }
1708 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001709 if (w.mAppToken != null) {
1710 // If this window's app token is hidden and not animating,
1711 // it is of no interest to us.
1712 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001713 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001714 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001715 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001716 continue;
1717 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001718 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001719 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001720 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1721 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001722 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001723 && (mWallpaperTarget == w
1724 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001725 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001726 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001727 foundW = w;
1728 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001729 if (w == mWallpaperTarget && ((w.mAppToken != null
1730 && w.mAppToken.animation != null)
1731 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001732 // The current wallpaper target is animating, so we'll
1733 // look behind it for another possible target and figure
1734 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001735 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001736 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001737 continue;
1738 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001739 break;
1740 }
1741 }
1742
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001743 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001744 // If we are currently waiting for an app transition, and either
1745 // the current target or the next target are involved with it,
1746 // then hold off on doing anything with the wallpaper.
1747 // Note that we are checking here for just whether the target
1748 // is part of an app token... which is potentially overly aggressive
1749 // (the app token may not be involved in the transition), but good
1750 // enough (we'll just wait until whatever transition is pending
1751 // executes).
1752 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001753 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001754 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001755 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001756 }
1757 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001758 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001759 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001760 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001761 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001763
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001764 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001765 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001766 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001767 + " oldTarget: " + mWallpaperTarget);
1768 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001769
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 mLowerWallpaperTarget = null;
1771 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001772
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001773 WindowState oldW = mWallpaperTarget;
1774 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001775
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001776 // Now what is happening... if the current and new targets are
1777 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001778 if (foundW != null && oldW != null) {
1779 boolean oldAnim = oldW.mAnimation != null
1780 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1781 boolean foundAnim = foundW.mAnimation != null
1782 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001783 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001784 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001785 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001786 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001787 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001788 int oldI = localmWindows.indexOf(oldW);
1789 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001790 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001791 }
1792 if (oldI >= 0) {
1793 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001794 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001795 + "=" + oldW + "; new#" + foundI
1796 + "=" + foundW);
1797 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001798
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001799 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001800 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001802 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001803 }
1804 mWallpaperTarget = oldW;
1805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001806
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001807 // Now set the upper and lower wallpaper targets
1808 // correctly, and make sure that we are positioning
1809 // the wallpaper below the lower.
1810 if (foundI > oldI) {
1811 // The new target is on top of the old one.
1812 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 }
1815 mUpperWallpaperTarget = foundW;
1816 mLowerWallpaperTarget = oldW;
1817 foundW = oldW;
1818 foundI = oldI;
1819 } else {
1820 // The new target is below the old one.
1821 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001822 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001823 }
1824 mUpperWallpaperTarget = oldW;
1825 mLowerWallpaperTarget = foundW;
1826 }
1827 }
1828 }
1829 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001830
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001831 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001832 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001833 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1834 || (mLowerWallpaperTarget.mAppToken != null
1835 && mLowerWallpaperTarget.mAppToken.animation != null);
1836 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1837 || (mUpperWallpaperTarget.mAppToken != null
1838 && mUpperWallpaperTarget.mAppToken.animation != null);
1839 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001840 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001841 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001842 }
1843 mLowerWallpaperTarget = null;
1844 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001845 }
1846 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001847
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001848 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001849 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001850 // The window is visible to the compositor... but is it visible
1851 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001852 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001854
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001855 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001856 // its layer adjustment. Only do this if we are not transfering
1857 // between two wallpaper targets.
1858 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001859 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001860 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001861
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001862 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1863 * TYPE_LAYER_MULTIPLIER
1864 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001865
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001866 // Now w is the window we are supposed to be behind... but we
1867 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001868 // AND any starting window associated with it, AND below the
1869 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001870 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001871 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001872 if (wb.mBaseLayer < maxLayer &&
1873 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001874 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001875 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001876 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001877 // This window is not related to the previous one in any
1878 // interesting way, so stop here.
1879 break;
1880 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001881 foundW = wb;
1882 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001883 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001884 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001885 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001886 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001887
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001888 if (foundW == null && topCurW != null) {
1889 // There is no wallpaper target, so it goes at the bottom.
1890 // We will assume it is the same place as last time, if known.
1891 foundW = topCurW;
1892 foundI = topCurI+1;
1893 } else {
1894 // Okay i is the position immediately above the wallpaper. Look at
1895 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001896 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001898
Dianne Hackborn284ac932009-08-28 10:34:25 -07001899 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001900 if (mWallpaperTarget.mWallpaperX >= 0) {
1901 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001902 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001903 }
1904 if (mWallpaperTarget.mWallpaperY >= 0) {
1905 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001906 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001907 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001909
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001910 // Start stepping backwards from here, ensuring that our wallpaper windows
1911 // are correctly placed.
1912 int curTokenIndex = mWallpaperTokens.size();
1913 while (curTokenIndex > 0) {
1914 curTokenIndex--;
1915 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001916 if (token.hidden == visible) {
1917 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1918 token.hidden = !visible;
1919 // Need to do a layout to ensure the wallpaper now has the
1920 // correct size.
1921 mLayoutNeeded = true;
1922 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001923
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001924 int curWallpaperIndex = token.windows.size();
1925 while (curWallpaperIndex > 0) {
1926 curWallpaperIndex--;
1927 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001928
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001929 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001930 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001932
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001933 // First, make sure the client has the current visibility
1934 // state.
1935 if (wallpaper.mWallpaperVisible != visible) {
1936 wallpaper.mWallpaperVisible = visible;
1937 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001938 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001939 "Setting visibility of wallpaper " + wallpaper
1940 + ": " + visible);
1941 wallpaper.mClient.dispatchAppVisibility(visible);
1942 } catch (RemoteException e) {
1943 }
1944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001945
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001946 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001947 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001948 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001949
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001950 // First, if this window is at the current index, then all
1951 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001952 if (wallpaper == foundW) {
1953 foundI--;
1954 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001955 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001956 continue;
1957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001958
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001959 // The window didn't match... the current wallpaper window,
1960 // wherever it is, is in the wrong place, so make sure it is
1961 // not in the list.
1962 int oldIndex = localmWindows.indexOf(wallpaper);
1963 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001964 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001965 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001966 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001967 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001968 if (oldIndex < foundI) {
1969 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001970 }
1971 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001972
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001973 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001974 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001975 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001976 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001977
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001978 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001979 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001980 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 }
1982 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001983
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001984 return changed;
1985 }
1986
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001987 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001988 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001989 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001990 mWallpaperAnimLayerAdjustment = adj;
1991 int curTokenIndex = mWallpaperTokens.size();
1992 while (curTokenIndex > 0) {
1993 curTokenIndex--;
1994 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1995 int curWallpaperIndex = token.windows.size();
1996 while (curWallpaperIndex > 0) {
1997 curWallpaperIndex--;
1998 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1999 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002000 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002001 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002002 }
2003 }
2004 }
2005
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002006 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2007 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002008 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002009 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002010 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002011 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002012 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2013 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2014 changed = wallpaperWin.mXOffset != offset;
2015 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002016 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002017 + wallpaperWin + " x: " + offset);
2018 wallpaperWin.mXOffset = offset;
2019 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002020 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002021 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002022 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002023 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002024 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002025
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002026 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002027 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002028 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2029 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2030 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002031 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002032 + wallpaperWin + " y: " + offset);
2033 changed = true;
2034 wallpaperWin.mYOffset = offset;
2035 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002036 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002037 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002038 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002039 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002040 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002041
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002042 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002043 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002044 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002045 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2046 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002047 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002048 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002049 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002050 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002051 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2052 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002053 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002054 if (mWaitingOnWallpaper != null) {
2055 long start = SystemClock.uptimeMillis();
2056 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2057 < start) {
2058 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002059 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002060 "Waiting for offset complete...");
2061 mWindowMap.wait(WALLPAPER_TIMEOUT);
2062 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002063 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002064 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002065 if ((start+WALLPAPER_TIMEOUT)
2066 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002067 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002068 + wallpaperWin);
2069 mLastWallpaperTimeoutTime = start;
2070 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002071 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002072 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002073 }
2074 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002075 } catch (RemoteException e) {
2076 }
2077 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002078
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002079 return changed;
2080 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002081
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002082 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002083 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002084 if (mWaitingOnWallpaper != null &&
2085 mWaitingOnWallpaper.mClient.asBinder() == window) {
2086 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002087 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002088 }
2089 }
2090 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002091
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002092 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002093 final int dw = mDisplay.getWidth();
2094 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002095
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002096 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002097
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002098 WindowState target = mWallpaperTarget;
2099 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002100 if (target.mWallpaperX >= 0) {
2101 mLastWallpaperX = target.mWallpaperX;
2102 } else if (changingTarget.mWallpaperX >= 0) {
2103 mLastWallpaperX = changingTarget.mWallpaperX;
2104 }
2105 if (target.mWallpaperY >= 0) {
2106 mLastWallpaperY = target.mWallpaperY;
2107 } else if (changingTarget.mWallpaperY >= 0) {
2108 mLastWallpaperY = changingTarget.mWallpaperY;
2109 }
2110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002111
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002112 int curTokenIndex = mWallpaperTokens.size();
2113 while (curTokenIndex > 0) {
2114 curTokenIndex--;
2115 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2116 int curWallpaperIndex = token.windows.size();
2117 while (curWallpaperIndex > 0) {
2118 curWallpaperIndex--;
2119 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2120 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2121 wallpaper.computeShownFrameLocked();
2122 changed = true;
2123 // We only want to be synchronous with one wallpaper.
2124 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002125 }
2126 }
2127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002128
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002129 return changed;
2130 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002131
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002132 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002133 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002134 final int dw = mDisplay.getWidth();
2135 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002136
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002137 int curTokenIndex = mWallpaperTokens.size();
2138 while (curTokenIndex > 0) {
2139 curTokenIndex--;
2140 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002141 if (token.hidden == visible) {
2142 token.hidden = !visible;
2143 // Need to do a layout to ensure the wallpaper now has the
2144 // correct size.
2145 mLayoutNeeded = true;
2146 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002147
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002148 int curWallpaperIndex = token.windows.size();
2149 while (curWallpaperIndex > 0) {
2150 curWallpaperIndex--;
2151 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2152 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002153 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002154 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002155
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002156 if (wallpaper.mWallpaperVisible != visible) {
2157 wallpaper.mWallpaperVisible = visible;
2158 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002159 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002160 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002161 + ": " + visible);
2162 wallpaper.mClient.dispatchAppVisibility(visible);
2163 } catch (RemoteException e) {
2164 }
2165 }
2166 }
2167 }
2168 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 public int addWindow(Session session, IWindow client,
2171 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002172 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 int res = mPolicy.checkAddPermission(attrs);
2174 if (res != WindowManagerImpl.ADD_OKAY) {
2175 return res;
2176 }
Romain Guy06882f82009-06-10 13:36:04 -07002177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 boolean reportNewConfig = false;
2179 WindowState attachedWindow = null;
2180 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002181 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002185 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 }
Romain Guy06882f82009-06-10 13:36:04 -07002187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002189 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2191 }
2192
2193 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002194 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002196 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 + attrs.token + ". Aborting.");
2198 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2199 }
2200 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2201 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002202 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 + attrs.token + ". Aborting.");
2204 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2205 }
2206 }
2207
2208 boolean addToken = false;
2209 WindowToken token = mTokenMap.get(attrs.token);
2210 if (token == null) {
2211 if (attrs.type >= FIRST_APPLICATION_WINDOW
2212 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 + attrs.token + ". Aborting.");
2215 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2216 }
2217 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002218 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 + attrs.token + ". Aborting.");
2220 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2221 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002222 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002223 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002224 + attrs.token + ". Aborting.");
2225 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2226 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 token = new WindowToken(attrs.token, -1, false);
2228 addToken = true;
2229 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2230 && attrs.type <= LAST_APPLICATION_WINDOW) {
2231 AppWindowToken atoken = token.appWindowToken;
2232 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002233 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 + token + ". Aborting.");
2235 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2236 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002237 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 + token + ". Aborting.");
2239 return WindowManagerImpl.ADD_APP_EXITING;
2240 }
2241 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2242 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002243 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2245 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2246 }
2247 } else if (attrs.type == TYPE_INPUT_METHOD) {
2248 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002249 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 + attrs.token + ". Aborting.");
2251 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2252 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002253 } else if (attrs.type == TYPE_WALLPAPER) {
2254 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002255 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002256 + attrs.token + ". Aborting.");
2257 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 }
2260
2261 win = new WindowState(session, client, token,
2262 attachedWindow, attrs, viewVisibility);
2263 if (win.mDeathRecipient == null) {
2264 // Client has apparently died, so there is no reason to
2265 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002266 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 + " that is dead, aborting.");
2268 return WindowManagerImpl.ADD_APP_EXITING;
2269 }
2270
2271 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 res = mPolicy.prepareAddWindowLw(win, attrs);
2274 if (res != WindowManagerImpl.ADD_OKAY) {
2275 return res;
2276 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002277
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002278 if (outInputChannel != null) {
2279 String name = win.makeInputChannelName();
2280 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2281 win.mInputChannel = inputChannels[0];
2282 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2283
2284 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002285 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286
2287 // From now on, no exceptions or errors allowed!
2288
2289 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002290
Dianne Hackborn5132b372010-07-29 12:51:35 -07002291 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 if (addToken) {
2294 mTokenMap.put(attrs.token, token);
2295 mTokenList.add(token);
2296 }
2297 win.attach();
2298 mWindowMap.put(client.asBinder(), win);
2299
2300 if (attrs.type == TYPE_APPLICATION_STARTING &&
2301 token.appWindowToken != null) {
2302 token.appWindowToken.startingWindow = win;
2303 }
2304
2305 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 if (attrs.type == TYPE_INPUT_METHOD) {
2308 mInputMethodWindow = win;
2309 addInputMethodWindowToListLocked(win);
2310 imMayMove = false;
2311 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2312 mInputMethodDialogs.add(win);
2313 addWindowToListInOrderLocked(win, true);
2314 adjustInputMethodDialogsLocked();
2315 imMayMove = false;
2316 } else {
2317 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002318 if (attrs.type == TYPE_WALLPAPER) {
2319 mLastWallpaperTimeoutTime = 0;
2320 adjustWallpaperWindowsLocked();
2321 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002322 adjustWallpaperWindowsLocked();
2323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 }
Romain Guy06882f82009-06-10 13:36:04 -07002325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 if (mInTouchMode) {
2331 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2332 }
2333 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2334 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2335 }
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002337 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002339 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2340 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 imMayMove = false;
2342 }
2343 }
Romain Guy06882f82009-06-10 13:36:04 -07002344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002346 moveInputMethodWindowsIfNeededLocked(false);
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 assignLayersLocked();
2350 // Don't do layout here, the window must call
2351 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 //dump();
2354
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002355 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002356 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002357 }
Jeff Brown349703e2010-06-22 01:27:15 -07002358
Joe Onorato8a9b2202010-02-26 18:56:32 -08002359 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 TAG, "New client " + client.asBinder()
2361 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002362
2363 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2364 reportNewConfig = true;
2365 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 }
2367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 if (reportNewConfig) {
2369 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 return res;
2375 }
Romain Guy06882f82009-06-10 13:36:04 -07002376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 public void removeWindow(Session session, IWindow client) {
2378 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002379 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 if (win == null) {
2381 return;
2382 }
2383 removeWindowLocked(session, win);
2384 }
2385 }
Romain Guy06882f82009-06-10 13:36:04 -07002386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 public void removeWindowLocked(Session session, WindowState win) {
2388
Joe Onorato8a9b2202010-02-26 18:56:32 -08002389 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 TAG, "Remove " + win + " client="
2391 + Integer.toHexString(System.identityHashCode(
2392 win.mClient.asBinder()))
2393 + ", surface=" + win.mSurface);
2394
2395 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002396
2397 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002398
Joe Onorato8a9b2202010-02-26 18:56:32 -08002399 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2401 + " mExiting=" + win.mExiting
2402 + " isAnimating=" + win.isAnimating()
2403 + " app-animation="
2404 + (win.mAppToken != null ? win.mAppToken.animation : null)
2405 + " inPendingTransaction="
2406 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2407 + " mDisplayFrozen=" + mDisplayFrozen);
2408 // Visibility of the removed window. Will be used later to update orientation later on.
2409 boolean wasVisible = false;
2410 // First, see if we need to run an animation. If we do, we have
2411 // to hold off on removing the window until the animation is done.
2412 // If the display is frozen, just remove immediately, since the
2413 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002414 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 // If we are not currently running the exit animation, we
2416 // need to see about starting one.
2417 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2420 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2421 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2422 }
2423 // Try starting an animation.
2424 if (applyAnimationLocked(win, transit, false)) {
2425 win.mExiting = true;
2426 }
2427 }
2428 if (win.mExiting || win.isAnimating()) {
2429 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002430 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 win.mExiting = true;
2432 win.mRemoveOnExit = true;
2433 mLayoutNeeded = true;
2434 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2435 performLayoutAndPlaceSurfacesLocked();
2436 if (win.mAppToken != null) {
2437 win.mAppToken.updateReportedVisibilityLocked();
2438 }
2439 //dump();
2440 Binder.restoreCallingIdentity(origId);
2441 return;
2442 }
2443 }
2444
2445 removeWindowInnerLocked(session, win);
2446 // Removing a visible window will effect the computed orientation
2447 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002448 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002449 != mForcedAppOrientation
2450 && updateOrientationFromAppTokensLocked()) {
2451 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 }
2453 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2454 Binder.restoreCallingIdentity(origId);
2455 }
Romain Guy06882f82009-06-10 13:36:04 -07002456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 if (mInputMethodTarget == win) {
2461 moveInputMethodWindowsIfNeededLocked(false);
2462 }
Romain Guy06882f82009-06-10 13:36:04 -07002463
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002464 if (false) {
2465 RuntimeException e = new RuntimeException("here");
2466 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002467 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002468 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 mPolicy.removeWindowLw(win);
2471 win.removeLocked();
2472
2473 mWindowMap.remove(win.mClient.asBinder());
2474 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002475 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002476 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477
2478 if (mInputMethodWindow == win) {
2479 mInputMethodWindow = null;
2480 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2481 mInputMethodDialogs.remove(win);
2482 }
Romain Guy06882f82009-06-10 13:36:04 -07002483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 final WindowToken token = win.mToken;
2485 final AppWindowToken atoken = win.mAppToken;
2486 token.windows.remove(win);
2487 if (atoken != null) {
2488 atoken.allAppWindows.remove(win);
2489 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002490 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 TAG, "**** Removing window " + win + ": count="
2492 + token.windows.size());
2493 if (token.windows.size() == 0) {
2494 if (!token.explicit) {
2495 mTokenMap.remove(token.token);
2496 mTokenList.remove(token);
2497 } else if (atoken != null) {
2498 atoken.firstWindowDrawn = false;
2499 }
2500 }
2501
2502 if (atoken != null) {
2503 if (atoken.startingWindow == win) {
2504 atoken.startingWindow = null;
2505 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2506 // If this is the last window and we had requested a starting
2507 // transition window, well there is no point now.
2508 atoken.startingData = null;
2509 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2510 // If this is the last window except for a starting transition
2511 // window, we need to get rid of the starting transition.
2512 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002513 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 + ": no more real windows");
2515 }
2516 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2517 mH.sendMessage(m);
2518 }
2519 }
Romain Guy06882f82009-06-10 13:36:04 -07002520
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002521 if (win.mAttrs.type == TYPE_WALLPAPER) {
2522 mLastWallpaperTimeoutTime = 0;
2523 adjustWallpaperWindowsLocked();
2524 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002525 adjustWallpaperWindowsLocked();
2526 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 if (!mInLayout) {
2529 assignLayersLocked();
2530 mLayoutNeeded = true;
2531 performLayoutAndPlaceSurfacesLocked();
2532 if (win.mAppToken != null) {
2533 win.mAppToken.updateReportedVisibilityLocked();
2534 }
2535 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002536
2537 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 }
2539
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002540 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2541 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2542 + ": " + msg + " / " + w.mAttrs.getTitle();
2543 if (where != null) {
2544 Slog.i(TAG, str, where);
2545 } else {
2546 Slog.i(TAG, str);
2547 }
2548 }
2549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2551 long origId = Binder.clearCallingIdentity();
2552 try {
2553 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002554 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002556 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 Surface.openTransaction();
2558 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002559 if (SHOW_TRANSACTIONS) logSurface(w,
2560 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 w.mSurface.setTransparentRegionHint(region);
2562 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002563 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 Surface.closeTransaction();
2565 }
2566 }
2567 }
2568 } finally {
2569 Binder.restoreCallingIdentity(origId);
2570 }
2571 }
2572
2573 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002574 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 Rect visibleInsets) {
2576 long origId = Binder.clearCallingIdentity();
2577 try {
2578 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002579 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 if (w != null) {
2581 w.mGivenInsetsPending = false;
2582 w.mGivenContentInsets.set(contentInsets);
2583 w.mGivenVisibleInsets.set(visibleInsets);
2584 w.mTouchableInsets = touchableInsets;
2585 mLayoutNeeded = true;
2586 performLayoutAndPlaceSurfacesLocked();
2587 }
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(origId);
2591 }
2592 }
Romain Guy06882f82009-06-10 13:36:04 -07002593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 public void getWindowDisplayFrame(Session session, IWindow client,
2595 Rect outDisplayFrame) {
2596 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002597 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 if (win == null) {
2599 outDisplayFrame.setEmpty();
2600 return;
2601 }
2602 outDisplayFrame.set(win.mDisplayFrame);
2603 }
2604 }
2605
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002606 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2607 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002608 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2609 window.mWallpaperX = x;
2610 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002611 window.mWallpaperXStep = xStep;
2612 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002613 if (updateWallpaperOffsetLocked(window, true)) {
2614 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002615 }
2616 }
2617 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002618
Dianne Hackborn75804932009-10-20 20:15:20 -07002619 void wallpaperCommandComplete(IBinder window, Bundle result) {
2620 synchronized (mWindowMap) {
2621 if (mWaitingOnWallpaper != null &&
2622 mWaitingOnWallpaper.mClient.asBinder() == window) {
2623 mWaitingOnWallpaper = null;
2624 mWindowMap.notifyAll();
2625 }
2626 }
2627 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002628
Dianne Hackborn75804932009-10-20 20:15:20 -07002629 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2630 String action, int x, int y, int z, Bundle extras, boolean sync) {
2631 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2632 || window == mUpperWallpaperTarget) {
2633 boolean doWait = sync;
2634 int curTokenIndex = mWallpaperTokens.size();
2635 while (curTokenIndex > 0) {
2636 curTokenIndex--;
2637 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2638 int curWallpaperIndex = token.windows.size();
2639 while (curWallpaperIndex > 0) {
2640 curWallpaperIndex--;
2641 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2642 try {
2643 wallpaper.mClient.dispatchWallpaperCommand(action,
2644 x, y, z, extras, sync);
2645 // We only want to be synchronous with one wallpaper.
2646 sync = false;
2647 } catch (RemoteException e) {
2648 }
2649 }
2650 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002651
Dianne Hackborn75804932009-10-20 20:15:20 -07002652 if (doWait) {
2653 // XXX Need to wait for result.
2654 }
2655 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002656
Dianne Hackborn75804932009-10-20 20:15:20 -07002657 return null;
2658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 public int relayoutWindow(Session session, IWindow client,
2661 WindowManager.LayoutParams attrs, int requestedWidth,
2662 int requestedHeight, int viewVisibility, boolean insetsPending,
2663 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002664 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665 boolean displayed = false;
2666 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002667 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002671 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 if (win == null) {
2673 return 0;
2674 }
2675 win.mRequestedWidth = requestedWidth;
2676 win.mRequestedHeight = requestedHeight;
2677
2678 if (attrs != null) {
2679 mPolicy.adjustWindowParamsLw(attrs);
2680 }
Romain Guy06882f82009-06-10 13:36:04 -07002681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 int attrChanges = 0;
2683 int flagChanges = 0;
2684 if (attrs != null) {
2685 flagChanges = win.mAttrs.flags ^= attrs.flags;
2686 attrChanges = win.mAttrs.copyFrom(attrs);
2687 }
2688
Joe Onorato8a9b2202010-02-26 18:56:32 -08002689 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690
2691 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2692 win.mAlpha = attrs.alpha;
2693 }
2694
2695 final boolean scaledWindow =
2696 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2697
2698 if (scaledWindow) {
2699 // requested{Width|Height} Surface's physical size
2700 // attrs.{width|height} Size on screen
2701 win.mHScale = (attrs.width != requestedWidth) ?
2702 (attrs.width / (float)requestedWidth) : 1.0f;
2703 win.mVScale = (attrs.height != requestedHeight) ?
2704 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002705 } else {
2706 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 }
2708
2709 boolean imMayMove = (flagChanges&(
2710 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2711 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 boolean focusMayChange = win.mViewVisibility != viewVisibility
2714 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2715 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002716
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002717 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2718 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002720 win.mRelayoutCalled = true;
2721 final int oldVisibility = win.mViewVisibility;
2722 win.mViewVisibility = viewVisibility;
2723 if (viewVisibility == View.VISIBLE &&
2724 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2725 displayed = !win.isVisibleLw();
2726 if (win.mExiting) {
2727 win.mExiting = false;
2728 win.mAnimation = null;
2729 }
2730 if (win.mDestroying) {
2731 win.mDestroying = false;
2732 mDestroySurface.remove(win);
2733 }
2734 if (oldVisibility == View.GONE) {
2735 win.mEnterAnimationPending = true;
2736 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002737 if (displayed) {
2738 if (win.mSurface != null && !win.mDrawPending
2739 && !win.mCommitDrawPending && !mDisplayFrozen
2740 && mPolicy.isScreenOn()) {
2741 applyEnterAnimationLocked(win);
2742 }
2743 if ((win.mAttrs.flags
2744 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2745 if (DEBUG_VISIBILITY) Slog.v(TAG,
2746 "Relayout window turning screen on: " + win);
2747 win.mTurnOnScreen = true;
2748 }
2749 int diff = 0;
2750 if (win.mConfiguration != mCurConfiguration
2751 && (win.mConfiguration == null
2752 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2753 win.mConfiguration = mCurConfiguration;
2754 if (DEBUG_CONFIGURATION) {
2755 Slog.i(TAG, "Window " + win + " visible with new config: "
2756 + win.mConfiguration + " / 0x"
2757 + Integer.toHexString(diff));
2758 }
2759 outConfig.setTo(mCurConfiguration);
2760 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2763 // To change the format, we need to re-build the surface.
2764 win.destroySurfaceLocked();
2765 displayed = true;
2766 }
2767 try {
2768 Surface surface = win.createSurfaceLocked();
2769 if (surface != null) {
2770 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002771 win.mReportDestroySurface = false;
2772 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002773 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002774 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002776 // For some reason there isn't a surface. Clear the
2777 // caller's object so they see the same state.
2778 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 }
2780 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002781 mInputMonitor.updateInputWindowsLw();
2782
Joe Onorato8a9b2202010-02-26 18:56:32 -08002783 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002784 + client + " (" + win.mAttrs.getTitle() + ")",
2785 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 Binder.restoreCallingIdentity(origId);
2787 return 0;
2788 }
2789 if (displayed) {
2790 focusMayChange = true;
2791 }
2792 if (win.mAttrs.type == TYPE_INPUT_METHOD
2793 && mInputMethodWindow == null) {
2794 mInputMethodWindow = win;
2795 imMayMove = true;
2796 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002797 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2798 && win.mAppToken != null
2799 && win.mAppToken.startingWindow != null) {
2800 // Special handling of starting window over the base
2801 // window of the app: propagate lock screen flags to it,
2802 // to provide the correct semantics while starting.
2803 final int mask =
2804 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002805 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2806 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002807 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2808 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 } else {
2811 win.mEnterAnimationPending = false;
2812 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002813 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002814 + ": mExiting=" + win.mExiting
2815 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 // If we are not currently running the exit animation, we
2817 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002818 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 // Try starting an animation; if there isn't one, we
2820 // can destroy the surface right away.
2821 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2822 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2823 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2824 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002825 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002827 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 } else if (win.isAnimating()) {
2830 // Currently in a hide animation... turn this into
2831 // an exit.
2832 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002833 } else if (win == mWallpaperTarget) {
2834 // If the wallpaper is currently behind this
2835 // window, we need to change both of them inside
2836 // of a transaction to avoid artifacts.
2837 win.mExiting = true;
2838 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 } else {
2840 if (mInputMethodWindow == win) {
2841 mInputMethodWindow = null;
2842 }
2843 win.destroySurfaceLocked();
2844 }
2845 }
2846 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002847
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002848 if (win.mSurface == null || (win.getAttrs().flags
2849 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2850 || win.mSurfacePendingDestroy) {
2851 // We are being called from a local process, which
2852 // means outSurface holds its current surface. Ensure the
2853 // surface object is cleared, but we don't want it actually
2854 // destroyed at this point.
2855 win.mSurfacePendingDestroy = false;
2856 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002857 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002858 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002859 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002860 "Keeping surface, will report destroy: " + win);
2861 win.mReportDestroySurface = true;
2862 outSurface.copyFrom(win.mSurface);
2863 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 }
2865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 if (focusMayChange) {
2867 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2868 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 imMayMove = false;
2870 }
2871 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2872 }
Romain Guy06882f82009-06-10 13:36:04 -07002873
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002874 // updateFocusedWindowLocked() already assigned layers so we only need to
2875 // reassign them at this point if the IM window state gets shuffled
2876 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002879 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2880 // Little hack here -- we -should- be able to rely on the
2881 // function to return true if the IME has moved and needs
2882 // its layer recomputed. However, if the IME was hidden
2883 // and isn't actually moved in the list, its layer may be
2884 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 assignLayers = true;
2886 }
2887 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002888 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002889 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002890 assignLayers = true;
2891 }
2892 }
Romain Guy06882f82009-06-10 13:36:04 -07002893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 mLayoutNeeded = true;
2895 win.mGivenInsetsPending = insetsPending;
2896 if (assignLayers) {
2897 assignLayersLocked();
2898 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002899 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002901 if (displayed && win.mIsWallpaper) {
2902 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002903 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 if (win.mAppToken != null) {
2906 win.mAppToken.updateReportedVisibilityLocked();
2907 }
2908 outFrame.set(win.mFrame);
2909 outContentInsets.set(win.mContentInsets);
2910 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002911 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002913 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 + ", requestedHeight=" + requestedHeight
2915 + ", viewVisibility=" + viewVisibility
2916 + "\nRelayout returning frame=" + outFrame
2917 + ", surface=" + outSurface);
2918
Joe Onorato8a9b2202010-02-26 18:56:32 -08002919 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2921
2922 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002923
2924 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 }
2926
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002927 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 sendNewConfiguration();
2929 }
Romain Guy06882f82009-06-10 13:36:04 -07002930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2934 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2935 }
2936
2937 public void finishDrawingWindow(Session session, IWindow client) {
2938 final long origId = Binder.clearCallingIdentity();
2939 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002940 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002942 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2943 adjustWallpaperWindowsLocked();
2944 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 mLayoutNeeded = true;
2946 performLayoutAndPlaceSurfacesLocked();
2947 }
2948 }
2949 Binder.restoreCallingIdentity(origId);
2950 }
2951
2952 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002953 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 + (lp != null ? lp.packageName : null)
2955 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2956 if (lp != null && lp.windowAnimations != 0) {
2957 // If this is a system resource, don't try to load it from the
2958 // application resources. It is nice to avoid loading application
2959 // resources if we can.
2960 String packageName = lp.packageName != null ? lp.packageName : "android";
2961 int resId = lp.windowAnimations;
2962 if ((resId&0xFF000000) == 0x01000000) {
2963 packageName = "android";
2964 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002965 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 + packageName);
2967 return AttributeCache.instance().get(packageName, resId,
2968 com.android.internal.R.styleable.WindowAnimation);
2969 }
2970 return null;
2971 }
Romain Guy06882f82009-06-10 13:36:04 -07002972
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002973 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002974 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002975 + packageName + " resId=0x" + Integer.toHexString(resId));
2976 if (packageName != null) {
2977 if ((resId&0xFF000000) == 0x01000000) {
2978 packageName = "android";
2979 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002980 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002981 + packageName);
2982 return AttributeCache.instance().get(packageName, resId,
2983 com.android.internal.R.styleable.WindowAnimation);
2984 }
2985 return null;
2986 }
2987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 private void applyEnterAnimationLocked(WindowState win) {
2989 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2990 if (win.mEnterAnimationPending) {
2991 win.mEnterAnimationPending = false;
2992 transit = WindowManagerPolicy.TRANSIT_ENTER;
2993 }
2994
2995 applyAnimationLocked(win, transit, true);
2996 }
2997
2998 private boolean applyAnimationLocked(WindowState win,
2999 int transit, boolean isEntrance) {
3000 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3001 // If we are trying to apply an animation, but already running
3002 // an animation of the same type, then just leave that one alone.
3003 return true;
3004 }
Romain Guy06882f82009-06-10 13:36:04 -07003005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 // Only apply an animation if the display isn't frozen. If it is
3007 // frozen, there is no reason to animate and it can cause strange
3008 // artifacts when we unfreeze the display if some different animation
3009 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003010 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 int anim = mPolicy.selectAnimationLw(win, transit);
3012 int attr = -1;
3013 Animation a = null;
3014 if (anim != 0) {
3015 a = AnimationUtils.loadAnimation(mContext, anim);
3016 } else {
3017 switch (transit) {
3018 case WindowManagerPolicy.TRANSIT_ENTER:
3019 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3020 break;
3021 case WindowManagerPolicy.TRANSIT_EXIT:
3022 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3023 break;
3024 case WindowManagerPolicy.TRANSIT_SHOW:
3025 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3026 break;
3027 case WindowManagerPolicy.TRANSIT_HIDE:
3028 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3029 break;
3030 }
3031 if (attr >= 0) {
3032 a = loadAnimation(win.mAttrs, attr);
3033 }
3034 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003035 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3037 + " mAnimation=" + win.mAnimation
3038 + " isEntrance=" + isEntrance);
3039 if (a != null) {
3040 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003041 RuntimeException e = null;
3042 if (!HIDE_STACK_CRAWLS) {
3043 e = new RuntimeException();
3044 e.fillInStackTrace();
3045 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003046 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 }
3048 win.setAnimation(a);
3049 win.mAnimationIsEntrance = isEntrance;
3050 }
3051 } else {
3052 win.clearAnimation();
3053 }
3054
3055 return win.mAnimation != null;
3056 }
3057
3058 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3059 int anim = 0;
3060 Context context = mContext;
3061 if (animAttr >= 0) {
3062 AttributeCache.Entry ent = getCachedAnimations(lp);
3063 if (ent != null) {
3064 context = ent.context;
3065 anim = ent.array.getResourceId(animAttr, 0);
3066 }
3067 }
3068 if (anim != 0) {
3069 return AnimationUtils.loadAnimation(context, anim);
3070 }
3071 return null;
3072 }
Romain Guy06882f82009-06-10 13:36:04 -07003073
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003074 private Animation loadAnimation(String packageName, int resId) {
3075 int anim = 0;
3076 Context context = mContext;
3077 if (resId >= 0) {
3078 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3079 if (ent != null) {
3080 context = ent.context;
3081 anim = resId;
3082 }
3083 }
3084 if (anim != 0) {
3085 return AnimationUtils.loadAnimation(context, anim);
3086 }
3087 return null;
3088 }
3089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 private boolean applyAnimationLocked(AppWindowToken wtoken,
3091 WindowManager.LayoutParams lp, int transit, boolean enter) {
3092 // Only apply an animation if the display isn't frozen. If it is
3093 // frozen, there is no reason to animate and it can cause strange
3094 // artifacts when we unfreeze the display if some different animation
3095 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003096 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003097 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003098 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003099 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003100 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003101 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003102 } else if (mNextAppTransitionPackage != null) {
3103 a = loadAnimation(mNextAppTransitionPackage, enter ?
3104 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003105 } else {
3106 int animAttr = 0;
3107 switch (transit) {
3108 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3109 animAttr = enter
3110 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3111 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3112 break;
3113 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3114 animAttr = enter
3115 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3116 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3117 break;
3118 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3119 animAttr = enter
3120 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3121 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3122 break;
3123 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3124 animAttr = enter
3125 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3126 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3127 break;
3128 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3129 animAttr = enter
3130 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3131 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3132 break;
3133 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3134 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003135 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003136 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3137 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003138 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003139 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003140 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3141 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003142 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003143 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003144 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003145 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3146 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3147 break;
3148 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3149 animAttr = enter
3150 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3151 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3152 break;
3153 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3154 animAttr = enter
3155 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3156 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003157 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003158 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003159 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003160 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003161 + " anim=" + a
3162 + " animAttr=0x" + Integer.toHexString(animAttr)
3163 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003165 if (a != null) {
3166 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003167 RuntimeException e = null;
3168 if (!HIDE_STACK_CRAWLS) {
3169 e = new RuntimeException();
3170 e.fillInStackTrace();
3171 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003172 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 }
3174 wtoken.setAnimation(a);
3175 }
3176 } else {
3177 wtoken.clearAnimation();
3178 }
3179
3180 return wtoken.animation != null;
3181 }
3182
3183 // -------------------------------------------------------------
3184 // Application Window Tokens
3185 // -------------------------------------------------------------
3186
3187 public void validateAppTokens(List tokens) {
3188 int v = tokens.size()-1;
3189 int m = mAppTokens.size()-1;
3190 while (v >= 0 && m >= 0) {
3191 AppWindowToken wtoken = mAppTokens.get(m);
3192 if (wtoken.removed) {
3193 m--;
3194 continue;
3195 }
3196 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003197 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3199 }
3200 v--;
3201 m--;
3202 }
3203 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003204 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 v--;
3206 }
3207 while (m >= 0) {
3208 AppWindowToken wtoken = mAppTokens.get(m);
3209 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003210 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 }
3212 m--;
3213 }
3214 }
3215
3216 boolean checkCallingPermission(String permission, String func) {
3217 // Quick check: if the calling permission is me, it's all okay.
3218 if (Binder.getCallingPid() == Process.myPid()) {
3219 return true;
3220 }
Romain Guy06882f82009-06-10 13:36:04 -07003221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 if (mContext.checkCallingPermission(permission)
3223 == PackageManager.PERMISSION_GRANTED) {
3224 return true;
3225 }
3226 String msg = "Permission Denial: " + func + " from pid="
3227 + Binder.getCallingPid()
3228 + ", uid=" + Binder.getCallingUid()
3229 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003230 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 return false;
3232 }
Romain Guy06882f82009-06-10 13:36:04 -07003233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003234 AppWindowToken findAppWindowToken(IBinder token) {
3235 WindowToken wtoken = mTokenMap.get(token);
3236 if (wtoken == null) {
3237 return null;
3238 }
3239 return wtoken.appWindowToken;
3240 }
Romain Guy06882f82009-06-10 13:36:04 -07003241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 public void addWindowToken(IBinder token, int type) {
3243 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3244 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003245 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 }
Romain Guy06882f82009-06-10 13:36:04 -07003247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 synchronized(mWindowMap) {
3249 WindowToken wtoken = mTokenMap.get(token);
3250 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003251 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 return;
3253 }
3254 wtoken = new WindowToken(token, type, true);
3255 mTokenMap.put(token, wtoken);
3256 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003257 if (type == TYPE_WALLPAPER) {
3258 mWallpaperTokens.add(wtoken);
3259 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 }
3261 }
Romain Guy06882f82009-06-10 13:36:04 -07003262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 public void removeWindowToken(IBinder token) {
3264 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3265 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003266 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 }
3268
3269 final long origId = Binder.clearCallingIdentity();
3270 synchronized(mWindowMap) {
3271 WindowToken wtoken = mTokenMap.remove(token);
3272 mTokenList.remove(wtoken);
3273 if (wtoken != null) {
3274 boolean delayed = false;
3275 if (!wtoken.hidden) {
3276 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 final int N = wtoken.windows.size();
3279 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 for (int i=0; i<N; i++) {
3282 WindowState win = wtoken.windows.get(i);
3283
3284 if (win.isAnimating()) {
3285 delayed = true;
3286 }
Romain Guy06882f82009-06-10 13:36:04 -07003287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 if (win.isVisibleNow()) {
3289 applyAnimationLocked(win,
3290 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 changed = true;
3292 }
3293 }
3294
3295 if (changed) {
3296 mLayoutNeeded = true;
3297 performLayoutAndPlaceSurfacesLocked();
3298 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3299 }
Romain Guy06882f82009-06-10 13:36:04 -07003300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 if (delayed) {
3302 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003303 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3304 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 }
3306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
Jeff Brownc5ed5912010-07-14 18:48:53 -07003308 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003310 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 }
3312 }
3313 Binder.restoreCallingIdentity(origId);
3314 }
3315
3316 public void addAppToken(int addPos, IApplicationToken token,
3317 int groupId, int requestedOrientation, boolean fullscreen) {
3318 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3319 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003320 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 }
Jeff Brown349703e2010-06-22 01:27:15 -07003322
3323 // Get the dispatching timeout here while we are not holding any locks so that it
3324 // can be cached by the AppWindowToken. The timeout value is used later by the
3325 // input dispatcher in code that does hold locks. If we did not cache the value
3326 // here we would run the chance of introducing a deadlock between the window manager
3327 // (which holds locks while updating the input dispatcher state) and the activity manager
3328 // (which holds locks while querying the application token).
3329 long inputDispatchingTimeoutNanos;
3330 try {
3331 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3332 } catch (RemoteException ex) {
3333 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3334 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3335 }
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 synchronized(mWindowMap) {
3338 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3339 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003340 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 return;
3342 }
3343 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003344 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 wtoken.groupId = groupId;
3346 wtoken.appFullscreen = fullscreen;
3347 wtoken.requestedOrientation = requestedOrientation;
3348 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003349 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 mTokenMap.put(token.asBinder(), wtoken);
3351 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 // Application tokens start out hidden.
3354 wtoken.hidden = true;
3355 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 //dump();
3358 }
3359 }
Romain Guy06882f82009-06-10 13:36:04 -07003360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 public void setAppGroupId(IBinder token, int groupId) {
3362 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3363 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003364 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 }
3366
3367 synchronized(mWindowMap) {
3368 AppWindowToken wtoken = findAppWindowToken(token);
3369 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003370 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 return;
3372 }
3373 wtoken.groupId = groupId;
3374 }
3375 }
Romain Guy06882f82009-06-10 13:36:04 -07003376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 public int getOrientationFromWindowsLocked() {
3378 int pos = mWindows.size() - 1;
3379 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003380 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 pos--;
3382 if (wtoken.mAppToken != null) {
3383 // We hit an application window. so the orientation will be determined by the
3384 // app window. No point in continuing further.
3385 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3386 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003387 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 continue;
3389 }
3390 int req = wtoken.mAttrs.screenOrientation;
3391 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3392 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3393 continue;
3394 } else {
3395 return req;
3396 }
3397 }
3398 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3399 }
Romain Guy06882f82009-06-10 13:36:04 -07003400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003402 int pos = mAppTokens.size() - 1;
3403 int curGroup = 0;
3404 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3405 boolean findingBehind = false;
3406 boolean haveGroup = false;
3407 boolean lastFullscreen = false;
3408 while (pos >= 0) {
3409 AppWindowToken wtoken = mAppTokens.get(pos);
3410 pos--;
3411 // if we're about to tear down this window and not seek for
3412 // the behind activity, don't use it for orientation
3413 if (!findingBehind
3414 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3415 continue;
3416 }
3417
3418 if (!haveGroup) {
3419 // We ignore any hidden applications on the top.
3420 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003421 continue;
3422 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003423 haveGroup = true;
3424 curGroup = wtoken.groupId;
3425 lastOrientation = wtoken.requestedOrientation;
3426 } else if (curGroup != wtoken.groupId) {
3427 // If we have hit a new application group, and the bottom
3428 // of the previous group didn't explicitly say to use
3429 // the orientation behind it, and the last app was
3430 // full screen, then we'll stick with the
3431 // user's orientation.
3432 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3433 && lastFullscreen) {
3434 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003437 int or = wtoken.requestedOrientation;
3438 // If this application is fullscreen, and didn't explicitly say
3439 // to use the orientation behind it, then just take whatever
3440 // orientation it has and ignores whatever is under it.
3441 lastFullscreen = wtoken.appFullscreen;
3442 if (lastFullscreen
3443 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3444 return or;
3445 }
3446 // If this application has requested an explicit orientation,
3447 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003448 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3449 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003450 return or;
3451 }
3452 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3453 }
3454 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 }
Romain Guy06882f82009-06-10 13:36:04 -07003456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003458 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003459 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3460 "updateOrientationFromAppTokens()")) {
3461 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3462 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003463
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003464 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003465 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003466
3467 synchronized(mWindowMap) {
3468 if (updateOrientationFromAppTokensLocked()) {
3469 if (freezeThisOneIfNeeded != null) {
3470 AppWindowToken wtoken = findAppWindowToken(
3471 freezeThisOneIfNeeded);
3472 if (wtoken != null) {
3473 startAppFreezingScreenLocked(wtoken,
3474 ActivityInfo.CONFIG_ORIENTATION);
3475 }
3476 }
3477 config = computeNewConfigurationLocked();
3478
3479 } else if (currentConfig != null) {
3480 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003481 // state mismatches the activity manager's, update it,
3482 // disregarding font scale, which should remain set to
3483 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003484 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003485 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003486 if (computeNewConfigurationLocked(mTempConfiguration)) {
3487 if (currentConfig.diff(mTempConfiguration) != 0) {
3488 mWaitingForConfig = true;
3489 mLayoutNeeded = true;
3490 startFreezingDisplayLocked();
3491 config = new Configuration(mTempConfiguration);
3492 }
3493 }
3494 }
3495 }
3496
Dianne Hackborncfaef692009-06-15 14:24:44 -07003497 Binder.restoreCallingIdentity(ident);
3498 return config;
3499 }
3500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003502 * Determine the new desired orientation of the display, returning
3503 * a non-null new Configuration if it has changed from the current
3504 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3505 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3506 * SCREEN. This will typically be done for you if you call
3507 * sendNewConfiguration().
3508 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 * The orientation is computed from non-application windows first. If none of
3510 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003511 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3513 * android.os.IBinder)
3514 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003515 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003516 if (mDisplayFrozen) {
3517 // If the display is frozen, some activities may be in the middle
3518 // of restarting, and thus have removed their old window. If the
3519 // window has the flag to hide the lock screen, then the lock screen
3520 // can re-appear and inflict its own orientation on us. Keep the
3521 // orientation stable until this all settles down.
3522 return false;
3523 }
3524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003525 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 long ident = Binder.clearCallingIdentity();
3527 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003528 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 mForcedAppOrientation = req;
3532 //send a message to Policy indicating orientation change to take
3533 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003534 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003535 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3536 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3537 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 }
3539 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003540
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003541 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 } finally {
3543 Binder.restoreCallingIdentity(ident);
3544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 }
Romain Guy06882f82009-06-10 13:36:04 -07003546
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003547 int computeForcedAppOrientationLocked() {
3548 int req = getOrientationFromWindowsLocked();
3549 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3550 req = getOrientationFromAppTokensLocked();
3551 }
3552 return req;
3553 }
Romain Guy06882f82009-06-10 13:36:04 -07003554
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003555 public void setNewConfiguration(Configuration config) {
3556 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3557 "setNewConfiguration()")) {
3558 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3559 }
3560
3561 synchronized(mWindowMap) {
3562 mCurConfiguration = new Configuration(config);
3563 mWaitingForConfig = false;
3564 performLayoutAndPlaceSurfacesLocked();
3565 }
3566 }
3567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3569 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3570 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003571 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 }
Romain Guy06882f82009-06-10 13:36:04 -07003573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 synchronized(mWindowMap) {
3575 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3576 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003577 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 return;
3579 }
Romain Guy06882f82009-06-10 13:36:04 -07003580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 wtoken.requestedOrientation = requestedOrientation;
3582 }
3583 }
Romain Guy06882f82009-06-10 13:36:04 -07003584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 public int getAppOrientation(IApplicationToken token) {
3586 synchronized(mWindowMap) {
3587 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3588 if (wtoken == null) {
3589 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3590 }
Romain Guy06882f82009-06-10 13:36:04 -07003591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 return wtoken.requestedOrientation;
3593 }
3594 }
Romain Guy06882f82009-06-10 13:36:04 -07003595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3598 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 }
3601
3602 synchronized(mWindowMap) {
3603 boolean changed = false;
3604 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003605 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 changed = mFocusedApp != null;
3607 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003608 if (changed) {
3609 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 } else {
3612 AppWindowToken newFocus = findAppWindowToken(token);
3613 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003614 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 return;
3616 }
3617 changed = mFocusedApp != newFocus;
3618 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003619 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003620 if (changed) {
3621 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 }
3624
3625 if (moveFocusNow && changed) {
3626 final long origId = Binder.clearCallingIdentity();
3627 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3628 Binder.restoreCallingIdentity(origId);
3629 }
3630 }
3631 }
3632
3633 public void prepareAppTransition(int transit) {
3634 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3635 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003636 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 }
Romain Guy06882f82009-06-10 13:36:04 -07003638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003640 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 TAG, "Prepare app transition: transit=" + transit
3642 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003643 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003644 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3645 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003646 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003647 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3648 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3649 // Opening a new task always supersedes a close for the anim.
3650 mNextAppTransition = transit;
3651 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3652 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3653 // Opening a new activity always supersedes a close for the anim.
3654 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 }
3656 mAppTransitionReady = false;
3657 mAppTransitionTimeout = false;
3658 mStartingIconInTransition = false;
3659 mSkipAppTransitionAnimation = false;
3660 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3661 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3662 5000);
3663 }
3664 }
3665 }
3666
3667 public int getPendingAppTransition() {
3668 return mNextAppTransition;
3669 }
Romain Guy06882f82009-06-10 13:36:04 -07003670
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003671 public void overridePendingAppTransition(String packageName,
3672 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003673 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003674 mNextAppTransitionPackage = packageName;
3675 mNextAppTransitionEnter = enterAnim;
3676 mNextAppTransitionExit = exitAnim;
3677 }
3678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 public void executeAppTransition() {
3681 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3682 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003683 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 }
Romain Guy06882f82009-06-10 13:36:04 -07003685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003687 if (DEBUG_APP_TRANSITIONS) {
3688 RuntimeException e = new RuntimeException("here");
3689 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003690 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003691 + mNextAppTransition, e);
3692 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003693 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 mAppTransitionReady = true;
3695 final long origId = Binder.clearCallingIdentity();
3696 performLayoutAndPlaceSurfacesLocked();
3697 Binder.restoreCallingIdentity(origId);
3698 }
3699 }
3700 }
3701
3702 public void setAppStartingWindow(IBinder token, String pkg,
3703 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3704 IBinder transferFrom, boolean createIfNeeded) {
3705 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3706 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003707 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 }
3709
3710 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003711 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3713 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 AppWindowToken wtoken = findAppWindowToken(token);
3716 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003717 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 return;
3719 }
3720
3721 // If the display is frozen, we won't do anything until the
3722 // actual window is displayed so there is no reason to put in
3723 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003724 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 return;
3726 }
Romain Guy06882f82009-06-10 13:36:04 -07003727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 if (wtoken.startingData != null) {
3729 return;
3730 }
Romain Guy06882f82009-06-10 13:36:04 -07003731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003732 if (transferFrom != null) {
3733 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3734 if (ttoken != null) {
3735 WindowState startingWindow = ttoken.startingWindow;
3736 if (startingWindow != null) {
3737 if (mStartingIconInTransition) {
3738 // In this case, the starting icon has already
3739 // been displayed, so start letting windows get
3740 // shown immediately without any more transitions.
3741 mSkipAppTransitionAnimation = true;
3742 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003743 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 "Moving existing starting from " + ttoken
3745 + " to " + wtoken);
3746 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 // Transfer the starting window over to the new
3749 // token.
3750 wtoken.startingData = ttoken.startingData;
3751 wtoken.startingView = ttoken.startingView;
3752 wtoken.startingWindow = startingWindow;
3753 ttoken.startingData = null;
3754 ttoken.startingView = null;
3755 ttoken.startingWindow = null;
3756 ttoken.startingMoved = true;
3757 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003758 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003760 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003761 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003763 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 ttoken.windows.remove(startingWindow);
3765 ttoken.allAppWindows.remove(startingWindow);
3766 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 // Propagate other interesting state between the
3769 // tokens. If the old token is displayed, we should
3770 // immediately force the new one to be displayed. If
3771 // it is animating, we need to move that animation to
3772 // the new one.
3773 if (ttoken.allDrawn) {
3774 wtoken.allDrawn = true;
3775 }
3776 if (ttoken.firstWindowDrawn) {
3777 wtoken.firstWindowDrawn = true;
3778 }
3779 if (!ttoken.hidden) {
3780 wtoken.hidden = false;
3781 wtoken.hiddenRequested = false;
3782 wtoken.willBeHidden = false;
3783 }
3784 if (wtoken.clientHidden != ttoken.clientHidden) {
3785 wtoken.clientHidden = ttoken.clientHidden;
3786 wtoken.sendAppVisibilityToClients();
3787 }
3788 if (ttoken.animation != null) {
3789 wtoken.animation = ttoken.animation;
3790 wtoken.animating = ttoken.animating;
3791 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3792 ttoken.animation = null;
3793 ttoken.animLayerAdjustment = 0;
3794 wtoken.updateLayers();
3795 ttoken.updateLayers();
3796 }
Romain Guy06882f82009-06-10 13:36:04 -07003797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 mLayoutNeeded = true;
3800 performLayoutAndPlaceSurfacesLocked();
3801 Binder.restoreCallingIdentity(origId);
3802 return;
3803 } else if (ttoken.startingData != null) {
3804 // The previous app was getting ready to show a
3805 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003806 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 "Moving pending starting from " + ttoken
3808 + " to " + wtoken);
3809 wtoken.startingData = ttoken.startingData;
3810 ttoken.startingData = null;
3811 ttoken.startingMoved = true;
3812 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3813 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3814 // want to process the message ASAP, before any other queued
3815 // messages.
3816 mH.sendMessageAtFrontOfQueue(m);
3817 return;
3818 }
3819 }
3820 }
3821
3822 // There is no existing starting window, and the caller doesn't
3823 // want us to create one, so that's it!
3824 if (!createIfNeeded) {
3825 return;
3826 }
Romain Guy06882f82009-06-10 13:36:04 -07003827
Dianne Hackborn284ac932009-08-28 10:34:25 -07003828 // If this is a translucent or wallpaper window, then don't
3829 // show a starting window -- the current effect (a full-screen
3830 // opaque starting window that fades away to the real contents
3831 // when it is ready) does not work for this.
3832 if (theme != 0) {
3833 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3834 com.android.internal.R.styleable.Window);
3835 if (ent.array.getBoolean(
3836 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3837 return;
3838 }
3839 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003840 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3841 return;
3842 }
3843 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003844 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3845 return;
3846 }
3847 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003849 mStartingIconInTransition = true;
3850 wtoken.startingData = new StartingData(
3851 pkg, theme, nonLocalizedLabel,
3852 labelRes, icon);
3853 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3854 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3855 // want to process the message ASAP, before any other queued
3856 // messages.
3857 mH.sendMessageAtFrontOfQueue(m);
3858 }
3859 }
3860
3861 public void setAppWillBeHidden(IBinder token) {
3862 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3863 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003864 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 }
3866
3867 AppWindowToken wtoken;
3868
3869 synchronized(mWindowMap) {
3870 wtoken = findAppWindowToken(token);
3871 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003872 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 -08003873 return;
3874 }
3875 wtoken.willBeHidden = true;
3876 }
3877 }
Romain Guy06882f82009-06-10 13:36:04 -07003878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3880 boolean visible, int transit, boolean performLayout) {
3881 boolean delayed = false;
3882
3883 if (wtoken.clientHidden == visible) {
3884 wtoken.clientHidden = !visible;
3885 wtoken.sendAppVisibilityToClients();
3886 }
Romain Guy06882f82009-06-10 13:36:04 -07003887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 wtoken.willBeHidden = false;
3889 if (wtoken.hidden == visible) {
3890 final int N = wtoken.allAppWindows.size();
3891 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003892 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3894 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003897
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003898 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 if (wtoken.animation == sDummyAnimation) {
3900 wtoken.animation = null;
3901 }
3902 applyAnimationLocked(wtoken, lp, transit, visible);
3903 changed = true;
3904 if (wtoken.animation != null) {
3905 delayed = runningAppAnimation = true;
3906 }
3907 }
Romain Guy06882f82009-06-10 13:36:04 -07003908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003909 for (int i=0; i<N; i++) {
3910 WindowState win = wtoken.allAppWindows.get(i);
3911 if (win == wtoken.startingWindow) {
3912 continue;
3913 }
3914
3915 if (win.isAnimating()) {
3916 delayed = true;
3917 }
Romain Guy06882f82009-06-10 13:36:04 -07003918
Joe Onorato8a9b2202010-02-26 18:56:32 -08003919 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 //win.dump(" ");
3921 if (visible) {
3922 if (!win.isVisibleNow()) {
3923 if (!runningAppAnimation) {
3924 applyAnimationLocked(win,
3925 WindowManagerPolicy.TRANSIT_ENTER, true);
3926 }
3927 changed = true;
3928 }
3929 } else if (win.isVisibleNow()) {
3930 if (!runningAppAnimation) {
3931 applyAnimationLocked(win,
3932 WindowManagerPolicy.TRANSIT_EXIT, false);
3933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 changed = true;
3935 }
3936 }
3937
3938 wtoken.hidden = wtoken.hiddenRequested = !visible;
3939 if (!visible) {
3940 unsetAppFreezingScreenLocked(wtoken, true, true);
3941 } else {
3942 // If we are being set visible, and the starting window is
3943 // not yet displayed, then make sure it doesn't get displayed.
3944 WindowState swin = wtoken.startingWindow;
3945 if (swin != null && (swin.mDrawPending
3946 || swin.mCommitDrawPending)) {
3947 swin.mPolicyVisibility = false;
3948 swin.mPolicyVisibilityAfterAnim = false;
3949 }
3950 }
Romain Guy06882f82009-06-10 13:36:04 -07003951
Joe Onorato8a9b2202010-02-26 18:56:32 -08003952 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3954 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003955
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003956 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003958 if (performLayout) {
3959 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3960 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003961 } else {
3962 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 }
3965 }
3966
3967 if (wtoken.animation != null) {
3968 delayed = true;
3969 }
Romain Guy06882f82009-06-10 13:36:04 -07003970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 return delayed;
3972 }
3973
3974 public void setAppVisibility(IBinder token, boolean visible) {
3975 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3976 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003977 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 }
3979
3980 AppWindowToken wtoken;
3981
3982 synchronized(mWindowMap) {
3983 wtoken = findAppWindowToken(token);
3984 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003985 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 return;
3987 }
3988
3989 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003990 RuntimeException e = null;
3991 if (!HIDE_STACK_CRAWLS) {
3992 e = new RuntimeException();
3993 e.fillInStackTrace();
3994 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 + "): mNextAppTransition=" + mNextAppTransition
3997 + " hidden=" + wtoken.hidden
3998 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3999 }
Romain Guy06882f82009-06-10 13:36:04 -07004000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 // If we are preparing an app transition, then delay changing
4002 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004003 if (!mDisplayFrozen && mPolicy.isScreenOn()
4004 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 // Already in requested state, don't do anything more.
4006 if (wtoken.hiddenRequested != visible) {
4007 return;
4008 }
4009 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004010
Joe Onorato8a9b2202010-02-26 18:56:32 -08004011 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 TAG, "Setting dummy animation on: " + wtoken);
4013 wtoken.setDummyAnimation();
4014 mOpeningApps.remove(wtoken);
4015 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004016 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004017 wtoken.inPendingTransaction = true;
4018 if (visible) {
4019 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 wtoken.startingDisplayed = false;
4021 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004022
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004023 // If the token is currently hidden (should be the
4024 // common case), then we need to set up to wait for
4025 // its windows to be ready.
4026 if (wtoken.hidden) {
4027 wtoken.allDrawn = false;
4028 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004029
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004030 if (wtoken.clientHidden) {
4031 // In the case where we are making an app visible
4032 // but holding off for a transition, we still need
4033 // to tell the client to make its windows visible so
4034 // they get drawn. Otherwise, we will wait on
4035 // performing the transition until all windows have
4036 // been drawn, they never will be, and we are sad.
4037 wtoken.clientHidden = false;
4038 wtoken.sendAppVisibilityToClients();
4039 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 }
4041 } else {
4042 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004043
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004044 // If the token is currently visible (should be the
4045 // common case), then set up to wait for it to be hidden.
4046 if (!wtoken.hidden) {
4047 wtoken.waitingToHide = true;
4048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004049 }
4050 return;
4051 }
Romain Guy06882f82009-06-10 13:36:04 -07004052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004053 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004054 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004055 wtoken.updateReportedVisibilityLocked();
4056 Binder.restoreCallingIdentity(origId);
4057 }
4058 }
4059
4060 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4061 boolean unfreezeSurfaceNow, boolean force) {
4062 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004063 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 + " force=" + force);
4065 final int N = wtoken.allAppWindows.size();
4066 boolean unfrozeWindows = false;
4067 for (int i=0; i<N; i++) {
4068 WindowState w = wtoken.allAppWindows.get(i);
4069 if (w.mAppFreezing) {
4070 w.mAppFreezing = false;
4071 if (w.mSurface != null && !w.mOrientationChanging) {
4072 w.mOrientationChanging = true;
4073 }
4074 unfrozeWindows = true;
4075 }
4076 }
4077 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004078 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 wtoken.freezingScreen = false;
4080 mAppsFreezingScreen--;
4081 }
4082 if (unfreezeSurfaceNow) {
4083 if (unfrozeWindows) {
4084 mLayoutNeeded = true;
4085 performLayoutAndPlaceSurfacesLocked();
4086 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004087 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 }
4089 }
4090 }
Romain Guy06882f82009-06-10 13:36:04 -07004091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4093 int configChanges) {
4094 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004095 RuntimeException e = null;
4096 if (!HIDE_STACK_CRAWLS) {
4097 e = new RuntimeException();
4098 e.fillInStackTrace();
4099 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004100 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 + ": hidden=" + wtoken.hidden + " freezing="
4102 + wtoken.freezingScreen, e);
4103 }
4104 if (!wtoken.hiddenRequested) {
4105 if (!wtoken.freezingScreen) {
4106 wtoken.freezingScreen = true;
4107 mAppsFreezingScreen++;
4108 if (mAppsFreezingScreen == 1) {
4109 startFreezingDisplayLocked();
4110 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4111 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4112 5000);
4113 }
4114 }
4115 final int N = wtoken.allAppWindows.size();
4116 for (int i=0; i<N; i++) {
4117 WindowState w = wtoken.allAppWindows.get(i);
4118 w.mAppFreezing = true;
4119 }
4120 }
4121 }
Romain Guy06882f82009-06-10 13:36:04 -07004122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 public void startAppFreezingScreen(IBinder token, int configChanges) {
4124 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4125 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004126 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 }
4128
4129 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004130 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004131 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 return;
4133 }
Romain Guy06882f82009-06-10 13:36:04 -07004134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 AppWindowToken wtoken = findAppWindowToken(token);
4136 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004137 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 return;
4139 }
4140 final long origId = Binder.clearCallingIdentity();
4141 startAppFreezingScreenLocked(wtoken, configChanges);
4142 Binder.restoreCallingIdentity(origId);
4143 }
4144 }
Romain Guy06882f82009-06-10 13:36:04 -07004145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 public void stopAppFreezingScreen(IBinder token, boolean force) {
4147 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4148 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004149 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004150 }
4151
4152 synchronized(mWindowMap) {
4153 AppWindowToken wtoken = findAppWindowToken(token);
4154 if (wtoken == null || wtoken.appToken == null) {
4155 return;
4156 }
4157 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004158 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004159 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4160 unsetAppFreezingScreenLocked(wtoken, true, force);
4161 Binder.restoreCallingIdentity(origId);
4162 }
4163 }
Romain Guy06882f82009-06-10 13:36:04 -07004164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 public void removeAppToken(IBinder token) {
4166 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4167 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004168 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 }
4170
4171 AppWindowToken wtoken = null;
4172 AppWindowToken startingToken = null;
4173 boolean delayed = false;
4174
4175 final long origId = Binder.clearCallingIdentity();
4176 synchronized(mWindowMap) {
4177 WindowToken basewtoken = mTokenMap.remove(token);
4178 mTokenList.remove(basewtoken);
4179 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004180 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004181 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 wtoken.inPendingTransaction = false;
4183 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004184 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 if (mClosingApps.contains(wtoken)) {
4186 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004187 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004189 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 delayed = true;
4191 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004192 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 TAG, "Removing app " + wtoken + " delayed=" + delayed
4194 + " animation=" + wtoken.animation
4195 + " animating=" + wtoken.animating);
4196 if (delayed) {
4197 // set the token aside because it has an active animation to be finished
4198 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004199 } else {
4200 // Make sure there is no animation running on this token,
4201 // so any windows associated with it will be removed as
4202 // soon as their animations are complete
4203 wtoken.animation = null;
4204 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 }
4206 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004207 if (mLastEnterAnimToken == wtoken) {
4208 mLastEnterAnimToken = null;
4209 mLastEnterAnimParams = null;
4210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 wtoken.removed = true;
4212 if (wtoken.startingData != null) {
4213 startingToken = wtoken;
4214 }
4215 unsetAppFreezingScreenLocked(wtoken, true, true);
4216 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004217 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 mFocusedApp = null;
4219 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004220 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 }
4222 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004223 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004224 }
Romain Guy06882f82009-06-10 13:36:04 -07004225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 if (!delayed && wtoken != null) {
4227 wtoken.updateReportedVisibilityLocked();
4228 }
4229 }
4230 Binder.restoreCallingIdentity(origId);
4231
4232 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004233 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004234 + startingToken + ": app token removed");
4235 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4236 mH.sendMessage(m);
4237 }
4238 }
4239
4240 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4241 final int NW = token.windows.size();
4242 for (int i=0; i<NW; i++) {
4243 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004244 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004246 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 int j = win.mChildWindows.size();
4248 while (j > 0) {
4249 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004250 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004251 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004252 "Tmp removing child window " + cwin);
4253 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 }
4255 }
4256 return NW > 0;
4257 }
4258
4259 void dumpAppTokensLocked() {
4260 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004261 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 }
4263 }
Romain Guy06882f82009-06-10 13:36:04 -07004264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 void dumpWindowsLocked() {
4266 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004267 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 }
4269 }
Romain Guy06882f82009-06-10 13:36:04 -07004270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 private int findWindowOffsetLocked(int tokenPos) {
4272 final int NW = mWindows.size();
4273
4274 if (tokenPos >= mAppTokens.size()) {
4275 int i = NW;
4276 while (i > 0) {
4277 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004278 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 if (win.getAppToken() != null) {
4280 return i+1;
4281 }
4282 }
4283 }
4284
4285 while (tokenPos > 0) {
4286 // Find the first app token below the new position that has
4287 // a window displayed.
4288 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004289 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004291 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004292 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004293 "Skipping token -- currently sending to bottom");
4294 tokenPos--;
4295 continue;
4296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 int i = wtoken.windows.size();
4298 while (i > 0) {
4299 i--;
4300 WindowState win = wtoken.windows.get(i);
4301 int j = win.mChildWindows.size();
4302 while (j > 0) {
4303 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004304 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004305 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 for (int pos=NW-1; pos>=0; pos--) {
4307 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004308 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 "Found child win @" + (pos+1));
4310 return pos+1;
4311 }
4312 }
4313 }
4314 }
4315 for (int pos=NW-1; pos>=0; pos--) {
4316 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004317 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 return pos+1;
4319 }
4320 }
4321 }
4322 tokenPos--;
4323 }
4324
4325 return 0;
4326 }
4327
4328 private final int reAddWindowLocked(int index, WindowState win) {
4329 final int NCW = win.mChildWindows.size();
4330 boolean added = false;
4331 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004332 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004334 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004335 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 mWindows.add(index, win);
4337 index++;
4338 added = true;
4339 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004340 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004341 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 mWindows.add(index, cwin);
4343 index++;
4344 }
4345 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004346 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004347 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348 mWindows.add(index, win);
4349 index++;
4350 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004351 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 return index;
4353 }
Romain Guy06882f82009-06-10 13:36:04 -07004354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4356 final int NW = token.windows.size();
4357 for (int i=0; i<NW; i++) {
4358 index = reAddWindowLocked(index, token.windows.get(i));
4359 }
4360 return index;
4361 }
4362
4363 public void moveAppToken(int index, IBinder token) {
4364 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4365 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004366 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 }
4368
4369 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004370 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004371 if (DEBUG_REORDER) dumpAppTokensLocked();
4372 final AppWindowToken wtoken = findAppWindowToken(token);
4373 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004374 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004375 + token + " (" + wtoken + ")");
4376 return;
4377 }
4378 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004379 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004383 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 if (DEBUG_REORDER) dumpWindowsLocked();
4385 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004386 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 if (DEBUG_REORDER) dumpWindowsLocked();
4388 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004389 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 if (DEBUG_REORDER) dumpWindowsLocked();
4391 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392 mLayoutNeeded = true;
4393 performLayoutAndPlaceSurfacesLocked();
4394 }
4395 Binder.restoreCallingIdentity(origId);
4396 }
4397 }
4398
4399 private void removeAppTokensLocked(List<IBinder> tokens) {
4400 // XXX This should be done more efficiently!
4401 // (take advantage of the fact that both lists should be
4402 // ordered in the same way.)
4403 int N = tokens.size();
4404 for (int i=0; i<N; i++) {
4405 IBinder token = tokens.get(i);
4406 final AppWindowToken wtoken = findAppWindowToken(token);
4407 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004408 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 + token + " (" + wtoken + ")");
4410 i--;
4411 N--;
4412 }
4413 }
4414 }
4415
Dianne Hackborna8f60182009-09-01 19:01:50 -07004416 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4417 boolean updateFocusAndLayout) {
4418 // First remove all of the windows from the list.
4419 tmpRemoveAppWindowsLocked(wtoken);
4420
4421 // Where to start adding?
4422 int pos = findWindowOffsetLocked(tokenPos);
4423
4424 // And now add them back at the correct place.
4425 pos = reAddAppWindowsLocked(pos, wtoken);
4426
4427 if (updateFocusAndLayout) {
4428 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4429 assignLayersLocked();
4430 }
4431 mLayoutNeeded = true;
4432 performLayoutAndPlaceSurfacesLocked();
4433 }
4434 }
4435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4437 // First remove all of the windows from the list.
4438 final int N = tokens.size();
4439 int i;
4440 for (i=0; i<N; i++) {
4441 WindowToken token = mTokenMap.get(tokens.get(i));
4442 if (token != null) {
4443 tmpRemoveAppWindowsLocked(token);
4444 }
4445 }
4446
4447 // Where to start adding?
4448 int pos = findWindowOffsetLocked(tokenPos);
4449
4450 // And now add them back at the correct place.
4451 for (i=0; i<N; i++) {
4452 WindowToken token = mTokenMap.get(tokens.get(i));
4453 if (token != null) {
4454 pos = reAddAppWindowsLocked(pos, token);
4455 }
4456 }
4457
Dianne Hackborna8f60182009-09-01 19:01:50 -07004458 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4459 assignLayersLocked();
4460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 mLayoutNeeded = true;
4462 performLayoutAndPlaceSurfacesLocked();
4463
4464 //dump();
4465 }
4466
4467 public void moveAppTokensToTop(List<IBinder> tokens) {
4468 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4469 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004470 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 }
4472
4473 final long origId = Binder.clearCallingIdentity();
4474 synchronized(mWindowMap) {
4475 removeAppTokensLocked(tokens);
4476 final int N = tokens.size();
4477 for (int i=0; i<N; i++) {
4478 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4479 if (wt != null) {
4480 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004481 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004482 mToTopApps.remove(wt);
4483 mToBottomApps.remove(wt);
4484 mToTopApps.add(wt);
4485 wt.sendingToBottom = false;
4486 wt.sendingToTop = true;
4487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 }
4489 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004490
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004491 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004492 moveAppWindowsLocked(tokens, mAppTokens.size());
4493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 }
4495 Binder.restoreCallingIdentity(origId);
4496 }
4497
4498 public void moveAppTokensToBottom(List<IBinder> tokens) {
4499 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4500 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004501 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 }
4503
4504 final long origId = Binder.clearCallingIdentity();
4505 synchronized(mWindowMap) {
4506 removeAppTokensLocked(tokens);
4507 final int N = tokens.size();
4508 int pos = 0;
4509 for (int i=0; i<N; i++) {
4510 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4511 if (wt != null) {
4512 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004513 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004514 mToTopApps.remove(wt);
4515 mToBottomApps.remove(wt);
4516 mToBottomApps.add(i, wt);
4517 wt.sendingToTop = false;
4518 wt.sendingToBottom = true;
4519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 pos++;
4521 }
4522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004523
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004524 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004525 moveAppWindowsLocked(tokens, 0);
4526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 }
4528 Binder.restoreCallingIdentity(origId);
4529 }
4530
4531 // -------------------------------------------------------------
4532 // Misc IWindowSession methods
4533 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004534
Jim Miller284b62e2010-06-08 14:27:42 -07004535 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004536 {
Jim Miller284b62e2010-06-08 14:27:42 -07004537 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4538 // called before DevicePolicyManagerService has started.
4539 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4540 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4541 Context.DEVICE_POLICY_SERVICE);
4542 if (dpm != null) {
4543 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4544 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4545 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4546 }
Jim Millerd6b57052010-06-07 17:52:42 -07004547 }
Jim Miller284b62e2010-06-08 14:27:42 -07004548 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004549 }
4550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004552 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004553 != PackageManager.PERMISSION_GRANTED) {
4554 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4555 }
Jim Millerd6b57052010-06-07 17:52:42 -07004556
Jim Miller284b62e2010-06-08 14:27:42 -07004557 synchronized (mKeyguardTokenWatcher) {
4558 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004560 }
4561
4562 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004563 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004564 != PackageManager.PERMISSION_GRANTED) {
4565 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004567
Jim Miller284b62e2010-06-08 14:27:42 -07004568 synchronized (mKeyguardTokenWatcher) {
4569 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004570
Jim Miller284b62e2010-06-08 14:27:42 -07004571 if (!mKeyguardTokenWatcher.isAcquired()) {
4572 // If we are the last one to reenable the keyguard wait until
4573 // we have actually finished reenabling until returning.
4574 // It is possible that reenableKeyguard() can be called before
4575 // the previous disableKeyguard() is handled, in which case
4576 // neither mKeyguardTokenWatcher.acquired() or released() would
4577 // be called. In that case mKeyguardDisabled will be false here
4578 // and we have nothing to wait for.
4579 while (mKeyguardDisabled) {
4580 try {
4581 mKeyguardTokenWatcher.wait();
4582 } catch (InterruptedException e) {
4583 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004584 }
4585 }
4586 }
4587 }
4588 }
4589
4590 /**
4591 * @see android.app.KeyguardManager#exitKeyguardSecurely
4592 */
4593 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004594 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595 != PackageManager.PERMISSION_GRANTED) {
4596 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4597 }
4598 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4599 public void onKeyguardExitResult(boolean success) {
4600 try {
4601 callback.onKeyguardExitResult(success);
4602 } catch (RemoteException e) {
4603 // Client has died, we don't care.
4604 }
4605 }
4606 });
4607 }
4608
4609 public boolean inKeyguardRestrictedInputMode() {
4610 return mPolicy.inKeyguardRestrictedKeyInputMode();
4611 }
Romain Guy06882f82009-06-10 13:36:04 -07004612
Dianne Hackbornffa42482009-09-23 22:20:11 -07004613 public void closeSystemDialogs(String reason) {
4614 synchronized(mWindowMap) {
4615 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004616 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004617 if (w.mSurface != null) {
4618 try {
4619 w.mClient.closeSystemDialogs(reason);
4620 } catch (RemoteException e) {
4621 }
4622 }
4623 }
4624 }
4625 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 static float fixScale(float scale) {
4628 if (scale < 0) scale = 0;
4629 else if (scale > 20) scale = 20;
4630 return Math.abs(scale);
4631 }
Romain Guy06882f82009-06-10 13:36:04 -07004632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 public void setAnimationScale(int which, float scale) {
4634 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4635 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004636 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004637 }
4638
4639 if (scale < 0) scale = 0;
4640 else if (scale > 20) scale = 20;
4641 scale = Math.abs(scale);
4642 switch (which) {
4643 case 0: mWindowAnimationScale = fixScale(scale); break;
4644 case 1: mTransitionAnimationScale = fixScale(scale); break;
4645 }
Romain Guy06882f82009-06-10 13:36:04 -07004646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004647 // Persist setting
4648 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4649 }
Romain Guy06882f82009-06-10 13:36:04 -07004650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 public void setAnimationScales(float[] scales) {
4652 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4653 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004654 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 }
4656
4657 if (scales != null) {
4658 if (scales.length >= 1) {
4659 mWindowAnimationScale = fixScale(scales[0]);
4660 }
4661 if (scales.length >= 2) {
4662 mTransitionAnimationScale = fixScale(scales[1]);
4663 }
4664 }
Romain Guy06882f82009-06-10 13:36:04 -07004665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 // Persist setting
4667 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4668 }
Romain Guy06882f82009-06-10 13:36:04 -07004669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 public float getAnimationScale(int which) {
4671 switch (which) {
4672 case 0: return mWindowAnimationScale;
4673 case 1: return mTransitionAnimationScale;
4674 }
4675 return 0;
4676 }
Romain Guy06882f82009-06-10 13:36:04 -07004677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 public float[] getAnimationScales() {
4679 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4680 }
Romain Guy06882f82009-06-10 13:36:04 -07004681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 public int getSwitchState(int sw) {
4683 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4684 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004685 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004687 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 }
Romain Guy06882f82009-06-10 13:36:04 -07004689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004690 public int getSwitchStateForDevice(int devid, int sw) {
4691 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4692 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004693 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004695 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 }
Romain Guy06882f82009-06-10 13:36:04 -07004697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004698 public int getScancodeState(int sw) {
4699 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4700 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004701 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004703 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004704 }
Romain Guy06882f82009-06-10 13:36:04 -07004705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 public int getScancodeStateForDevice(int devid, int sw) {
4707 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4708 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004709 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004711 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 }
Romain Guy06882f82009-06-10 13:36:04 -07004713
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004714 public int getTrackballScancodeState(int sw) {
4715 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4716 "getTrackballScancodeState()")) {
4717 throw new SecurityException("Requires READ_INPUT_STATE permission");
4718 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004719 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004720 }
4721
4722 public int getDPadScancodeState(int sw) {
4723 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4724 "getDPadScancodeState()")) {
4725 throw new SecurityException("Requires READ_INPUT_STATE permission");
4726 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004727 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004728 }
4729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004730 public int getKeycodeState(int sw) {
4731 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4732 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004733 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004734 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004735 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004736 }
Romain Guy06882f82009-06-10 13:36:04 -07004737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 public int getKeycodeStateForDevice(int devid, int sw) {
4739 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4740 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004741 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004742 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004743 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004744 }
Romain Guy06882f82009-06-10 13:36:04 -07004745
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004746 public int getTrackballKeycodeState(int sw) {
4747 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4748 "getTrackballKeycodeState()")) {
4749 throw new SecurityException("Requires READ_INPUT_STATE permission");
4750 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004751 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004752 }
4753
4754 public int getDPadKeycodeState(int sw) {
4755 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4756 "getDPadKeycodeState()")) {
4757 throw new SecurityException("Requires READ_INPUT_STATE permission");
4758 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004759 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004760 }
Jeff Browna41ca772010-08-11 14:46:32 -07004761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004762 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004763 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
Jeff Browna41ca772010-08-11 14:46:32 -07004766 public InputChannel monitorInput(String inputChannelName) {
4767 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4768 "monitorInput()")) {
4769 throw new SecurityException("Requires READ_INPUT_STATE permission");
4770 }
4771 return mInputManager.monitorInput(inputChannelName);
4772 }
4773
Jeff Brown8d608662010-08-30 03:02:23 -07004774 public InputDevice getInputDevice(int deviceId) {
4775 return mInputManager.getInputDevice(deviceId);
4776 }
4777
4778 public int[] getInputDeviceIds() {
4779 return mInputManager.getInputDeviceIds();
4780 }
4781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004782 public void enableScreenAfterBoot() {
4783 synchronized(mWindowMap) {
4784 if (mSystemBooted) {
4785 return;
4786 }
4787 mSystemBooted = true;
4788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 performEnableScreen();
4791 }
Romain Guy06882f82009-06-10 13:36:04 -07004792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 public void enableScreenIfNeededLocked() {
4794 if (mDisplayEnabled) {
4795 return;
4796 }
4797 if (!mSystemBooted) {
4798 return;
4799 }
4800 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4801 }
Romain Guy06882f82009-06-10 13:36:04 -07004802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 public void performEnableScreen() {
4804 synchronized(mWindowMap) {
4805 if (mDisplayEnabled) {
4806 return;
4807 }
4808 if (!mSystemBooted) {
4809 return;
4810 }
Romain Guy06882f82009-06-10 13:36:04 -07004811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 // Don't enable the screen until all existing windows
4813 // have been drawn.
4814 final int N = mWindows.size();
4815 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004816 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004817 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 return;
4819 }
4820 }
Romain Guy06882f82009-06-10 13:36:04 -07004821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 mDisplayEnabled = true;
4823 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004824 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 StringWriter sw = new StringWriter();
4826 PrintWriter pw = new PrintWriter(sw);
4827 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004828 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 }
4830 try {
4831 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4832 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004833 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834 Parcel data = Parcel.obtain();
4835 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4836 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4837 data, null, 0);
4838 data.recycle();
4839 }
4840 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004841 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 }
4843 }
Romain Guy06882f82009-06-10 13:36:04 -07004844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004847 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004848 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4849 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 }
Romain Guy06882f82009-06-10 13:36:04 -07004851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 public void setInTouchMode(boolean mode) {
4853 synchronized(mWindowMap) {
4854 mInTouchMode = mode;
4855 }
4856 }
4857
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004858 public void freezeRotation() {
4859 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4860 "setRotation()")) {
4861 throw new SecurityException("Requires SET_ORIENTATION permission");
4862 }
4863
4864 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4865 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4866 }
4867
4868 public void thawRotation() {
4869 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4870 "setRotation()")) {
4871 throw new SecurityException("Requires SET_ORIENTATION permission");
4872 }
4873
4874 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4875 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4876 }
4877
Romain Guy06882f82009-06-10 13:36:04 -07004878 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004879 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004881 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004882 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 }
4884
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004885 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886 }
Romain Guy06882f82009-06-10 13:36:04 -07004887
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004888 public void setRotationUnchecked(int rotation,
4889 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004890 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004893 long origId = Binder.clearCallingIdentity();
4894 boolean changed;
4895 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004896 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 }
Romain Guy06882f82009-06-10 13:36:04 -07004898
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004899 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 sendNewConfiguration();
4901 }
Romain Guy06882f82009-06-10 13:36:04 -07004902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004903 Binder.restoreCallingIdentity(origId);
4904 }
Romain Guy06882f82009-06-10 13:36:04 -07004905
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004906 /**
4907 * Apply a new rotation to the screen, respecting the requests of
4908 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4909 * re-evaluate the desired rotation.
4910 *
4911 * Returns null if the rotation has been changed. In this case YOU
4912 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4913 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004914 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 boolean changed;
4916 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4917 rotation = mRequestedRotation;
4918 } else {
4919 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004920 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004922 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004923 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004924 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004925 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004929 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 "Rotation changed to " + rotation
4931 + " from " + mRotation
4932 + " (forceApp=" + mForcedAppOrientation
4933 + ", req=" + mRequestedRotation + ")");
4934 mRotation = rotation;
4935 mWindowsFreezingScreen = true;
4936 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4937 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4938 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004939 mWaitingForConfig = true;
4940 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004942 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004943 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004944 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004945 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004946 }
4947 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004948 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 if (w.mSurface != null) {
4950 w.mOrientationChanging = true;
4951 }
4952 }
4953 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4954 try {
4955 mRotationWatchers.get(i).onRotationChanged(rotation);
4956 } catch (RemoteException e) {
4957 }
4958 }
4959 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961 return changed;
4962 }
Romain Guy06882f82009-06-10 13:36:04 -07004963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 public int getRotation() {
4965 return mRotation;
4966 }
4967
4968 public int watchRotation(IRotationWatcher watcher) {
4969 final IBinder watcherBinder = watcher.asBinder();
4970 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4971 public void binderDied() {
4972 synchronized (mWindowMap) {
4973 for (int i=0; i<mRotationWatchers.size(); i++) {
4974 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004975 IRotationWatcher removed = mRotationWatchers.remove(i);
4976 if (removed != null) {
4977 removed.asBinder().unlinkToDeath(this, 0);
4978 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004979 i--;
4980 }
4981 }
4982 }
4983 }
4984 };
Romain Guy06882f82009-06-10 13:36:04 -07004985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004986 synchronized (mWindowMap) {
4987 try {
4988 watcher.asBinder().linkToDeath(dr, 0);
4989 mRotationWatchers.add(watcher);
4990 } catch (RemoteException e) {
4991 // Client died, no cleanup needed.
4992 }
Romain Guy06882f82009-06-10 13:36:04 -07004993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004994 return mRotation;
4995 }
4996 }
4997
4998 /**
4999 * Starts the view server on the specified port.
5000 *
5001 * @param port The port to listener to.
5002 *
5003 * @return True if the server was successfully started, false otherwise.
5004 *
5005 * @see com.android.server.ViewServer
5006 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5007 */
5008 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005009 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005010 return false;
5011 }
5012
5013 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5014 return false;
5015 }
5016
5017 if (port < 1024) {
5018 return false;
5019 }
5020
5021 if (mViewServer != null) {
5022 if (!mViewServer.isRunning()) {
5023 try {
5024 return mViewServer.start();
5025 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005026 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005027 }
5028 }
5029 return false;
5030 }
5031
5032 try {
5033 mViewServer = new ViewServer(this, port);
5034 return mViewServer.start();
5035 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005036 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005037 }
5038 return false;
5039 }
5040
Romain Guy06882f82009-06-10 13:36:04 -07005041 private boolean isSystemSecure() {
5042 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5043 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5044 }
5045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005046 /**
5047 * Stops the view server if it exists.
5048 *
5049 * @return True if the server stopped, false if it wasn't started or
5050 * couldn't be stopped.
5051 *
5052 * @see com.android.server.ViewServer
5053 */
5054 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005055 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005056 return false;
5057 }
5058
5059 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5060 return false;
5061 }
5062
5063 if (mViewServer != null) {
5064 return mViewServer.stop();
5065 }
5066 return false;
5067 }
5068
5069 /**
5070 * Indicates whether the view server is running.
5071 *
5072 * @return True if the server is running, false otherwise.
5073 *
5074 * @see com.android.server.ViewServer
5075 */
5076 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005077 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005078 return false;
5079 }
5080
5081 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5082 return false;
5083 }
5084
5085 return mViewServer != null && mViewServer.isRunning();
5086 }
5087
5088 /**
5089 * Lists all availble windows in the system. The listing is written in the
5090 * specified Socket's output stream with the following syntax:
5091 * windowHashCodeInHexadecimal windowName
5092 * Each line of the ouput represents a different window.
5093 *
5094 * @param client The remote client to send the listing to.
5095 * @return False if an error occured, true otherwise.
5096 */
5097 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005098 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005099 return false;
5100 }
5101
5102 boolean result = true;
5103
Jeff Browne33348b2010-07-15 23:54:05 -07005104 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005105 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005107 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005108 }
5109
5110 BufferedWriter out = null;
5111
5112 // Any uncaught exception will crash the system process
5113 try {
5114 OutputStream clientStream = client.getOutputStream();
5115 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5116
5117 final int count = windows.length;
5118 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005119 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005120 out.write(Integer.toHexString(System.identityHashCode(w)));
5121 out.write(' ');
5122 out.append(w.mAttrs.getTitle());
5123 out.write('\n');
5124 }
5125
5126 out.write("DONE.\n");
5127 out.flush();
5128 } catch (Exception e) {
5129 result = false;
5130 } finally {
5131 if (out != null) {
5132 try {
5133 out.close();
5134 } catch (IOException e) {
5135 result = false;
5136 }
5137 }
5138 }
5139
5140 return result;
5141 }
5142
5143 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005144 * Returns the focused window in the following format:
5145 * windowHashCodeInHexadecimal windowName
5146 *
5147 * @param client The remote client to send the listing to.
5148 * @return False if an error occurred, true otherwise.
5149 */
5150 boolean viewServerGetFocusedWindow(Socket client) {
5151 if (isSystemSecure()) {
5152 return false;
5153 }
5154
5155 boolean result = true;
5156
5157 WindowState focusedWindow = getFocusedWindow();
5158
5159 BufferedWriter out = null;
5160
5161 // Any uncaught exception will crash the system process
5162 try {
5163 OutputStream clientStream = client.getOutputStream();
5164 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5165
5166 if(focusedWindow != null) {
5167 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5168 out.write(' ');
5169 out.append(focusedWindow.mAttrs.getTitle());
5170 }
5171 out.write('\n');
5172 out.flush();
5173 } catch (Exception e) {
5174 result = false;
5175 } finally {
5176 if (out != null) {
5177 try {
5178 out.close();
5179 } catch (IOException e) {
5180 result = false;
5181 }
5182 }
5183 }
5184
5185 return result;
5186 }
5187
5188 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 * Sends a command to a target window. The result of the command, if any, will be
5190 * written in the output stream of the specified socket.
5191 *
5192 * The parameters must follow this syntax:
5193 * windowHashcode extra
5194 *
5195 * Where XX is the length in characeters of the windowTitle.
5196 *
5197 * The first parameter is the target window. The window with the specified hashcode
5198 * will be the target. If no target can be found, nothing happens. The extra parameters
5199 * will be delivered to the target window and as parameters to the command itself.
5200 *
5201 * @param client The remote client to sent the result, if any, to.
5202 * @param command The command to execute.
5203 * @param parameters The command parameters.
5204 *
5205 * @return True if the command was successfully delivered, false otherwise. This does
5206 * not indicate whether the command itself was successful.
5207 */
5208 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005209 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 return false;
5211 }
5212
5213 boolean success = true;
5214 Parcel data = null;
5215 Parcel reply = null;
5216
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005217 BufferedWriter out = null;
5218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005219 // Any uncaught exception will crash the system process
5220 try {
5221 // Find the hashcode of the window
5222 int index = parameters.indexOf(' ');
5223 if (index == -1) {
5224 index = parameters.length();
5225 }
5226 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005227 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228
5229 // Extract the command's parameter after the window description
5230 if (index < parameters.length()) {
5231 parameters = parameters.substring(index + 1);
5232 } else {
5233 parameters = "";
5234 }
5235
5236 final WindowManagerService.WindowState window = findWindow(hashCode);
5237 if (window == null) {
5238 return false;
5239 }
5240
5241 data = Parcel.obtain();
5242 data.writeInterfaceToken("android.view.IWindow");
5243 data.writeString(command);
5244 data.writeString(parameters);
5245 data.writeInt(1);
5246 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5247
5248 reply = Parcel.obtain();
5249
5250 final IBinder binder = window.mClient.asBinder();
5251 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5252 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5253
5254 reply.readException();
5255
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005256 if (!client.isOutputShutdown()) {
5257 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5258 out.write("DONE\n");
5259 out.flush();
5260 }
5261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005263 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005264 success = false;
5265 } finally {
5266 if (data != null) {
5267 data.recycle();
5268 }
5269 if (reply != null) {
5270 reply.recycle();
5271 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005272 if (out != null) {
5273 try {
5274 out.close();
5275 } catch (IOException e) {
5276
5277 }
5278 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005279 }
5280
5281 return success;
5282 }
5283
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005284 public void addWindowChangeListener(WindowChangeListener listener) {
5285 synchronized(mWindowMap) {
5286 mWindowChangeListeners.add(listener);
5287 }
5288 }
5289
5290 public void removeWindowChangeListener(WindowChangeListener listener) {
5291 synchronized(mWindowMap) {
5292 mWindowChangeListeners.remove(listener);
5293 }
5294 }
5295
5296 private void notifyWindowsChanged() {
5297 WindowChangeListener[] windowChangeListeners;
5298 synchronized(mWindowMap) {
5299 if(mWindowChangeListeners.isEmpty()) {
5300 return;
5301 }
5302 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5303 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5304 }
5305 int N = windowChangeListeners.length;
5306 for(int i = 0; i < N; i++) {
5307 windowChangeListeners[i].windowsChanged();
5308 }
5309 }
5310
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005311 private void notifyFocusChanged() {
5312 WindowChangeListener[] windowChangeListeners;
5313 synchronized(mWindowMap) {
5314 if(mWindowChangeListeners.isEmpty()) {
5315 return;
5316 }
5317 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5318 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5319 }
5320 int N = windowChangeListeners.length;
5321 for(int i = 0; i < N; i++) {
5322 windowChangeListeners[i].focusChanged();
5323 }
5324 }
5325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005326 private WindowState findWindow(int hashCode) {
5327 if (hashCode == -1) {
5328 return getFocusedWindow();
5329 }
5330
5331 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005332 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333 final int count = windows.size();
5334
5335 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005336 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005337 if (System.identityHashCode(w) == hashCode) {
5338 return w;
5339 }
5340 }
5341 }
5342
5343 return null;
5344 }
5345
5346 /*
5347 * Instruct the Activity Manager to fetch the current configuration and broadcast
5348 * that to config-changed listeners if appropriate.
5349 */
5350 void sendNewConfiguration() {
5351 try {
5352 mActivityManager.updateConfiguration(null);
5353 } catch (RemoteException e) {
5354 }
5355 }
Romain Guy06882f82009-06-10 13:36:04 -07005356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005357 public Configuration computeNewConfiguration() {
5358 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005359 return computeNewConfigurationLocked();
5360 }
5361 }
Romain Guy06882f82009-06-10 13:36:04 -07005362
Dianne Hackbornc485a602009-03-24 22:39:49 -07005363 Configuration computeNewConfigurationLocked() {
5364 Configuration config = new Configuration();
5365 if (!computeNewConfigurationLocked(config)) {
5366 return null;
5367 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005368 return config;
5369 }
Romain Guy06882f82009-06-10 13:36:04 -07005370
Dianne Hackbornc485a602009-03-24 22:39:49 -07005371 boolean computeNewConfigurationLocked(Configuration config) {
5372 if (mDisplay == null) {
5373 return false;
5374 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005375
5376 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005377
5378 // Use the effective "visual" dimensions based on current rotation
5379 final boolean rotated = (mRotation == Surface.ROTATION_90
5380 || mRotation == Surface.ROTATION_270);
5381 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5382 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5383
Dianne Hackbornc485a602009-03-24 22:39:49 -07005384 int orientation = Configuration.ORIENTATION_SQUARE;
5385 if (dw < dh) {
5386 orientation = Configuration.ORIENTATION_PORTRAIT;
5387 } else if (dw > dh) {
5388 orientation = Configuration.ORIENTATION_LANDSCAPE;
5389 }
5390 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005391
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005392 DisplayMetrics dm = new DisplayMetrics();
5393 mDisplay.getMetrics(dm);
5394 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5395
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005396 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005397 // Note we only do this once because at this point we don't
5398 // expect the screen to change in this way at runtime, and want
5399 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005400 int longSize = dw;
5401 int shortSize = dh;
5402 if (longSize < shortSize) {
5403 int tmp = longSize;
5404 longSize = shortSize;
5405 shortSize = tmp;
5406 }
5407 longSize = (int)(longSize/dm.density);
5408 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005409
Dianne Hackborn723738c2009-06-25 19:48:04 -07005410 // These semi-magic numbers define our compatibility modes for
5411 // applications with different screens. Don't change unless you
5412 // make sure to test lots and lots of apps!
5413 if (longSize < 470) {
5414 // This is shorter than an HVGA normal density screen (which
5415 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005416 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5417 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005418 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005419 // What size is this screen screen?
5420 if (longSize >= 800 && shortSize >= 600) {
5421 // SVGA or larger screens at medium density are the point
5422 // at which we consider it to be an extra large screen.
5423 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005424 } else if (longSize >= 530 && shortSize >= 400) {
5425 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005426 // at which we consider it to be a large screen.
5427 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5428 } else {
5429 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005430
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005431 // If this screen is wider than normal HVGA, or taller
5432 // than FWVGA, then for old apps we want to run in size
5433 // compatibility mode.
5434 if (shortSize > 321 || longSize > 570) {
5435 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5436 }
5437 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005438
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005439 // Is this a long screen?
5440 if (((longSize*3)/5) >= (shortSize-1)) {
5441 // Anything wider than WVGA (5:3) is considering to be long.
5442 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5443 } else {
5444 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5445 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005446 }
5447 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005448 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005449
Dianne Hackbornc485a602009-03-24 22:39:49 -07005450 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5451 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5452 mPolicy.adjustConfigurationLw(config);
5453 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005454 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005455
5456 // -------------------------------------------------------------
5457 // Drag and drop
5458 // -------------------------------------------------------------
5459
5460 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5461 boolean localOnly, int width, int height, Surface outSurface) {
5462 if (DEBUG_DRAG) {
5463 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5464 + " local=" + localOnly + " win=" + window
5465 + " asbinder=" + window.asBinder());
5466 }
5467
5468 final int callerPid = Binder.getCallingPid();
5469 final long origId = Binder.clearCallingIdentity();
5470 IBinder token = null;
5471
5472 try {
5473 synchronized (mWindowMap) {
5474 try {
5475 // !!! TODO: fail if the given window does not currently have touch focus?
5476
5477 if (mDragState == null) {
5478 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5479 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5480 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005481 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005482 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005483 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005484 mDragState.mSurface = surface;
5485 mDragState.mLocalOnly = localOnly;
5486 token = mDragState.mToken = new Binder();
5487
5488 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005489 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5490 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005491 mH.sendMessageDelayed(msg, 5000);
5492 } else {
5493 Slog.w(TAG, "Drag already in progress");
5494 }
5495 } catch (Surface.OutOfResourcesException e) {
5496 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5497 if (mDragState != null) {
5498 mDragState.reset();
5499 mDragState = null;
5500 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005501 }
5502 }
5503 } finally {
5504 Binder.restoreCallingIdentity(origId);
5505 }
5506
5507 return token;
5508 }
5509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005510 // -------------------------------------------------------------
5511 // Input Events and Focus Management
5512 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005513
Jeff Brown349703e2010-06-22 01:27:15 -07005514 InputMonitor mInputMonitor = new InputMonitor();
5515
5516 /* Tracks the progress of input dispatch and ensures that input dispatch state
5517 * is kept in sync with changes in window focus, visibility, registration, and
5518 * other relevant Window Manager state transitions. */
5519 final class InputMonitor {
5520 // Current window with input focus for keys and other non-touch events. May be null.
5521 private WindowState mInputFocus;
5522
5523 // When true, prevents input dispatch from proceeding until set to false again.
5524 private boolean mInputDispatchFrozen;
5525
5526 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5527 private boolean mInputDispatchEnabled = true;
5528
5529 // Temporary list of windows information to provide to the input dispatcher.
5530 private InputWindowList mTempInputWindows = new InputWindowList();
5531
5532 // Temporary input application object to provide to the input dispatcher.
5533 private InputApplication mTempInputApplication = new InputApplication();
5534
5535 /* Notifies the window manager about a broken input channel.
5536 *
5537 * Called by the InputManager.
5538 */
5539 public void notifyInputChannelBroken(InputChannel inputChannel) {
5540 synchronized (mWindowMap) {
5541 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5542 if (windowState == null) {
5543 return; // irrelevant
5544 }
5545
5546 Slog.i(TAG, "WINDOW DIED " + windowState);
5547 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005548 }
5549 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005550
Jeff Brown519e0242010-09-15 15:18:56 -07005551 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005552 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005553 *
5554 * Called by the InputManager.
5555 */
Jeff Brown519e0242010-09-15 15:18:56 -07005556 public long notifyANR(Object token, InputChannel inputChannel) {
5557 AppWindowToken appWindowToken = null;
5558 if (inputChannel != null) {
5559 synchronized (mWindowMap) {
5560 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5561 if (windowState != null) {
5562 Slog.i(TAG, "Input event dispatching timed out sending to "
5563 + windowState.mAttrs.getTitle());
5564 appWindowToken = windowState.mAppToken;
5565 }
Jeff Brown349703e2010-06-22 01:27:15 -07005566 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005567 }
5568
Jeff Brown519e0242010-09-15 15:18:56 -07005569 if (appWindowToken == null && token != null) {
5570 appWindowToken = (AppWindowToken) token;
5571 Slog.i(TAG, "Input event dispatching timed out sending to application "
5572 + appWindowToken.stringName);
5573 }
Jeff Brown349703e2010-06-22 01:27:15 -07005574
Jeff Brown519e0242010-09-15 15:18:56 -07005575 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005576 try {
5577 // Notify the activity manager about the timeout and let it decide whether
5578 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005579 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005580 if (! abort) {
5581 // The activity manager declined to abort dispatching.
5582 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005583 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005584 }
Jeff Brown349703e2010-06-22 01:27:15 -07005585 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005586 }
5587 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005588 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005589 }
5590
Jeff Brown349703e2010-06-22 01:27:15 -07005591 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5592 synchronized (mWindowMap) {
5593 return getWindowStateForInputChannelLocked(inputChannel);
5594 }
5595 }
5596
5597 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5598 int windowCount = mWindows.size();
5599 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005600 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005601 if (windowState.mInputChannel == inputChannel) {
5602 return windowState;
5603 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005604 }
5605
Jeff Brown349703e2010-06-22 01:27:15 -07005606 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005607 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005608
Chris Tatea32dcf72010-10-14 12:13:50 -07005609 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005610 final InputWindow inputWindow = windowList.add();
5611 inputWindow.inputChannel = mDragState.mServerChannel;
5612 inputWindow.name = "drag";
5613 inputWindow.layoutParamsFlags = 0;
5614 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5615 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5616 inputWindow.visible = true;
5617 inputWindow.canReceiveKeys = false;
5618 inputWindow.hasFocus = true;
5619 inputWindow.hasWallpaper = false;
5620 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005621 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005622 inputWindow.ownerPid = Process.myPid();
5623 inputWindow.ownerUid = Process.myUid();
5624
5625 // The drag window covers the entire display
5626 inputWindow.frameLeft = 0;
5627 inputWindow.frameTop = 0;
5628 inputWindow.frameRight = mDisplay.getWidth();
5629 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005630
Christopher Tatea53146c2010-09-07 11:57:52 -07005631 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5632 inputWindow.visibleFrameTop = inputWindow.frameTop;
5633 inputWindow.visibleFrameRight = inputWindow.frameRight;
5634 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5635
5636 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5637 inputWindow.touchableAreaTop = inputWindow.frameTop;
5638 inputWindow.touchableAreaRight = inputWindow.frameRight;
5639 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5640 }
5641
Jeff Brown349703e2010-06-22 01:27:15 -07005642 /* Updates the cached window information provided to the input dispatcher. */
5643 public void updateInputWindowsLw() {
5644 // Populate the input window list with information about all of the windows that
5645 // could potentially receive input.
5646 // As an optimization, we could try to prune the list of windows but this turns
5647 // out to be difficult because only the native code knows for sure which window
5648 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005649 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005650
5651 // If there's a drag in flight, provide a pseudowindow to catch drag input
5652 final boolean inDrag = (mDragState != null);
5653 if (inDrag) {
5654 if (DEBUG_DRAG) {
5655 Log.d(TAG, "Inserting drag window");
5656 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005657 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005658 }
5659
Jeff Brown7fbdc842010-06-17 20:52:56 -07005660 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005661 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005662 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005663 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005664 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005665 continue;
5666 }
5667
Jeff Brown349703e2010-06-22 01:27:15 -07005668 final int flags = child.mAttrs.flags;
5669 final int type = child.mAttrs.type;
5670
5671 final boolean hasFocus = (child == mInputFocus);
5672 final boolean isVisible = child.isVisibleLw();
5673 final boolean hasWallpaper = (child == mWallpaperTarget)
5674 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005675
5676 // If there's a drag in progress and 'child' is a potential drop target,
5677 // make sure it's been told about the drag
5678 if (inDrag && isVisible) {
5679 mDragState.sendDragStartedIfNeededLw(child);
5680 }
5681
Jeff Brown349703e2010-06-22 01:27:15 -07005682 // Add a window to our list of input windows.
5683 final InputWindow inputWindow = mTempInputWindows.add();
5684 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005685 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005686 inputWindow.layoutParamsFlags = flags;
5687 inputWindow.layoutParamsType = type;
5688 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5689 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005690 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005691 inputWindow.hasFocus = hasFocus;
5692 inputWindow.hasWallpaper = hasWallpaper;
5693 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005694 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005695 inputWindow.ownerPid = child.mSession.mPid;
5696 inputWindow.ownerUid = child.mSession.mUid;
5697
5698 final Rect frame = child.mFrame;
5699 inputWindow.frameLeft = frame.left;
5700 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005701 inputWindow.frameRight = frame.right;
5702 inputWindow.frameBottom = frame.bottom;
5703
5704 final Rect visibleFrame = child.mVisibleFrame;
5705 inputWindow.visibleFrameLeft = visibleFrame.left;
5706 inputWindow.visibleFrameTop = visibleFrame.top;
5707 inputWindow.visibleFrameRight = visibleFrame.right;
5708 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005709
5710 switch (child.mTouchableInsets) {
5711 default:
5712 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5713 inputWindow.touchableAreaLeft = frame.left;
5714 inputWindow.touchableAreaTop = frame.top;
5715 inputWindow.touchableAreaRight = frame.right;
5716 inputWindow.touchableAreaBottom = frame.bottom;
5717 break;
5718
5719 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5720 Rect inset = child.mGivenContentInsets;
5721 inputWindow.touchableAreaLeft = frame.left + inset.left;
5722 inputWindow.touchableAreaTop = frame.top + inset.top;
5723 inputWindow.touchableAreaRight = frame.right - inset.right;
5724 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5725 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005726 }
Jeff Brown349703e2010-06-22 01:27:15 -07005727
5728 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5729 Rect inset = child.mGivenVisibleInsets;
5730 inputWindow.touchableAreaLeft = frame.left + inset.left;
5731 inputWindow.touchableAreaTop = frame.top + inset.top;
5732 inputWindow.touchableAreaRight = frame.right - inset.right;
5733 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005734 break;
5735 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005736 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005737 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005738
Jeff Brown349703e2010-06-22 01:27:15 -07005739 // Send windows to native code.
5740 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005741
Jeff Brown349703e2010-06-22 01:27:15 -07005742 // Clear the list in preparation for the next round.
5743 // Also avoids keeping InputChannel objects referenced unnecessarily.
5744 mTempInputWindows.clear();
5745 }
5746
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005747 /* Notifies that the lid switch changed state. */
5748 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5749 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5750 }
5751
Jeff Brown349703e2010-06-22 01:27:15 -07005752 /* Provides an opportunity for the window manager policy to intercept early key
5753 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005754 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5755 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5756 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5757 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005758 }
5759
5760 /* Provides an opportunity for the window manager policy to process a key before
5761 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005762 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005763 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005764 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005765 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005766 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005767 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005768 }
5769
5770 /* Called when the current input focus changes.
5771 * Layer assignment is assumed to be complete by the time this is called.
5772 */
5773 public void setInputFocusLw(WindowState newWindow) {
5774 if (DEBUG_INPUT) {
5775 Slog.d(TAG, "Input focus has changed to " + newWindow);
5776 }
5777
5778 if (newWindow != mInputFocus) {
5779 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005780 // Displaying a window implicitly causes dispatching to be unpaused.
5781 // This is to protect against bugs if someone pauses dispatching but
5782 // forgets to resume.
5783 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005784 }
Jeff Brown349703e2010-06-22 01:27:15 -07005785
5786 mInputFocus = newWindow;
5787 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005788 }
5789 }
5790
Jeff Brown349703e2010-06-22 01:27:15 -07005791 public void setFocusedAppLw(AppWindowToken newApp) {
5792 // Focused app has changed.
5793 if (newApp == null) {
5794 mInputManager.setFocusedApplication(null);
5795 } else {
5796 mTempInputApplication.name = newApp.toString();
5797 mTempInputApplication.dispatchingTimeoutNanos =
5798 newApp.inputDispatchingTimeoutNanos;
5799 mTempInputApplication.token = newApp;
5800
5801 mInputManager.setFocusedApplication(mTempInputApplication);
5802 }
5803 }
5804
Jeff Brown349703e2010-06-22 01:27:15 -07005805 public void pauseDispatchingLw(WindowToken window) {
5806 if (! window.paused) {
5807 if (DEBUG_INPUT) {
5808 Slog.v(TAG, "Pausing WindowToken " + window);
5809 }
5810
5811 window.paused = true;
5812 updateInputWindowsLw();
5813 }
5814 }
5815
5816 public void resumeDispatchingLw(WindowToken window) {
5817 if (window.paused) {
5818 if (DEBUG_INPUT) {
5819 Slog.v(TAG, "Resuming WindowToken " + window);
5820 }
5821
5822 window.paused = false;
5823 updateInputWindowsLw();
5824 }
5825 }
5826
5827 public void freezeInputDispatchingLw() {
5828 if (! mInputDispatchFrozen) {
5829 if (DEBUG_INPUT) {
5830 Slog.v(TAG, "Freezing input dispatching");
5831 }
5832
5833 mInputDispatchFrozen = true;
5834 updateInputDispatchModeLw();
5835 }
5836 }
5837
5838 public void thawInputDispatchingLw() {
5839 if (mInputDispatchFrozen) {
5840 if (DEBUG_INPUT) {
5841 Slog.v(TAG, "Thawing input dispatching");
5842 }
5843
5844 mInputDispatchFrozen = false;
5845 updateInputDispatchModeLw();
5846 }
5847 }
5848
5849 public void setEventDispatchingLw(boolean enabled) {
5850 if (mInputDispatchEnabled != enabled) {
5851 if (DEBUG_INPUT) {
5852 Slog.v(TAG, "Setting event dispatching to " + enabled);
5853 }
5854
5855 mInputDispatchEnabled = enabled;
5856 updateInputDispatchModeLw();
5857 }
5858 }
5859
5860 private void updateInputDispatchModeLw() {
5861 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5862 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005863 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865 public void pauseKeyDispatching(IBinder _token) {
5866 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5867 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005868 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005869 }
5870
5871 synchronized (mWindowMap) {
5872 WindowToken token = mTokenMap.get(_token);
5873 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005874 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 }
5876 }
5877 }
5878
5879 public void resumeKeyDispatching(IBinder _token) {
5880 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5881 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005882 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 }
5884
5885 synchronized (mWindowMap) {
5886 WindowToken token = mTokenMap.get(_token);
5887 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005888 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005889 }
5890 }
5891 }
5892
5893 public void setEventDispatching(boolean enabled) {
5894 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5895 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005896 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005897 }
5898
5899 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005900 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901 }
5902 }
Romain Guy06882f82009-06-10 13:36:04 -07005903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904 /**
5905 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005906 * Even when sync is false, this method may block while waiting for current
5907 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005908 *
5909 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005910 * {@link SystemClock#uptimeMillis()} as the timebase.)
5911 * @param sync If true, wait for the event to be completed before returning to the caller.
5912 * @return Returns true if event was dispatched, false if it was dropped for any reason
5913 */
5914 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5915 long downTime = ev.getDownTime();
5916 long eventTime = ev.getEventTime();
5917
5918 int action = ev.getAction();
5919 int code = ev.getKeyCode();
5920 int repeatCount = ev.getRepeatCount();
5921 int metaState = ev.getMetaState();
5922 int deviceId = ev.getDeviceId();
5923 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005924 int source = ev.getSource();
5925
5926 if (source == InputDevice.SOURCE_UNKNOWN) {
5927 source = InputDevice.SOURCE_KEYBOARD;
5928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005929
5930 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5931 if (downTime == 0) downTime = eventTime;
5932
5933 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005934 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005936 final int pid = Binder.getCallingPid();
5937 final int uid = Binder.getCallingUid();
5938 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005939
Jeff Brownbbda99d2010-07-28 15:48:59 -07005940 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5941 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5942 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5943 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005944
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005945 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005946 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 }
5948
5949 /**
5950 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005951 * Even when sync is false, this method may block while waiting for current
5952 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005953 *
5954 * @param ev A motion event describing the pointer (touch) action. (As noted in
5955 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005956 * {@link SystemClock#uptimeMillis()} as the timebase.)
5957 * @param sync If true, wait for the event to be completed before returning to the caller.
5958 * @return Returns true if event was dispatched, false if it was dropped for any reason
5959 */
5960 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005961 final int pid = Binder.getCallingPid();
5962 final int uid = Binder.getCallingUid();
5963 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005964
Jeff Brownc5ed5912010-07-14 18:48:53 -07005965 MotionEvent newEvent = MotionEvent.obtain(ev);
5966 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5967 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5968 }
5969
Jeff Brownbbda99d2010-07-28 15:48:59 -07005970 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5971 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5972 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5973 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005974
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005975 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005976 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005977 }
Romain Guy06882f82009-06-10 13:36:04 -07005978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005979 /**
5980 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005981 * Even when sync is false, this method may block while waiting for current
5982 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005983 *
5984 * @param ev A motion event describing the trackball action. (As noted in
5985 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005986 * {@link SystemClock#uptimeMillis()} as the timebase.)
5987 * @param sync If true, wait for the event to be completed before returning to the caller.
5988 * @return Returns true if event was dispatched, false if it was dropped for any reason
5989 */
5990 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005991 final int pid = Binder.getCallingPid();
5992 final int uid = Binder.getCallingUid();
5993 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005994
Jeff Brownc5ed5912010-07-14 18:48:53 -07005995 MotionEvent newEvent = MotionEvent.obtain(ev);
5996 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5997 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5998 }
5999
Jeff Brownbbda99d2010-07-28 15:48:59 -07006000 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6001 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6002 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6003 INJECTION_TIMEOUT_MILLIS);
6004
6005 Binder.restoreCallingIdentity(ident);
6006 return reportInjectionResult(result);
6007 }
6008
6009 /**
6010 * Inject an input event into the UI without waiting for dispatch to commence.
6011 * This variant is useful for fire-and-forget input event injection. It does not
6012 * block any longer than it takes to enqueue the input event.
6013 *
6014 * @param ev An input event. (Be sure to set the input source correctly.)
6015 * @return Returns true if event was dispatched, false if it was dropped for any reason
6016 */
6017 public boolean injectInputEventNoWait(InputEvent ev) {
6018 final int pid = Binder.getCallingPid();
6019 final int uid = Binder.getCallingUid();
6020 final long ident = Binder.clearCallingIdentity();
6021
6022 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6023 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6024 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006025
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006026 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006027 return reportInjectionResult(result);
6028 }
6029
6030 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006031 switch (result) {
6032 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6033 Slog.w(TAG, "Input event injection permission denied.");
6034 throw new SecurityException(
6035 "Injecting to another application requires INJECT_EVENTS permission");
6036 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006037 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006038 return true;
6039 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6040 Slog.w(TAG, "Input event injection timed out.");
6041 return false;
6042 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6043 default:
6044 Slog.w(TAG, "Input event injection failed.");
6045 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006047 }
Romain Guy06882f82009-06-10 13:36:04 -07006048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006049 private WindowState getFocusedWindow() {
6050 synchronized (mWindowMap) {
6051 return getFocusedWindowLocked();
6052 }
6053 }
6054
6055 private WindowState getFocusedWindowLocked() {
6056 return mCurrentFocus;
6057 }
Romain Guy06882f82009-06-10 13:36:04 -07006058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059 public boolean detectSafeMode() {
6060 mSafeMode = mPolicy.detectSafeMode();
6061 return mSafeMode;
6062 }
Romain Guy06882f82009-06-10 13:36:04 -07006063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006064 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006065 synchronized(mWindowMap) {
6066 if (mDisplay != null) {
6067 throw new IllegalStateException("Display already initialized");
6068 }
6069 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6070 mDisplay = wm.getDefaultDisplay();
6071 mInitialDisplayWidth = mDisplay.getWidth();
6072 mInitialDisplayHeight = mDisplay.getHeight();
6073 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6074 }
6075
6076 try {
6077 mActivityManager.updateConfiguration(null);
6078 } catch (RemoteException e) {
6079 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006080
6081 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006082 }
6083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 // -------------------------------------------------------------
6085 // Client Session State
6086 // -------------------------------------------------------------
6087
6088 private final class Session extends IWindowSession.Stub
6089 implements IBinder.DeathRecipient {
6090 final IInputMethodClient mClient;
6091 final IInputContext mInputContext;
6092 final int mUid;
6093 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006094 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095 SurfaceSession mSurfaceSession;
6096 int mNumWindow = 0;
6097 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006099 public Session(IInputMethodClient client, IInputContext inputContext) {
6100 mClient = client;
6101 mInputContext = inputContext;
6102 mUid = Binder.getCallingUid();
6103 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006104 StringBuilder sb = new StringBuilder();
6105 sb.append("Session{");
6106 sb.append(Integer.toHexString(System.identityHashCode(this)));
6107 sb.append(" uid ");
6108 sb.append(mUid);
6109 sb.append("}");
6110 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006112 synchronized (mWindowMap) {
6113 if (mInputMethodManager == null && mHaveInputMethods) {
6114 IBinder b = ServiceManager.getService(
6115 Context.INPUT_METHOD_SERVICE);
6116 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6117 }
6118 }
6119 long ident = Binder.clearCallingIdentity();
6120 try {
6121 // Note: it is safe to call in to the input method manager
6122 // here because we are not holding our lock.
6123 if (mInputMethodManager != null) {
6124 mInputMethodManager.addClient(client, inputContext,
6125 mUid, mPid);
6126 } else {
6127 client.setUsingInputMethod(false);
6128 }
6129 client.asBinder().linkToDeath(this, 0);
6130 } catch (RemoteException e) {
6131 // The caller has died, so we can just forget about this.
6132 try {
6133 if (mInputMethodManager != null) {
6134 mInputMethodManager.removeClient(client);
6135 }
6136 } catch (RemoteException ee) {
6137 }
6138 } finally {
6139 Binder.restoreCallingIdentity(ident);
6140 }
6141 }
Romain Guy06882f82009-06-10 13:36:04 -07006142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 @Override
6144 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6145 throws RemoteException {
6146 try {
6147 return super.onTransact(code, data, reply, flags);
6148 } catch (RuntimeException e) {
6149 // Log all 'real' exceptions thrown to the caller
6150 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006151 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 }
6153 throw e;
6154 }
6155 }
6156
6157 public void binderDied() {
6158 // Note: it is safe to call in to the input method manager
6159 // here because we are not holding our lock.
6160 try {
6161 if (mInputMethodManager != null) {
6162 mInputMethodManager.removeClient(mClient);
6163 }
6164 } catch (RemoteException e) {
6165 }
6166 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006167 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 mClientDead = true;
6169 killSessionLocked();
6170 }
6171 }
6172
6173 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006174 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6175 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6176 outInputChannel);
6177 }
6178
6179 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006181 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006182 }
Romain Guy06882f82009-06-10 13:36:04 -07006183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006184 public void remove(IWindow window) {
6185 removeWindow(this, window);
6186 }
Romain Guy06882f82009-06-10 13:36:04 -07006187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006188 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6189 int requestedWidth, int requestedHeight, int viewFlags,
6190 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006191 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006192 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6193 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006195 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006196 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6197 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006198 }
Romain Guy06882f82009-06-10 13:36:04 -07006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 public void setTransparentRegion(IWindow window, Region region) {
6201 setTransparentRegionWindow(this, window, region);
6202 }
Romain Guy06882f82009-06-10 13:36:04 -07006203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 public void setInsets(IWindow window, int touchableInsets,
6205 Rect contentInsets, Rect visibleInsets) {
6206 setInsetsWindow(this, window, touchableInsets, contentInsets,
6207 visibleInsets);
6208 }
Romain Guy06882f82009-06-10 13:36:04 -07006209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006210 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6211 getWindowDisplayFrame(this, window, outDisplayFrame);
6212 }
Romain Guy06882f82009-06-10 13:36:04 -07006213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006214 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006215 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 TAG, "IWindow finishDrawing called for " + window);
6217 finishDrawingWindow(this, window);
6218 }
6219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006220 public void setInTouchMode(boolean mode) {
6221 synchronized(mWindowMap) {
6222 mInTouchMode = mode;
6223 }
6224 }
6225
6226 public boolean getInTouchMode() {
6227 synchronized(mWindowMap) {
6228 return mInTouchMode;
6229 }
6230 }
6231
6232 public boolean performHapticFeedback(IWindow window, int effectId,
6233 boolean always) {
6234 synchronized(mWindowMap) {
6235 long ident = Binder.clearCallingIdentity();
6236 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006237 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006238 windowForClientLocked(this, window, true),
6239 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240 } finally {
6241 Binder.restoreCallingIdentity(ident);
6242 }
6243 }
6244 }
Romain Guy06882f82009-06-10 13:36:04 -07006245
Christopher Tatea53146c2010-09-07 11:57:52 -07006246 /* Drag/drop */
6247 public IBinder prepareDrag(IWindow window, boolean localOnly,
6248 int width, int height, Surface outSurface) {
6249 return prepareDragSurface(window, mSurfaceSession, localOnly,
6250 width, height, outSurface);
6251 }
6252
6253 public boolean performDrag(IWindow window, IBinder dragToken,
6254 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6255 ClipData data) {
6256 if (DEBUG_DRAG) {
6257 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6258 }
6259
6260 synchronized (mWindowMap) {
6261 if (mDragState == null) {
6262 Slog.w(TAG, "No drag prepared");
6263 throw new IllegalStateException("performDrag() without prepareDrag()");
6264 }
6265
6266 if (dragToken != mDragState.mToken) {
6267 Slog.w(TAG, "Performing mismatched drag");
6268 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6269 }
6270
6271 WindowState callingWin = windowForClientLocked(null, window, false);
6272 if (callingWin == null) {
6273 Slog.w(TAG, "Bad requesting window " + window);
6274 return false; // !!! TODO: throw here?
6275 }
6276
6277 // !!! TODO: if input is not still focused on the initiating window, fail
6278 // the drag initiation (e.g. an alarm window popped up just as the application
6279 // called performDrag()
6280
6281 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6282
Christopher Tate2c095f32010-10-04 14:13:40 -07006283 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6284 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006285
Chris Tateb478f462010-10-15 16:02:26 -07006286 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6287 // the actual drag event dispatch stuff in the dragstate
6288
Christopher Tatea53146c2010-09-07 11:57:52 -07006289 mDragState.register();
6290 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006291 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6292 mDragState.mServerChannel)) {
6293 Slog.e(TAG, "Unable to transfer touch focus");
6294 mDragState.unregister();
6295 mDragState = null;
6296 mInputMonitor.updateInputWindowsLw();
6297 return false;
6298 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006299
6300 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006301 mDragState.mCurrentX = touchX;
6302 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006303 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006304
6305 // remember the thumb offsets for later
6306 mDragState.mThumbOffsetX = thumbCenterX;
6307 mDragState.mThumbOffsetY = thumbCenterY;
6308
6309 // Make the surface visible at the proper location
6310 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006311 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006312 try {
6313 surface.setPosition((int)(touchX - thumbCenterX),
6314 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006315 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006316 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006317 surface.show();
6318 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006319 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006320 }
6321 }
6322
6323 return true; // success!
6324 }
6325
Chris Tated4533f12010-10-19 15:15:08 -07006326 public void reportDropResult(IWindow window, boolean consumed) {
6327 IBinder token = window.asBinder();
6328 if (DEBUG_DRAG) {
6329 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6330 }
6331
6332 synchronized (mWindowMap) {
6333 if (mDragState.mToken != token) {
6334 Slog.w(TAG, "Invalid drop-result claim by " + window);
6335 throw new IllegalStateException("reportDropResult() by non-recipient");
6336 }
6337
6338 // The right window has responded, even if it's no longer around,
6339 // so be sure to halt the timeout even if the later WindowState
6340 // lookup fails.
6341 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6342
6343 WindowState callingWin = windowForClientLocked(null, window, false);
6344 if (callingWin == null) {
6345 Slog.w(TAG, "Bad result-reporting window " + window);
6346 return; // !!! TODO: throw here?
6347 }
6348
6349 mDragState.mDragResult = consumed;
6350 mDragState.endDragLw();
6351 }
6352 }
6353
Christopher Tatea53146c2010-09-07 11:57:52 -07006354 public void dragRecipientEntered(IWindow window) {
6355 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006356 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006357 }
6358 }
6359
6360 public void dragRecipientExited(IWindow window) {
6361 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006362 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006363 }
6364 }
6365
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006366 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006367 synchronized(mWindowMap) {
6368 long ident = Binder.clearCallingIdentity();
6369 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006370 setWindowWallpaperPositionLocked(
6371 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006372 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006373 } finally {
6374 Binder.restoreCallingIdentity(ident);
6375 }
6376 }
6377 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006378
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006379 public void wallpaperOffsetsComplete(IBinder window) {
6380 WindowManagerService.this.wallpaperOffsetsComplete(window);
6381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006382
Dianne Hackborn75804932009-10-20 20:15:20 -07006383 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6384 int z, Bundle extras, boolean sync) {
6385 synchronized(mWindowMap) {
6386 long ident = Binder.clearCallingIdentity();
6387 try {
6388 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006389 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006390 action, x, y, z, extras, sync);
6391 } finally {
6392 Binder.restoreCallingIdentity(ident);
6393 }
6394 }
6395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006396
Dianne Hackborn75804932009-10-20 20:15:20 -07006397 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6398 WindowManagerService.this.wallpaperCommandComplete(window, result);
6399 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 void windowAddedLocked() {
6402 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006403 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006404 TAG, "First window added to " + this + ", creating SurfaceSession");
6405 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006406 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006407 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 mSessions.add(this);
6409 }
6410 mNumWindow++;
6411 }
6412
6413 void windowRemovedLocked() {
6414 mNumWindow--;
6415 killSessionLocked();
6416 }
Romain Guy06882f82009-06-10 13:36:04 -07006417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006418 void killSessionLocked() {
6419 if (mNumWindow <= 0 && mClientDead) {
6420 mSessions.remove(this);
6421 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006422 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006423 TAG, "Last window removed from " + this
6424 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006425 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006426 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 try {
6428 mSurfaceSession.kill();
6429 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006430 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431 + mSurfaceSession + " in session " + this
6432 + ": " + e.toString());
6433 }
6434 mSurfaceSession = null;
6435 }
6436 }
6437 }
Romain Guy06882f82009-06-10 13:36:04 -07006438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006440 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6441 pw.print(" mClientDead="); pw.print(mClientDead);
6442 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 }
6444
6445 @Override
6446 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006447 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 }
6449 }
6450
6451 // -------------------------------------------------------------
6452 // Client Window State
6453 // -------------------------------------------------------------
6454
6455 private final class WindowState implements WindowManagerPolicy.WindowState {
6456 final Session mSession;
6457 final IWindow mClient;
6458 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006459 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 AppWindowToken mAppToken;
6461 AppWindowToken mTargetAppToken;
6462 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6463 final DeathRecipient mDeathRecipient;
6464 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006465 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 final int mBaseLayer;
6467 final int mSubLayer;
6468 final boolean mLayoutAttached;
6469 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006470 final boolean mIsWallpaper;
6471 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 int mViewVisibility;
6473 boolean mPolicyVisibility = true;
6474 boolean mPolicyVisibilityAfterAnim = true;
6475 boolean mAppFreezing;
6476 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006477 boolean mReportDestroySurface;
6478 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006479 boolean mAttachedHidden; // is our parent window hidden?
6480 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006481 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 int mRequestedWidth;
6483 int mRequestedHeight;
6484 int mLastRequestedWidth;
6485 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 int mLayer;
6487 int mAnimLayer;
6488 int mLastLayer;
6489 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006490 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006491 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006493 int mLayoutSeq = -1;
6494
6495 Configuration mConfiguration = null;
6496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006497 // Actual frame shown on-screen (may be modified by animation)
6498 final Rect mShownFrame = new Rect();
6499 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006501 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006502 * Set when we have changed the size of the surface, to know that
6503 * we must tell them application to resize (and thus redraw itself).
6504 */
6505 boolean mSurfaceResized;
6506
6507 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 * Insets that determine the actually visible area
6509 */
6510 final Rect mVisibleInsets = new Rect();
6511 final Rect mLastVisibleInsets = new Rect();
6512 boolean mVisibleInsetsChanged;
6513
6514 /**
6515 * Insets that are covered by system windows
6516 */
6517 final Rect mContentInsets = new Rect();
6518 final Rect mLastContentInsets = new Rect();
6519 boolean mContentInsetsChanged;
6520
6521 /**
6522 * Set to true if we are waiting for this window to receive its
6523 * given internal insets before laying out other windows based on it.
6524 */
6525 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006527 /**
6528 * These are the content insets that were given during layout for
6529 * this window, to be applied to windows behind it.
6530 */
6531 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 /**
6534 * These are the visible insets that were given during layout for
6535 * this window, to be applied to windows behind it.
6536 */
6537 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006539 /**
6540 * Flag indicating whether the touchable region should be adjusted by
6541 * the visible insets; if false the area outside the visible insets is
6542 * NOT touchable, so we must use those to adjust the frame during hit
6543 * tests.
6544 */
6545 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 // Current transformation being applied.
6548 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6549 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6550 float mHScale=1, mVScale=1;
6551 float mLastHScale=1, mLastVScale=1;
6552 final Matrix mTmpMatrix = new Matrix();
6553
6554 // "Real" frame that the application sees.
6555 final Rect mFrame = new Rect();
6556 final Rect mLastFrame = new Rect();
6557
6558 final Rect mContainingFrame = new Rect();
6559 final Rect mDisplayFrame = new Rect();
6560 final Rect mContentFrame = new Rect();
6561 final Rect mVisibleFrame = new Rect();
6562
6563 float mShownAlpha = 1;
6564 float mAlpha = 1;
6565 float mLastAlpha = 1;
6566
6567 // Set to true if, when the window gets displayed, it should perform
6568 // an enter animation.
6569 boolean mEnterAnimationPending;
6570
6571 // Currently running animation.
6572 boolean mAnimating;
6573 boolean mLocalAnimating;
6574 Animation mAnimation;
6575 boolean mAnimationIsEntrance;
6576 boolean mHasTransformation;
6577 boolean mHasLocalTransformation;
6578 final Transformation mTransformation = new Transformation();
6579
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006580 // If a window showing a wallpaper: the requested offset for the
6581 // wallpaper; if a wallpaper window: the currently applied offset.
6582 float mWallpaperX = -1;
6583 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006584
6585 // If a window showing a wallpaper: what fraction of the offset
6586 // range corresponds to a full virtual screen.
6587 float mWallpaperXStep = -1;
6588 float mWallpaperYStep = -1;
6589
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006590 // Wallpaper windows: pixels offset based on above variables.
6591 int mXOffset;
6592 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 // This is set after IWindowSession.relayout() has been called at
6595 // least once for the window. It allows us to detect the situation
6596 // where we don't yet have a surface, but should have one soon, so
6597 // we can give the window focus before waiting for the relayout.
6598 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 // This is set after the Surface has been created but before the
6601 // window has been drawn. During this time the surface is hidden.
6602 boolean mDrawPending;
6603
6604 // This is set after the window has finished drawing for the first
6605 // time but before its surface is shown. The surface will be
6606 // displayed when the next layout is run.
6607 boolean mCommitDrawPending;
6608
6609 // This is set during the time after the window's drawing has been
6610 // committed, and before its surface is actually shown. It is used
6611 // to delay showing the surface until all windows in a token are ready
6612 // to be shown.
6613 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 // Set when the window has been shown in the screen the first time.
6616 boolean mHasDrawn;
6617
6618 // Currently running an exit animation?
6619 boolean mExiting;
6620
6621 // Currently on the mDestroySurface list?
6622 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006624 // Completely remove from window manager after exit animation?
6625 boolean mRemoveOnExit;
6626
6627 // Set when the orientation is changing and this window has not yet
6628 // been updated for the new orientation.
6629 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006631 // Is this window now (or just being) removed?
6632 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006633
Dianne Hackborn16064f92010-03-25 00:47:24 -07006634 // For debugging, this is the last information given to the surface flinger.
6635 boolean mSurfaceShown;
6636 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6637 int mSurfaceLayer;
6638 float mSurfaceAlpha;
6639
Jeff Brown46b9ac02010-04-22 18:58:52 -07006640 // Input channel
6641 InputChannel mInputChannel;
6642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006643 WindowState(Session s, IWindow c, WindowToken token,
6644 WindowState attachedWindow, WindowManager.LayoutParams a,
6645 int viewVisibility) {
6646 mSession = s;
6647 mClient = c;
6648 mToken = token;
6649 mAttrs.copyFrom(a);
6650 mViewVisibility = viewVisibility;
6651 DeathRecipient deathRecipient = new DeathRecipient();
6652 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006653 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 TAG, "Window " + this + " client=" + c.asBinder()
6655 + " token=" + token + " (" + mAttrs.token + ")");
6656 try {
6657 c.asBinder().linkToDeath(deathRecipient, 0);
6658 } catch (RemoteException e) {
6659 mDeathRecipient = null;
6660 mAttachedWindow = null;
6661 mLayoutAttached = false;
6662 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006663 mIsWallpaper = false;
6664 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006665 mBaseLayer = 0;
6666 mSubLayer = 0;
6667 return;
6668 }
6669 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6672 mAttrs.type <= LAST_SUB_WINDOW)) {
6673 // The multiplier here is to reserve space for multiple
6674 // windows in the same type layer.
6675 mBaseLayer = mPolicy.windowTypeToLayerLw(
6676 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6677 + TYPE_LAYER_OFFSET;
6678 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6679 mAttachedWindow = attachedWindow;
6680 mAttachedWindow.mChildWindows.add(this);
6681 mLayoutAttached = mAttrs.type !=
6682 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6683 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6684 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006685 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6686 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006687 } else {
6688 // The multiplier here is to reserve space for multiple
6689 // windows in the same type layer.
6690 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6691 * TYPE_LAYER_MULTIPLIER
6692 + TYPE_LAYER_OFFSET;
6693 mSubLayer = 0;
6694 mAttachedWindow = null;
6695 mLayoutAttached = false;
6696 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6697 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006698 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6699 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006700 }
6701
6702 WindowState appWin = this;
6703 while (appWin.mAttachedWindow != null) {
6704 appWin = mAttachedWindow;
6705 }
6706 WindowToken appToken = appWin.mToken;
6707 while (appToken.appWindowToken == null) {
6708 WindowToken parent = mTokenMap.get(appToken.token);
6709 if (parent == null || appToken == parent) {
6710 break;
6711 }
6712 appToken = parent;
6713 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006714 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 mAppToken = appToken.appWindowToken;
6716
6717 mSurface = null;
6718 mRequestedWidth = 0;
6719 mRequestedHeight = 0;
6720 mLastRequestedWidth = 0;
6721 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006722 mXOffset = 0;
6723 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006724 mLayer = 0;
6725 mAnimLayer = 0;
6726 mLastLayer = 0;
6727 }
6728
6729 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006730 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 TAG, "Attaching " + this + " token=" + mToken
6732 + ", list=" + mToken.windows);
6733 mSession.windowAddedLocked();
6734 }
6735
6736 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6737 mHaveFrame = true;
6738
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006739 final Rect container = mContainingFrame;
6740 container.set(pf);
6741
6742 final Rect display = mDisplayFrame;
6743 display.set(df);
6744
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006745 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006746 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006747 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6748 display.intersect(mCompatibleScreenFrame);
6749 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006750 }
6751
6752 final int pw = container.right - container.left;
6753 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006754
6755 int w,h;
6756 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6757 w = mAttrs.width < 0 ? pw : mAttrs.width;
6758 h = mAttrs.height< 0 ? ph : mAttrs.height;
6759 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006760 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6761 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 }
Romain Guy06882f82009-06-10 13:36:04 -07006763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764 final Rect content = mContentFrame;
6765 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 final Rect visible = mVisibleFrame;
6768 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006770 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006771 final int fw = frame.width();
6772 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006774 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6775 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6776
6777 Gravity.apply(mAttrs.gravity, w, h, container,
6778 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6779 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6780
6781 //System.out.println("Out: " + mFrame);
6782
6783 // Now make sure the window fits in the overall display.
6784 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006786 // Make sure the content and visible frames are inside of the
6787 // final window frame.
6788 if (content.left < frame.left) content.left = frame.left;
6789 if (content.top < frame.top) content.top = frame.top;
6790 if (content.right > frame.right) content.right = frame.right;
6791 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6792 if (visible.left < frame.left) visible.left = frame.left;
6793 if (visible.top < frame.top) visible.top = frame.top;
6794 if (visible.right > frame.right) visible.right = frame.right;
6795 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 final Rect contentInsets = mContentInsets;
6798 contentInsets.left = content.left-frame.left;
6799 contentInsets.top = content.top-frame.top;
6800 contentInsets.right = frame.right-content.right;
6801 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 final Rect visibleInsets = mVisibleInsets;
6804 visibleInsets.left = visible.left-frame.left;
6805 visibleInsets.top = visible.top-frame.top;
6806 visibleInsets.right = frame.right-visible.right;
6807 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006808
Dianne Hackborn284ac932009-08-28 10:34:25 -07006809 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6810 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006811 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006812 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 if (localLOGV) {
6815 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6816 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006817 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 + mRequestedWidth + ", mRequestedheight="
6819 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6820 + "): frame=" + mFrame.toShortString()
6821 + " ci=" + contentInsets.toShortString()
6822 + " vi=" + visibleInsets.toShortString());
6823 //}
6824 }
6825 }
Romain Guy06882f82009-06-10 13:36:04 -07006826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 public Rect getFrameLw() {
6828 return mFrame;
6829 }
6830
6831 public Rect getShownFrameLw() {
6832 return mShownFrame;
6833 }
6834
6835 public Rect getDisplayFrameLw() {
6836 return mDisplayFrame;
6837 }
6838
6839 public Rect getContentFrameLw() {
6840 return mContentFrame;
6841 }
6842
6843 public Rect getVisibleFrameLw() {
6844 return mVisibleFrame;
6845 }
6846
6847 public boolean getGivenInsetsPendingLw() {
6848 return mGivenInsetsPending;
6849 }
6850
6851 public Rect getGivenContentInsetsLw() {
6852 return mGivenContentInsets;
6853 }
Romain Guy06882f82009-06-10 13:36:04 -07006854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006855 public Rect getGivenVisibleInsetsLw() {
6856 return mGivenVisibleInsets;
6857 }
Romain Guy06882f82009-06-10 13:36:04 -07006858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 public WindowManager.LayoutParams getAttrs() {
6860 return mAttrs;
6861 }
6862
6863 public int getSurfaceLayer() {
6864 return mLayer;
6865 }
Romain Guy06882f82009-06-10 13:36:04 -07006866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 public IApplicationToken getAppToken() {
6868 return mAppToken != null ? mAppToken.appToken : null;
6869 }
Jeff Brown349703e2010-06-22 01:27:15 -07006870
6871 public long getInputDispatchingTimeoutNanos() {
6872 return mAppToken != null
6873 ? mAppToken.inputDispatchingTimeoutNanos
6874 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006876
6877 public boolean hasAppShownWindows() {
6878 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6879 }
6880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006881 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006882 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 TAG, "Setting animation in " + this + ": " + anim);
6884 mAnimating = false;
6885 mLocalAnimating = false;
6886 mAnimation = anim;
6887 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6888 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6889 }
6890
6891 public void clearAnimation() {
6892 if (mAnimation != null) {
6893 mAnimating = true;
6894 mLocalAnimating = false;
6895 mAnimation = null;
6896 }
6897 }
Romain Guy06882f82009-06-10 13:36:04 -07006898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006899 Surface createSurfaceLocked() {
6900 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006901 mReportDestroySurface = false;
6902 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 mDrawPending = true;
6904 mCommitDrawPending = false;
6905 mReadyToShow = false;
6906 if (mAppToken != null) {
6907 mAppToken.allDrawn = false;
6908 }
6909
6910 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006911 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006912 flags |= Surface.PUSH_BUFFERS;
6913 }
6914
6915 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6916 flags |= Surface.SECURE;
6917 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006918 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 TAG, "Creating surface in session "
6920 + mSession.mSurfaceSession + " window " + this
6921 + " w=" + mFrame.width()
6922 + " h=" + mFrame.height() + " format="
6923 + mAttrs.format + " flags=" + flags);
6924
6925 int w = mFrame.width();
6926 int h = mFrame.height();
6927 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6928 // for a scaled surface, we always want the requested
6929 // size.
6930 w = mRequestedWidth;
6931 h = mRequestedHeight;
6932 }
6933
Romain Guy9825ec62009-10-01 00:58:09 -07006934 // Something is wrong and SurfaceFlinger will not like this,
6935 // try to revert to sane values
6936 if (w <= 0) w = 1;
6937 if (h <= 0) h = 1;
6938
Dianne Hackborn16064f92010-03-25 00:47:24 -07006939 mSurfaceShown = false;
6940 mSurfaceLayer = 0;
6941 mSurfaceAlpha = 1;
6942 mSurfaceX = 0;
6943 mSurfaceY = 0;
6944 mSurfaceW = w;
6945 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006947 final boolean isHwAccelerated = (mAttrs.flags &
6948 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6949 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6950 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6951 flags |= Surface.OPAQUE;
6952 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006954 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006955 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006956 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006957 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006958 + mSurface + " IN SESSION "
6959 + mSession.mSurfaceSession
6960 + ": pid=" + mSession.mPid + " format="
6961 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006962 + Integer.toHexString(flags)
6963 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006965 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006966 reclaimSomeSurfaceMemoryLocked(this, "create");
6967 return null;
6968 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006969 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006970 return null;
6971 }
Romain Guy06882f82009-06-10 13:36:04 -07006972
Joe Onorato8a9b2202010-02-26 18:56:32 -08006973 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 TAG, "Got surface: " + mSurface
6975 + ", set left=" + mFrame.left + " top=" + mFrame.top
6976 + ", animLayer=" + mAnimLayer);
6977 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006978 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006979 if (SHOW_TRANSACTIONS) logSurface(this,
6980 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6981 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6982 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006983 }
6984 Surface.openTransaction();
6985 try {
6986 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006987 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006988 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006989 mSurface.setPosition(mSurfaceX, mSurfaceY);
6990 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006991 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006992 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006993 mSurface.hide();
6994 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006995 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006996 mSurface.setFlags(Surface.SURFACE_DITHER,
6997 Surface.SURFACE_DITHER);
6998 }
6999 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007000 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007001 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7002 }
7003 mLastHidden = true;
7004 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007005 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007006 Surface.closeTransaction();
7007 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007008 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 TAG, "Created surface " + this);
7010 }
7011 return mSurface;
7012 }
Romain Guy06882f82009-06-10 13:36:04 -07007013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007015 if (mAppToken != null && this == mAppToken.startingWindow) {
7016 mAppToken.startingDisplayed = false;
7017 }
Romain Guy06882f82009-06-10 13:36:04 -07007018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007019 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007020 mDrawPending = false;
7021 mCommitDrawPending = false;
7022 mReadyToShow = false;
7023
7024 int i = mChildWindows.size();
7025 while (i > 0) {
7026 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007027 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007028 c.mAttachedHidden = true;
7029 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007030
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007031 if (mReportDestroySurface) {
7032 mReportDestroySurface = false;
7033 mSurfacePendingDestroy = true;
7034 try {
7035 mClient.dispatchGetNewSurface();
7036 // We'll really destroy on the next time around.
7037 return;
7038 } catch (RemoteException e) {
7039 }
7040 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007042 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007043 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007044 RuntimeException e = null;
7045 if (!HIDE_STACK_CRAWLS) {
7046 e = new RuntimeException();
7047 e.fillInStackTrace();
7048 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007049 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007050 + mSurface + ", session " + mSession, e);
7051 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007052 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007053 RuntimeException e = null;
7054 if (!HIDE_STACK_CRAWLS) {
7055 e = new RuntimeException();
7056 e.fillInStackTrace();
7057 }
7058 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007059 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007060 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007062 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 + " surface " + mSurface + " session " + mSession
7064 + ": " + e.toString());
7065 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007066
Dianne Hackborn16064f92010-03-25 00:47:24 -07007067 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007069 }
7070 }
7071
7072 boolean finishDrawingLocked() {
7073 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007074 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007075 TAG, "finishDrawingLocked: " + mSurface);
7076 mCommitDrawPending = true;
7077 mDrawPending = false;
7078 return true;
7079 }
7080 return false;
7081 }
7082
7083 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007084 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007085 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007087 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007088 }
7089 mCommitDrawPending = false;
7090 mReadyToShow = true;
7091 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7092 final AppWindowToken atoken = mAppToken;
7093 if (atoken == null || atoken.allDrawn || starting) {
7094 performShowLocked();
7095 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007096 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 }
7098
7099 // This must be called while inside a transaction.
7100 boolean performShowLocked() {
7101 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007102 RuntimeException e = null;
7103 if (!HIDE_STACK_CRAWLS) {
7104 e = new RuntimeException();
7105 e.fillInStackTrace();
7106 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007107 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7109 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7110 }
7111 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007112 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7113 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007114 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 + " during animation: policyVis=" + mPolicyVisibility
7116 + " attHidden=" + mAttachedHidden
7117 + " tok.hiddenRequested="
7118 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007119 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007120 + (mAppToken != null ? mAppToken.hidden : false)
7121 + " animating=" + mAnimating
7122 + " tok animating="
7123 + (mAppToken != null ? mAppToken.animating : false));
7124 if (!showSurfaceRobustlyLocked(this)) {
7125 return false;
7126 }
7127 mLastAlpha = -1;
7128 mHasDrawn = true;
7129 mLastHidden = false;
7130 mReadyToShow = false;
7131 enableScreenIfNeededLocked();
7132
7133 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007135 int i = mChildWindows.size();
7136 while (i > 0) {
7137 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007138 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007139 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007140 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007141 if (c.mSurface != null) {
7142 c.performShowLocked();
7143 // It hadn't been shown, which means layout not
7144 // performed on it, so now we want to make sure to
7145 // do a layout. If called from within the transaction
7146 // loop, this will cause it to restart with a new
7147 // layout.
7148 mLayoutNeeded = true;
7149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 }
7151 }
Romain Guy06882f82009-06-10 13:36:04 -07007152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007153 if (mAttrs.type != TYPE_APPLICATION_STARTING
7154 && mAppToken != null) {
7155 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007156
Dianne Hackborn248b1882009-09-16 16:46:44 -07007157 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007158 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007159 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007160 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007161 // If this initial window is animating, stop it -- we
7162 // will do an animation to reveal it from behind the
7163 // starting window, so there is no need for it to also
7164 // be doing its own stuff.
7165 if (mAnimation != null) {
7166 mAnimation = null;
7167 // Make sure we clean up the animation.
7168 mAnimating = true;
7169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007170 mFinishedStarting.add(mAppToken);
7171 mH.sendEmptyMessage(H.FINISHED_STARTING);
7172 }
7173 mAppToken.updateReportedVisibilityLocked();
7174 }
7175 }
7176 return true;
7177 }
Romain Guy06882f82009-06-10 13:36:04 -07007178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179 // This must be called while inside a transaction. Returns true if
7180 // there is more animation to run.
7181 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007182 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007183 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007185 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7186 mHasTransformation = true;
7187 mHasLocalTransformation = true;
7188 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007189 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007190 TAG, "Starting animation in " + this +
7191 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7192 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7193 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7194 mAnimation.setStartTime(currentTime);
7195 mLocalAnimating = true;
7196 mAnimating = true;
7197 }
7198 mTransformation.clear();
7199 final boolean more = mAnimation.getTransformation(
7200 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007201 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 TAG, "Stepped animation in " + this +
7203 ": more=" + more + ", xform=" + mTransformation);
7204 if (more) {
7205 // we're not done!
7206 return true;
7207 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007208 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007209 TAG, "Finished animation in " + this +
7210 " @ " + currentTime);
7211 mAnimation = null;
7212 //WindowManagerService.this.dump();
7213 }
7214 mHasLocalTransformation = false;
7215 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007216 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007217 // When our app token is animating, we kind-of pretend like
7218 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7219 // part of this check means that we will only do this if
7220 // our window is not currently exiting, or it is not
7221 // locally animating itself. The idea being that one that
7222 // is exiting and doing a local animation should be removed
7223 // once that animation is done.
7224 mAnimating = true;
7225 mHasTransformation = true;
7226 mTransformation.clear();
7227 return false;
7228 } else if (mHasTransformation) {
7229 // Little trick to get through the path below to act like
7230 // we have finished an animation.
7231 mAnimating = true;
7232 } else if (isAnimating()) {
7233 mAnimating = true;
7234 }
7235 } else if (mAnimation != null) {
7236 // If the display is frozen, and there is a pending animation,
7237 // clear it and make sure we run the cleanup code.
7238 mAnimating = true;
7239 mLocalAnimating = true;
7240 mAnimation = null;
7241 }
Romain Guy06882f82009-06-10 13:36:04 -07007242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007243 if (!mAnimating && !mLocalAnimating) {
7244 return false;
7245 }
7246
Joe Onorato8a9b2202010-02-26 18:56:32 -08007247 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 TAG, "Animation done in " + this + ": exiting=" + mExiting
7249 + ", reportedVisible="
7250 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 mAnimating = false;
7253 mLocalAnimating = false;
7254 mAnimation = null;
7255 mAnimLayer = mLayer;
7256 if (mIsImWindow) {
7257 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007258 } else if (mIsWallpaper) {
7259 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007260 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007261 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 + " anim layer: " + mAnimLayer);
7263 mHasTransformation = false;
7264 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007265 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7266 if (DEBUG_VISIBILITY) {
7267 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7268 + mPolicyVisibilityAfterAnim);
7269 }
7270 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7271 if (!mPolicyVisibility) {
7272 if (mCurrentFocus == this) {
7273 mFocusMayChange = true;
7274 }
7275 // Window is no longer visible -- make sure if we were waiting
7276 // for it to be displayed before enabling the display, that
7277 // we allow the display to be enabled now.
7278 enableScreenIfNeededLocked();
7279 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 mTransformation.clear();
7282 if (mHasDrawn
7283 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7284 && mAppToken != null
7285 && mAppToken.firstWindowDrawn
7286 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007287 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007288 + mToken + ": first real window done animating");
7289 mFinishedStarting.add(mAppToken);
7290 mH.sendEmptyMessage(H.FINISHED_STARTING);
7291 }
Romain Guy06882f82009-06-10 13:36:04 -07007292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 finishExit();
7294
7295 if (mAppToken != null) {
7296 mAppToken.updateReportedVisibilityLocked();
7297 }
7298
7299 return false;
7300 }
7301
7302 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007303 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 TAG, "finishExit in " + this
7305 + ": exiting=" + mExiting
7306 + " remove=" + mRemoveOnExit
7307 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 final int N = mChildWindows.size();
7310 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007311 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007312 }
Romain Guy06882f82009-06-10 13:36:04 -07007313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007314 if (!mExiting) {
7315 return;
7316 }
Romain Guy06882f82009-06-10 13:36:04 -07007317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007318 if (isWindowAnimating()) {
7319 return;
7320 }
7321
Joe Onorato8a9b2202010-02-26 18:56:32 -08007322 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007323 TAG, "Exit animation finished in " + this
7324 + ": remove=" + mRemoveOnExit);
7325 if (mSurface != null) {
7326 mDestroySurface.add(this);
7327 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007328 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007329 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 try {
7331 mSurface.hide();
7332 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007333 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 }
7335 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 }
7337 mExiting = false;
7338 if (mRemoveOnExit) {
7339 mPendingRemove.add(this);
7340 mRemoveOnExit = false;
7341 }
7342 }
Romain Guy06882f82009-06-10 13:36:04 -07007343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7345 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7346 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7347 if (dtdx < -.000001f || dtdx > .000001f) return false;
7348 if (dsdy < -.000001f || dsdy > .000001f) return false;
7349 return true;
7350 }
Romain Guy06882f82009-06-10 13:36:04 -07007351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 void computeShownFrameLocked() {
7353 final boolean selfTransformation = mHasLocalTransformation;
7354 Transformation attachedTransformation =
7355 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7356 ? mAttachedWindow.mTransformation : null;
7357 Transformation appTransformation =
7358 (mAppToken != null && mAppToken.hasTransformation)
7359 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007360
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007361 // Wallpapers are animated based on the "real" window they
7362 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007363 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007364 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007365 if (mWallpaperTarget.mHasLocalTransformation &&
7366 mWallpaperTarget.mAnimation != null &&
7367 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007368 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007369 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007370 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007371 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007372 }
7373 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007374 mWallpaperTarget.mAppToken.hasTransformation &&
7375 mWallpaperTarget.mAppToken.animation != null &&
7376 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007377 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007378 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007379 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007380 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007381 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007384 if (selfTransformation || attachedTransformation != null
7385 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007386 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 final Rect frame = mFrame;
7388 final float tmpFloats[] = mTmpFloats;
7389 final Matrix tmpMatrix = mTmpMatrix;
7390
7391 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007392 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007393 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007394 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007395 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007396 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007397 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007398 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 }
7400 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007401 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 }
7403
7404 // "convert" it into SurfaceFlinger's format
7405 // (a 2x2 matrix + an offset)
7406 // Here we must not transform the position of the surface
7407 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007408 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 tmpMatrix.getValues(tmpFloats);
7411 mDsDx = tmpFloats[Matrix.MSCALE_X];
7412 mDtDx = tmpFloats[Matrix.MSKEW_X];
7413 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7414 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007415 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7416 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007417 int w = frame.width();
7418 int h = frame.height();
7419 mShownFrame.set(x, y, x+w, y+h);
7420
7421 // Now set the alpha... but because our current hardware
7422 // can't do alpha transformation on a non-opaque surface,
7423 // turn it off if we are running an animation that is also
7424 // transforming since it is more important to have that
7425 // animation be smooth.
7426 mShownAlpha = mAlpha;
7427 if (!mLimitedAlphaCompositing
7428 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7429 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7430 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007431 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 if (selfTransformation) {
7433 mShownAlpha *= mTransformation.getAlpha();
7434 }
7435 if (attachedTransformation != null) {
7436 mShownAlpha *= attachedTransformation.getAlpha();
7437 }
7438 if (appTransformation != null) {
7439 mShownAlpha *= appTransformation.getAlpha();
7440 }
7441 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007442 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 }
Romain Guy06882f82009-06-10 13:36:04 -07007444
Joe Onorato8a9b2202010-02-26 18:56:32 -08007445 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 TAG, "Continuing animation in " + this +
7447 ": " + mShownFrame +
7448 ", alpha=" + mTransformation.getAlpha());
7449 return;
7450 }
Romain Guy06882f82009-06-10 13:36:04 -07007451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007453 if (mXOffset != 0 || mYOffset != 0) {
7454 mShownFrame.offset(mXOffset, mYOffset);
7455 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 mShownAlpha = mAlpha;
7457 mDsDx = 1;
7458 mDtDx = 0;
7459 mDsDy = 0;
7460 mDtDy = 1;
7461 }
Romain Guy06882f82009-06-10 13:36:04 -07007462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 /**
7464 * Is this window visible? It is not visible if there is no
7465 * surface, or we are in the process of running an exit animation
7466 * that will remove the surface, or its app token has been hidden.
7467 */
7468 public boolean isVisibleLw() {
7469 final AppWindowToken atoken = mAppToken;
7470 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7471 && (atoken == null || !atoken.hiddenRequested)
7472 && !mExiting && !mDestroying;
7473 }
7474
7475 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007476 * Like {@link #isVisibleLw}, but also counts a window that is currently
7477 * "hidden" behind the keyguard as visible. This allows us to apply
7478 * things like window flags that impact the keyguard.
7479 * XXX I am starting to think we need to have ANOTHER visibility flag
7480 * for this "hidden behind keyguard" state rather than overloading
7481 * mPolicyVisibility. Ungh.
7482 */
7483 public boolean isVisibleOrBehindKeyguardLw() {
7484 final AppWindowToken atoken = mAppToken;
7485 return mSurface != null && !mAttachedHidden
7486 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007487 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007488 && !mExiting && !mDestroying;
7489 }
7490
7491 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007492 * Is this window visible, ignoring its app token? It is not visible
7493 * if there is no surface, or we are in the process of running an exit animation
7494 * that will remove the surface.
7495 */
7496 public boolean isWinVisibleLw() {
7497 final AppWindowToken atoken = mAppToken;
7498 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7499 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7500 && !mExiting && !mDestroying;
7501 }
7502
7503 /**
7504 * The same as isVisible(), but follows the current hidden state of
7505 * the associated app token, not the pending requested hidden state.
7506 */
7507 boolean isVisibleNow() {
7508 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007509 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 }
7511
7512 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007513 * Can this window possibly be a drag/drop target? The test here is
7514 * a combination of the above "visible now" with the check that the
7515 * Input Manager uses when discarding windows from input consideration.
7516 */
7517 boolean isPotentialDragTarget() {
7518 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7519 }
7520
7521 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 * Same as isVisible(), but we also count it as visible between the
7523 * call to IWindowSession.add() and the first relayout().
7524 */
7525 boolean isVisibleOrAdding() {
7526 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007527 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7529 && mPolicyVisibility && !mAttachedHidden
7530 && (atoken == null || !atoken.hiddenRequested)
7531 && !mExiting && !mDestroying;
7532 }
7533
7534 /**
7535 * Is this window currently on-screen? It is on-screen either if it
7536 * is visible or it is currently running an animation before no longer
7537 * being visible.
7538 */
7539 boolean isOnScreen() {
7540 final AppWindowToken atoken = mAppToken;
7541 if (atoken != null) {
7542 return mSurface != null && mPolicyVisibility && !mDestroying
7543 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007544 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007545 } else {
7546 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007547 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 }
7549 }
Romain Guy06882f82009-06-10 13:36:04 -07007550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 /**
7552 * Like isOnScreen(), but we don't return true if the window is part
7553 * of a transition that has not yet been started.
7554 */
7555 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007556 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007557 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007558 return false;
7559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007561 final boolean animating = atoken != null
7562 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007564 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7565 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007566 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 }
7568
7569 /** Is the window or its container currently animating? */
7570 boolean isAnimating() {
7571 final WindowState attached = mAttachedWindow;
7572 final AppWindowToken atoken = mAppToken;
7573 return mAnimation != null
7574 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007575 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 (atoken.animation != null
7577 || atoken.inPendingTransaction));
7578 }
7579
7580 /** Is this window currently animating? */
7581 boolean isWindowAnimating() {
7582 return mAnimation != null;
7583 }
7584
7585 /**
7586 * Like isOnScreen, but returns false if the surface hasn't yet
7587 * been drawn.
7588 */
7589 public boolean isDisplayedLw() {
7590 final AppWindowToken atoken = mAppToken;
7591 return mSurface != null && mPolicyVisibility && !mDestroying
7592 && !mDrawPending && !mCommitDrawPending
7593 && ((!mAttachedHidden &&
7594 (atoken == null || !atoken.hiddenRequested))
7595 || mAnimating);
7596 }
7597
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007598 /**
7599 * Returns true if the window has a surface that it has drawn a
7600 * complete UI in to.
7601 */
7602 public boolean isDrawnLw() {
7603 final AppWindowToken atoken = mAppToken;
7604 return mSurface != null && !mDestroying
7605 && !mDrawPending && !mCommitDrawPending;
7606 }
7607
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007608 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007609 * Return true if the window is opaque and fully drawn. This indicates
7610 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007611 */
7612 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007613 return (mAttrs.format == PixelFormat.OPAQUE
7614 || mAttrs.type == TYPE_WALLPAPER)
7615 && mSurface != null && mAnimation == null
7616 && (mAppToken == null || mAppToken.animation == null)
7617 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007618 }
7619
7620 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7621 return
7622 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007623 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7624 // only if it's visible
7625 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007626 // and only if the application fills the compatible screen
7627 mFrame.left <= mCompatibleScreenFrame.left &&
7628 mFrame.top <= mCompatibleScreenFrame.top &&
7629 mFrame.right >= mCompatibleScreenFrame.right &&
7630 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007631 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007632 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007633 }
7634
7635 boolean isFullscreen(int screenWidth, int screenHeight) {
7636 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007637 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 }
7639
7640 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007641 disposeInputChannel();
7642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 if (mAttachedWindow != null) {
7644 mAttachedWindow.mChildWindows.remove(this);
7645 }
7646 destroySurfaceLocked();
7647 mSession.windowRemovedLocked();
7648 try {
7649 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7650 } catch (RuntimeException e) {
7651 // Ignore if it has already been removed (usually because
7652 // we are doing this as part of processing a death note.)
7653 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007654 }
7655
7656 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007657 if (mInputChannel != null) {
7658 mInputManager.unregisterInputChannel(mInputChannel);
7659
7660 mInputChannel.dispose();
7661 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07007662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 }
7664
7665 private class DeathRecipient implements IBinder.DeathRecipient {
7666 public void binderDied() {
7667 try {
7668 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007669 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007670 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007671 if (win != null) {
7672 removeWindowLocked(mSession, win);
7673 }
7674 }
7675 } catch (IllegalArgumentException ex) {
7676 // This will happen if the window has already been
7677 // removed.
7678 }
7679 }
7680 }
7681
7682 /** Returns true if this window desires key events. */
7683 public final boolean canReceiveKeys() {
7684 return isVisibleOrAdding()
7685 && (mViewVisibility == View.VISIBLE)
7686 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7687 }
7688
7689 public boolean hasDrawnLw() {
7690 return mHasDrawn;
7691 }
7692
7693 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007694 return showLw(doAnimation, true);
7695 }
7696
7697 boolean showLw(boolean doAnimation, boolean requestAnim) {
7698 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7699 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007700 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007701 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007702 if (doAnimation) {
7703 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7704 + mPolicyVisibility + " mAnimation=" + mAnimation);
7705 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7706 doAnimation = false;
7707 } else if (mPolicyVisibility && mAnimation == null) {
7708 // Check for the case where we are currently visible and
7709 // not animating; we do not want to do animation at such a
7710 // point to become visible when we already are.
7711 doAnimation = false;
7712 }
7713 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007714 mPolicyVisibility = true;
7715 mPolicyVisibilityAfterAnim = true;
7716 if (doAnimation) {
7717 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7718 }
7719 if (requestAnim) {
7720 requestAnimationLocked(0);
7721 }
7722 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 }
7724
7725 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007726 return hideLw(doAnimation, true);
7727 }
7728
7729 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007730 if (doAnimation) {
7731 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7732 doAnimation = false;
7733 }
7734 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007735 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7736 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007737 if (!current) {
7738 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007739 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007740 if (doAnimation) {
7741 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7742 if (mAnimation == null) {
7743 doAnimation = false;
7744 }
7745 }
7746 if (doAnimation) {
7747 mPolicyVisibilityAfterAnim = false;
7748 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007749 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007750 mPolicyVisibilityAfterAnim = false;
7751 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007752 // Window is no longer visible -- make sure if we were waiting
7753 // for it to be displayed before enabling the display, that
7754 // we allow the display to be enabled now.
7755 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007756 if (mCurrentFocus == this) {
7757 mFocusMayChange = true;
7758 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007759 }
7760 if (requestAnim) {
7761 requestAnimationLocked(0);
7762 }
7763 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007764 }
7765
7766 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007767 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7768 pw.print(" mClient="); pw.println(mClient.asBinder());
7769 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7770 if (mAttachedWindow != null || mLayoutAttached) {
7771 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7772 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7773 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007774 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7775 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7776 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007777 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7778 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007779 }
7780 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7781 pw.print(" mSubLayer="); pw.print(mSubLayer);
7782 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7783 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7784 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7785 pw.print("="); pw.print(mAnimLayer);
7786 pw.print(" mLastLayer="); pw.println(mLastLayer);
7787 if (mSurface != null) {
7788 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007789 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7790 pw.print(" layer="); pw.print(mSurfaceLayer);
7791 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7792 pw.print(" rect=("); pw.print(mSurfaceX);
7793 pw.print(","); pw.print(mSurfaceY);
7794 pw.print(") "); pw.print(mSurfaceW);
7795 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007796 }
7797 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7798 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7799 if (mAppToken != null) {
7800 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7801 }
7802 if (mTargetAppToken != null) {
7803 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7804 }
7805 pw.print(prefix); pw.print("mViewVisibility=0x");
7806 pw.print(Integer.toHexString(mViewVisibility));
7807 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007808 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7809 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007810 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7811 pw.print(prefix); pw.print("mPolicyVisibility=");
7812 pw.print(mPolicyVisibility);
7813 pw.print(" mPolicyVisibilityAfterAnim=");
7814 pw.print(mPolicyVisibilityAfterAnim);
7815 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7816 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007817 if (!mRelayoutCalled) {
7818 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7819 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007820 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007821 pw.print(" h="); pw.print(mRequestedHeight);
7822 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007823 if (mXOffset != 0 || mYOffset != 0) {
7824 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7825 pw.print(" y="); pw.println(mYOffset);
7826 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007827 pw.print(prefix); pw.print("mGivenContentInsets=");
7828 mGivenContentInsets.printShortString(pw);
7829 pw.print(" mGivenVisibleInsets=");
7830 mGivenVisibleInsets.printShortString(pw);
7831 pw.println();
7832 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7833 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7834 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7835 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007836 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007837 pw.print(prefix); pw.print("mShownFrame=");
7838 mShownFrame.printShortString(pw);
7839 pw.print(" last="); mLastShownFrame.printShortString(pw);
7840 pw.println();
7841 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7842 pw.print(" last="); mLastFrame.printShortString(pw);
7843 pw.println();
7844 pw.print(prefix); pw.print("mContainingFrame=");
7845 mContainingFrame.printShortString(pw);
7846 pw.print(" mDisplayFrame=");
7847 mDisplayFrame.printShortString(pw);
7848 pw.println();
7849 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7850 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7851 pw.println();
7852 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7853 pw.print(" last="); mLastContentInsets.printShortString(pw);
7854 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7855 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7856 pw.println();
7857 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7858 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7859 pw.print(" mAlpha="); pw.print(mAlpha);
7860 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7861 }
7862 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7863 || mAnimation != null) {
7864 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7865 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7866 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7867 pw.print(" mAnimation="); pw.println(mAnimation);
7868 }
7869 if (mHasTransformation || mHasLocalTransformation) {
7870 pw.print(prefix); pw.print("XForm: has=");
7871 pw.print(mHasTransformation);
7872 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7873 pw.print(" "); mTransformation.printShortString(pw);
7874 pw.println();
7875 }
7876 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7877 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7878 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7879 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7880 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7881 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7882 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7883 pw.print(" mDestroying="); pw.print(mDestroying);
7884 pw.print(" mRemoved="); pw.println(mRemoved);
7885 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007886 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007887 pw.print(prefix); pw.print("mOrientationChanging=");
7888 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007889 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7890 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007891 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007892 if (mHScale != 1 || mVScale != 1) {
7893 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7894 pw.print(" mVScale="); pw.println(mVScale);
7895 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007896 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007897 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7898 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7899 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007900 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7901 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7902 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007904 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007905
7906 String makeInputChannelName() {
7907 return Integer.toHexString(System.identityHashCode(this))
7908 + " " + mAttrs.getTitle();
7909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007910
7911 @Override
7912 public String toString() {
7913 return "Window{"
7914 + Integer.toHexString(System.identityHashCode(this))
7915 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7916 }
7917 }
Romain Guy06882f82009-06-10 13:36:04 -07007918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 // -------------------------------------------------------------
7920 // Window Token State
7921 // -------------------------------------------------------------
7922
7923 class WindowToken {
7924 // The actual token.
7925 final IBinder token;
7926
7927 // The type of window this token is for, as per WindowManager.LayoutParams.
7928 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007930 // Set if this token was explicitly added by a client, so should
7931 // not be removed when all windows are removed.
7932 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007933
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007934 // For printing.
7935 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007937 // If this is an AppWindowToken, this is non-null.
7938 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007940 // All of the windows associated with this token.
7941 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7942
7943 // Is key dispatching paused for this token?
7944 boolean paused = false;
7945
7946 // Should this token's windows be hidden?
7947 boolean hidden;
7948
7949 // Temporary for finding which tokens no longer have visible windows.
7950 boolean hasVisible;
7951
Dianne Hackborna8f60182009-09-01 19:01:50 -07007952 // Set to true when this token is in a pending transaction where it
7953 // will be shown.
7954 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007955
Dianne Hackborna8f60182009-09-01 19:01:50 -07007956 // Set to true when this token is in a pending transaction where it
7957 // will be hidden.
7958 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007959
Dianne Hackborna8f60182009-09-01 19:01:50 -07007960 // Set to true when this token is in a pending transaction where its
7961 // windows will be put to the bottom of the list.
7962 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007963
Dianne Hackborna8f60182009-09-01 19:01:50 -07007964 // Set to true when this token is in a pending transaction where its
7965 // windows will be put to the top of the list.
7966 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007968 WindowToken(IBinder _token, int type, boolean _explicit) {
7969 token = _token;
7970 windowType = type;
7971 explicit = _explicit;
7972 }
7973
7974 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007975 pw.print(prefix); pw.print("token="); pw.println(token);
7976 pw.print(prefix); pw.print("windows="); pw.println(windows);
7977 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7978 pw.print(" hidden="); pw.print(hidden);
7979 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007980 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7981 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7982 pw.print(" waitingToHide="); pw.print(waitingToHide);
7983 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7984 pw.print(" sendingToTop="); pw.println(sendingToTop);
7985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007986 }
7987
7988 @Override
7989 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007990 if (stringName == null) {
7991 StringBuilder sb = new StringBuilder();
7992 sb.append("WindowToken{");
7993 sb.append(Integer.toHexString(System.identityHashCode(this)));
7994 sb.append(" token="); sb.append(token); sb.append('}');
7995 stringName = sb.toString();
7996 }
7997 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007998 }
7999 };
8000
8001 class AppWindowToken extends WindowToken {
8002 // Non-null only for application tokens.
8003 final IApplicationToken appToken;
8004
8005 // All of the windows and child windows that are included in this
8006 // application token. Note this list is NOT sorted!
8007 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8008
8009 int groupId = -1;
8010 boolean appFullscreen;
8011 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008012
8013 // The input dispatching timeout for this application token in nanoseconds.
8014 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 // These are used for determining when all windows associated with
8017 // an activity have been drawn, so they can be made visible together
8018 // at the same time.
8019 int lastTransactionSequence = mTransactionSequence-1;
8020 int numInterestingWindows;
8021 int numDrawnWindows;
8022 boolean inPendingTransaction;
8023 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 // Is this token going to be hidden in a little while? If so, it
8026 // won't be taken into account for setting the screen orientation.
8027 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008029 // Is this window's surface needed? This is almost like hidden, except
8030 // it will sometimes be true a little earlier: when the token has
8031 // been shown, but is still waiting for its app transition to execute
8032 // before making its windows shown.
8033 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 // Have we told the window clients to hide themselves?
8036 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 // Last visibility state we reported to the app token.
8039 boolean reportedVisible;
8040
8041 // Set to true when the token has been removed from the window mgr.
8042 boolean removed;
8043
8044 // Have we been asked to have this token keep the screen frozen?
8045 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 boolean animating;
8048 Animation animation;
8049 boolean hasTransformation;
8050 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 // Offset to the window of all layers in the token, for use by
8053 // AppWindowToken animations.
8054 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008056 // Information about an application starting window if displayed.
8057 StartingData startingData;
8058 WindowState startingWindow;
8059 View startingView;
8060 boolean startingDisplayed;
8061 boolean startingMoved;
8062 boolean firstWindowDrawn;
8063
8064 AppWindowToken(IApplicationToken _token) {
8065 super(_token.asBinder(),
8066 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8067 appWindowToken = this;
8068 appToken = _token;
8069 }
Romain Guy06882f82009-06-10 13:36:04 -07008070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008071 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008072 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008073 TAG, "Setting animation in " + this + ": " + anim);
8074 animation = anim;
8075 animating = false;
8076 anim.restrictDuration(MAX_ANIMATION_DURATION);
8077 anim.scaleCurrentDuration(mTransitionAnimationScale);
8078 int zorder = anim.getZAdjustment();
8079 int adj = 0;
8080 if (zorder == Animation.ZORDER_TOP) {
8081 adj = TYPE_LAYER_OFFSET;
8082 } else if (zorder == Animation.ZORDER_BOTTOM) {
8083 adj = -TYPE_LAYER_OFFSET;
8084 }
Romain Guy06882f82009-06-10 13:36:04 -07008085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008086 if (animLayerAdjustment != adj) {
8087 animLayerAdjustment = adj;
8088 updateLayers();
8089 }
8090 }
Romain Guy06882f82009-06-10 13:36:04 -07008091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008092 public void setDummyAnimation() {
8093 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008094 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 TAG, "Setting dummy animation in " + this);
8096 animation = sDummyAnimation;
8097 }
8098 }
8099
8100 public void clearAnimation() {
8101 if (animation != null) {
8102 animation = null;
8103 animating = true;
8104 }
8105 }
Romain Guy06882f82009-06-10 13:36:04 -07008106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 void updateLayers() {
8108 final int N = allAppWindows.size();
8109 final int adj = animLayerAdjustment;
8110 for (int i=0; i<N; i++) {
8111 WindowState w = allAppWindows.get(i);
8112 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008113 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 + w.mAnimLayer);
8115 if (w == mInputMethodTarget) {
8116 setInputMethodAnimLayerAdjustment(adj);
8117 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008118 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008119 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 }
8122 }
Romain Guy06882f82009-06-10 13:36:04 -07008123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124 void sendAppVisibilityToClients() {
8125 final int N = allAppWindows.size();
8126 for (int i=0; i<N; i++) {
8127 WindowState win = allAppWindows.get(i);
8128 if (win == startingWindow && clientHidden) {
8129 // Don't hide the starting window.
8130 continue;
8131 }
8132 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008133 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 "Setting visibility of " + win + ": " + (!clientHidden));
8135 win.mClient.dispatchAppVisibility(!clientHidden);
8136 } catch (RemoteException e) {
8137 }
8138 }
8139 }
Romain Guy06882f82009-06-10 13:36:04 -07008140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008141 void showAllWindowsLocked() {
8142 final int NW = allAppWindows.size();
8143 for (int i=0; i<NW; i++) {
8144 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008145 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008146 "performing show on: " + w);
8147 w.performShowLocked();
8148 }
8149 }
Romain Guy06882f82009-06-10 13:36:04 -07008150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 // This must be called while inside a transaction.
8152 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008153 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008154 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008156 if (animation == sDummyAnimation) {
8157 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008158 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 // when it is really time to animate, this will be set to
8160 // a real animation and the next call will execute normally.
8161 return false;
8162 }
Romain Guy06882f82009-06-10 13:36:04 -07008163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008164 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8165 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008166 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 TAG, "Starting animation in " + this +
8168 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8169 + " scale=" + mTransitionAnimationScale
8170 + " allDrawn=" + allDrawn + " animating=" + animating);
8171 animation.initialize(dw, dh, dw, dh);
8172 animation.setStartTime(currentTime);
8173 animating = true;
8174 }
8175 transformation.clear();
8176 final boolean more = animation.getTransformation(
8177 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008178 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008179 TAG, "Stepped animation in " + this +
8180 ": more=" + more + ", xform=" + transformation);
8181 if (more) {
8182 // we're done!
8183 hasTransformation = true;
8184 return true;
8185 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008186 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008187 TAG, "Finished animation in " + this +
8188 " @ " + currentTime);
8189 animation = null;
8190 }
8191 } else if (animation != null) {
8192 // If the display is frozen, and there is a pending animation,
8193 // clear it and make sure we run the cleanup code.
8194 animating = true;
8195 animation = null;
8196 }
8197
8198 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008200 if (!animating) {
8201 return false;
8202 }
8203
8204 clearAnimation();
8205 animating = false;
8206 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8207 moveInputMethodWindowsIfNeededLocked(true);
8208 }
Romain Guy06882f82009-06-10 13:36:04 -07008209
Joe Onorato8a9b2202010-02-26 18:56:32 -08008210 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008211 TAG, "Animation done in " + this
8212 + ": reportedVisible=" + reportedVisible);
8213
8214 transformation.clear();
8215 if (animLayerAdjustment != 0) {
8216 animLayerAdjustment = 0;
8217 updateLayers();
8218 }
Romain Guy06882f82009-06-10 13:36:04 -07008219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008220 final int N = windows.size();
8221 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008222 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008223 }
8224 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008226 return false;
8227 }
8228
8229 void updateReportedVisibilityLocked() {
8230 if (appToken == null) {
8231 return;
8232 }
Romain Guy06882f82009-06-10 13:36:04 -07008233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008234 int numInteresting = 0;
8235 int numVisible = 0;
8236 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008237
Joe Onorato8a9b2202010-02-26 18:56:32 -08008238 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008239 final int N = allAppWindows.size();
8240 for (int i=0; i<N; i++) {
8241 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008242 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008243 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008244 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8245 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008246 continue;
8247 }
8248 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008249 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008250 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008252 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008253 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008254 + " pv=" + win.mPolicyVisibility
8255 + " dp=" + win.mDrawPending
8256 + " cdp=" + win.mCommitDrawPending
8257 + " ah=" + win.mAttachedHidden
8258 + " th="
8259 + (win.mAppToken != null
8260 ? win.mAppToken.hiddenRequested : false)
8261 + " a=" + win.mAnimating);
8262 }
8263 }
8264 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008265 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008266 if (!win.isAnimating()) {
8267 numVisible++;
8268 }
8269 nowGone = false;
8270 } else if (win.isAnimating()) {
8271 nowGone = false;
8272 }
8273 }
Romain Guy06882f82009-06-10 13:36:04 -07008274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008275 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008276 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277 + numInteresting + " visible=" + numVisible);
8278 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008279 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008280 TAG, "Visibility changed in " + this
8281 + ": vis=" + nowVisible);
8282 reportedVisible = nowVisible;
8283 Message m = mH.obtainMessage(
8284 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8285 nowVisible ? 1 : 0,
8286 nowGone ? 1 : 0,
8287 this);
8288 mH.sendMessage(m);
8289 }
8290 }
Romain Guy06882f82009-06-10 13:36:04 -07008291
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008292 WindowState findMainWindow() {
8293 int j = windows.size();
8294 while (j > 0) {
8295 j--;
8296 WindowState win = windows.get(j);
8297 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8298 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8299 return win;
8300 }
8301 }
8302 return null;
8303 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008305 void dump(PrintWriter pw, String prefix) {
8306 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008307 if (appToken != null) {
8308 pw.print(prefix); pw.println("app=true");
8309 }
8310 if (allAppWindows.size() > 0) {
8311 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8312 }
8313 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008314 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008315 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8316 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8317 pw.print(" clientHidden="); pw.print(clientHidden);
8318 pw.print(" willBeHidden="); pw.print(willBeHidden);
8319 pw.print(" reportedVisible="); pw.println(reportedVisible);
8320 if (paused || freezingScreen) {
8321 pw.print(prefix); pw.print("paused="); pw.print(paused);
8322 pw.print(" freezingScreen="); pw.println(freezingScreen);
8323 }
8324 if (numInterestingWindows != 0 || numDrawnWindows != 0
8325 || inPendingTransaction || allDrawn) {
8326 pw.print(prefix); pw.print("numInterestingWindows=");
8327 pw.print(numInterestingWindows);
8328 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8329 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8330 pw.print(" allDrawn="); pw.println(allDrawn);
8331 }
8332 if (animating || animation != null) {
8333 pw.print(prefix); pw.print("animating="); pw.print(animating);
8334 pw.print(" animation="); pw.println(animation);
8335 }
8336 if (animLayerAdjustment != 0) {
8337 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8338 }
8339 if (hasTransformation) {
8340 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8341 pw.print(" transformation="); transformation.printShortString(pw);
8342 pw.println();
8343 }
8344 if (startingData != null || removed || firstWindowDrawn) {
8345 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8346 pw.print(" removed="); pw.print(removed);
8347 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8348 }
8349 if (startingWindow != null || startingView != null
8350 || startingDisplayed || startingMoved) {
8351 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8352 pw.print(" startingView="); pw.print(startingView);
8353 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8354 pw.print(" startingMoved"); pw.println(startingMoved);
8355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356 }
8357
8358 @Override
8359 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008360 if (stringName == null) {
8361 StringBuilder sb = new StringBuilder();
8362 sb.append("AppWindowToken{");
8363 sb.append(Integer.toHexString(System.identityHashCode(this)));
8364 sb.append(" token="); sb.append(token); sb.append('}');
8365 stringName = sb.toString();
8366 }
8367 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008368 }
8369 }
Romain Guy06882f82009-06-10 13:36:04 -07008370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008371 // -------------------------------------------------------------
8372 // DummyAnimation
8373 // -------------------------------------------------------------
8374
8375 // This is an animation that does nothing: it just immediately finishes
8376 // itself every time it is called. It is used as a stub animation in cases
8377 // where we want to synchronize multiple things that may be animating.
8378 static final class DummyAnimation extends Animation {
8379 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8380 return false;
8381 }
8382 }
8383 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008385 // -------------------------------------------------------------
8386 // Async Handler
8387 // -------------------------------------------------------------
8388
8389 static final class StartingData {
8390 final String pkg;
8391 final int theme;
8392 final CharSequence nonLocalizedLabel;
8393 final int labelRes;
8394 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008396 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8397 int _labelRes, int _icon) {
8398 pkg = _pkg;
8399 theme = _theme;
8400 nonLocalizedLabel = _nonLocalizedLabel;
8401 labelRes = _labelRes;
8402 icon = _icon;
8403 }
8404 }
8405
8406 private final class H extends Handler {
8407 public static final int REPORT_FOCUS_CHANGE = 2;
8408 public static final int REPORT_LOSING_FOCUS = 3;
8409 public static final int ANIMATE = 4;
8410 public static final int ADD_STARTING = 5;
8411 public static final int REMOVE_STARTING = 6;
8412 public static final int FINISHED_STARTING = 7;
8413 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8415 public static final int HOLD_SCREEN_CHANGED = 12;
8416 public static final int APP_TRANSITION_TIMEOUT = 13;
8417 public static final int PERSIST_ANIMATION_SCALE = 14;
8418 public static final int FORCE_GC = 15;
8419 public static final int ENABLE_SCREEN = 16;
8420 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008421 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008422 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008423 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008424 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008426 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428 public H() {
8429 }
Romain Guy06882f82009-06-10 13:36:04 -07008430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008431 @Override
8432 public void handleMessage(Message msg) {
8433 switch (msg.what) {
8434 case REPORT_FOCUS_CHANGE: {
8435 WindowState lastFocus;
8436 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438 synchronized(mWindowMap) {
8439 lastFocus = mLastFocus;
8440 newFocus = mCurrentFocus;
8441 if (lastFocus == newFocus) {
8442 // Focus is not changing, so nothing to do.
8443 return;
8444 }
8445 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008446 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 // + " to " + newFocus);
8448 if (newFocus != null && lastFocus != null
8449 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008450 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008451 mLosingFocus.add(lastFocus);
8452 lastFocus = null;
8453 }
8454 }
8455
8456 if (lastFocus != newFocus) {
8457 //System.out.println("Changing focus from " + lastFocus
8458 // + " to " + newFocus);
8459 if (newFocus != null) {
8460 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008461 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8463 } catch (RemoteException e) {
8464 // Ignore if process has died.
8465 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008466 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 }
8468
8469 if (lastFocus != null) {
8470 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008471 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008472 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8473 } catch (RemoteException e) {
8474 // Ignore if process has died.
8475 }
8476 }
8477 }
8478 } break;
8479
8480 case REPORT_LOSING_FOCUS: {
8481 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008483 synchronized(mWindowMap) {
8484 losers = mLosingFocus;
8485 mLosingFocus = new ArrayList<WindowState>();
8486 }
8487
8488 final int N = losers.size();
8489 for (int i=0; i<N; i++) {
8490 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008491 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008492 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8493 } catch (RemoteException e) {
8494 // Ignore if process has died.
8495 }
8496 }
8497 } break;
8498
8499 case ANIMATE: {
8500 synchronized(mWindowMap) {
8501 mAnimationPending = false;
8502 performLayoutAndPlaceSurfacesLocked();
8503 }
8504 } break;
8505
8506 case ADD_STARTING: {
8507 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8508 final StartingData sd = wtoken.startingData;
8509
8510 if (sd == null) {
8511 // Animation has been canceled... do nothing.
8512 return;
8513 }
Romain Guy06882f82009-06-10 13:36:04 -07008514
Joe Onorato8a9b2202010-02-26 18:56:32 -08008515 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 View view = null;
8519 try {
8520 view = mPolicy.addStartingWindow(
8521 wtoken.token, sd.pkg,
8522 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8523 sd.icon);
8524 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008525 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 }
8527
8528 if (view != null) {
8529 boolean abort = false;
8530
8531 synchronized(mWindowMap) {
8532 if (wtoken.removed || wtoken.startingData == null) {
8533 // If the window was successfully added, then
8534 // we need to remove it.
8535 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008536 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 "Aborted starting " + wtoken
8538 + ": removed=" + wtoken.removed
8539 + " startingData=" + wtoken.startingData);
8540 wtoken.startingWindow = null;
8541 wtoken.startingData = null;
8542 abort = true;
8543 }
8544 } else {
8545 wtoken.startingView = view;
8546 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008547 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 "Added starting " + wtoken
8549 + ": startingWindow="
8550 + wtoken.startingWindow + " startingView="
8551 + wtoken.startingView);
8552 }
8553
8554 if (abort) {
8555 try {
8556 mPolicy.removeStartingWindow(wtoken.token, view);
8557 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008558 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 }
8560 }
8561 }
8562 } break;
8563
8564 case REMOVE_STARTING: {
8565 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8566 IBinder token = null;
8567 View view = null;
8568 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008569 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 + wtoken + ": startingWindow="
8571 + wtoken.startingWindow + " startingView="
8572 + wtoken.startingView);
8573 if (wtoken.startingWindow != null) {
8574 view = wtoken.startingView;
8575 token = wtoken.token;
8576 wtoken.startingData = null;
8577 wtoken.startingView = null;
8578 wtoken.startingWindow = null;
8579 }
8580 }
8581 if (view != null) {
8582 try {
8583 mPolicy.removeStartingWindow(token, view);
8584 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008585 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 }
8587 }
8588 } break;
8589
8590 case FINISHED_STARTING: {
8591 IBinder token = null;
8592 View view = null;
8593 while (true) {
8594 synchronized (mWindowMap) {
8595 final int N = mFinishedStarting.size();
8596 if (N <= 0) {
8597 break;
8598 }
8599 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8600
Joe Onorato8a9b2202010-02-26 18:56:32 -08008601 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008602 "Finished starting " + wtoken
8603 + ": startingWindow=" + wtoken.startingWindow
8604 + " startingView=" + wtoken.startingView);
8605
8606 if (wtoken.startingWindow == null) {
8607 continue;
8608 }
8609
8610 view = wtoken.startingView;
8611 token = wtoken.token;
8612 wtoken.startingData = null;
8613 wtoken.startingView = null;
8614 wtoken.startingWindow = null;
8615 }
8616
8617 try {
8618 mPolicy.removeStartingWindow(token, view);
8619 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008620 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621 }
8622 }
8623 } break;
8624
8625 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8626 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8627
8628 boolean nowVisible = msg.arg1 != 0;
8629 boolean nowGone = msg.arg2 != 0;
8630
8631 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008632 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008633 TAG, "Reporting visible in " + wtoken
8634 + " visible=" + nowVisible
8635 + " gone=" + nowGone);
8636 if (nowVisible) {
8637 wtoken.appToken.windowsVisible();
8638 } else {
8639 wtoken.appToken.windowsGone();
8640 }
8641 } catch (RemoteException ex) {
8642 }
8643 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 case WINDOW_FREEZE_TIMEOUT: {
8646 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008647 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 int i = mWindows.size();
8649 while (i > 0) {
8650 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008651 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008652 if (w.mOrientationChanging) {
8653 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008654 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 }
8656 }
8657 performLayoutAndPlaceSurfacesLocked();
8658 }
8659 break;
8660 }
Romain Guy06882f82009-06-10 13:36:04 -07008661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008662 case HOLD_SCREEN_CHANGED: {
8663 Session oldHold;
8664 Session newHold;
8665 synchronized (mWindowMap) {
8666 oldHold = mLastReportedHold;
8667 newHold = (Session)msg.obj;
8668 mLastReportedHold = newHold;
8669 }
Romain Guy06882f82009-06-10 13:36:04 -07008670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 if (oldHold != newHold) {
8672 try {
8673 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008674 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008675 "window",
8676 BatteryStats.WAKE_TYPE_WINDOW);
8677 }
8678 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008679 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 "window",
8681 BatteryStats.WAKE_TYPE_WINDOW);
8682 }
8683 } catch (RemoteException e) {
8684 }
8685 }
8686 break;
8687 }
Romain Guy06882f82009-06-10 13:36:04 -07008688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008689 case APP_TRANSITION_TIMEOUT: {
8690 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008691 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008692 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 "*** APP TRANSITION TIMEOUT");
8694 mAppTransitionReady = true;
8695 mAppTransitionTimeout = true;
8696 performLayoutAndPlaceSurfacesLocked();
8697 }
8698 }
8699 break;
8700 }
Romain Guy06882f82009-06-10 13:36:04 -07008701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008702 case PERSIST_ANIMATION_SCALE: {
8703 Settings.System.putFloat(mContext.getContentResolver(),
8704 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8705 Settings.System.putFloat(mContext.getContentResolver(),
8706 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8707 break;
8708 }
Romain Guy06882f82009-06-10 13:36:04 -07008709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 case FORCE_GC: {
8711 synchronized(mWindowMap) {
8712 if (mAnimationPending) {
8713 // If we are animating, don't do the gc now but
8714 // delay a bit so we don't interrupt the animation.
8715 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8716 2000);
8717 return;
8718 }
8719 // If we are currently rotating the display, it will
8720 // schedule a new message when done.
8721 if (mDisplayFrozen) {
8722 return;
8723 }
8724 mFreezeGcPending = 0;
8725 }
8726 Runtime.getRuntime().gc();
8727 break;
8728 }
Romain Guy06882f82009-06-10 13:36:04 -07008729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008730 case ENABLE_SCREEN: {
8731 performEnableScreen();
8732 break;
8733 }
Romain Guy06882f82009-06-10 13:36:04 -07008734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008735 case APP_FREEZE_TIMEOUT: {
8736 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008737 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008738 int i = mAppTokens.size();
8739 while (i > 0) {
8740 i--;
8741 AppWindowToken tok = mAppTokens.get(i);
8742 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008743 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008744 unsetAppFreezingScreenLocked(tok, true, true);
8745 }
8746 }
8747 }
8748 break;
8749 }
Romain Guy06882f82009-06-10 13:36:04 -07008750
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008751 case SEND_NEW_CONFIGURATION: {
8752 removeMessages(SEND_NEW_CONFIGURATION);
8753 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008754 break;
8755 }
Romain Guy06882f82009-06-10 13:36:04 -07008756
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008757 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008758 if (mWindowsChanged) {
8759 synchronized (mWindowMap) {
8760 mWindowsChanged = false;
8761 }
8762 notifyWindowsChanged();
8763 }
8764 break;
8765 }
8766
Christopher Tatea53146c2010-09-07 11:57:52 -07008767 case DRAG_START_TIMEOUT: {
8768 IBinder win = (IBinder)msg.obj;
8769 if (DEBUG_DRAG) {
8770 Slog.w(TAG, "Timeout starting drag by win " + win);
8771 }
8772 synchronized (mWindowMap) {
8773 // !!! TODO: ANR the app that has failed to start the drag in time
8774 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07008775 mDragState.unregister();
8776 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008777 mDragState.reset();
8778 mDragState = null;
8779 }
8780 }
Chris Tated4533f12010-10-19 15:15:08 -07008781 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008782 }
8783
Chris Tated4533f12010-10-19 15:15:08 -07008784 case DRAG_END_TIMEOUT: {
8785 IBinder win = (IBinder)msg.obj;
8786 if (DEBUG_DRAG) {
8787 Slog.w(TAG, "Timeout ending drag to win " + win);
8788 }
8789 synchronized (mWindowMap) {
8790 // !!! TODO: ANR the drag-receiving app
8791 mDragState.mDragResult = false;
8792 mDragState.endDragLw();
8793 }
8794 break;
8795 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 }
8797 }
8798 }
8799
8800 // -------------------------------------------------------------
8801 // IWindowManager API
8802 // -------------------------------------------------------------
8803
8804 public IWindowSession openSession(IInputMethodClient client,
8805 IInputContext inputContext) {
8806 if (client == null) throw new IllegalArgumentException("null client");
8807 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008808 Session session = new Session(client, inputContext);
8809 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 }
8811
8812 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8813 synchronized (mWindowMap) {
8814 // The focus for the client is the window immediately below
8815 // where we would place the input method window.
8816 int idx = findDesiredInputMethodWindowIndexLocked(false);
8817 WindowState imFocus;
8818 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008819 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008820 if (imFocus != null) {
8821 if (imFocus.mSession.mClient != null &&
8822 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8823 return true;
8824 }
8825 }
8826 }
8827 }
8828 return false;
8829 }
Romain Guy06882f82009-06-10 13:36:04 -07008830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 // -------------------------------------------------------------
8832 // Internals
8833 // -------------------------------------------------------------
8834
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008835 final WindowState windowForClientLocked(Session session, IWindow client,
8836 boolean throwOnError) {
8837 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008838 }
Romain Guy06882f82009-06-10 13:36:04 -07008839
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008840 final WindowState windowForClientLocked(Session session, IBinder client,
8841 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008842 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008843 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008844 TAG, "Looking up client " + client + ": " + win);
8845 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008846 RuntimeException ex = new IllegalArgumentException(
8847 "Requested window " + client + " does not exist");
8848 if (throwOnError) {
8849 throw ex;
8850 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008851 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008852 return null;
8853 }
8854 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008855 RuntimeException ex = new IllegalArgumentException(
8856 "Requested window " + client + " is in session " +
8857 win.mSession + ", not " + session);
8858 if (throwOnError) {
8859 throw ex;
8860 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008861 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008862 return null;
8863 }
8864
8865 return win;
8866 }
8867
Dianne Hackborna8f60182009-09-01 19:01:50 -07008868 final void rebuildAppWindowListLocked() {
8869 int NW = mWindows.size();
8870 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008871 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008872 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008873
Dianne Hackborna8f60182009-09-01 19:01:50 -07008874 // First remove all existing app windows.
8875 i=0;
8876 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008877 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008878 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008879 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008880 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008881 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008882 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008883 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008884 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008885 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008886 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8887 && lastWallpaper == i-1) {
8888 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008889 }
8890 i++;
8891 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008892
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008893 // The wallpaper window(s) typically live at the bottom of the stack,
8894 // so skip them before adding app tokens.
8895 lastWallpaper++;
8896 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008897
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008898 // First add all of the exiting app tokens... these are no longer
8899 // in the main app list, but still have windows shown. We put them
8900 // in the back because now that the animation is over we no longer
8901 // will care about them.
8902 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008903 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008904 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8905 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008906
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008907 // And add in the still active app tokens in Z order.
8908 NT = mAppTokens.size();
8909 for (int j=0; j<NT; j++) {
8910 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008912
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008913 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008914 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008915 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008916 + " windows but added " + i);
8917 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008918 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008920 private final void assignLayersLocked() {
8921 int N = mWindows.size();
8922 int curBaseLayer = 0;
8923 int curLayer = 0;
8924 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008926 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008927 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008928 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8929 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008930 curLayer += WINDOW_LAYER_MULTIPLIER;
8931 w.mLayer = curLayer;
8932 } else {
8933 curBaseLayer = curLayer = w.mBaseLayer;
8934 w.mLayer = curLayer;
8935 }
8936 if (w.mTargetAppToken != null) {
8937 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8938 } else if (w.mAppToken != null) {
8939 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8940 } else {
8941 w.mAnimLayer = w.mLayer;
8942 }
8943 if (w.mIsImWindow) {
8944 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008945 } else if (w.mIsWallpaper) {
8946 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008947 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008948 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008949 + w.mAnimLayer);
8950 //System.out.println(
8951 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8952 }
8953 }
8954
8955 private boolean mInLayout = false;
8956 private final void performLayoutAndPlaceSurfacesLocked() {
8957 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008958 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008959 throw new RuntimeException("Recursive call!");
8960 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008961 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008962 return;
8963 }
8964
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008965 if (mWaitingForConfig) {
8966 // Our configuration has changed (most likely rotation), but we
8967 // don't yet have the complete configuration to report to
8968 // applications. Don't do any window layout until we have it.
8969 return;
8970 }
8971
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008972 if (mDisplay == null) {
8973 // Not yet initialized, nothing to do.
8974 return;
8975 }
8976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008977 boolean recoveringMemory = false;
8978 if (mForceRemoves != null) {
8979 recoveringMemory = true;
8980 // Wait a little it for things to settle down, and off we go.
8981 for (int i=0; i<mForceRemoves.size(); i++) {
8982 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008983 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 removeWindowInnerLocked(ws.mSession, ws);
8985 }
8986 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008987 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008988 Object tmp = new Object();
8989 synchronized (tmp) {
8990 try {
8991 tmp.wait(250);
8992 } catch (InterruptedException e) {
8993 }
8994 }
8995 }
Romain Guy06882f82009-06-10 13:36:04 -07008996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 mInLayout = true;
8998 try {
8999 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 int i = mPendingRemove.size()-1;
9002 if (i >= 0) {
9003 while (i >= 0) {
9004 WindowState w = mPendingRemove.get(i);
9005 removeWindowInnerLocked(w.mSession, w);
9006 i--;
9007 }
9008 mPendingRemove.clear();
9009
9010 mInLayout = false;
9011 assignLayersLocked();
9012 mLayoutNeeded = true;
9013 performLayoutAndPlaceSurfacesLocked();
9014
9015 } else {
9016 mInLayout = false;
9017 if (mLayoutNeeded) {
9018 requestAnimationLocked(0);
9019 }
9020 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009021 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009022 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9023 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009025 } catch (RuntimeException e) {
9026 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009027 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009028 }
9029 }
9030
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009031 private final int performLayoutLockedInner() {
9032 if (!mLayoutNeeded) {
9033 return 0;
9034 }
9035
9036 mLayoutNeeded = false;
9037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009038 final int dw = mDisplay.getWidth();
9039 final int dh = mDisplay.getHeight();
9040
9041 final int N = mWindows.size();
9042 int i;
9043
Joe Onorato8a9b2202010-02-26 18:56:32 -08009044 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009045 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9046
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009047 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009048
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009049 int seq = mLayoutSeq+1;
9050 if (seq < 0) seq = 0;
9051 mLayoutSeq = seq;
9052
9053 // First perform layout of any root windows (not attached
9054 // to another window).
9055 int topAttached = -1;
9056 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009057 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009059 // Don't do layout of a window if it is not visible, or
9060 // soon won't be visible, to avoid wasting time and funky
9061 // changes while a window is animating away.
9062 final AppWindowToken atoken = win.mAppToken;
9063 final boolean gone = win.mViewVisibility == View.GONE
9064 || !win.mRelayoutCalled
9065 || win.mRootToken.hidden
9066 || (atoken != null && atoken.hiddenRequested)
9067 || win.mAttachedHidden
9068 || win.mExiting || win.mDestroying;
9069
9070 if (!win.mLayoutAttached) {
9071 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9072 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9073 + " mLayoutAttached=" + win.mLayoutAttached);
9074 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9075 + win.mViewVisibility + " mRelayoutCalled="
9076 + win.mRelayoutCalled + " hidden="
9077 + win.mRootToken.hidden + " hiddenRequested="
9078 + (atoken != null && atoken.hiddenRequested)
9079 + " mAttachedHidden=" + win.mAttachedHidden);
9080 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009081
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009082 // If this view is GONE, then skip it -- keep the current
9083 // frame, and let the caller know so they can ignore it
9084 // if they want. (We do the normal layout for INVISIBLE
9085 // windows, since that means "perform layout as normal,
9086 // just don't display").
9087 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009088 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009089 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9090 win.mLayoutSeq = seq;
9091 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9092 + win.mFrame + " mContainingFrame="
9093 + win.mContainingFrame + " mDisplayFrame="
9094 + win.mDisplayFrame);
9095 } else {
9096 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009097 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009099 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009100
9101 // Now perform layout of attached windows, which usually
9102 // depend on the position of the window they are attached to.
9103 // XXX does not deal with windows that are attached to windows
9104 // that are themselves attached.
9105 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009106 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009107
9108 // If this view is GONE, then skip it -- keep the current
9109 // frame, and let the caller know so they can ignore it
9110 // if they want. (We do the normal layout for INVISIBLE
9111 // windows, since that means "perform layout as normal,
9112 // just don't display").
9113 if (win.mLayoutAttached) {
9114 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9115 + " mHaveFrame=" + win.mHaveFrame
9116 + " mViewVisibility=" + win.mViewVisibility
9117 + " mRelayoutCalled=" + win.mRelayoutCalled);
9118 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9119 || !win.mHaveFrame) {
9120 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9121 win.mLayoutSeq = seq;
9122 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9123 + win.mFrame + " mContainingFrame="
9124 + win.mContainingFrame + " mDisplayFrame="
9125 + win.mDisplayFrame);
9126 }
9127 }
9128 }
Jeff Brown349703e2010-06-22 01:27:15 -07009129
9130 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009131 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009132
9133 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009134 }
Romain Guy06882f82009-06-10 13:36:04 -07009135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009136 private final void performLayoutAndPlaceSurfacesLockedInner(
9137 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009138 if (mDisplay == null) {
9139 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9140 return;
9141 }
9142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 final long currentTime = SystemClock.uptimeMillis();
9144 final int dw = mDisplay.getWidth();
9145 final int dh = mDisplay.getHeight();
9146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009147 int i;
9148
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009149 if (mFocusMayChange) {
9150 mFocusMayChange = false;
9151 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9152 }
9153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009154 // Initialize state of exiting tokens.
9155 for (i=mExitingTokens.size()-1; i>=0; i--) {
9156 mExitingTokens.get(i).hasVisible = false;
9157 }
9158
9159 // Initialize state of exiting applications.
9160 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9161 mExitingAppTokens.get(i).hasVisible = false;
9162 }
9163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009164 boolean orientationChangeComplete = true;
9165 Session holdScreen = null;
9166 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009167 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009168 boolean focusDisplayed = false;
9169 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009170 boolean createWatermark = false;
9171
9172 if (mFxSession == null) {
9173 mFxSession = new SurfaceSession();
9174 createWatermark = true;
9175 }
9176
9177 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009178
9179 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009180
9181 if (createWatermark) {
9182 createWatermark();
9183 }
9184 if (mWatermark != null) {
9185 mWatermark.positionSurface(dw, dh);
9186 }
9187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009188 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009189 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009190 int repeats = 0;
9191 int changes = 0;
9192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009193 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009194 repeats++;
9195 if (repeats > 6) {
9196 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9197 mLayoutNeeded = false;
9198 break;
9199 }
9200
9201 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9202 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9203 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9204 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9205 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9206 assignLayersLocked();
9207 mLayoutNeeded = true;
9208 }
9209 }
9210 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9211 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9212 if (updateOrientationFromAppTokensLocked()) {
9213 mLayoutNeeded = true;
9214 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9215 }
9216 }
9217 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9218 mLayoutNeeded = true;
9219 }
9220 }
9221
9222 // FIRST LOOP: Perform a layout, if needed.
9223 if (repeats < 4) {
9224 changes = performLayoutLockedInner();
9225 if (changes != 0) {
9226 continue;
9227 }
9228 } else {
9229 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9230 changes = 0;
9231 }
9232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009233 final int transactionSequence = ++mTransactionSequence;
9234
9235 // Update animations of all applications, including those
9236 // associated with exiting/removed apps
9237 boolean tokensAnimating = false;
9238 final int NAT = mAppTokens.size();
9239 for (i=0; i<NAT; i++) {
9240 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9241 tokensAnimating = true;
9242 }
9243 }
9244 final int NEAT = mExitingAppTokens.size();
9245 for (i=0; i<NEAT; i++) {
9246 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9247 tokensAnimating = true;
9248 }
9249 }
9250
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009251 // SECOND LOOP: Execute animations and update visibility of windows.
9252
Joe Onorato8a9b2202010-02-26 18:56:32 -08009253 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009254 + transactionSequence + " tokensAnimating="
9255 + tokensAnimating);
9256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258
9259 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009260 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009261 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262
9263 mPolicy.beginAnimationLw(dw, dh);
9264
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009265 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009267 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009268 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009269
9270 final WindowManager.LayoutParams attrs = w.mAttrs;
9271
9272 if (w.mSurface != null) {
9273 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009274 if (w.commitFinishDrawingLocked(currentTime)) {
9275 if ((w.mAttrs.flags
9276 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009277 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009278 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009279 wallpaperMayChange = true;
9280 }
9281 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009282
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009283 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009284 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9285 animating = true;
9286 //w.dump(" ");
9287 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009288 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9289 wallpaperMayChange = true;
9290 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009291
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009292 if (mPolicy.doesForceHide(w, attrs)) {
9293 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009294 if (DEBUG_VISIBILITY) Slog.v(TAG,
9295 "Animation done that could impact force hide: "
9296 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009297 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009298 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009299 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9300 forceHiding = true;
9301 }
9302 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9303 boolean changed;
9304 if (forceHiding) {
9305 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009306 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9307 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009308 } else {
9309 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009310 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9311 "Now policy shown: " + w);
9312 if (changed) {
9313 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009314 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009315 // Assume we will need to animate. If
9316 // we don't (because the wallpaper will
9317 // stay with the lock screen), then we will
9318 // clean up later.
9319 Animation a = mPolicy.createForceHideEnterAnimation();
9320 if (a != null) {
9321 w.setAnimation(a);
9322 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009323 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009324 if (mCurrentFocus == null ||
9325 mCurrentFocus.mLayer < w.mLayer) {
9326 // We are showing on to of the current
9327 // focus, so re-evaluate focus to make
9328 // sure it is correct.
9329 mFocusMayChange = true;
9330 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009331 }
9332 }
9333 if (changed && (attrs.flags
9334 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9335 wallpaperMayChange = true;
9336 }
9337 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009339 mPolicy.animatingWindowLw(w, attrs);
9340 }
9341
9342 final AppWindowToken atoken = w.mAppToken;
9343 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9344 if (atoken.lastTransactionSequence != transactionSequence) {
9345 atoken.lastTransactionSequence = transactionSequence;
9346 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9347 atoken.startingDisplayed = false;
9348 }
9349 if ((w.isOnScreen() || w.mAttrs.type
9350 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9351 && !w.mExiting && !w.mDestroying) {
9352 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009353 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009354 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009355 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009356 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009357 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 + " pv=" + w.mPolicyVisibility
9359 + " dp=" + w.mDrawPending
9360 + " cdp=" + w.mCommitDrawPending
9361 + " ah=" + w.mAttachedHidden
9362 + " th=" + atoken.hiddenRequested
9363 + " a=" + w.mAnimating);
9364 }
9365 }
9366 if (w != atoken.startingWindow) {
9367 if (!atoken.freezingScreen || !w.mAppFreezing) {
9368 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009369 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009370 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009371 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009372 "tokenMayBeDrawn: " + atoken
9373 + " freezingScreen=" + atoken.freezingScreen
9374 + " mAppFreezing=" + w.mAppFreezing);
9375 tokenMayBeDrawn = true;
9376 }
9377 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009378 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 atoken.startingDisplayed = true;
9380 }
9381 }
9382 } else if (w.mReadyToShow) {
9383 w.performShowLocked();
9384 }
9385 }
9386
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009387 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388
9389 if (tokenMayBeDrawn) {
9390 // See if any windows have been drawn, so they (and others
9391 // associated with them) can now be shown.
9392 final int NT = mTokenList.size();
9393 for (i=0; i<NT; i++) {
9394 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9395 if (wtoken == null) {
9396 continue;
9397 }
9398 if (wtoken.freezingScreen) {
9399 int numInteresting = wtoken.numInterestingWindows;
9400 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009401 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 "allDrawn: " + wtoken
9403 + " interesting=" + numInteresting
9404 + " drawn=" + wtoken.numDrawnWindows);
9405 wtoken.showAllWindowsLocked();
9406 unsetAppFreezingScreenLocked(wtoken, false, true);
9407 orientationChangeComplete = true;
9408 }
9409 } else if (!wtoken.allDrawn) {
9410 int numInteresting = wtoken.numInterestingWindows;
9411 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009412 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009413 "allDrawn: " + wtoken
9414 + " interesting=" + numInteresting
9415 + " drawn=" + wtoken.numDrawnWindows);
9416 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009417 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009418
9419 // We can now show all of the drawn windows!
9420 if (!mOpeningApps.contains(wtoken)) {
9421 wtoken.showAllWindowsLocked();
9422 }
9423 }
9424 }
9425 }
9426 }
9427
9428 // If we are ready to perform an app transition, check through
9429 // all of the app tokens to be shown and see if they are ready
9430 // to go.
9431 if (mAppTransitionReady) {
9432 int NN = mOpeningApps.size();
9433 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009434 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009435 "Checking " + NN + " opening apps (frozen="
9436 + mDisplayFrozen + " timeout="
9437 + mAppTransitionTimeout + ")...");
9438 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9439 // If the display isn't frozen, wait to do anything until
9440 // all of the apps are ready. Otherwise just go because
9441 // we'll unfreeze the display when everyone is ready.
9442 for (i=0; i<NN && goodToGo; i++) {
9443 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009444 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 "Check opening app" + wtoken + ": allDrawn="
9446 + wtoken.allDrawn + " startingDisplayed="
9447 + wtoken.startingDisplayed);
9448 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9449 && !wtoken.startingMoved) {
9450 goodToGo = false;
9451 }
9452 }
9453 }
9454 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009455 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009456 int transit = mNextAppTransition;
9457 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009458 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009459 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009460 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009461 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009462 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009463 mAppTransitionTimeout = false;
9464 mStartingIconInTransition = false;
9465 mSkipAppTransitionAnimation = false;
9466
9467 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9468
Dianne Hackborna8f60182009-09-01 19:01:50 -07009469 // If there are applications waiting to come to the
9470 // top of the stack, now is the time to move their windows.
9471 // (Note that we don't do apps going to the bottom
9472 // here -- we want to keep their windows in the old
9473 // Z-order until the animation completes.)
9474 if (mToTopApps.size() > 0) {
9475 NN = mAppTokens.size();
9476 for (i=0; i<NN; i++) {
9477 AppWindowToken wtoken = mAppTokens.get(i);
9478 if (wtoken.sendingToTop) {
9479 wtoken.sendingToTop = false;
9480 moveAppWindowsLocked(wtoken, NN, false);
9481 }
9482 }
9483 mToTopApps.clear();
9484 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009485
Dianne Hackborn25994b42009-09-04 14:21:19 -07009486 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009487
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009488 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009489 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009490
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009491 // The top-most window will supply the layout params,
9492 // and we will determine it below.
9493 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009494 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009495 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009496
Joe Onorato8a9b2202010-02-26 18:56:32 -08009497 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009498 "New wallpaper target=" + mWallpaperTarget
9499 + ", lower target=" + mLowerWallpaperTarget
9500 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009501 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009502 // Do a first pass through the tokens for two
9503 // things:
9504 // (1) Determine if both the closing and opening
9505 // app token sets are wallpaper targets, in which
9506 // case special animations are needed
9507 // (since the wallpaper needs to stay static
9508 // behind them).
9509 // (2) Find the layout params of the top-most
9510 // application window in the tokens, which is
9511 // what will control the animation theme.
9512 final int NC = mClosingApps.size();
9513 NN = NC + mOpeningApps.size();
9514 for (i=0; i<NN; i++) {
9515 AppWindowToken wtoken;
9516 int mode;
9517 if (i < NC) {
9518 wtoken = mClosingApps.get(i);
9519 mode = 1;
9520 } else {
9521 wtoken = mOpeningApps.get(i-NC);
9522 mode = 2;
9523 }
9524 if (mLowerWallpaperTarget != null) {
9525 if (mLowerWallpaperTarget.mAppToken == wtoken
9526 || mUpperWallpaperTarget.mAppToken == wtoken) {
9527 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009528 }
9529 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009530 if (wtoken.appFullscreen) {
9531 WindowState ws = wtoken.findMainWindow();
9532 if (ws != null) {
9533 // If this is a compatibility mode
9534 // window, we will always use its anim.
9535 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9536 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009537 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009538 bestAnimLayer = Integer.MAX_VALUE;
9539 } else if (ws.mLayer > bestAnimLayer) {
9540 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009541 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009542 bestAnimLayer = ws.mLayer;
9543 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009544 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009545 }
9546 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009547
Dianne Hackborn25994b42009-09-04 14:21:19 -07009548 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009549 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009550 "Wallpaper animation!");
9551 switch (transit) {
9552 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9553 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9554 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9555 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9556 break;
9557 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9558 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9559 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9560 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9561 break;
9562 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009563 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009564 "New transit: " + transit);
9565 } else if (oldWallpaper != null) {
9566 // We are transitioning from an activity with
9567 // a wallpaper to one without.
9568 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009569 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009570 "New transit away from wallpaper: " + transit);
9571 } else if (mWallpaperTarget != null) {
9572 // We are transitioning from an activity without
9573 // a wallpaper to now showing the wallpaper
9574 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009575 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009576 "New transit into wallpaper: " + transit);
9577 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009578
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009579 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9580 mLastEnterAnimToken = animToken;
9581 mLastEnterAnimParams = animLp;
9582 } else if (mLastEnterAnimParams != null) {
9583 animLp = mLastEnterAnimParams;
9584 mLastEnterAnimToken = null;
9585 mLastEnterAnimParams = null;
9586 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009587
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009588 // If all closing windows are obscured, then there is
9589 // no need to do an animation. This is the case, for
9590 // example, when this transition is being done behind
9591 // the lock screen.
9592 if (!mPolicy.allowAppAnimationsLw()) {
9593 animLp = null;
9594 }
9595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596 NN = mOpeningApps.size();
9597 for (i=0; i<NN; i++) {
9598 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009599 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 "Now opening app" + wtoken);
9601 wtoken.reportedVisible = false;
9602 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009603 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009604 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009606 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009607 wtoken.showAllWindowsLocked();
9608 }
9609 NN = mClosingApps.size();
9610 for (i=0; i<NN; i++) {
9611 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009612 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 "Now closing app" + wtoken);
9614 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009615 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009616 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009617 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009618 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009619 // Force the allDrawn flag, because we want to start
9620 // this guy's animations regardless of whether it's
9621 // gotten drawn.
9622 wtoken.allDrawn = true;
9623 }
9624
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009625 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009627 mOpeningApps.clear();
9628 mClosingApps.clear();
9629
9630 // This has changed the visibility of windows, so perform
9631 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009632 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009634 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9635 assignLayersLocked();
9636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009637 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009638 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009639 }
9640 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009641
Dianne Hackborn16064f92010-03-25 00:47:24 -07009642 int adjResult = 0;
9643
Dianne Hackborna8f60182009-09-01 19:01:50 -07009644 if (!animating && mAppTransitionRunning) {
9645 // We have finished the animation of an app transition. To do
9646 // this, we have delayed a lot of operations like showing and
9647 // hiding apps, moving apps in Z-order, etc. The app token list
9648 // reflects the correct Z-order, but the window list may now
9649 // be out of sync with it. So here we will just rebuild the
9650 // entire app window list. Fun!
9651 mAppTransitionRunning = false;
9652 // Clear information about apps that were moving.
9653 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009654
Dianne Hackborna8f60182009-09-01 19:01:50 -07009655 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009656 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009657 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009658 moveInputMethodWindowsIfNeededLocked(false);
9659 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009660 // Since the window list has been rebuilt, focus might
9661 // have to be recomputed since the actual order of windows
9662 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009663 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009664 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009665
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009666 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009667 // At this point, there was a window with a wallpaper that
9668 // was force hiding other windows behind it, but now it
9669 // is going away. This may be simple -- just animate
9670 // away the wallpaper and its window -- or it may be
9671 // hard -- the wallpaper now needs to be shown behind
9672 // something that was hidden.
9673 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009674 if (mLowerWallpaperTarget != null
9675 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009676 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009677 "wallpaperForceHiding changed with lower="
9678 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009679 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009680 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9681 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9682 if (mLowerWallpaperTarget.mAppToken.hidden) {
9683 // The lower target has become hidden before we
9684 // actually started the animation... let's completely
9685 // re-evaluate everything.
9686 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009687 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009688 }
9689 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009690 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009691 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009692 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009693 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009694 + " NEW: " + mWallpaperTarget
9695 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009696 if (mLowerWallpaperTarget == null) {
9697 // Whoops, we don't need a special wallpaper animation.
9698 // Clear them out.
9699 forceHiding = false;
9700 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009701 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009702 if (w.mSurface != null) {
9703 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009704 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009705 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009706 forceHiding = true;
9707 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9708 if (!w.mAnimating) {
9709 // We set the animation above so it
9710 // is not yet running.
9711 w.clearAnimation();
9712 }
9713 }
9714 }
9715 }
9716 }
9717 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009718
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009719 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009720 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009721 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009722 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009724
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009725 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009726 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009727 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009728 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009729 assignLayersLocked();
9730 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009731 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009732 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009733 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009734 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009735
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009736 if (mFocusMayChange) {
9737 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009738 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009739 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009740 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009741 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009742 }
9743
9744 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009745 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009747
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009748 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9749 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009750
Jeff Browne33348b2010-07-15 23:54:05 -07009751 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009752 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753
9754 // THIRD LOOP: Update the surfaces of all windows.
9755
9756 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9757
9758 boolean obscured = false;
9759 boolean blurring = false;
9760 boolean dimming = false;
9761 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009762 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009763 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009765 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009768 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769
9770 boolean displayed = false;
9771 final WindowManager.LayoutParams attrs = w.mAttrs;
9772 final int attrFlags = attrs.flags;
9773
9774 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009775 // XXX NOTE: The logic here could be improved. We have
9776 // the decision about whether to resize a window separated
9777 // from whether to hide the surface. This can cause us to
9778 // resize a surface even if we are going to hide it. You
9779 // can see this by (1) holding device in landscape mode on
9780 // home screen; (2) tapping browser icon (device will rotate
9781 // to landscape; (3) tap home. The wallpaper will be resized
9782 // in step 2 but then immediately hidden, causing us to
9783 // have to resize and then redraw it again in step 3. It
9784 // would be nice to figure out how to avoid this, but it is
9785 // difficult because we do need to resize surfaces in some
9786 // cases while they are hidden such as when first showing a
9787 // window.
9788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009790 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 TAG, "Placing surface #" + i + " " + w.mSurface
9792 + ": new=" + w.mShownFrame + ", old="
9793 + w.mLastShownFrame);
9794
9795 boolean resize;
9796 int width, height;
9797 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9798 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9799 w.mLastRequestedHeight != w.mRequestedHeight;
9800 // for a scaled surface, we just want to use
9801 // the requested size.
9802 width = w.mRequestedWidth;
9803 height = w.mRequestedHeight;
9804 w.mLastRequestedWidth = width;
9805 w.mLastRequestedHeight = height;
9806 w.mLastShownFrame.set(w.mShownFrame);
9807 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009808 if (SHOW_TRANSACTIONS) logSurface(w,
9809 "POS " + w.mShownFrame.left
9810 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009811 w.mSurfaceX = w.mShownFrame.left;
9812 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9814 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009815 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 if (!recoveringMemory) {
9817 reclaimSomeSurfaceMemoryLocked(w, "position");
9818 }
9819 }
9820 } else {
9821 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9822 width = w.mShownFrame.width();
9823 height = w.mShownFrame.height();
9824 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009825 }
9826
9827 if (resize) {
9828 if (width < 1) width = 1;
9829 if (height < 1) height = 1;
9830 if (w.mSurface != null) {
9831 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009832 if (SHOW_TRANSACTIONS) logSurface(w,
9833 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009834 + w.mShownFrame.top + " SIZE "
9835 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009836 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009837 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009838 w.mSurfaceW = width;
9839 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009841 w.mSurfaceX = w.mShownFrame.left;
9842 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009843 w.mSurface.setPosition(w.mShownFrame.left,
9844 w.mShownFrame.top);
9845 } catch (RuntimeException e) {
9846 // If something goes wrong with the surface (such
9847 // as running out of memory), don't take down the
9848 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009849 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009850 + "size=(" + width + "x" + height
9851 + "), pos=(" + w.mShownFrame.left
9852 + "," + w.mShownFrame.top + ")", e);
9853 if (!recoveringMemory) {
9854 reclaimSomeSurfaceMemoryLocked(w, "size");
9855 }
9856 }
9857 }
9858 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009859 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009860 w.mContentInsetsChanged =
9861 !w.mLastContentInsets.equals(w.mContentInsets);
9862 w.mVisibleInsetsChanged =
9863 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009864 boolean configChanged =
9865 w.mConfiguration != mCurConfiguration
9866 && (w.mConfiguration == null
9867 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009868 if (DEBUG_CONFIGURATION && configChanged) {
9869 Slog.v(TAG, "Win " + w + " config changed: "
9870 + mCurConfiguration);
9871 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009872 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009873 + ": configChanged=" + configChanged
9874 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009875 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009877 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009878 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009879 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009880 w.mLastFrame.set(w.mFrame);
9881 w.mLastContentInsets.set(w.mContentInsets);
9882 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009883 // If the screen is currently frozen, then keep
9884 // it frozen until this window draws at its new
9885 // orientation.
9886 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009887 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009888 "Resizing while display frozen: " + w);
9889 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009890 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009891 mWindowsFreezingScreen = true;
9892 // XXX should probably keep timeout from
9893 // when we first froze the display.
9894 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9895 mH.sendMessageDelayed(mH.obtainMessage(
9896 H.WINDOW_FREEZE_TIMEOUT), 2000);
9897 }
9898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 // If the orientation is changing, then we need to
9900 // hold off on unfreezing the display until this
9901 // window has been redrawn; to do that, we need
9902 // to go through the process of getting informed
9903 // by the application when it has finished drawing.
9904 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009906 "Orientation start waiting for draw in "
9907 + w + ", surface " + w.mSurface);
9908 w.mDrawPending = true;
9909 w.mCommitDrawPending = false;
9910 w.mReadyToShow = false;
9911 if (w.mAppToken != null) {
9912 w.mAppToken.allDrawn = false;
9913 }
9914 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009915 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009916 "Resizing window " + w + " to " + w.mFrame);
9917 mResizingWindows.add(w);
9918 } else if (w.mOrientationChanging) {
9919 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009920 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009921 "Orientation not waiting for draw in "
9922 + w + ", surface " + w.mSurface);
9923 w.mOrientationChanging = false;
9924 }
9925 }
9926 }
9927
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009928 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 if (!w.mLastHidden) {
9930 //dump();
9931 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009932 if (SHOW_TRANSACTIONS) logSurface(w,
9933 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009934 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009935 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 try {
9937 w.mSurface.hide();
9938 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009939 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 }
9941 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 }
9943 // If we are waiting for this window to handle an
9944 // orientation change, well, it is hidden, so
9945 // doesn't really matter. Note that this does
9946 // introduce a potential glitch if the window
9947 // becomes unhidden before it has drawn for the
9948 // new orientation.
9949 if (w.mOrientationChanging) {
9950 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009951 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009952 "Orientation change skips hidden " + w);
9953 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009954 } else if (w.mLastLayer != w.mAnimLayer
9955 || w.mLastAlpha != w.mShownAlpha
9956 || w.mLastDsDx != w.mDsDx
9957 || w.mLastDtDx != w.mDtDx
9958 || w.mLastDsDy != w.mDsDy
9959 || w.mLastDtDy != w.mDtDy
9960 || w.mLastHScale != w.mHScale
9961 || w.mLastVScale != w.mVScale
9962 || w.mLastHidden) {
9963 displayed = true;
9964 w.mLastAlpha = w.mShownAlpha;
9965 w.mLastLayer = w.mAnimLayer;
9966 w.mLastDsDx = w.mDsDx;
9967 w.mLastDtDx = w.mDtDx;
9968 w.mLastDsDy = w.mDsDy;
9969 w.mLastDtDy = w.mDtDy;
9970 w.mLastHScale = w.mHScale;
9971 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009972 if (SHOW_TRANSACTIONS) logSurface(w,
9973 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009974 + " matrix=[" + (w.mDsDx*w.mHScale)
9975 + "," + (w.mDtDx*w.mVScale)
9976 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009977 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 if (w.mSurface != null) {
9979 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009980 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009981 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009982 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 w.mSurface.setLayer(w.mAnimLayer);
9984 w.mSurface.setMatrix(
9985 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9986 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9987 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009988 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 if (!recoveringMemory) {
9990 reclaimSomeSurfaceMemoryLocked(w, "update");
9991 }
9992 }
9993 }
9994
9995 if (w.mLastHidden && !w.mDrawPending
9996 && !w.mCommitDrawPending
9997 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009998 if (SHOW_TRANSACTIONS) logSurface(w,
9999 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010000 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010001 + " during relayout");
10002 if (showSurfaceRobustlyLocked(w)) {
10003 w.mHasDrawn = true;
10004 w.mLastHidden = false;
10005 } else {
10006 w.mOrientationChanging = false;
10007 }
10008 }
10009 if (w.mSurface != null) {
10010 w.mToken.hasVisible = true;
10011 }
10012 } else {
10013 displayed = true;
10014 }
10015
10016 if (displayed) {
10017 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010018 if (attrs.width == LayoutParams.MATCH_PARENT
10019 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010020 covered = true;
10021 }
10022 }
10023 if (w.mOrientationChanging) {
10024 if (w.mDrawPending || w.mCommitDrawPending) {
10025 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010026 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010027 "Orientation continue waiting for draw in " + w);
10028 } else {
10029 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010030 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010031 "Orientation change complete in " + w);
10032 }
10033 }
10034 w.mToken.hasVisible = true;
10035 }
10036 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010037 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 "Orientation change skips hidden " + w);
10039 w.mOrientationChanging = false;
10040 }
10041
10042 final boolean canBeSeen = w.isDisplayedLw();
10043
10044 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10045 focusDisplayed = true;
10046 }
10047
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010048 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010051 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010052 if (w.mSurface != null) {
10053 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10054 holdScreen = w.mSession;
10055 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010056 if (!syswin && w.mAttrs.screenBrightness >= 0
10057 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 screenBrightness = w.mAttrs.screenBrightness;
10059 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010060 if (!syswin && w.mAttrs.buttonBrightness >= 0
10061 && buttonBrightness < 0) {
10062 buttonBrightness = w.mAttrs.buttonBrightness;
10063 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010064 if (canBeSeen
10065 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10066 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10067 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010068 syswin = true;
10069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010070 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010071
Dianne Hackborn25994b42009-09-04 14:21:19 -070010072 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10073 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074 // This window completely covers everything behind it,
10075 // so we want to leave all of them as unblurred (for
10076 // performance reasons).
10077 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010078 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010079 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010080 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010081 obscured = true;
10082 if (mBackgroundFillerSurface == null) {
10083 try {
10084 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010085 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010086 0, dw, dh,
10087 PixelFormat.OPAQUE,
10088 Surface.FX_SURFACE_NORMAL);
10089 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010090 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010091 }
10092 }
10093 try {
10094 mBackgroundFillerSurface.setPosition(0, 0);
10095 mBackgroundFillerSurface.setSize(dw, dh);
10096 // Using the same layer as Dim because they will never be shown at the
10097 // same time.
10098 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10099 mBackgroundFillerSurface.show();
10100 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010101 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010102 }
10103 backgroundFillerShown = true;
10104 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010105 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010107 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010108 + ": blurring=" + blurring
10109 + " obscured=" + obscured
10110 + " displayed=" + displayed);
10111 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10112 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010113 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010114 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010115 if (mDimAnimator == null) {
10116 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010118 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010119 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010121 }
10122 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10123 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010124 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010125 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010126 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010127 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010128 + mBlurSurface + ": CREATE");
10129 try {
Romain Guy06882f82009-06-10 13:36:04 -070010130 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010131 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010132 -1, 16, 16,
10133 PixelFormat.OPAQUE,
10134 Surface.FX_SURFACE_BLUR);
10135 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010136 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010137 }
10138 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010139 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010140 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10141 + mBlurSurface + ": pos=(0,0) (" +
10142 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010143 mBlurSurface.setPosition(0, 0);
10144 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010145 mBlurSurface.setLayer(w.mAnimLayer-2);
10146 if (!mBlurShown) {
10147 try {
10148 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10149 + mBlurSurface + ": SHOW");
10150 mBlurSurface.show();
10151 } catch (RuntimeException e) {
10152 Slog.w(TAG, "Failure showing blur surface", e);
10153 }
10154 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010155 }
10156 }
10157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 }
10159 }
10160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010161
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010162 if (obscuredChanged && mWallpaperTarget == w) {
10163 // This is the wallpaper target and its obscured state
10164 // changed... make sure the current wallaper's visibility
10165 // has been updated accordingly.
10166 updateWallpaperVisibilityLocked();
10167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010168 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010169
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010170 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10171 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010172 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010173 try {
10174 mBackgroundFillerSurface.hide();
10175 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010176 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010177 }
10178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010179
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010180 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010181 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10182 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010183 }
Romain Guy06882f82009-06-10 13:36:04 -070010184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010185 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010186 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010187 + ": HIDE");
10188 try {
10189 mBlurSurface.hide();
10190 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010191 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010192 }
10193 mBlurShown = false;
10194 }
10195
Joe Onorato8a9b2202010-02-26 18:56:32 -080010196 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010197 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010198 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010199 }
10200
Jeff Browne33348b2010-07-15 23:54:05 -070010201 mInputMonitor.updateInputWindowsLw();
10202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010203 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010204
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010205 if (mWatermark != null) {
10206 mWatermark.drawIfNeeded();
10207 }
10208
Joe Onorato8a9b2202010-02-26 18:56:32 -080010209 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010210 "With display frozen, orientationChangeComplete="
10211 + orientationChangeComplete);
10212 if (orientationChangeComplete) {
10213 if (mWindowsFreezingScreen) {
10214 mWindowsFreezingScreen = false;
10215 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10216 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010217 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010218 }
Romain Guy06882f82009-06-10 13:36:04 -070010219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010220 i = mResizingWindows.size();
10221 if (i > 0) {
10222 do {
10223 i--;
10224 WindowState win = mResizingWindows.get(i);
10225 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010226 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10227 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010228 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010229 boolean configChanged =
10230 win.mConfiguration != mCurConfiguration
10231 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010232 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10233 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10234 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010235 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010236 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010237 + " / " + mCurConfiguration + " / 0x"
10238 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010239 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010240 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010241 win.mClient.resized(win.mFrame.width(),
10242 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010243 win.mLastVisibleInsets, win.mDrawPending,
10244 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010245 win.mContentInsetsChanged = false;
10246 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010247 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010248 } catch (RemoteException e) {
10249 win.mOrientationChanging = false;
10250 }
10251 } while (i > 0);
10252 mResizingWindows.clear();
10253 }
Romain Guy06882f82009-06-10 13:36:04 -070010254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010255 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010256 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010257 i = mDestroySurface.size();
10258 if (i > 0) {
10259 do {
10260 i--;
10261 WindowState win = mDestroySurface.get(i);
10262 win.mDestroying = false;
10263 if (mInputMethodWindow == win) {
10264 mInputMethodWindow = null;
10265 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010266 if (win == mWallpaperTarget) {
10267 wallpaperDestroyed = true;
10268 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 win.destroySurfaceLocked();
10270 } while (i > 0);
10271 mDestroySurface.clear();
10272 }
10273
10274 // Time to remove any exiting tokens?
10275 for (i=mExitingTokens.size()-1; i>=0; i--) {
10276 WindowToken token = mExitingTokens.get(i);
10277 if (!token.hasVisible) {
10278 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010279 if (token.windowType == TYPE_WALLPAPER) {
10280 mWallpaperTokens.remove(token);
10281 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010282 }
10283 }
10284
10285 // Time to remove any exiting applications?
10286 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10287 AppWindowToken token = mExitingAppTokens.get(i);
10288 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010289 // Make sure there is no animation running on this token,
10290 // so any windows associated with it will be removed as
10291 // soon as their animations are complete
10292 token.animation = null;
10293 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010294 mAppTokens.remove(token);
10295 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010296 if (mLastEnterAnimToken == token) {
10297 mLastEnterAnimToken = null;
10298 mLastEnterAnimParams = null;
10299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010300 }
10301 }
10302
Dianne Hackborna8f60182009-09-01 19:01:50 -070010303 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010304
Dianne Hackborna8f60182009-09-01 19:01:50 -070010305 if (!animating && mAppTransitionRunning) {
10306 // We have finished the animation of an app transition. To do
10307 // this, we have delayed a lot of operations like showing and
10308 // hiding apps, moving apps in Z-order, etc. The app token list
10309 // reflects the correct Z-order, but the window list may now
10310 // be out of sync with it. So here we will just rebuild the
10311 // entire app window list. Fun!
10312 mAppTransitionRunning = false;
10313 needRelayout = true;
10314 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010315 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010316 // Clear information about apps that were moving.
10317 mToBottomApps.clear();
10318 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010320 if (focusDisplayed) {
10321 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10322 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010323 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010324 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010325 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010326 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010327 requestAnimationLocked(0);
10328 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10330 }
Jeff Browneb857f12010-07-16 10:06:33 -070010331
Jeff Browne33348b2010-07-15 23:54:05 -070010332 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010333
Jeff Brown8e03b752010-06-13 19:16:55 -070010334 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10336 mPowerManager.setScreenBrightnessOverride(-1);
10337 } else {
10338 mPowerManager.setScreenBrightnessOverride((int)
10339 (screenBrightness * Power.BRIGHTNESS_ON));
10340 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010341 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10342 mPowerManager.setButtonBrightnessOverride(-1);
10343 } else {
10344 mPowerManager.setButtonBrightnessOverride((int)
10345 (buttonBrightness * Power.BRIGHTNESS_ON));
10346 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 if (holdScreen != mHoldingScreenOn) {
10348 mHoldingScreenOn = holdScreen;
10349 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10350 mH.sendMessage(m);
10351 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010352
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010353 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010354 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010355 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10356 LocalPowerManager.BUTTON_EVENT, true);
10357 mTurnOnScreen = false;
10358 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010359
10360 // Check to see if we are now in a state where the screen should
10361 // be enabled, because the window obscured flags have changed.
10362 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010364
10365 /**
10366 * Must be called with the main window manager lock held.
10367 */
10368 void setHoldScreenLocked(boolean holding) {
10369 boolean state = mHoldingScreenWakeLock.isHeld();
10370 if (holding != state) {
10371 if (holding) {
10372 mHoldingScreenWakeLock.acquire();
10373 } else {
10374 mPolicy.screenOnStoppedLw();
10375 mHoldingScreenWakeLock.release();
10376 }
10377 }
10378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010379
10380 void requestAnimationLocked(long delay) {
10381 if (!mAnimationPending) {
10382 mAnimationPending = true;
10383 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10384 }
10385 }
Romain Guy06882f82009-06-10 13:36:04 -070010386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 /**
10388 * Have the surface flinger show a surface, robustly dealing with
10389 * error conditions. In particular, if there is not enough memory
10390 * to show the surface, then we will try to get rid of other surfaces
10391 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010392 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 * @return Returns true if the surface was successfully shown.
10394 */
10395 boolean showSurfaceRobustlyLocked(WindowState win) {
10396 try {
10397 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010398 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010399 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010400 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010401 if (DEBUG_VISIBILITY) Slog.v(TAG,
10402 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010403 win.mTurnOnScreen = false;
10404 mTurnOnScreen = true;
10405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010406 }
10407 return true;
10408 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010409 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010410 }
Romain Guy06882f82009-06-10 13:36:04 -070010411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010414 return false;
10415 }
Romain Guy06882f82009-06-10 13:36:04 -070010416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10418 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010419
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010420 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 if (mForceRemoves == null) {
10424 mForceRemoves = new ArrayList<WindowState>();
10425 }
Romain Guy06882f82009-06-10 13:36:04 -070010426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427 long callingIdentity = Binder.clearCallingIdentity();
10428 try {
10429 // There was some problem... first, do a sanity check of the
10430 // window list to make sure we haven't left any dangling surfaces
10431 // around.
10432 int N = mWindows.size();
10433 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010434 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010436 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 if (ws.mSurface != null) {
10438 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010439 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010440 + ws + " surface=" + ws.mSurface
10441 + " token=" + win.mToken
10442 + " pid=" + ws.mSession.mPid
10443 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010444 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010445 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 ws.mSurface = null;
10447 mForceRemoves.add(ws);
10448 i--;
10449 N--;
10450 leakedSurface = true;
10451 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010452 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010453 + ws + " surface=" + ws.mSurface
10454 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010455 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010456 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 ws.mSurface = null;
10458 leakedSurface = true;
10459 }
10460 }
10461 }
Romain Guy06882f82009-06-10 13:36:04 -070010462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 boolean killedApps = false;
10464 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010465 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 SparseIntArray pidCandidates = new SparseIntArray();
10467 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010468 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010469 if (ws.mSurface != null) {
10470 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10471 }
10472 }
10473 if (pidCandidates.size() > 0) {
10474 int[] pids = new int[pidCandidates.size()];
10475 for (int i=0; i<pids.length; i++) {
10476 pids[i] = pidCandidates.keyAt(i);
10477 }
10478 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010479 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 killedApps = true;
10481 }
10482 } catch (RemoteException e) {
10483 }
10484 }
10485 }
Romain Guy06882f82009-06-10 13:36:04 -070010486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010487 if (leakedSurface || killedApps) {
10488 // We managed to reclaim some memory, so get rid of the trouble
10489 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010490 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010492 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010493 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010494 win.mSurface = null;
10495 }
Romain Guy06882f82009-06-10 13:36:04 -070010496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010497 try {
10498 win.mClient.dispatchGetNewSurface();
10499 } catch (RemoteException e) {
10500 }
10501 }
10502 } finally {
10503 Binder.restoreCallingIdentity(callingIdentity);
10504 }
10505 }
Romain Guy06882f82009-06-10 13:36:04 -070010506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 private boolean updateFocusedWindowLocked(int mode) {
10508 WindowState newFocus = computeFocusedWindowLocked();
10509 if (mCurrentFocus != newFocus) {
10510 // This check makes sure that we don't already have the focus
10511 // change message pending.
10512 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10513 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010514 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10516 final WindowState oldFocus = mCurrentFocus;
10517 mCurrentFocus = newFocus;
10518 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010520 final WindowState imWindow = mInputMethodWindow;
10521 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010522 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010523 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010524 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10525 mLayoutNeeded = true;
10526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010527 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10528 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010529 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10530 // Client will do the layout, but we need to assign layers
10531 // for handleNewWindowLocked() below.
10532 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010533 }
10534 }
Jeff Brown349703e2010-06-22 01:27:15 -070010535
10536 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10537 // If we defer assigning layers, then the caller is responsible for
10538 // doing this part.
10539 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010541 return true;
10542 }
10543 return false;
10544 }
Jeff Brown349703e2010-06-22 01:27:15 -070010545
10546 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010547 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549
10550 private WindowState computeFocusedWindowLocked() {
10551 WindowState result = null;
10552 WindowState win;
10553
10554 int i = mWindows.size() - 1;
10555 int nextAppIndex = mAppTokens.size()-1;
10556 WindowToken nextApp = nextAppIndex >= 0
10557 ? mAppTokens.get(nextAppIndex) : null;
10558
10559 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010560 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561
Joe Onorato8a9b2202010-02-26 18:56:32 -080010562 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010563 TAG, "Looking for focus: " + i
10564 + " = " + win
10565 + ", flags=" + win.mAttrs.flags
10566 + ", canReceive=" + win.canReceiveKeys());
10567
10568 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010570 // If this window's application has been removed, just skip it.
10571 if (thisApp != null && thisApp.removed) {
10572 i--;
10573 continue;
10574 }
Romain Guy06882f82009-06-10 13:36:04 -070010575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010576 // If there is a focused app, don't allow focus to go to any
10577 // windows below it. If this is an application window, step
10578 // through the app tokens until we find its app.
10579 if (thisApp != null && nextApp != null && thisApp != nextApp
10580 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10581 int origAppIndex = nextAppIndex;
10582 while (nextAppIndex > 0) {
10583 if (nextApp == mFocusedApp) {
10584 // Whoops, we are below the focused app... no focus
10585 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010586 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010587 TAG, "Reached focused app: " + mFocusedApp);
10588 return null;
10589 }
10590 nextAppIndex--;
10591 nextApp = mAppTokens.get(nextAppIndex);
10592 if (nextApp == thisApp) {
10593 break;
10594 }
10595 }
10596 if (thisApp != nextApp) {
10597 // Uh oh, the app token doesn't exist! This shouldn't
10598 // happen, but if it does we can get totally hosed...
10599 // so restart at the original app.
10600 nextAppIndex = origAppIndex;
10601 nextApp = mAppTokens.get(nextAppIndex);
10602 }
10603 }
10604
10605 // Dispatch to this window if it is wants key events.
10606 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010607 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010608 TAG, "Found focus @ " + i + " = " + win);
10609 result = win;
10610 break;
10611 }
10612
10613 i--;
10614 }
10615
10616 return result;
10617 }
10618
10619 private void startFreezingDisplayLocked() {
10620 if (mDisplayFrozen) {
10621 return;
10622 }
Romain Guy06882f82009-06-10 13:36:04 -070010623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010624 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010627 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010628 if (mFreezeGcPending != 0) {
10629 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010630 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010631 mH.removeMessages(H.FORCE_GC);
10632 Runtime.getRuntime().gc();
10633 mFreezeGcPending = now;
10634 }
10635 } else {
10636 mFreezeGcPending = now;
10637 }
Romain Guy06882f82009-06-10 13:36:04 -070010638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010639 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010640
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010641 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010642
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010643 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10644 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010645 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010646 mAppTransitionReady = true;
10647 }
Romain Guy06882f82009-06-10 13:36:04 -070010648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010649 if (PROFILE_ORIENTATION) {
10650 File file = new File("/data/system/frozen");
10651 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10652 }
10653 Surface.freezeDisplay(0);
10654 }
Romain Guy06882f82009-06-10 13:36:04 -070010655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010656 private void stopFreezingDisplayLocked() {
10657 if (!mDisplayFrozen) {
10658 return;
10659 }
Romain Guy06882f82009-06-10 13:36:04 -070010660
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010661 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10662 return;
10663 }
10664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010665 mDisplayFrozen = false;
10666 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10667 if (PROFILE_ORIENTATION) {
10668 Debug.stopMethodTracing();
10669 }
10670 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010671
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010672 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010673
Christopher Tateb696aee2010-04-02 19:08:30 -070010674 // While the display is frozen we don't re-compute the orientation
10675 // to avoid inconsistent states. However, something interesting
10676 // could have actually changed during that time so re-evaluate it
10677 // now to catch that.
10678 if (updateOrientationFromAppTokensLocked()) {
10679 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10680 }
10681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010682 // A little kludge: a lot could have happened while the
10683 // display was frozen, so now that we are coming back we
10684 // do a gc so that any remote references the system
10685 // processes holds on others can be released if they are
10686 // no longer needed.
10687 mH.removeMessages(H.FORCE_GC);
10688 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10689 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010691 mScreenFrozenLock.release();
10692 }
Romain Guy06882f82009-06-10 13:36:04 -070010693
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010694 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10695 DisplayMetrics dm) {
10696 if (index < tokens.length) {
10697 String str = tokens[index];
10698 if (str != null && str.length() > 0) {
10699 try {
10700 int val = Integer.parseInt(str);
10701 return val;
10702 } catch (Exception e) {
10703 }
10704 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010705 }
10706 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10707 return defDps;
10708 }
10709 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10710 return val;
10711 }
10712
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010713 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010714 final String[] mTokens;
10715 final String mText;
10716 final Paint mTextPaint;
10717 final int mTextWidth;
10718 final int mTextHeight;
10719 final int mTextAscent;
10720 final int mTextDescent;
10721 final int mDeltaX;
10722 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010723
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010724 Surface mSurface;
10725 int mLastDW;
10726 int mLastDH;
10727 boolean mDrawNeeded;
10728
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010729 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010730 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010731 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010732
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010733 if (false) {
10734 Log.i(TAG, "*********************** WATERMARK");
10735 for (int i=0; i<tokens.length; i++) {
10736 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10737 }
10738 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010739
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010740 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010741
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010742 StringBuilder builder = new StringBuilder(32);
10743 int len = mTokens[0].length();
10744 len = len & ~1;
10745 for (int i=0; i<len; i+=2) {
10746 int c1 = mTokens[0].charAt(i);
10747 int c2 = mTokens[0].charAt(i+1);
10748 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10749 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10750 else c1 -= '0';
10751 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10752 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10753 else c2 -= '0';
10754 builder.append((char)(255-((c1*16)+c2)));
10755 }
10756 mText = builder.toString();
10757 if (false) {
10758 Log.i(TAG, "Final text: " + mText);
10759 }
10760
10761 int fontSize = getPropertyInt(tokens, 1,
10762 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10763
10764 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10765 mTextPaint.setTextSize(fontSize);
10766 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10767
10768 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10769 mTextWidth = (int)mTextPaint.measureText(mText);
10770 mTextAscent = fm.ascent;
10771 mTextDescent = fm.descent;
10772 mTextHeight = fm.descent - fm.ascent;
10773
10774 mDeltaX = getPropertyInt(tokens, 2,
10775 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10776 mDeltaY = getPropertyInt(tokens, 3,
10777 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10778 int shadowColor = getPropertyInt(tokens, 4,
10779 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10780 int color = getPropertyInt(tokens, 5,
10781 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10782 int shadowRadius = getPropertyInt(tokens, 6,
10783 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10784 int shadowDx = getPropertyInt(tokens, 8,
10785 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10786 int shadowDy = getPropertyInt(tokens, 9,
10787 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10788
10789 mTextPaint.setColor(color);
10790 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010791
10792 try {
10793 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010794 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010795 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010796 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010797 mSurface.show();
10798 } catch (OutOfResourcesException e) {
10799 }
10800 }
10801
10802 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010803 if (mLastDW != dw || mLastDH != dh) {
10804 mLastDW = dw;
10805 mLastDH = dh;
10806 mSurface.setSize(dw, dh);
10807 mDrawNeeded = true;
10808 }
10809 }
10810
10811 void drawIfNeeded() {
10812 if (mDrawNeeded) {
10813 final int dw = mLastDW;
10814 final int dh = mLastDH;
10815
10816 mDrawNeeded = false;
10817 Rect dirty = new Rect(0, 0, dw, dh);
10818 Canvas c = null;
10819 try {
10820 c = mSurface.lockCanvas(dirty);
10821 } catch (IllegalArgumentException e) {
10822 } catch (OutOfResourcesException e) {
10823 }
10824 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010825 c.drawColor(0, PorterDuff.Mode.CLEAR);
10826
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010827 int deltaX = mDeltaX;
10828 int deltaY = mDeltaY;
10829
10830 // deltaX shouldn't be close to a round fraction of our
10831 // x step, or else things will line up too much.
10832 int div = (dw+mTextWidth)/deltaX;
10833 int rem = (dw+mTextWidth) - (div*deltaX);
10834 int qdelta = deltaX/4;
10835 if (rem < qdelta || rem > (deltaX-qdelta)) {
10836 deltaX += deltaX/3;
10837 }
10838
10839 int y = -mTextHeight;
10840 int x = -mTextWidth;
10841 while (y < (dh+mTextHeight)) {
10842 c.drawText(mText, x, y, mTextPaint);
10843 x += deltaX;
10844 if (x >= dw) {
10845 x -= (dw+mTextWidth);
10846 y += deltaY;
10847 }
10848 }
10849 mSurface.unlockCanvasAndPost(c);
10850 }
10851 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010852 }
10853 }
10854
10855 void createWatermark() {
10856 if (mWatermark != null) {
10857 return;
10858 }
10859
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010860 File file = new File("/system/etc/setup.conf");
10861 FileInputStream in = null;
10862 try {
10863 in = new FileInputStream(file);
10864 DataInputStream ind = new DataInputStream(in);
10865 String line = ind.readLine();
10866 if (line != null) {
10867 String[] toks = line.split("%");
10868 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010869 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010870 }
10871 }
10872 } catch (FileNotFoundException e) {
10873 } catch (IOException e) {
10874 } finally {
10875 if (in != null) {
10876 try {
10877 in.close();
10878 } catch (IOException e) {
10879 }
10880 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010881 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010882 }
10883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 @Override
10885 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10886 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10887 != PackageManager.PERMISSION_GRANTED) {
10888 pw.println("Permission Denial: can't dump WindowManager from from pid="
10889 + Binder.getCallingPid()
10890 + ", uid=" + Binder.getCallingUid());
10891 return;
10892 }
Romain Guy06882f82009-06-10 13:36:04 -070010893
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010894 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010895 pw.println(" ");
10896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010897 synchronized(mWindowMap) {
10898 pw.println("Current Window Manager state:");
10899 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010900 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010901 pw.print(" Window #"); pw.print(i); pw.print(' ');
10902 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010903 w.dump(pw, " ");
10904 }
10905 if (mInputMethodDialogs.size() > 0) {
10906 pw.println(" ");
10907 pw.println(" Input method dialogs:");
10908 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10909 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010910 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010911 }
10912 }
10913 if (mPendingRemove.size() > 0) {
10914 pw.println(" ");
10915 pw.println(" Remove pending for:");
10916 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10917 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010918 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10919 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010920 w.dump(pw, " ");
10921 }
10922 }
10923 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10924 pw.println(" ");
10925 pw.println(" Windows force removing:");
10926 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10927 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010928 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10929 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010930 w.dump(pw, " ");
10931 }
10932 }
10933 if (mDestroySurface.size() > 0) {
10934 pw.println(" ");
10935 pw.println(" Windows waiting to destroy their surface:");
10936 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10937 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010938 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10939 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010940 w.dump(pw, " ");
10941 }
10942 }
10943 if (mLosingFocus.size() > 0) {
10944 pw.println(" ");
10945 pw.println(" Windows losing focus:");
10946 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10947 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010948 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10949 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010950 w.dump(pw, " ");
10951 }
10952 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010953 if (mResizingWindows.size() > 0) {
10954 pw.println(" ");
10955 pw.println(" Windows waiting to resize:");
10956 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10957 WindowState w = mResizingWindows.get(i);
10958 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10959 pw.print(w); pw.println(":");
10960 w.dump(pw, " ");
10961 }
10962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010963 if (mSessions.size() > 0) {
10964 pw.println(" ");
10965 pw.println(" All active sessions:");
10966 Iterator<Session> it = mSessions.iterator();
10967 while (it.hasNext()) {
10968 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010969 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010970 s.dump(pw, " ");
10971 }
10972 }
10973 if (mTokenMap.size() > 0) {
10974 pw.println(" ");
10975 pw.println(" All tokens:");
10976 Iterator<WindowToken> it = mTokenMap.values().iterator();
10977 while (it.hasNext()) {
10978 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010979 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 token.dump(pw, " ");
10981 }
10982 }
10983 if (mTokenList.size() > 0) {
10984 pw.println(" ");
10985 pw.println(" Window token list:");
10986 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010987 pw.print(" #"); pw.print(i); pw.print(": ");
10988 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010989 }
10990 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010991 if (mWallpaperTokens.size() > 0) {
10992 pw.println(" ");
10993 pw.println(" Wallpaper tokens:");
10994 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10995 WindowToken token = mWallpaperTokens.get(i);
10996 pw.print(" Wallpaper #"); pw.print(i);
10997 pw.print(' '); pw.print(token); pw.println(':');
10998 token.dump(pw, " ");
10999 }
11000 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011001 if (mAppTokens.size() > 0) {
11002 pw.println(" ");
11003 pw.println(" Application tokens in Z order:");
11004 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011005 pw.print(" App #"); pw.print(i); pw.print(": ");
11006 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 }
11008 }
11009 if (mFinishedStarting.size() > 0) {
11010 pw.println(" ");
11011 pw.println(" Finishing start of application tokens:");
11012 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11013 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011014 pw.print(" Finished Starting #"); pw.print(i);
11015 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011016 token.dump(pw, " ");
11017 }
11018 }
11019 if (mExitingTokens.size() > 0) {
11020 pw.println(" ");
11021 pw.println(" Exiting tokens:");
11022 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11023 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011024 pw.print(" Exiting #"); pw.print(i);
11025 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 token.dump(pw, " ");
11027 }
11028 }
11029 if (mExitingAppTokens.size() > 0) {
11030 pw.println(" ");
11031 pw.println(" Exiting application tokens:");
11032 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11033 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011034 pw.print(" Exiting App #"); pw.print(i);
11035 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011036 token.dump(pw, " ");
11037 }
11038 }
11039 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011040 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11041 pw.print(" mLastFocus="); pw.println(mLastFocus);
11042 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11043 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11044 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011045 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011046 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11047 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11048 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11049 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011050 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11051 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11052 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011053 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11054 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11055 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11056 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011057 if (mDimAnimator != null) {
11058 mDimAnimator.printTo(pw);
11059 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011060 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011061 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011062 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011063 pw.print(mInputMethodAnimLayerAdjustment);
11064 pw.print(" mWallpaperAnimLayerAdjustment=");
11065 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011066 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11067 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011068 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11069 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011070 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11071 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011072 pw.print(" mRotation="); pw.print(mRotation);
11073 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11074 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11075 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11076 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11077 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11078 pw.print(" mNextAppTransition=0x");
11079 pw.print(Integer.toHexString(mNextAppTransition));
11080 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011081 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011082 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011083 if (mNextAppTransitionPackage != null) {
11084 pw.print(" mNextAppTransitionPackage=");
11085 pw.print(mNextAppTransitionPackage);
11086 pw.print(", mNextAppTransitionEnter=0x");
11087 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11088 pw.print(", mNextAppTransitionExit=0x");
11089 pw.print(Integer.toHexString(mNextAppTransitionExit));
11090 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011091 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11092 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011093 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11094 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11095 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11096 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011097 if (mOpeningApps.size() > 0) {
11098 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11099 }
11100 if (mClosingApps.size() > 0) {
11101 pw.print(" mClosingApps="); pw.println(mClosingApps);
11102 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011103 if (mToTopApps.size() > 0) {
11104 pw.print(" mToTopApps="); pw.println(mToTopApps);
11105 }
11106 if (mToBottomApps.size() > 0) {
11107 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11108 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011109 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11110 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011111 }
11112 }
11113
Jeff Brown349703e2010-06-22 01:27:15 -070011114 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 public void monitor() {
11116 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011117 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011118 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011119
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011120 /**
11121 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011122 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011123 */
11124 private static class DimAnimator {
11125 Surface mDimSurface;
11126 boolean mDimShown = false;
11127 float mDimCurrentAlpha;
11128 float mDimTargetAlpha;
11129 float mDimDeltaPerMs;
11130 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011131
11132 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011133
11134 DimAnimator (SurfaceSession session) {
11135 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011136 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011137 + mDimSurface + ": CREATE");
11138 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011139 mDimSurface = new Surface(session, 0,
11140 "DimSurface",
11141 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011142 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011143 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011144 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011145 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011146 }
11147 }
11148 }
11149
11150 /**
11151 * Show the dim surface.
11152 */
11153 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011154 if (!mDimShown) {
11155 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11156 dw + "x" + dh + ")");
11157 mDimShown = true;
11158 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011159 mLastDimWidth = dw;
11160 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011161 mDimSurface.setPosition(0, 0);
11162 mDimSurface.setSize(dw, dh);
11163 mDimSurface.show();
11164 } catch (RuntimeException e) {
11165 Slog.w(TAG, "Failure showing dim surface", e);
11166 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011167 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11168 mLastDimWidth = dw;
11169 mLastDimHeight = dh;
11170 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011171 }
11172 }
11173
11174 /**
11175 * Set's the dim surface's layer and update dim parameters that will be used in
11176 * {@link updateSurface} after all windows are examined.
11177 */
11178 void updateParameters(WindowState w, long currentTime) {
11179 mDimSurface.setLayer(w.mAnimLayer-1);
11180
11181 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011182 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011183 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011184 if (mDimTargetAlpha != target) {
11185 // If the desired dim level has changed, then
11186 // start an animation to it.
11187 mLastDimAnimTime = currentTime;
11188 long duration = (w.mAnimating && w.mAnimation != null)
11189 ? w.mAnimation.computeDurationHint()
11190 : DEFAULT_DIM_DURATION;
11191 if (target > mDimTargetAlpha) {
11192 // This is happening behind the activity UI,
11193 // so we can make it run a little longer to
11194 // give a stronger impression without disrupting
11195 // the user.
11196 duration *= DIM_DURATION_MULTIPLIER;
11197 }
11198 if (duration < 1) {
11199 // Don't divide by zero
11200 duration = 1;
11201 }
11202 mDimTargetAlpha = target;
11203 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11204 }
11205 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011206
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011207 /**
11208 * Updating the surface's alpha. Returns true if the animation continues, or returns
11209 * false when the animation is finished and the dim surface is hidden.
11210 */
11211 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11212 if (!dimming) {
11213 if (mDimTargetAlpha != 0) {
11214 mLastDimAnimTime = currentTime;
11215 mDimTargetAlpha = 0;
11216 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11217 }
11218 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011219
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011220 boolean animating = false;
11221 if (mLastDimAnimTime != 0) {
11222 mDimCurrentAlpha += mDimDeltaPerMs
11223 * (currentTime-mLastDimAnimTime);
11224 boolean more = true;
11225 if (displayFrozen) {
11226 // If the display is frozen, there is no reason to animate.
11227 more = false;
11228 } else if (mDimDeltaPerMs > 0) {
11229 if (mDimCurrentAlpha > mDimTargetAlpha) {
11230 more = false;
11231 }
11232 } else if (mDimDeltaPerMs < 0) {
11233 if (mDimCurrentAlpha < mDimTargetAlpha) {
11234 more = false;
11235 }
11236 } else {
11237 more = false;
11238 }
11239
11240 // Do we need to continue animating?
11241 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011242 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011243 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11244 mLastDimAnimTime = currentTime;
11245 mDimSurface.setAlpha(mDimCurrentAlpha);
11246 animating = true;
11247 } else {
11248 mDimCurrentAlpha = mDimTargetAlpha;
11249 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011250 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011251 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11252 mDimSurface.setAlpha(mDimCurrentAlpha);
11253 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011254 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011255 + ": HIDE");
11256 try {
11257 mDimSurface.hide();
11258 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011259 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011260 }
11261 mDimShown = false;
11262 }
11263 }
11264 }
11265 return animating;
11266 }
11267
11268 public void printTo(PrintWriter pw) {
11269 pw.print(" mDimShown="); pw.print(mDimShown);
11270 pw.print(" current="); pw.print(mDimCurrentAlpha);
11271 pw.print(" target="); pw.print(mDimTargetAlpha);
11272 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11273 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11274 }
11275 }
11276
11277 /**
11278 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11279 * This is used for opening/closing transition for apps in compatible mode.
11280 */
11281 private static class FadeInOutAnimation extends Animation {
11282 int mWidth;
11283 boolean mFadeIn;
11284
11285 public FadeInOutAnimation(boolean fadeIn) {
11286 setInterpolator(new AccelerateInterpolator());
11287 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11288 mFadeIn = fadeIn;
11289 }
11290
11291 @Override
11292 protected void applyTransformation(float interpolatedTime, Transformation t) {
11293 float x = interpolatedTime;
11294 if (!mFadeIn) {
11295 x = 1.0f - x; // reverse the interpolation for fade out
11296 }
11297 if (x < 0.5) {
11298 // move the window out of the screen.
11299 t.getMatrix().setTranslate(mWidth, 0);
11300 } else {
11301 t.getMatrix().setTranslate(0, 0);// show
11302 t.setAlpha((x - 0.5f) * 2);
11303 }
11304 }
11305
11306 @Override
11307 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11308 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11309 mWidth = width;
11310 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011311
11312 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011313 public int getZAdjustment() {
11314 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011315 }
11316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011317}