blob: def36de4f22bfd55c7fe761950e5f86a2009a1fd [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;
68import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
88import android.os.SystemClock;
89import android.os.SystemProperties;
90import android.os.TokenWatcher;
91import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070092import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070094import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080095import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070097import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -070099import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700101import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700163 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_APP_TRANSITIONS = false;
165 static final boolean DEBUG_STARTING_WINDOW = false;
166 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700167 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700168 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700170 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 static final boolean PROFILE_ORIENTATION = false;
173 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700174 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to multiply the policy's type layer, to reserve room
177 * for multiple windows of the same type and Z-ordering adjustment
178 * with TYPE_LAYER_OFFSET. */
179 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
182 * or below others in the same layer. */
183 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /** How much to increment the layer for each window, to reserve room
186 * for effect surfaces between them.
187 */
188 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /** The maximum length we will accept for a loaded animation duration:
191 * this is 10 seconds.
192 */
193 static final int MAX_ANIMATION_DURATION = 10*1000;
194
195 /** Amount of time (in milliseconds) to animate the dim surface from one
196 * value to another, when no window animation is driving it.
197 */
198 static final int DEFAULT_DIM_DURATION = 200;
199
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700200 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
201 * compatible windows.
202 */
203 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /** Adjustment to time to perform a dim, to make it more dramatic.
206 */
207 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700208
209 // Maximum number of milliseconds to wait for input event injection.
210 // FIXME is this value reasonable?
211 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700212
213 // Default input dispatching timeout in nanoseconds.
214 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 static final int UPDATE_FOCUS_NORMAL = 0;
217 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
218 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
219 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700222 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 /**
225 * Condition waited on by {@link #reenableKeyguard} to know the call to
226 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500227 * This is set to true only if mKeyguardTokenWatcher.acquired() has
228 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
Jim Miller284b62e2010-06-08 14:27:42 -0700232 private static final int ALLOW_DISABLE_YES = 1;
233 private static final int ALLOW_DISABLE_NO = 0;
234 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
235 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
236
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
238 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700240 if (shouldAllowDisableKeyguard()) {
241 mPolicy.enableKeyguard(false);
242 mKeyguardDisabled = true;
243 } else {
244 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 }
247 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700248 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500249 synchronized (mKeyguardTokenWatcher) {
250 mKeyguardDisabled = false;
251 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253 }
254 };
255
Jim Miller284b62e2010-06-08 14:27:42 -0700256 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 mPolicy.enableKeyguard(true);
260 synchronized(mKeyguardTokenWatcher) {
261 // lazily evaluate this next time we're asked to disable keyguard
262 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
263 mKeyguardDisabled = false;
264 }
265 }
266 };
267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 final Context mContext;
269
270 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
275
276 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * All currently active sessions with clients.
282 */
283 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Mapping from an IWindow IBinder to the server's Window object.
287 * This is also used as the lock for all of our state.
288 */
289 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
290
291 /**
292 * Mapping from a token IBinder to a WindowToken object.
293 */
294 final HashMap<IBinder, WindowToken> mTokenMap =
295 new HashMap<IBinder, WindowToken>();
296
297 /**
298 * The same tokens as mTokenMap, stored in a list for efficient iteration
299 * over them.
300 */
301 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * Window tokens that are in the process of exiting, but still
305 * on screen for animations.
306 */
307 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
308
309 /**
310 * Z-ordered (bottom-most first) list of all application tokens, for
311 * controlling the ordering of windows in different applications. This
312 * contains WindowToken objects.
313 */
314 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
315
316 /**
317 * Application tokens that are in the process of exiting, but still
318 * on screen for animations.
319 */
320 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
321
322 /**
323 * List of window tokens that have finished starting their application,
324 * and now need to have the policy remove their windows.
325 */
326 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
327
328 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700329 * This was the app token that was used to retrieve the last enter
330 * animation. It will be used for the next exit animation.
331 */
332 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800333
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700334 /**
335 * These were the layout params used to retrieve the last enter animation.
336 * They will be used for the next exit animation.
337 */
338 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800339
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700340 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * Z-ordered (bottom-most first) list of all Window objects.
342 */
Jeff Browne33348b2010-07-15 23:54:05 -0700343 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 /**
346 * Windows that are being resized. Used so we can tell the client about
347 * the resize after closing the transaction in which we resized the
348 * underlying surface.
349 */
350 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
351
352 /**
353 * Windows whose animations have ended and now must be removed.
354 */
355 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
356
357 /**
358 * Windows whose surface should be destroyed.
359 */
360 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
361
362 /**
363 * Windows that have lost input focus and are waiting for the new
364 * focus window to be displayed before they are told about this.
365 */
366 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
367
368 /**
369 * This is set when we have run out of memory, and will either be an empty
370 * list or contain windows that need to be force removed.
371 */
372 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 final float[] mTmpFloats = new float[9];
385
386 boolean mSafeMode;
387 boolean mDisplayEnabled = false;
388 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700389 int mInitialDisplayWidth = 0;
390 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 int mRotation = 0;
392 int mRequestedRotation = 0;
393 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700394 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 ArrayList<IRotationWatcher> mRotationWatchers
396 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 boolean mLayoutNeeded = true;
399 boolean mAnimationPending = false;
400 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800401 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mWindowsFreezingScreen = false;
403 long mFreezeGcPending = 0;
404 int mAppsFreezingScreen = 0;
405
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 int mLayoutSeq = 0;
407
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800408 // State while inside of layoutAndPlaceSurfacesLocked().
409 boolean mFocusMayChange;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 Configuration mCurConfiguration = new Configuration();
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This is held as long as we have the screen frozen, to give us time to
414 // perform a rotation animation when turning off shows the lock screen which
415 // changes the orientation.
416 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // State management of app transitions. When we are preparing for a
419 // transition, mNextAppTransition will be the kind of transition to
420 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
421 // mOpeningApps and mClosingApps are the lists of tokens that will be
422 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700423 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700424 String mNextAppTransitionPackage;
425 int mNextAppTransitionEnter;
426 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700428 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionTimeout = false;
430 boolean mStartingIconInTransition = false;
431 boolean mSkipAppTransitionAnimation = false;
432 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700434 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 H mH = new H();
440
441 WindowState mCurrentFocus = null;
442 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 // This just indicates the window the input method is on top of, not
445 // necessarily the window its input is going to.
446 WindowState mInputMethodTarget = null;
447 WindowState mUpcomingInputMethodTarget = null;
448 boolean mInputMethodTargetWaitingAnim;
449 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 WindowState mInputMethodWindow = null;
452 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
453
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700454 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800455
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 // If non-null, this is the currently visible window that is associated
457 // with the wallpaper.
458 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the lower one in Z-order.
461 WindowState mLowerWallpaperTarget = null;
462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the higher one in Z-order.
464 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700465 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700466 float mLastWallpaperX = -1;
467 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800468 float mLastWallpaperXStep = -1;
469 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700470 // This is set when we are waiting for a wallpaper to tell us it is done
471 // changing its scroll position.
472 WindowState mWaitingOnWallpaper;
473 // The last time we had a timeout when waiting for a wallpaper.
474 long mLastWallpaperTimeoutTime;
475 // We give a wallpaper up to 150ms to finish scrolling.
476 static final long WALLPAPER_TIMEOUT = 150;
477 // Time we wait after a timeout before trying to wait again.
478 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 AppWindowToken mFocusedApp = null;
481
482 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 float mWindowAnimationScale = 1.0f;
485 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700486
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488
489 // Who is holding the screen on.
490 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700491 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700493 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700496 * Drag/drop state
497 */
498 class DragState {
499 IBinder mToken;
500 Surface mSurface;
501 boolean mLocalOnly;
502 ClipData mData;
503 ClipDescription mDataDescription;
504 float mThumbOffsetX, mThumbOffsetY;
505 InputChannel mServerChannel, mClientChannel;
506 WindowState mTargetWindow;
507 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700508 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509
510 private final Rect tmpRect = new Rect();
511
512 DragState(IBinder token, Surface surface, boolean localOnly) {
513 mToken = token;
514 mSurface = surface;
515 mLocalOnly = localOnly;
516 mNotifiedWindows = new ArrayList<WindowState>();
517 }
518
519 void reset() {
520 if (mSurface != null) {
521 mSurface.destroy();
522 }
523 mSurface = null;
524 mLocalOnly = false;
525 mToken = null;
526 mData = null;
527 mThumbOffsetX = mThumbOffsetY = 0;
528 mNotifiedWindows = null;
529 }
530
531 void register() {
532 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
533 if (mClientChannel != null) {
534 Slog.e(TAG, "Duplicate register of drag input channel");
535 } else {
536 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
537 mServerChannel = channels[0];
538 mClientChannel = channels[1];
539 mInputManager.registerInputChannel(mServerChannel);
540 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
541 mH.getLooper().getQueue());
542 }
543 }
544
545 void unregister() {
546 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
547 if (mClientChannel == null) {
548 Slog.e(TAG, "Unregister of nonexistent drag input channel");
549 } else {
550 mInputManager.unregisterInputChannel(mServerChannel);
551 InputQueue.unregisterInputChannel(mClientChannel);
552 mClientChannel.dispose();
553 mClientChannel = null;
554 mServerChannel = null;
555 }
556 }
557
Chris Tatea32dcf72010-10-14 12:13:50 -0700558 int getDragLayerLw() {
559 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
560 * TYPE_LAYER_MULTIPLIER
561 + TYPE_LAYER_OFFSET;
562 }
563
Christopher Tatea53146c2010-09-07 11:57:52 -0700564 /* call out to each visible window/session informing it about the drag
565 */
Chris Tateb8203e92010-10-12 14:23:21 -0700566 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 // Cache a base-class instance of the clip metadata so that parceling
568 // works correctly in calling out to the apps.
569 mDataDescription = new ClipDescription(mData);
570 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700571 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700572
Chris Tateb8203e92010-10-12 14:23:21 -0700573 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, touchX, touchY,
574 mDataDescription, null);
575
Christopher Tatea53146c2010-09-07 11:57:52 -0700576 if (DEBUG_DRAG) {
Chris Tateb8203e92010-10-12 14:23:21 -0700577 Slog.d(TAG, "broadcasting DRAG_STARTED: " + evt);
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 }
579
Christopher Tate2c095f32010-10-04 14:13:40 -0700580 final int N = mWindows.size();
581 for (int i = 0; i < N; i++) {
582 // sendDragStartedLw() clones evt for local-process dispatch
583 sendDragStartedLw(mWindows.get(i), evt);
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 }
585 evt.recycle();
586 }
587
588 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
589 * designated window is potentially a drop recipient. There are race situations
590 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
591 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700592 *
593 * This method clones the 'event' parameter if it's being delivered to the same
594 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700595 */
Christopher Tate2c095f32010-10-04 14:13:40 -0700596 private void sendDragStartedLw(WindowState newWin, DragEvent event) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700597 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 try {
Christopher Tate2c095f32010-10-04 14:13:40 -0700599 // clone for local callees since dispatch will recycle the event
600 if (Process.myPid() == newWin.mSession.mPid) {
601 event = DragEvent.obtain(event);
602 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700603 newWin.mClient.dispatchDragEvent(event);
604 // track each window that we've notified that the drag is starting
605 mNotifiedWindows.add(newWin);
606 } catch (RemoteException e) {
607 Slog.w(TAG, "Unable to drag-start window " + newWin);
608 }
609 }
610 }
611
612 /* helper - construct and send a DRAG_STARTED event only if the window has not
613 * previously been notified, i.e. it became visible after the drag operation
614 * was begun. This is a rare case.
615 */
616 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700617 if (mDragInProgress) {
618 // If we have sent the drag-started, we needn't do so again
619 for (WindowState ws : mNotifiedWindows) {
620 if (ws == newWin) {
621 return;
622 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700623 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700624 if (DEBUG_DRAG) {
625 Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin);
626 }
627 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0,
628 mDataDescription, null);
629 // sendDragStartedLw() clones 'event' if the window is process-local
630 sendDragStartedLw(newWin, event);
631 event.recycle();
Christopher Tatea53146c2010-09-07 11:57:52 -0700632 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700633 }
634
635 void broadcastDragEnded() {
636 if (DEBUG_DRAG) {
637 Slog.d(TAG, "broadcasting DRAG_ENDED");
638 }
639 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null);
640 synchronized (mWindowMap) {
641 for (WindowState ws: mNotifiedWindows) {
642 try {
643 ws.mClient.dispatchDragEvent(evt);
644 } catch (RemoteException e) {
645 Slog.w(TAG, "Unable to drag-end window " + ws);
646 }
647 }
648 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700649 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700650 }
651 evt.recycle();
652 }
653
654 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700655 final int myPid = Process.myPid();
656
657 // Move the surface to the given touch
658 mSurface.openTransaction();
659 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
660 mSurface.closeTransaction();
661
662 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
664 try {
665 // have we dragged over a new window?
666 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
667 if (DEBUG_DRAG) {
668 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
669 }
670 // force DRAG_EXITED_EVENT if appropriate
671 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
672 0, 0, null, null);
673 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700674 if (myPid != mTargetWindow.mSession.mPid) {
675 evt.recycle();
676 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700677 }
678 if (touchedWin != null) {
679 if (DEBUG_DRAG) {
680 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
681 }
682 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
683 x, y, null, null);
684 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700685 if (myPid != touchedWin.mSession.mPid) {
686 evt.recycle();
687 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700688 }
689 } catch (RemoteException e) {
690 Slog.w(TAG, "can't send drag notification to windows");
691 }
692 mTargetWindow = touchedWin;
693 }
694
695 // Tell the drop target about the data, and then broadcast the drag-ended notification
696 void notifyDropLw(float x, float y) {
697 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
698 if (touchedWin != null) {
699 if (DEBUG_DRAG) {
700 Slog.d(TAG, "sending DROP to " + touchedWin);
701 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700702 final int myPid = Process.myPid();
Christopher Tatea53146c2010-09-07 11:57:52 -0700703 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, x, y, null, mData);
704 try {
705 touchedWin.mClient.dispatchDragEvent(evt);
706 } catch (RemoteException e) {
707 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
708 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700709 if (myPid != touchedWin.mSession.mPid) {
710 evt.recycle();
711 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700712 }
713 }
714
715 // Find the visible, touch-deliverable window under the given point
716 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
717 WindowState touchedWin = null;
718 final int x = (int) xf;
719 final int y = (int) yf;
720 final ArrayList<WindowState> windows = mWindows;
721 final int N = windows.size();
722 for (int i = N - 1; i >= 0; i--) {
723 WindowState child = windows.get(i);
724 final int flags = child.mAttrs.flags;
725 if (!child.isVisibleLw()) {
726 // not visible == don't tell about drags
727 continue;
728 }
729 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
730 // not touchable == don't tell about drags
731 continue;
732 }
733 // account for the window's decor etc
734 tmpRect.set(child.mFrame);
735 if (child.mTouchableInsets == ViewTreeObserver
736 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
737 // The point is inside of the window if it is
738 // inside the frame, AND the content part of that
739 // frame that was given by the application.
740 tmpRect.left += child.mGivenContentInsets.left;
741 tmpRect.top += child.mGivenContentInsets.top;
742 tmpRect.right -= child.mGivenContentInsets.right;
743 tmpRect.bottom -= child.mGivenContentInsets.bottom;
744 } else if (child.mTouchableInsets == ViewTreeObserver
745 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
746 // The point is inside of the window if it is
747 // inside the frame, AND the visible part of that
748 // frame that was given by the application.
749 tmpRect.left += child.mGivenVisibleInsets.left;
750 tmpRect.top += child.mGivenVisibleInsets.top;
751 tmpRect.right -= child.mGivenVisibleInsets.right;
752 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
753 }
754 final int touchFlags = flags &
755 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
756 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
757 if (tmpRect.contains(x, y) || touchFlags == 0) {
758 // Found it
759 touchedWin = child;
760 break;
761 }
762 }
763
764 return touchedWin;
765 }
766 }
767
768 DragState mDragState = null;
769 private final InputHandler mDragInputHandler = new BaseInputHandler() {
770 @Override
771 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
772 boolean endDrag = false;
773 final float newX = event.getRawX();
774 final float newY = event.getRawY();
775
776 try {
777 if (mDragState != null) {
778 switch (event.getAction()) {
779 case MotionEvent.ACTION_DOWN: {
780 if (DEBUG_DRAG) {
781 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
782 }
783 } break;
784
785 case MotionEvent.ACTION_MOVE: {
786 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700787 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700788 mDragState.notifyMoveLw(newX, newY);
789 }
790 } break;
791
792 case MotionEvent.ACTION_UP: {
793 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
794 + newX + "," + newY);
795 synchronized (mWindowMap) {
796 mDragState.notifyDropLw(newX, newY);
797 }
798 endDrag = true;
799 } break;
800
801 case MotionEvent.ACTION_CANCEL: {
802 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
803 endDrag = true;
804 } break;
805 }
806
807 if (endDrag) {
808 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
809 // tell all the windows that the drag has ended
810 mDragState.broadcastDragEnded();
811
812 // stop intercepting input
813 mDragState.unregister();
Chris Tate59943592010-10-11 20:33:44 -0700814 synchronized (mWindowMap) {
815 mInputMonitor.updateInputWindowsLw();
816 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700817
818 // free our resources and drop all the object references
819 mDragState.reset();
820 mDragState = null;
821 }
822 }
823 } catch (Exception e) {
824 Slog.e(TAG, "Exception caught by drag handleMotion", e);
825 } finally {
826 finishedCallback.run();
827 }
828 }
829 };
830
831 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 * Whether the UI is currently running in touch mode (not showing
833 * navigational focus because the user is directly pressing the screen).
834 */
835 boolean mInTouchMode = false;
836
837 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700838 private ArrayList<WindowChangeListener> mWindowChangeListeners =
839 new ArrayList<WindowChangeListener>();
840 private boolean mWindowsChanged = false;
841
842 public interface WindowChangeListener {
843 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700844 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846
Dianne Hackbornc485a602009-03-24 22:39:49 -0700847 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700848 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700849
850 // The frame use to limit the size of the app running in compatibility mode.
851 Rect mCompatibleScreenFrame = new Rect();
852 // The surface used to fill the outer rim of the app running in compatibility mode.
853 Surface mBackgroundFillerSurface = null;
854 boolean mBackgroundFillerShown = false;
855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 public static WindowManagerService main(Context context,
857 PowerManagerService pm, boolean haveInputMethods) {
858 WMThread thr = new WMThread(context, pm, haveInputMethods);
859 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 synchronized (thr) {
862 while (thr.mService == null) {
863 try {
864 thr.wait();
865 } catch (InterruptedException e) {
866 }
867 }
868 }
Romain Guy06882f82009-06-10 13:36:04 -0700869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 return thr.mService;
871 }
Romain Guy06882f82009-06-10 13:36:04 -0700872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 static class WMThread extends Thread {
874 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 private final Context mContext;
877 private final PowerManagerService mPM;
878 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 public WMThread(Context context, PowerManagerService pm,
881 boolean haveInputMethods) {
882 super("WindowManager");
883 mContext = context;
884 mPM = pm;
885 mHaveInputMethods = haveInputMethods;
886 }
Romain Guy06882f82009-06-10 13:36:04 -0700887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 public void run() {
889 Looper.prepare();
890 WindowManagerService s = new WindowManagerService(mContext, mPM,
891 mHaveInputMethods);
892 android.os.Process.setThreadPriority(
893 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700894 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 synchronized (this) {
897 mService = s;
898 notifyAll();
899 }
Romain Guy06882f82009-06-10 13:36:04 -0700900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 Looper.loop();
902 }
903 }
904
905 static class PolicyThread extends Thread {
906 private final WindowManagerPolicy mPolicy;
907 private final WindowManagerService mService;
908 private final Context mContext;
909 private final PowerManagerService mPM;
910 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 public PolicyThread(WindowManagerPolicy policy,
913 WindowManagerService service, Context context,
914 PowerManagerService pm) {
915 super("WindowManagerPolicy");
916 mPolicy = policy;
917 mService = service;
918 mContext = context;
919 mPM = pm;
920 }
Romain Guy06882f82009-06-10 13:36:04 -0700921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 public void run() {
923 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800924 WindowManagerPolicyThread.set(this, Looper.myLooper());
925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800927 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 android.os.Process.setThreadPriority(
929 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700930 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 synchronized (this) {
934 mRunning = true;
935 notifyAll();
936 }
Romain Guy06882f82009-06-10 13:36:04 -0700937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 Looper.loop();
939 }
940 }
941
942 private WindowManagerService(Context context, PowerManagerService pm,
943 boolean haveInputMethods) {
944 mContext = context;
945 mHaveInputMethods = haveInputMethods;
946 mLimitedAlphaCompositing = context.getResources().getBoolean(
947 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 mPowerManager = pm;
950 mPowerManager.setPolicy(mPolicy);
951 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
952 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
953 "SCREEN_FROZEN");
954 mScreenFrozenLock.setReferenceCounted(false);
955
956 mActivityManager = ActivityManagerNative.getDefault();
957 mBatteryStats = BatteryStatsService.getService();
958
959 // Get persisted window scale setting
960 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
961 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
962 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
963 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700964
Jim Miller284b62e2010-06-08 14:27:42 -0700965 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
966 IntentFilter filter = new IntentFilter();
967 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
968 mContext.registerReceiver(mBroadcastReceiver, filter);
969
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700970 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
971 "KEEP_SCREEN_ON_FLAG");
972 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973
Jeff Browne33348b2010-07-15 23:54:05 -0700974 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
977 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 synchronized (thr) {
980 while (!thr.mRunning) {
981 try {
982 thr.wait();
983 } catch (InterruptedException e) {
984 }
985 }
986 }
Romain Guy06882f82009-06-10 13:36:04 -0700987
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700988 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 // Add ourself to the Watchdog monitors.
991 Watchdog.getInstance().addMonitor(this);
992 }
993
994 @Override
995 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
996 throws RemoteException {
997 try {
998 return super.onTransact(code, data, reply, flags);
999 } catch (RuntimeException e) {
1000 // The window manager only throws security exceptions, so let's
1001 // log all others.
1002 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001003 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 }
1005 throw e;
1006 }
1007 }
1008
Jeff Browne33348b2010-07-15 23:54:05 -07001009 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001011 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 TAG, "Adding window " + window + " at "
1013 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1014 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001015 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 }
1017
Jeff Browne33348b2010-07-15 23:54:05 -07001018 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001020 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 TAG, "Adding window " + window + " at "
1022 + i + " of " + mWindows.size() + " (before " + pos + ")");
1023 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001024 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 }
1026
1027 //This method finds out the index of a window that has the same app token as
1028 //win. used for z ordering the windows in mWindows
1029 private int findIdxBasedOnAppTokens(WindowState win) {
1030 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001031 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 int jmax = localmWindows.size();
1033 if(jmax == 0) {
1034 return -1;
1035 }
1036 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001037 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 if(wentry.mAppToken == win.mAppToken) {
1039 return j;
1040 }
1041 }
1042 return -1;
1043 }
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1046 final IWindow client = win.mClient;
1047 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001048 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 final int N = localmWindows.size();
1051 final WindowState attached = win.mAttachedWindow;
1052 int i;
1053 if (attached == null) {
1054 int tokenWindowsPos = token.windows.size();
1055 if (token.appWindowToken != null) {
1056 int index = tokenWindowsPos-1;
1057 if (index >= 0) {
1058 // If this application has existing windows, we
1059 // simply place the new window on top of them... but
1060 // keep the starting window on top.
1061 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1062 // Base windows go behind everything else.
1063 placeWindowBefore(token.windows.get(0), win);
1064 tokenWindowsPos = 0;
1065 } else {
1066 AppWindowToken atoken = win.mAppToken;
1067 if (atoken != null &&
1068 token.windows.get(index) == atoken.startingWindow) {
1069 placeWindowBefore(token.windows.get(index), win);
1070 tokenWindowsPos--;
1071 } else {
1072 int newIdx = findIdxBasedOnAppTokens(win);
1073 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001074 //there is a window above this one associated with the same
1075 //apptoken note that the window could be a floating window
1076 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001078 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001079 TAG, "Adding window " + win + " at "
1080 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001082 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 }
1085 }
1086 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001087 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 TAG, "Figuring out where to add app window "
1089 + client.asBinder() + " (token=" + token + ")");
1090 // Figure out where the window should go, based on the
1091 // order of applications.
1092 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001093 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 for (i=NA-1; i>=0; i--) {
1095 AppWindowToken t = mAppTokens.get(i);
1096 if (t == token) {
1097 i--;
1098 break;
1099 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001100
Dianne Hackborna8f60182009-09-01 19:01:50 -07001101 // We haven't reached the token yet; if this token
1102 // is not going to the bottom and has windows, we can
1103 // use it as an anchor for when we do reach the token.
1104 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 pos = t.windows.get(0);
1106 }
1107 }
1108 // We now know the index into the apps. If we found
1109 // an app window above, that gives us the position; else
1110 // we need to look some more.
1111 if (pos != null) {
1112 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001113 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 if (atoken != null) {
1115 final int NC = atoken.windows.size();
1116 if (NC > 0) {
1117 WindowState bottom = atoken.windows.get(0);
1118 if (bottom.mSubLayer < 0) {
1119 pos = bottom;
1120 }
1121 }
1122 }
1123 placeWindowBefore(pos, win);
1124 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001125 // Continue looking down until we find the first
1126 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 while (i >= 0) {
1128 AppWindowToken t = mAppTokens.get(i);
1129 final int NW = t.windows.size();
1130 if (NW > 0) {
1131 pos = t.windows.get(NW-1);
1132 break;
1133 }
1134 i--;
1135 }
1136 if (pos != null) {
1137 // Move in front of any windows attached to this
1138 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001139 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 if (atoken != null) {
1141 final int NC = atoken.windows.size();
1142 if (NC > 0) {
1143 WindowState top = atoken.windows.get(NC-1);
1144 if (top.mSubLayer >= 0) {
1145 pos = top;
1146 }
1147 }
1148 }
1149 placeWindowAfter(pos, win);
1150 } else {
1151 // Just search for the start of this layer.
1152 final int myLayer = win.mBaseLayer;
1153 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001154 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 if (w.mBaseLayer > myLayer) {
1156 break;
1157 }
1158 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001159 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001160 TAG, "Adding window " + win + " at "
1161 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001163 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 }
1165 }
1166 }
1167 } else {
1168 // Figure out where window should go, based on layer.
1169 final int myLayer = win.mBaseLayer;
1170 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001171 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 i++;
1173 break;
1174 }
1175 }
1176 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001177 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001178 TAG, "Adding window " + win + " at "
1179 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001181 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 }
1183 if (addToToken) {
1184 token.windows.add(tokenWindowsPos, win);
1185 }
1186
1187 } else {
1188 // Figure out this window's ordering relative to the window
1189 // it is attached to.
1190 final int NA = token.windows.size();
1191 final int sublayer = win.mSubLayer;
1192 int largestSublayer = Integer.MIN_VALUE;
1193 WindowState windowWithLargestSublayer = null;
1194 for (i=0; i<NA; i++) {
1195 WindowState w = token.windows.get(i);
1196 final int wSublayer = w.mSubLayer;
1197 if (wSublayer >= largestSublayer) {
1198 largestSublayer = wSublayer;
1199 windowWithLargestSublayer = w;
1200 }
1201 if (sublayer < 0) {
1202 // For negative sublayers, we go below all windows
1203 // in the same sublayer.
1204 if (wSublayer >= sublayer) {
1205 if (addToToken) {
1206 token.windows.add(i, win);
1207 }
1208 placeWindowBefore(
1209 wSublayer >= 0 ? attached : w, win);
1210 break;
1211 }
1212 } else {
1213 // For positive sublayers, we go above all windows
1214 // in the same sublayer.
1215 if (wSublayer > sublayer) {
1216 if (addToToken) {
1217 token.windows.add(i, win);
1218 }
1219 placeWindowBefore(w, win);
1220 break;
1221 }
1222 }
1223 }
1224 if (i >= NA) {
1225 if (addToToken) {
1226 token.windows.add(win);
1227 }
1228 if (sublayer < 0) {
1229 placeWindowBefore(attached, win);
1230 } else {
1231 placeWindowAfter(largestSublayer >= 0
1232 ? windowWithLargestSublayer
1233 : attached,
1234 win);
1235 }
1236 }
1237 }
Romain Guy06882f82009-06-10 13:36:04 -07001238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 if (win.mAppToken != null && addToToken) {
1240 win.mAppToken.allAppWindows.add(win);
1241 }
1242 }
Romain Guy06882f82009-06-10 13:36:04 -07001243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 static boolean canBeImeTarget(WindowState w) {
1245 final int fl = w.mAttrs.flags
1246 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1247 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1248 return w.isVisibleOrAdding();
1249 }
1250 return false;
1251 }
Romain Guy06882f82009-06-10 13:36:04 -07001252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001254 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 final int N = localmWindows.size();
1256 WindowState w = null;
1257 int i = N;
1258 while (i > 0) {
1259 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001260 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001261
Joe Onorato8a9b2202010-02-26 18:56:32 -08001262 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 // + Integer.toHexString(w.mAttrs.flags));
1264 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001265 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 // Yet more tricksyness! If this window is a "starting"
1268 // window, we do actually want to be on top of it, but
1269 // it is not -really- where input will go. So if the caller
1270 // is not actually looking to move the IME, look down below
1271 // for a real window to target...
1272 if (!willMove
1273 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1274 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001275 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1277 i--;
1278 w = wb;
1279 }
1280 }
1281 break;
1282 }
1283 }
Romain Guy06882f82009-06-10 13:36:04 -07001284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001286
Joe Onorato8a9b2202010-02-26 18:56:32 -08001287 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 if (willMove && w != null) {
1291 final WindowState curTarget = mInputMethodTarget;
1292 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 // Now some fun for dealing with window animations that
1295 // modify the Z order. We need to look at all windows below
1296 // the current target that are in this app, finding the highest
1297 // visible one in layering.
1298 AppWindowToken token = curTarget.mAppToken;
1299 WindowState highestTarget = null;
1300 int highestPos = 0;
1301 if (token.animating || token.animation != null) {
1302 int pos = 0;
1303 pos = localmWindows.indexOf(curTarget);
1304 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001305 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 if (win.mAppToken != token) {
1307 break;
1308 }
1309 if (!win.mRemoved) {
1310 if (highestTarget == null || win.mAnimLayer >
1311 highestTarget.mAnimLayer) {
1312 highestTarget = win;
1313 highestPos = pos;
1314 }
1315 }
1316 pos--;
1317 }
1318 }
Romain Guy06882f82009-06-10 13:36:04 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001321 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 + mNextAppTransition + " " + highestTarget
1323 + " animating=" + highestTarget.isAnimating()
1324 + " layer=" + highestTarget.mAnimLayer
1325 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001326
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001327 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 // If we are currently setting up for an animation,
1329 // hold everything until we can find out what will happen.
1330 mInputMethodTargetWaitingAnim = true;
1331 mInputMethodTarget = highestTarget;
1332 return highestPos + 1;
1333 } else if (highestTarget.isAnimating() &&
1334 highestTarget.mAnimLayer > w.mAnimLayer) {
1335 // If the window we are currently targeting is involved
1336 // with an animation, and it is on top of the next target
1337 // we will be over, then hold off on moving until
1338 // that is done.
1339 mInputMethodTarget = highestTarget;
1340 return highestPos + 1;
1341 }
1342 }
1343 }
1344 }
Romain Guy06882f82009-06-10 13:36:04 -07001345
Joe Onorato8a9b2202010-02-26 18:56:32 -08001346 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 if (w != null) {
1348 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001349 if (DEBUG_INPUT_METHOD) {
1350 RuntimeException e = null;
1351 if (!HIDE_STACK_CRAWLS) {
1352 e = new RuntimeException();
1353 e.fillInStackTrace();
1354 }
1355 Slog.w(TAG, "Moving IM target from "
1356 + mInputMethodTarget + " to " + w, e);
1357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 mInputMethodTarget = w;
1359 if (w.mAppToken != null) {
1360 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1361 } else {
1362 setInputMethodAnimLayerAdjustment(0);
1363 }
1364 }
1365 return i+1;
1366 }
1367 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001368 if (DEBUG_INPUT_METHOD) {
1369 RuntimeException e = null;
1370 if (!HIDE_STACK_CRAWLS) {
1371 e = new RuntimeException();
1372 e.fillInStackTrace();
1373 }
1374 Slog.w(TAG, "Moving IM target from "
1375 + mInputMethodTarget + " to null", e);
1376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 mInputMethodTarget = null;
1378 setInputMethodAnimLayerAdjustment(0);
1379 }
1380 return -1;
1381 }
Romain Guy06882f82009-06-10 13:36:04 -07001382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 void addInputMethodWindowToListLocked(WindowState win) {
1384 int pos = findDesiredInputMethodWindowIndexLocked(true);
1385 if (pos >= 0) {
1386 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001387 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001388 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001390 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 moveInputMethodDialogsLocked(pos+1);
1392 return;
1393 }
1394 win.mTargetAppToken = null;
1395 addWindowToListInOrderLocked(win, true);
1396 moveInputMethodDialogsLocked(pos);
1397 }
Romain Guy06882f82009-06-10 13:36:04 -07001398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001400 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 mInputMethodAnimLayerAdjustment = adj;
1402 WindowState imw = mInputMethodWindow;
1403 if (imw != null) {
1404 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 + " anim layer: " + imw.mAnimLayer);
1407 int wi = imw.mChildWindows.size();
1408 while (wi > 0) {
1409 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001410 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001412 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 + " anim layer: " + cw.mAnimLayer);
1414 }
1415 }
1416 int di = mInputMethodDialogs.size();
1417 while (di > 0) {
1418 di --;
1419 imw = mInputMethodDialogs.get(di);
1420 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001421 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 + " anim layer: " + imw.mAnimLayer);
1423 }
1424 }
Romain Guy06882f82009-06-10 13:36:04 -07001425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1427 int wpos = mWindows.indexOf(win);
1428 if (wpos >= 0) {
1429 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001430 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001432 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 int NC = win.mChildWindows.size();
1434 while (NC > 0) {
1435 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001436 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 int cpos = mWindows.indexOf(cw);
1438 if (cpos >= 0) {
1439 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001440 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001441 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 mWindows.remove(cpos);
1443 }
1444 }
1445 }
1446 return interestingPos;
1447 }
Romain Guy06882f82009-06-10 13:36:04 -07001448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 private void reAddWindowToListInOrderLocked(WindowState win) {
1450 addWindowToListInOrderLocked(win, false);
1451 // This is a hack to get all of the child windows added as well
1452 // at the right position. Child windows should be rare and
1453 // this case should be rare, so it shouldn't be that big a deal.
1454 int wpos = mWindows.indexOf(win);
1455 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001456 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001457 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001459 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 reAddWindowLocked(wpos, win);
1461 }
1462 }
Romain Guy06882f82009-06-10 13:36:04 -07001463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 void logWindowList(String prefix) {
1465 int N = mWindows.size();
1466 while (N > 0) {
1467 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001468 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 }
1470 }
Romain Guy06882f82009-06-10 13:36:04 -07001471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 void moveInputMethodDialogsLocked(int pos) {
1473 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001476 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 for (int i=0; i<N; i++) {
1478 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1479 }
1480 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001481 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 logWindowList(" ");
1483 }
Romain Guy06882f82009-06-10 13:36:04 -07001484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 if (pos >= 0) {
1486 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1487 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001488 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 if (wp == mInputMethodWindow) {
1490 pos++;
1491 }
1492 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001493 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 for (int i=0; i<N; i++) {
1495 WindowState win = dialogs.get(i);
1496 win.mTargetAppToken = targetAppToken;
1497 pos = reAddWindowLocked(pos, win);
1498 }
1499 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001500 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 logWindowList(" ");
1502 }
1503 return;
1504 }
1505 for (int i=0; i<N; i++) {
1506 WindowState win = dialogs.get(i);
1507 win.mTargetAppToken = null;
1508 reAddWindowToListInOrderLocked(win);
1509 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001510 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 logWindowList(" ");
1512 }
1513 }
1514 }
Romain Guy06882f82009-06-10 13:36:04 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1517 final WindowState imWin = mInputMethodWindow;
1518 final int DN = mInputMethodDialogs.size();
1519 if (imWin == null && DN == 0) {
1520 return false;
1521 }
Romain Guy06882f82009-06-10 13:36:04 -07001522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1524 if (imPos >= 0) {
1525 // In this case, the input method windows are to be placed
1526 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 // First check to see if the input method windows are already
1529 // located here, and contiguous.
1530 final int N = mWindows.size();
1531 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001532 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 // Figure out the actual input method window that should be
1535 // at the bottom of their stack.
1536 WindowState baseImWin = imWin != null
1537 ? imWin : mInputMethodDialogs.get(0);
1538 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001539 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 if (cw.mSubLayer < 0) baseImWin = cw;
1541 }
Romain Guy06882f82009-06-10 13:36:04 -07001542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 if (firstImWin == baseImWin) {
1544 // The windows haven't moved... but are they still contiguous?
1545 // First find the top IM window.
1546 int pos = imPos+1;
1547 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001548 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 break;
1550 }
1551 pos++;
1552 }
1553 pos++;
1554 // Now there should be no more input method windows above.
1555 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001556 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 break;
1558 }
1559 pos++;
1560 }
1561 if (pos >= N) {
1562 // All is good!
1563 return false;
1564 }
1565 }
Romain Guy06882f82009-06-10 13:36:04 -07001566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 if (imWin != null) {
1568 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001569 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 logWindowList(" ");
1571 }
1572 imPos = tmpRemoveWindowLocked(imPos, imWin);
1573 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001574 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 logWindowList(" ");
1576 }
1577 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1578 reAddWindowLocked(imPos, imWin);
1579 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001580 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 logWindowList(" ");
1582 }
1583 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1584 } else {
1585 moveInputMethodDialogsLocked(imPos);
1586 }
Romain Guy06882f82009-06-10 13:36:04 -07001587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 } else {
1589 // In this case, the input method windows go in a fixed layer,
1590 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001593 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 tmpRemoveWindowLocked(0, imWin);
1595 imWin.mTargetAppToken = null;
1596 reAddWindowToListInOrderLocked(imWin);
1597 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001598 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 logWindowList(" ");
1600 }
1601 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1602 } else {
1603 moveInputMethodDialogsLocked(-1);;
1604 }
Romain Guy06882f82009-06-10 13:36:04 -07001605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 }
Romain Guy06882f82009-06-10 13:36:04 -07001607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 if (needAssignLayers) {
1609 assignLayersLocked();
1610 }
Romain Guy06882f82009-06-10 13:36:04 -07001611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 return true;
1613 }
Romain Guy06882f82009-06-10 13:36:04 -07001614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 void adjustInputMethodDialogsLocked() {
1616 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1617 }
Romain Guy06882f82009-06-10 13:36:04 -07001618
Dianne Hackborn25994b42009-09-04 14:21:19 -07001619 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001620 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001621 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1622 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1623 ? wallpaperTarget.mAppToken.animation : null)
1624 + " upper=" + mUpperWallpaperTarget
1625 + " lower=" + mLowerWallpaperTarget);
1626 return (wallpaperTarget != null
1627 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1628 && wallpaperTarget.mAppToken.animation != null)))
1629 || mUpperWallpaperTarget != null
1630 || mLowerWallpaperTarget != null;
1631 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001632
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001633 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1634 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001635
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001636 int adjustWallpaperWindowsLocked() {
1637 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001638
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001639 final int dw = mDisplay.getWidth();
1640 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001641
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001642 // First find top-most window that has asked to be on top of the
1643 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001644 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001645 int N = localmWindows.size();
1646 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001647 WindowState foundW = null;
1648 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001649 WindowState topCurW = null;
1650 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001651 int i = N;
1652 while (i > 0) {
1653 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001654 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001655 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1656 if (topCurW == null) {
1657 topCurW = w;
1658 topCurI = i;
1659 }
1660 continue;
1661 }
1662 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001663 if (w.mAppToken != null) {
1664 // If this window's app token is hidden and not animating,
1665 // it is of no interest to us.
1666 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001667 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001668 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001669 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001670 continue;
1671 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001672 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001673 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001674 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1675 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001676 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001677 && (mWallpaperTarget == w
1678 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001679 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001680 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001681 foundW = w;
1682 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001683 if (w == mWallpaperTarget && ((w.mAppToken != null
1684 && w.mAppToken.animation != null)
1685 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001686 // The current wallpaper target is animating, so we'll
1687 // look behind it for another possible target and figure
1688 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001689 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001690 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001691 continue;
1692 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001693 break;
1694 }
1695 }
1696
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001697 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001698 // If we are currently waiting for an app transition, and either
1699 // the current target or the next target are involved with it,
1700 // then hold off on doing anything with the wallpaper.
1701 // Note that we are checking here for just whether the target
1702 // is part of an app token... which is potentially overly aggressive
1703 // (the app token may not be involved in the transition), but good
1704 // enough (we'll just wait until whatever transition is pending
1705 // executes).
1706 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001707 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001708 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001709 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001710 }
1711 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001712 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001713 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001714 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001715 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001716 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001717
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001718 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001719 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001720 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001721 + " oldTarget: " + mWallpaperTarget);
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001724 mLowerWallpaperTarget = null;
1725 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001726
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001727 WindowState oldW = mWallpaperTarget;
1728 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001729
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001730 // Now what is happening... if the current and new targets are
1731 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001732 if (foundW != null && oldW != null) {
1733 boolean oldAnim = oldW.mAnimation != null
1734 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1735 boolean foundAnim = foundW.mAnimation != null
1736 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001737 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001738 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001739 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001740 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001741 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 int oldI = localmWindows.indexOf(oldW);
1743 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001744 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001745 }
1746 if (oldI >= 0) {
1747 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001748 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001749 + "=" + oldW + "; new#" + foundI
1750 + "=" + foundW);
1751 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001752
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001753 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001754 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001755 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001756 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001757 }
1758 mWallpaperTarget = oldW;
1759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001760
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001761 // Now set the upper and lower wallpaper targets
1762 // correctly, and make sure that we are positioning
1763 // the wallpaper below the lower.
1764 if (foundI > oldI) {
1765 // The new target is on top of the old one.
1766 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001767 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001768 }
1769 mUpperWallpaperTarget = foundW;
1770 mLowerWallpaperTarget = oldW;
1771 foundW = oldW;
1772 foundI = oldI;
1773 } else {
1774 // The new target is below the old one.
1775 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001776 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001777 }
1778 mUpperWallpaperTarget = oldW;
1779 mLowerWallpaperTarget = foundW;
1780 }
1781 }
1782 }
1783 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001784
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001785 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001786 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001787 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1788 || (mLowerWallpaperTarget.mAppToken != null
1789 && mLowerWallpaperTarget.mAppToken.animation != null);
1790 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1791 || (mUpperWallpaperTarget.mAppToken != null
1792 && mUpperWallpaperTarget.mAppToken.animation != null);
1793 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001794 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001796 }
1797 mLowerWallpaperTarget = null;
1798 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001799 }
1800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001801
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001802 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001803 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001804 // The window is visible to the compositor... but is it visible
1805 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001806 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001808
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001809 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001810 // its layer adjustment. Only do this if we are not transfering
1811 // between two wallpaper targets.
1812 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001813 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001814 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001815
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001816 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1817 * TYPE_LAYER_MULTIPLIER
1818 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001819
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001820 // Now w is the window we are supposed to be behind... but we
1821 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001822 // AND any starting window associated with it, AND below the
1823 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001824 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001825 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001826 if (wb.mBaseLayer < maxLayer &&
1827 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001828 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001829 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001830 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001831 // This window is not related to the previous one in any
1832 // interesting way, so stop here.
1833 break;
1834 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001835 foundW = wb;
1836 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001837 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001838 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001839 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001842 if (foundW == null && topCurW != null) {
1843 // There is no wallpaper target, so it goes at the bottom.
1844 // We will assume it is the same place as last time, if known.
1845 foundW = topCurW;
1846 foundI = topCurI+1;
1847 } else {
1848 // Okay i is the position immediately above the wallpaper. Look at
1849 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001850 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001851 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001852
Dianne Hackborn284ac932009-08-28 10:34:25 -07001853 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001854 if (mWallpaperTarget.mWallpaperX >= 0) {
1855 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001856 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001857 }
1858 if (mWallpaperTarget.mWallpaperY >= 0) {
1859 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001860 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001861 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001862 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001863
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001864 // Start stepping backwards from here, ensuring that our wallpaper windows
1865 // are correctly placed.
1866 int curTokenIndex = mWallpaperTokens.size();
1867 while (curTokenIndex > 0) {
1868 curTokenIndex--;
1869 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001870 if (token.hidden == visible) {
1871 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1872 token.hidden = !visible;
1873 // Need to do a layout to ensure the wallpaper now has the
1874 // correct size.
1875 mLayoutNeeded = true;
1876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001877
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001878 int curWallpaperIndex = token.windows.size();
1879 while (curWallpaperIndex > 0) {
1880 curWallpaperIndex--;
1881 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001882
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001883 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001884 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001885 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001886
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001887 // First, make sure the client has the current visibility
1888 // state.
1889 if (wallpaper.mWallpaperVisible != visible) {
1890 wallpaper.mWallpaperVisible = visible;
1891 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001892 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001893 "Setting visibility of wallpaper " + wallpaper
1894 + ": " + visible);
1895 wallpaper.mClient.dispatchAppVisibility(visible);
1896 } catch (RemoteException e) {
1897 }
1898 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001899
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001900 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001901 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001902 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001903
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001904 // First, if this window is at the current index, then all
1905 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001906 if (wallpaper == foundW) {
1907 foundI--;
1908 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001909 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001910 continue;
1911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001912
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 // The window didn't match... the current wallpaper window,
1914 // wherever it is, is in the wrong place, so make sure it is
1915 // not in the list.
1916 int oldIndex = localmWindows.indexOf(wallpaper);
1917 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001918 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001919 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001920 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001921 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001922 if (oldIndex < foundI) {
1923 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001924 }
1925 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001926
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001927 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001928 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001929 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001930 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001931
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001932 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001933 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001934 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 }
1936 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001937
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001938 return changed;
1939 }
1940
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001941 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001942 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001943 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001944 mWallpaperAnimLayerAdjustment = adj;
1945 int curTokenIndex = mWallpaperTokens.size();
1946 while (curTokenIndex > 0) {
1947 curTokenIndex--;
1948 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1949 int curWallpaperIndex = token.windows.size();
1950 while (curWallpaperIndex > 0) {
1951 curWallpaperIndex--;
1952 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1953 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001954 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001955 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001956 }
1957 }
1958 }
1959
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001960 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1961 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001962 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001963 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001964 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001965 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001966 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1967 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1968 changed = wallpaperWin.mXOffset != offset;
1969 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001970 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001971 + wallpaperWin + " x: " + offset);
1972 wallpaperWin.mXOffset = offset;
1973 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001974 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001975 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001976 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001977 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001978 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001979
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001980 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001981 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001982 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1983 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1984 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001985 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001986 + wallpaperWin + " y: " + offset);
1987 changed = true;
1988 wallpaperWin.mYOffset = offset;
1989 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001990 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001991 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001992 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001993 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001994 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001995
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001996 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001997 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001998 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001999 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2000 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002001 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002002 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002003 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002004 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002005 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2006 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002007 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002008 if (mWaitingOnWallpaper != null) {
2009 long start = SystemClock.uptimeMillis();
2010 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2011 < start) {
2012 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002014 "Waiting for offset complete...");
2015 mWindowMap.wait(WALLPAPER_TIMEOUT);
2016 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002017 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002019 if ((start+WALLPAPER_TIMEOUT)
2020 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002021 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002022 + wallpaperWin);
2023 mLastWallpaperTimeoutTime = start;
2024 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002025 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002026 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002027 }
2028 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002029 } catch (RemoteException e) {
2030 }
2031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002032
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002033 return changed;
2034 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002035
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002036 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002037 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002038 if (mWaitingOnWallpaper != null &&
2039 mWaitingOnWallpaper.mClient.asBinder() == window) {
2040 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002041 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002042 }
2043 }
2044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002045
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002046 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002047 final int dw = mDisplay.getWidth();
2048 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002049
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002050 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002051
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002052 WindowState target = mWallpaperTarget;
2053 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002054 if (target.mWallpaperX >= 0) {
2055 mLastWallpaperX = target.mWallpaperX;
2056 } else if (changingTarget.mWallpaperX >= 0) {
2057 mLastWallpaperX = changingTarget.mWallpaperX;
2058 }
2059 if (target.mWallpaperY >= 0) {
2060 mLastWallpaperY = target.mWallpaperY;
2061 } else if (changingTarget.mWallpaperY >= 0) {
2062 mLastWallpaperY = changingTarget.mWallpaperY;
2063 }
2064 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002065
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002066 int curTokenIndex = mWallpaperTokens.size();
2067 while (curTokenIndex > 0) {
2068 curTokenIndex--;
2069 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2070 int curWallpaperIndex = token.windows.size();
2071 while (curWallpaperIndex > 0) {
2072 curWallpaperIndex--;
2073 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2074 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2075 wallpaper.computeShownFrameLocked();
2076 changed = true;
2077 // We only want to be synchronous with one wallpaper.
2078 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002079 }
2080 }
2081 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002082
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002083 return changed;
2084 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002085
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002086 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002087 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002088 final int dw = mDisplay.getWidth();
2089 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002090
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002091 int curTokenIndex = mWallpaperTokens.size();
2092 while (curTokenIndex > 0) {
2093 curTokenIndex--;
2094 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002095 if (token.hidden == visible) {
2096 token.hidden = !visible;
2097 // Need to do a layout to ensure the wallpaper now has the
2098 // correct size.
2099 mLayoutNeeded = true;
2100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002101
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002102 int curWallpaperIndex = token.windows.size();
2103 while (curWallpaperIndex > 0) {
2104 curWallpaperIndex--;
2105 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2106 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002107 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002108 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002109
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002110 if (wallpaper.mWallpaperVisible != visible) {
2111 wallpaper.mWallpaperVisible = visible;
2112 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002113 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002114 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002115 + ": " + visible);
2116 wallpaper.mClient.dispatchAppVisibility(visible);
2117 } catch (RemoteException e) {
2118 }
2119 }
2120 }
2121 }
2122 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002124 public int addWindow(Session session, IWindow client,
2125 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002126 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 int res = mPolicy.checkAddPermission(attrs);
2128 if (res != WindowManagerImpl.ADD_OKAY) {
2129 return res;
2130 }
Romain Guy06882f82009-06-10 13:36:04 -07002131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 boolean reportNewConfig = false;
2133 WindowState attachedWindow = null;
2134 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002135 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002139 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 }
Romain Guy06882f82009-06-10 13:36:04 -07002141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002143 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2145 }
2146
2147 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002148 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002150 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002151 + attrs.token + ". Aborting.");
2152 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2153 }
2154 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2155 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002156 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 + attrs.token + ". Aborting.");
2158 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2159 }
2160 }
2161
2162 boolean addToken = false;
2163 WindowToken token = mTokenMap.get(attrs.token);
2164 if (token == null) {
2165 if (attrs.type >= FIRST_APPLICATION_WINDOW
2166 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002167 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002168 + attrs.token + ". Aborting.");
2169 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2170 }
2171 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002172 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 + attrs.token + ". Aborting.");
2174 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2175 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002176 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002177 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002178 + attrs.token + ". Aborting.");
2179 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 token = new WindowToken(attrs.token, -1, false);
2182 addToken = true;
2183 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2184 && attrs.type <= LAST_APPLICATION_WINDOW) {
2185 AppWindowToken atoken = token.appWindowToken;
2186 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002187 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 + token + ". Aborting.");
2189 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2190 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002191 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 + token + ". Aborting.");
2193 return WindowManagerImpl.ADD_APP_EXITING;
2194 }
2195 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2196 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002197 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2199 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2200 }
2201 } else if (attrs.type == TYPE_INPUT_METHOD) {
2202 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002203 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 + attrs.token + ". Aborting.");
2205 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2206 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002207 } else if (attrs.type == TYPE_WALLPAPER) {
2208 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002209 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002210 + attrs.token + ". Aborting.");
2211 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2212 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 }
2214
2215 win = new WindowState(session, client, token,
2216 attachedWindow, attrs, viewVisibility);
2217 if (win.mDeathRecipient == null) {
2218 // Client has apparently died, so there is no reason to
2219 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002220 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 + " that is dead, aborting.");
2222 return WindowManagerImpl.ADD_APP_EXITING;
2223 }
2224
2225 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 res = mPolicy.prepareAddWindowLw(win, attrs);
2228 if (res != WindowManagerImpl.ADD_OKAY) {
2229 return res;
2230 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002231
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002232 if (outInputChannel != null) {
2233 String name = win.makeInputChannelName();
2234 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2235 win.mInputChannel = inputChannels[0];
2236 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2237
2238 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002239 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240
2241 // From now on, no exceptions or errors allowed!
2242
2243 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002244
Dianne Hackborn5132b372010-07-29 12:51:35 -07002245 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 if (addToken) {
2248 mTokenMap.put(attrs.token, token);
2249 mTokenList.add(token);
2250 }
2251 win.attach();
2252 mWindowMap.put(client.asBinder(), win);
2253
2254 if (attrs.type == TYPE_APPLICATION_STARTING &&
2255 token.appWindowToken != null) {
2256 token.appWindowToken.startingWindow = win;
2257 }
2258
2259 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 if (attrs.type == TYPE_INPUT_METHOD) {
2262 mInputMethodWindow = win;
2263 addInputMethodWindowToListLocked(win);
2264 imMayMove = false;
2265 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2266 mInputMethodDialogs.add(win);
2267 addWindowToListInOrderLocked(win, true);
2268 adjustInputMethodDialogsLocked();
2269 imMayMove = false;
2270 } else {
2271 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002272 if (attrs.type == TYPE_WALLPAPER) {
2273 mLastWallpaperTimeoutTime = 0;
2274 adjustWallpaperWindowsLocked();
2275 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002276 adjustWallpaperWindowsLocked();
2277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 }
Romain Guy06882f82009-06-10 13:36:04 -07002279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 if (mInTouchMode) {
2285 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2286 }
2287 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2288 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2289 }
Romain Guy06882f82009-06-10 13:36:04 -07002290
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002291 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002293 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2294 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 imMayMove = false;
2296 }
2297 }
Romain Guy06882f82009-06-10 13:36:04 -07002298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002300 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 }
Romain Guy06882f82009-06-10 13:36:04 -07002302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 assignLayersLocked();
2304 // Don't do layout here, the window must call
2305 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 //dump();
2308
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002309 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002310 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002311 }
Jeff Brown349703e2010-06-22 01:27:15 -07002312
Joe Onorato8a9b2202010-02-26 18:56:32 -08002313 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 TAG, "New client " + client.asBinder()
2315 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002316
2317 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2318 reportNewConfig = true;
2319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 }
2321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 if (reportNewConfig) {
2323 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 return res;
2329 }
Romain Guy06882f82009-06-10 13:36:04 -07002330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 public void removeWindow(Session session, IWindow client) {
2332 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002333 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 if (win == null) {
2335 return;
2336 }
2337 removeWindowLocked(session, win);
2338 }
2339 }
Romain Guy06882f82009-06-10 13:36:04 -07002340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 public void removeWindowLocked(Session session, WindowState win) {
2342
Joe Onorato8a9b2202010-02-26 18:56:32 -08002343 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 TAG, "Remove " + win + " client="
2345 + Integer.toHexString(System.identityHashCode(
2346 win.mClient.asBinder()))
2347 + ", surface=" + win.mSurface);
2348
2349 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002350
2351 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002352
Joe Onorato8a9b2202010-02-26 18:56:32 -08002353 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2355 + " mExiting=" + win.mExiting
2356 + " isAnimating=" + win.isAnimating()
2357 + " app-animation="
2358 + (win.mAppToken != null ? win.mAppToken.animation : null)
2359 + " inPendingTransaction="
2360 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2361 + " mDisplayFrozen=" + mDisplayFrozen);
2362 // Visibility of the removed window. Will be used later to update orientation later on.
2363 boolean wasVisible = false;
2364 // First, see if we need to run an animation. If we do, we have
2365 // to hold off on removing the window until the animation is done.
2366 // If the display is frozen, just remove immediately, since the
2367 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002368 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 // If we are not currently running the exit animation, we
2370 // need to see about starting one.
2371 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2374 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2375 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2376 }
2377 // Try starting an animation.
2378 if (applyAnimationLocked(win, transit, false)) {
2379 win.mExiting = true;
2380 }
2381 }
2382 if (win.mExiting || win.isAnimating()) {
2383 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002384 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 win.mExiting = true;
2386 win.mRemoveOnExit = true;
2387 mLayoutNeeded = true;
2388 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2389 performLayoutAndPlaceSurfacesLocked();
2390 if (win.mAppToken != null) {
2391 win.mAppToken.updateReportedVisibilityLocked();
2392 }
2393 //dump();
2394 Binder.restoreCallingIdentity(origId);
2395 return;
2396 }
2397 }
2398
2399 removeWindowInnerLocked(session, win);
2400 // Removing a visible window will effect the computed orientation
2401 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002402 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002403 != mForcedAppOrientation
2404 && updateOrientationFromAppTokensLocked()) {
2405 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 }
2407 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2408 Binder.restoreCallingIdentity(origId);
2409 }
Romain Guy06882f82009-06-10 13:36:04 -07002410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 if (mInputMethodTarget == win) {
2415 moveInputMethodWindowsIfNeededLocked(false);
2416 }
Romain Guy06882f82009-06-10 13:36:04 -07002417
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002418 if (false) {
2419 RuntimeException e = new RuntimeException("here");
2420 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002421 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002422 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 mPolicy.removeWindowLw(win);
2425 win.removeLocked();
2426
2427 mWindowMap.remove(win.mClient.asBinder());
2428 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002429 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002430 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431
2432 if (mInputMethodWindow == win) {
2433 mInputMethodWindow = null;
2434 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2435 mInputMethodDialogs.remove(win);
2436 }
Romain Guy06882f82009-06-10 13:36:04 -07002437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 final WindowToken token = win.mToken;
2439 final AppWindowToken atoken = win.mAppToken;
2440 token.windows.remove(win);
2441 if (atoken != null) {
2442 atoken.allAppWindows.remove(win);
2443 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002444 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 TAG, "**** Removing window " + win + ": count="
2446 + token.windows.size());
2447 if (token.windows.size() == 0) {
2448 if (!token.explicit) {
2449 mTokenMap.remove(token.token);
2450 mTokenList.remove(token);
2451 } else if (atoken != null) {
2452 atoken.firstWindowDrawn = false;
2453 }
2454 }
2455
2456 if (atoken != null) {
2457 if (atoken.startingWindow == win) {
2458 atoken.startingWindow = null;
2459 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2460 // If this is the last window and we had requested a starting
2461 // transition window, well there is no point now.
2462 atoken.startingData = null;
2463 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2464 // If this is the last window except for a starting transition
2465 // window, we need to get rid of the starting transition.
2466 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002467 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 + ": no more real windows");
2469 }
2470 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2471 mH.sendMessage(m);
2472 }
2473 }
Romain Guy06882f82009-06-10 13:36:04 -07002474
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002475 if (win.mAttrs.type == TYPE_WALLPAPER) {
2476 mLastWallpaperTimeoutTime = 0;
2477 adjustWallpaperWindowsLocked();
2478 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002479 adjustWallpaperWindowsLocked();
2480 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 if (!mInLayout) {
2483 assignLayersLocked();
2484 mLayoutNeeded = true;
2485 performLayoutAndPlaceSurfacesLocked();
2486 if (win.mAppToken != null) {
2487 win.mAppToken.updateReportedVisibilityLocked();
2488 }
2489 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002490
2491 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 }
2493
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002494 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2495 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2496 + ": " + msg + " / " + w.mAttrs.getTitle();
2497 if (where != null) {
2498 Slog.i(TAG, str, where);
2499 } else {
2500 Slog.i(TAG, str);
2501 }
2502 }
2503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2505 long origId = Binder.clearCallingIdentity();
2506 try {
2507 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002508 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002510 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 Surface.openTransaction();
2512 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002513 if (SHOW_TRANSACTIONS) logSurface(w,
2514 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 w.mSurface.setTransparentRegionHint(region);
2516 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002517 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 Surface.closeTransaction();
2519 }
2520 }
2521 }
2522 } finally {
2523 Binder.restoreCallingIdentity(origId);
2524 }
2525 }
2526
2527 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002528 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 Rect visibleInsets) {
2530 long origId = Binder.clearCallingIdentity();
2531 try {
2532 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002533 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 if (w != null) {
2535 w.mGivenInsetsPending = false;
2536 w.mGivenContentInsets.set(contentInsets);
2537 w.mGivenVisibleInsets.set(visibleInsets);
2538 w.mTouchableInsets = touchableInsets;
2539 mLayoutNeeded = true;
2540 performLayoutAndPlaceSurfacesLocked();
2541 }
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(origId);
2545 }
2546 }
Romain Guy06882f82009-06-10 13:36:04 -07002547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002548 public void getWindowDisplayFrame(Session session, IWindow client,
2549 Rect outDisplayFrame) {
2550 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002551 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 if (win == null) {
2553 outDisplayFrame.setEmpty();
2554 return;
2555 }
2556 outDisplayFrame.set(win.mDisplayFrame);
2557 }
2558 }
2559
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002560 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2561 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002562 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2563 window.mWallpaperX = x;
2564 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002565 window.mWallpaperXStep = xStep;
2566 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002567 if (updateWallpaperOffsetLocked(window, true)) {
2568 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002569 }
2570 }
2571 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002572
Dianne Hackborn75804932009-10-20 20:15:20 -07002573 void wallpaperCommandComplete(IBinder window, Bundle result) {
2574 synchronized (mWindowMap) {
2575 if (mWaitingOnWallpaper != null &&
2576 mWaitingOnWallpaper.mClient.asBinder() == window) {
2577 mWaitingOnWallpaper = null;
2578 mWindowMap.notifyAll();
2579 }
2580 }
2581 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002582
Dianne Hackborn75804932009-10-20 20:15:20 -07002583 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2584 String action, int x, int y, int z, Bundle extras, boolean sync) {
2585 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2586 || window == mUpperWallpaperTarget) {
2587 boolean doWait = sync;
2588 int curTokenIndex = mWallpaperTokens.size();
2589 while (curTokenIndex > 0) {
2590 curTokenIndex--;
2591 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2592 int curWallpaperIndex = token.windows.size();
2593 while (curWallpaperIndex > 0) {
2594 curWallpaperIndex--;
2595 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2596 try {
2597 wallpaper.mClient.dispatchWallpaperCommand(action,
2598 x, y, z, extras, sync);
2599 // We only want to be synchronous with one wallpaper.
2600 sync = false;
2601 } catch (RemoteException e) {
2602 }
2603 }
2604 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002605
Dianne Hackborn75804932009-10-20 20:15:20 -07002606 if (doWait) {
2607 // XXX Need to wait for result.
2608 }
2609 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002610
Dianne Hackborn75804932009-10-20 20:15:20 -07002611 return null;
2612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 public int relayoutWindow(Session session, IWindow client,
2615 WindowManager.LayoutParams attrs, int requestedWidth,
2616 int requestedHeight, int viewVisibility, boolean insetsPending,
2617 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002618 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 boolean displayed = false;
2620 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002621 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002625 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002626 if (win == null) {
2627 return 0;
2628 }
2629 win.mRequestedWidth = requestedWidth;
2630 win.mRequestedHeight = requestedHeight;
2631
2632 if (attrs != null) {
2633 mPolicy.adjustWindowParamsLw(attrs);
2634 }
Romain Guy06882f82009-06-10 13:36:04 -07002635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 int attrChanges = 0;
2637 int flagChanges = 0;
2638 if (attrs != null) {
2639 flagChanges = win.mAttrs.flags ^= attrs.flags;
2640 attrChanges = win.mAttrs.copyFrom(attrs);
2641 }
2642
Joe Onorato8a9b2202010-02-26 18:56:32 -08002643 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644
2645 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2646 win.mAlpha = attrs.alpha;
2647 }
2648
2649 final boolean scaledWindow =
2650 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2651
2652 if (scaledWindow) {
2653 // requested{Width|Height} Surface's physical size
2654 // attrs.{width|height} Size on screen
2655 win.mHScale = (attrs.width != requestedWidth) ?
2656 (attrs.width / (float)requestedWidth) : 1.0f;
2657 win.mVScale = (attrs.height != requestedHeight) ?
2658 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002659 } else {
2660 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 }
2662
2663 boolean imMayMove = (flagChanges&(
2664 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2665 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 boolean focusMayChange = win.mViewVisibility != viewVisibility
2668 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2669 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002670
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002671 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2672 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 win.mRelayoutCalled = true;
2675 final int oldVisibility = win.mViewVisibility;
2676 win.mViewVisibility = viewVisibility;
2677 if (viewVisibility == View.VISIBLE &&
2678 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2679 displayed = !win.isVisibleLw();
2680 if (win.mExiting) {
2681 win.mExiting = false;
2682 win.mAnimation = null;
2683 }
2684 if (win.mDestroying) {
2685 win.mDestroying = false;
2686 mDestroySurface.remove(win);
2687 }
2688 if (oldVisibility == View.GONE) {
2689 win.mEnterAnimationPending = true;
2690 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002691 if (displayed) {
2692 if (win.mSurface != null && !win.mDrawPending
2693 && !win.mCommitDrawPending && !mDisplayFrozen
2694 && mPolicy.isScreenOn()) {
2695 applyEnterAnimationLocked(win);
2696 }
2697 if ((win.mAttrs.flags
2698 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2699 if (DEBUG_VISIBILITY) Slog.v(TAG,
2700 "Relayout window turning screen on: " + win);
2701 win.mTurnOnScreen = true;
2702 }
2703 int diff = 0;
2704 if (win.mConfiguration != mCurConfiguration
2705 && (win.mConfiguration == null
2706 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2707 win.mConfiguration = mCurConfiguration;
2708 if (DEBUG_CONFIGURATION) {
2709 Slog.i(TAG, "Window " + win + " visible with new config: "
2710 + win.mConfiguration + " / 0x"
2711 + Integer.toHexString(diff));
2712 }
2713 outConfig.setTo(mCurConfiguration);
2714 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002715 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2717 // To change the format, we need to re-build the surface.
2718 win.destroySurfaceLocked();
2719 displayed = true;
2720 }
2721 try {
2722 Surface surface = win.createSurfaceLocked();
2723 if (surface != null) {
2724 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002725 win.mReportDestroySurface = false;
2726 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002727 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002728 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002729 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002730 // For some reason there isn't a surface. Clear the
2731 // caller's object so they see the same state.
2732 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002733 }
2734 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002735 mInputMonitor.updateInputWindowsLw();
2736
Joe Onorato8a9b2202010-02-26 18:56:32 -08002737 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002738 + client + " (" + win.mAttrs.getTitle() + ")",
2739 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 Binder.restoreCallingIdentity(origId);
2741 return 0;
2742 }
2743 if (displayed) {
2744 focusMayChange = true;
2745 }
2746 if (win.mAttrs.type == TYPE_INPUT_METHOD
2747 && mInputMethodWindow == null) {
2748 mInputMethodWindow = win;
2749 imMayMove = true;
2750 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002751 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2752 && win.mAppToken != null
2753 && win.mAppToken.startingWindow != null) {
2754 // Special handling of starting window over the base
2755 // window of the app: propagate lock screen flags to it,
2756 // to provide the correct semantics while starting.
2757 final int mask =
2758 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002759 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2760 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002761 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2762 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2763 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002764 } else {
2765 win.mEnterAnimationPending = false;
2766 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002767 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002768 + ": mExiting=" + win.mExiting
2769 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 // If we are not currently running the exit animation, we
2771 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002772 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 // Try starting an animation; if there isn't one, we
2774 // can destroy the surface right away.
2775 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2776 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2777 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2778 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002779 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002781 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002782 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 } else if (win.isAnimating()) {
2784 // Currently in a hide animation... turn this into
2785 // an exit.
2786 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002787 } else if (win == mWallpaperTarget) {
2788 // If the wallpaper is currently behind this
2789 // window, we need to change both of them inside
2790 // of a transaction to avoid artifacts.
2791 win.mExiting = true;
2792 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793 } else {
2794 if (mInputMethodWindow == win) {
2795 mInputMethodWindow = null;
2796 }
2797 win.destroySurfaceLocked();
2798 }
2799 }
2800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002801
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002802 if (win.mSurface == null || (win.getAttrs().flags
2803 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2804 || win.mSurfacePendingDestroy) {
2805 // We are being called from a local process, which
2806 // means outSurface holds its current surface. Ensure the
2807 // surface object is cleared, but we don't want it actually
2808 // destroyed at this point.
2809 win.mSurfacePendingDestroy = false;
2810 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002811 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002812 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002813 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002814 "Keeping surface, will report destroy: " + win);
2815 win.mReportDestroySurface = true;
2816 outSurface.copyFrom(win.mSurface);
2817 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 }
2819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 if (focusMayChange) {
2821 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2822 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 imMayMove = false;
2824 }
2825 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2826 }
Romain Guy06882f82009-06-10 13:36:04 -07002827
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002828 // updateFocusedWindowLocked() already assigned layers so we only need to
2829 // reassign them at this point if the IM window state gets shuffled
2830 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002833 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2834 // Little hack here -- we -should- be able to rely on the
2835 // function to return true if the IME has moved and needs
2836 // its layer recomputed. However, if the IME was hidden
2837 // and isn't actually moved in the list, its layer may be
2838 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 assignLayers = true;
2840 }
2841 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002842 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002843 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002844 assignLayers = true;
2845 }
2846 }
Romain Guy06882f82009-06-10 13:36:04 -07002847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 mLayoutNeeded = true;
2849 win.mGivenInsetsPending = insetsPending;
2850 if (assignLayers) {
2851 assignLayersLocked();
2852 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002853 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002855 if (displayed && win.mIsWallpaper) {
2856 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002857 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002858 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 if (win.mAppToken != null) {
2860 win.mAppToken.updateReportedVisibilityLocked();
2861 }
2862 outFrame.set(win.mFrame);
2863 outContentInsets.set(win.mContentInsets);
2864 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002865 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002867 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 + ", requestedHeight=" + requestedHeight
2869 + ", viewVisibility=" + viewVisibility
2870 + "\nRelayout returning frame=" + outFrame
2871 + ", surface=" + outSurface);
2872
Joe Onorato8a9b2202010-02-26 18:56:32 -08002873 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2875
2876 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002877
2878 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 }
2880
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002881 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 sendNewConfiguration();
2883 }
Romain Guy06882f82009-06-10 13:36:04 -07002884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2888 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2889 }
2890
2891 public void finishDrawingWindow(Session session, IWindow client) {
2892 final long origId = Binder.clearCallingIdentity();
2893 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002894 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002896 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2897 adjustWallpaperWindowsLocked();
2898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 mLayoutNeeded = true;
2900 performLayoutAndPlaceSurfacesLocked();
2901 }
2902 }
2903 Binder.restoreCallingIdentity(origId);
2904 }
2905
2906 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002907 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 + (lp != null ? lp.packageName : null)
2909 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2910 if (lp != null && lp.windowAnimations != 0) {
2911 // If this is a system resource, don't try to load it from the
2912 // application resources. It is nice to avoid loading application
2913 // resources if we can.
2914 String packageName = lp.packageName != null ? lp.packageName : "android";
2915 int resId = lp.windowAnimations;
2916 if ((resId&0xFF000000) == 0x01000000) {
2917 packageName = "android";
2918 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002919 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 + packageName);
2921 return AttributeCache.instance().get(packageName, resId,
2922 com.android.internal.R.styleable.WindowAnimation);
2923 }
2924 return null;
2925 }
Romain Guy06882f82009-06-10 13:36:04 -07002926
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002927 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002928 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002929 + packageName + " resId=0x" + Integer.toHexString(resId));
2930 if (packageName != null) {
2931 if ((resId&0xFF000000) == 0x01000000) {
2932 packageName = "android";
2933 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002934 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002935 + packageName);
2936 return AttributeCache.instance().get(packageName, resId,
2937 com.android.internal.R.styleable.WindowAnimation);
2938 }
2939 return null;
2940 }
2941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 private void applyEnterAnimationLocked(WindowState win) {
2943 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2944 if (win.mEnterAnimationPending) {
2945 win.mEnterAnimationPending = false;
2946 transit = WindowManagerPolicy.TRANSIT_ENTER;
2947 }
2948
2949 applyAnimationLocked(win, transit, true);
2950 }
2951
2952 private boolean applyAnimationLocked(WindowState win,
2953 int transit, boolean isEntrance) {
2954 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2955 // If we are trying to apply an animation, but already running
2956 // an animation of the same type, then just leave that one alone.
2957 return true;
2958 }
Romain Guy06882f82009-06-10 13:36:04 -07002959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 // Only apply an animation if the display isn't frozen. If it is
2961 // frozen, there is no reason to animate and it can cause strange
2962 // artifacts when we unfreeze the display if some different animation
2963 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002964 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 int anim = mPolicy.selectAnimationLw(win, transit);
2966 int attr = -1;
2967 Animation a = null;
2968 if (anim != 0) {
2969 a = AnimationUtils.loadAnimation(mContext, anim);
2970 } else {
2971 switch (transit) {
2972 case WindowManagerPolicy.TRANSIT_ENTER:
2973 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2974 break;
2975 case WindowManagerPolicy.TRANSIT_EXIT:
2976 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2977 break;
2978 case WindowManagerPolicy.TRANSIT_SHOW:
2979 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2980 break;
2981 case WindowManagerPolicy.TRANSIT_HIDE:
2982 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2983 break;
2984 }
2985 if (attr >= 0) {
2986 a = loadAnimation(win.mAttrs, attr);
2987 }
2988 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002989 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002990 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2991 + " mAnimation=" + win.mAnimation
2992 + " isEntrance=" + isEntrance);
2993 if (a != null) {
2994 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002995 RuntimeException e = null;
2996 if (!HIDE_STACK_CRAWLS) {
2997 e = new RuntimeException();
2998 e.fillInStackTrace();
2999 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003000 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 }
3002 win.setAnimation(a);
3003 win.mAnimationIsEntrance = isEntrance;
3004 }
3005 } else {
3006 win.clearAnimation();
3007 }
3008
3009 return win.mAnimation != null;
3010 }
3011
3012 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3013 int anim = 0;
3014 Context context = mContext;
3015 if (animAttr >= 0) {
3016 AttributeCache.Entry ent = getCachedAnimations(lp);
3017 if (ent != null) {
3018 context = ent.context;
3019 anim = ent.array.getResourceId(animAttr, 0);
3020 }
3021 }
3022 if (anim != 0) {
3023 return AnimationUtils.loadAnimation(context, anim);
3024 }
3025 return null;
3026 }
Romain Guy06882f82009-06-10 13:36:04 -07003027
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003028 private Animation loadAnimation(String packageName, int resId) {
3029 int anim = 0;
3030 Context context = mContext;
3031 if (resId >= 0) {
3032 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3033 if (ent != null) {
3034 context = ent.context;
3035 anim = resId;
3036 }
3037 }
3038 if (anim != 0) {
3039 return AnimationUtils.loadAnimation(context, anim);
3040 }
3041 return null;
3042 }
3043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 private boolean applyAnimationLocked(AppWindowToken wtoken,
3045 WindowManager.LayoutParams lp, int transit, boolean enter) {
3046 // Only apply an animation if the display isn't frozen. If it is
3047 // frozen, there is no reason to animate and it can cause strange
3048 // artifacts when we unfreeze the display if some different animation
3049 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003050 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003051 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003052 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003053 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003054 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003055 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003056 } else if (mNextAppTransitionPackage != null) {
3057 a = loadAnimation(mNextAppTransitionPackage, enter ?
3058 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003059 } else {
3060 int animAttr = 0;
3061 switch (transit) {
3062 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3063 animAttr = enter
3064 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3065 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3066 break;
3067 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3068 animAttr = enter
3069 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3070 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3071 break;
3072 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3073 animAttr = enter
3074 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3075 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3076 break;
3077 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3078 animAttr = enter
3079 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3080 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3081 break;
3082 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3083 animAttr = enter
3084 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3085 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3086 break;
3087 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3088 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003089 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003090 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3091 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003092 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003093 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003094 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3095 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003096 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003097 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003098 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003099 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3100 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3101 break;
3102 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3103 animAttr = enter
3104 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3105 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3106 break;
3107 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3108 animAttr = enter
3109 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3110 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003111 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003112 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003113 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003114 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003115 + " anim=" + a
3116 + " animAttr=0x" + Integer.toHexString(animAttr)
3117 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 if (a != null) {
3120 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003121 RuntimeException e = null;
3122 if (!HIDE_STACK_CRAWLS) {
3123 e = new RuntimeException();
3124 e.fillInStackTrace();
3125 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003126 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003127 }
3128 wtoken.setAnimation(a);
3129 }
3130 } else {
3131 wtoken.clearAnimation();
3132 }
3133
3134 return wtoken.animation != null;
3135 }
3136
3137 // -------------------------------------------------------------
3138 // Application Window Tokens
3139 // -------------------------------------------------------------
3140
3141 public void validateAppTokens(List tokens) {
3142 int v = tokens.size()-1;
3143 int m = mAppTokens.size()-1;
3144 while (v >= 0 && m >= 0) {
3145 AppWindowToken wtoken = mAppTokens.get(m);
3146 if (wtoken.removed) {
3147 m--;
3148 continue;
3149 }
3150 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003151 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3153 }
3154 v--;
3155 m--;
3156 }
3157 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003158 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 v--;
3160 }
3161 while (m >= 0) {
3162 AppWindowToken wtoken = mAppTokens.get(m);
3163 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003164 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003165 }
3166 m--;
3167 }
3168 }
3169
3170 boolean checkCallingPermission(String permission, String func) {
3171 // Quick check: if the calling permission is me, it's all okay.
3172 if (Binder.getCallingPid() == Process.myPid()) {
3173 return true;
3174 }
Romain Guy06882f82009-06-10 13:36:04 -07003175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 if (mContext.checkCallingPermission(permission)
3177 == PackageManager.PERMISSION_GRANTED) {
3178 return true;
3179 }
3180 String msg = "Permission Denial: " + func + " from pid="
3181 + Binder.getCallingPid()
3182 + ", uid=" + Binder.getCallingUid()
3183 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003184 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 return false;
3186 }
Romain Guy06882f82009-06-10 13:36:04 -07003187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 AppWindowToken findAppWindowToken(IBinder token) {
3189 WindowToken wtoken = mTokenMap.get(token);
3190 if (wtoken == null) {
3191 return null;
3192 }
3193 return wtoken.appWindowToken;
3194 }
Romain Guy06882f82009-06-10 13:36:04 -07003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 public void addWindowToken(IBinder token, int type) {
3197 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3198 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003199 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 }
Romain Guy06882f82009-06-10 13:36:04 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 synchronized(mWindowMap) {
3203 WindowToken wtoken = mTokenMap.get(token);
3204 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003205 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 return;
3207 }
3208 wtoken = new WindowToken(token, type, true);
3209 mTokenMap.put(token, wtoken);
3210 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003211 if (type == TYPE_WALLPAPER) {
3212 mWallpaperTokens.add(wtoken);
3213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 }
3215 }
Romain Guy06882f82009-06-10 13:36:04 -07003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 public void removeWindowToken(IBinder token) {
3218 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3219 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003220 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 }
3222
3223 final long origId = Binder.clearCallingIdentity();
3224 synchronized(mWindowMap) {
3225 WindowToken wtoken = mTokenMap.remove(token);
3226 mTokenList.remove(wtoken);
3227 if (wtoken != null) {
3228 boolean delayed = false;
3229 if (!wtoken.hidden) {
3230 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 final int N = wtoken.windows.size();
3233 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 for (int i=0; i<N; i++) {
3236 WindowState win = wtoken.windows.get(i);
3237
3238 if (win.isAnimating()) {
3239 delayed = true;
3240 }
Romain Guy06882f82009-06-10 13:36:04 -07003241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 if (win.isVisibleNow()) {
3243 applyAnimationLocked(win,
3244 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 changed = true;
3246 }
3247 }
3248
3249 if (changed) {
3250 mLayoutNeeded = true;
3251 performLayoutAndPlaceSurfacesLocked();
3252 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3253 }
Romain Guy06882f82009-06-10 13:36:04 -07003254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 if (delayed) {
3256 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003257 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3258 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 }
3260 }
Romain Guy06882f82009-06-10 13:36:04 -07003261
Jeff Brownc5ed5912010-07-14 18:48:53 -07003262 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003264 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 }
3266 }
3267 Binder.restoreCallingIdentity(origId);
3268 }
3269
3270 public void addAppToken(int addPos, IApplicationToken token,
3271 int groupId, int requestedOrientation, boolean fullscreen) {
3272 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3273 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003274 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 }
Jeff Brown349703e2010-06-22 01:27:15 -07003276
3277 // Get the dispatching timeout here while we are not holding any locks so that it
3278 // can be cached by the AppWindowToken. The timeout value is used later by the
3279 // input dispatcher in code that does hold locks. If we did not cache the value
3280 // here we would run the chance of introducing a deadlock between the window manager
3281 // (which holds locks while updating the input dispatcher state) and the activity manager
3282 // (which holds locks while querying the application token).
3283 long inputDispatchingTimeoutNanos;
3284 try {
3285 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3286 } catch (RemoteException ex) {
3287 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3288 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3289 }
Romain Guy06882f82009-06-10 13:36:04 -07003290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 synchronized(mWindowMap) {
3292 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3293 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003294 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 return;
3296 }
3297 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003298 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 wtoken.groupId = groupId;
3300 wtoken.appFullscreen = fullscreen;
3301 wtoken.requestedOrientation = requestedOrientation;
3302 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003303 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 mTokenMap.put(token.asBinder(), wtoken);
3305 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 // Application tokens start out hidden.
3308 wtoken.hidden = true;
3309 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 //dump();
3312 }
3313 }
Romain Guy06882f82009-06-10 13:36:04 -07003314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 public void setAppGroupId(IBinder token, int groupId) {
3316 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3317 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003318 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 }
3320
3321 synchronized(mWindowMap) {
3322 AppWindowToken wtoken = findAppWindowToken(token);
3323 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003324 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 return;
3326 }
3327 wtoken.groupId = groupId;
3328 }
3329 }
Romain Guy06882f82009-06-10 13:36:04 -07003330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 public int getOrientationFromWindowsLocked() {
3332 int pos = mWindows.size() - 1;
3333 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003334 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 pos--;
3336 if (wtoken.mAppToken != null) {
3337 // We hit an application window. so the orientation will be determined by the
3338 // app window. No point in continuing further.
3339 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3340 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003341 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 continue;
3343 }
3344 int req = wtoken.mAttrs.screenOrientation;
3345 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3346 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3347 continue;
3348 } else {
3349 return req;
3350 }
3351 }
3352 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003356 int pos = mAppTokens.size() - 1;
3357 int curGroup = 0;
3358 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3359 boolean findingBehind = false;
3360 boolean haveGroup = false;
3361 boolean lastFullscreen = false;
3362 while (pos >= 0) {
3363 AppWindowToken wtoken = mAppTokens.get(pos);
3364 pos--;
3365 // if we're about to tear down this window and not seek for
3366 // the behind activity, don't use it for orientation
3367 if (!findingBehind
3368 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3369 continue;
3370 }
3371
3372 if (!haveGroup) {
3373 // We ignore any hidden applications on the top.
3374 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003375 continue;
3376 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003377 haveGroup = true;
3378 curGroup = wtoken.groupId;
3379 lastOrientation = wtoken.requestedOrientation;
3380 } else if (curGroup != wtoken.groupId) {
3381 // If we have hit a new application group, and the bottom
3382 // of the previous group didn't explicitly say to use
3383 // the orientation behind it, and the last app was
3384 // full screen, then we'll stick with the
3385 // user's orientation.
3386 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3387 && lastFullscreen) {
3388 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003391 int or = wtoken.requestedOrientation;
3392 // If this application is fullscreen, and didn't explicitly say
3393 // to use the orientation behind it, then just take whatever
3394 // orientation it has and ignores whatever is under it.
3395 lastFullscreen = wtoken.appFullscreen;
3396 if (lastFullscreen
3397 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3398 return or;
3399 }
3400 // If this application has requested an explicit orientation,
3401 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003402 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3403 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003404 return or;
3405 }
3406 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3407 }
3408 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 }
Romain Guy06882f82009-06-10 13:36:04 -07003410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003412 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003413 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3414 "updateOrientationFromAppTokens()")) {
3415 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3416 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003417
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003418 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003420
3421 synchronized(mWindowMap) {
3422 if (updateOrientationFromAppTokensLocked()) {
3423 if (freezeThisOneIfNeeded != null) {
3424 AppWindowToken wtoken = findAppWindowToken(
3425 freezeThisOneIfNeeded);
3426 if (wtoken != null) {
3427 startAppFreezingScreenLocked(wtoken,
3428 ActivityInfo.CONFIG_ORIENTATION);
3429 }
3430 }
3431 config = computeNewConfigurationLocked();
3432
3433 } else if (currentConfig != null) {
3434 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003435 // state mismatches the activity manager's, update it,
3436 // disregarding font scale, which should remain set to
3437 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003438 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003439 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003440 if (computeNewConfigurationLocked(mTempConfiguration)) {
3441 if (currentConfig.diff(mTempConfiguration) != 0) {
3442 mWaitingForConfig = true;
3443 mLayoutNeeded = true;
3444 startFreezingDisplayLocked();
3445 config = new Configuration(mTempConfiguration);
3446 }
3447 }
3448 }
3449 }
3450
Dianne Hackborncfaef692009-06-15 14:24:44 -07003451 Binder.restoreCallingIdentity(ident);
3452 return config;
3453 }
3454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003456 * Determine the new desired orientation of the display, returning
3457 * a non-null new Configuration if it has changed from the current
3458 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3459 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3460 * SCREEN. This will typically be done for you if you call
3461 * sendNewConfiguration().
3462 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 * The orientation is computed from non-application windows first. If none of
3464 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003465 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3467 * android.os.IBinder)
3468 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003469 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003470 if (mDisplayFrozen) {
3471 // If the display is frozen, some activities may be in the middle
3472 // of restarting, and thus have removed their old window. If the
3473 // window has the flag to hide the lock screen, then the lock screen
3474 // can re-appear and inflict its own orientation on us. Keep the
3475 // orientation stable until this all settles down.
3476 return false;
3477 }
3478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 long ident = Binder.clearCallingIdentity();
3481 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003482 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 mForcedAppOrientation = req;
3486 //send a message to Policy indicating orientation change to take
3487 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003488 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003489 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3490 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3491 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 }
3493 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003494
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003495 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 } finally {
3497 Binder.restoreCallingIdentity(ident);
3498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003499 }
Romain Guy06882f82009-06-10 13:36:04 -07003500
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003501 int computeForcedAppOrientationLocked() {
3502 int req = getOrientationFromWindowsLocked();
3503 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3504 req = getOrientationFromAppTokensLocked();
3505 }
3506 return req;
3507 }
Romain Guy06882f82009-06-10 13:36:04 -07003508
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003509 public void setNewConfiguration(Configuration config) {
3510 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3511 "setNewConfiguration()")) {
3512 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3513 }
3514
3515 synchronized(mWindowMap) {
3516 mCurConfiguration = new Configuration(config);
3517 mWaitingForConfig = false;
3518 performLayoutAndPlaceSurfacesLocked();
3519 }
3520 }
3521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3523 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3524 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003525 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 }
Romain Guy06882f82009-06-10 13:36:04 -07003527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 synchronized(mWindowMap) {
3529 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3530 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003531 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 return;
3533 }
Romain Guy06882f82009-06-10 13:36:04 -07003534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 wtoken.requestedOrientation = requestedOrientation;
3536 }
3537 }
Romain Guy06882f82009-06-10 13:36:04 -07003538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 public int getAppOrientation(IApplicationToken token) {
3540 synchronized(mWindowMap) {
3541 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3542 if (wtoken == null) {
3543 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3544 }
Romain Guy06882f82009-06-10 13:36:04 -07003545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 return wtoken.requestedOrientation;
3547 }
3548 }
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3551 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3552 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003553 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 }
3555
3556 synchronized(mWindowMap) {
3557 boolean changed = false;
3558 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003559 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 changed = mFocusedApp != null;
3561 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003562 if (changed) {
3563 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003565 } else {
3566 AppWindowToken newFocus = findAppWindowToken(token);
3567 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003568 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003569 return;
3570 }
3571 changed = mFocusedApp != newFocus;
3572 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003573 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003574 if (changed) {
3575 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 }
3578
3579 if (moveFocusNow && changed) {
3580 final long origId = Binder.clearCallingIdentity();
3581 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3582 Binder.restoreCallingIdentity(origId);
3583 }
3584 }
3585 }
3586
3587 public void prepareAppTransition(int transit) {
3588 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3589 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003590 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 }
Romain Guy06882f82009-06-10 13:36:04 -07003592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003594 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 TAG, "Prepare app transition: transit=" + transit
3596 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003597 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003598 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3599 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003601 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3602 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3603 // Opening a new task always supersedes a close for the anim.
3604 mNextAppTransition = transit;
3605 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3606 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3607 // Opening a new activity always supersedes a close for the anim.
3608 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 }
3610 mAppTransitionReady = false;
3611 mAppTransitionTimeout = false;
3612 mStartingIconInTransition = false;
3613 mSkipAppTransitionAnimation = false;
3614 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3615 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3616 5000);
3617 }
3618 }
3619 }
3620
3621 public int getPendingAppTransition() {
3622 return mNextAppTransition;
3623 }
Romain Guy06882f82009-06-10 13:36:04 -07003624
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003625 public void overridePendingAppTransition(String packageName,
3626 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003627 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003628 mNextAppTransitionPackage = packageName;
3629 mNextAppTransitionEnter = enterAnim;
3630 mNextAppTransitionExit = exitAnim;
3631 }
3632 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 public void executeAppTransition() {
3635 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3636 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003637 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 }
Romain Guy06882f82009-06-10 13:36:04 -07003639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003641 if (DEBUG_APP_TRANSITIONS) {
3642 RuntimeException e = new RuntimeException("here");
3643 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003644 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003645 + mNextAppTransition, e);
3646 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003647 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 mAppTransitionReady = true;
3649 final long origId = Binder.clearCallingIdentity();
3650 performLayoutAndPlaceSurfacesLocked();
3651 Binder.restoreCallingIdentity(origId);
3652 }
3653 }
3654 }
3655
3656 public void setAppStartingWindow(IBinder token, String pkg,
3657 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3658 IBinder transferFrom, boolean createIfNeeded) {
3659 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3660 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003661 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 }
3663
3664 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003665 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003666 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3667 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 AppWindowToken wtoken = findAppWindowToken(token);
3670 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003671 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 return;
3673 }
3674
3675 // If the display is frozen, we won't do anything until the
3676 // actual window is displayed so there is no reason to put in
3677 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003678 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 return;
3680 }
Romain Guy06882f82009-06-10 13:36:04 -07003681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 if (wtoken.startingData != null) {
3683 return;
3684 }
Romain Guy06882f82009-06-10 13:36:04 -07003685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 if (transferFrom != null) {
3687 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3688 if (ttoken != null) {
3689 WindowState startingWindow = ttoken.startingWindow;
3690 if (startingWindow != null) {
3691 if (mStartingIconInTransition) {
3692 // In this case, the starting icon has already
3693 // been displayed, so start letting windows get
3694 // shown immediately without any more transitions.
3695 mSkipAppTransitionAnimation = true;
3696 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003697 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 "Moving existing starting from " + ttoken
3699 + " to " + wtoken);
3700 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 // Transfer the starting window over to the new
3703 // token.
3704 wtoken.startingData = ttoken.startingData;
3705 wtoken.startingView = ttoken.startingView;
3706 wtoken.startingWindow = startingWindow;
3707 ttoken.startingData = null;
3708 ttoken.startingView = null;
3709 ttoken.startingWindow = null;
3710 ttoken.startingMoved = true;
3711 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003712 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003714 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003715 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003716 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003717 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 ttoken.windows.remove(startingWindow);
3719 ttoken.allAppWindows.remove(startingWindow);
3720 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 // Propagate other interesting state between the
3723 // tokens. If the old token is displayed, we should
3724 // immediately force the new one to be displayed. If
3725 // it is animating, we need to move that animation to
3726 // the new one.
3727 if (ttoken.allDrawn) {
3728 wtoken.allDrawn = true;
3729 }
3730 if (ttoken.firstWindowDrawn) {
3731 wtoken.firstWindowDrawn = true;
3732 }
3733 if (!ttoken.hidden) {
3734 wtoken.hidden = false;
3735 wtoken.hiddenRequested = false;
3736 wtoken.willBeHidden = false;
3737 }
3738 if (wtoken.clientHidden != ttoken.clientHidden) {
3739 wtoken.clientHidden = ttoken.clientHidden;
3740 wtoken.sendAppVisibilityToClients();
3741 }
3742 if (ttoken.animation != null) {
3743 wtoken.animation = ttoken.animation;
3744 wtoken.animating = ttoken.animating;
3745 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3746 ttoken.animation = null;
3747 ttoken.animLayerAdjustment = 0;
3748 wtoken.updateLayers();
3749 ttoken.updateLayers();
3750 }
Romain Guy06882f82009-06-10 13:36:04 -07003751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 mLayoutNeeded = true;
3754 performLayoutAndPlaceSurfacesLocked();
3755 Binder.restoreCallingIdentity(origId);
3756 return;
3757 } else if (ttoken.startingData != null) {
3758 // The previous app was getting ready to show a
3759 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003760 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 "Moving pending starting from " + ttoken
3762 + " to " + wtoken);
3763 wtoken.startingData = ttoken.startingData;
3764 ttoken.startingData = null;
3765 ttoken.startingMoved = true;
3766 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3767 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3768 // want to process the message ASAP, before any other queued
3769 // messages.
3770 mH.sendMessageAtFrontOfQueue(m);
3771 return;
3772 }
3773 }
3774 }
3775
3776 // There is no existing starting window, and the caller doesn't
3777 // want us to create one, so that's it!
3778 if (!createIfNeeded) {
3779 return;
3780 }
Romain Guy06882f82009-06-10 13:36:04 -07003781
Dianne Hackborn284ac932009-08-28 10:34:25 -07003782 // If this is a translucent or wallpaper window, then don't
3783 // show a starting window -- the current effect (a full-screen
3784 // opaque starting window that fades away to the real contents
3785 // when it is ready) does not work for this.
3786 if (theme != 0) {
3787 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3788 com.android.internal.R.styleable.Window);
3789 if (ent.array.getBoolean(
3790 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3791 return;
3792 }
3793 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003794 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3795 return;
3796 }
3797 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003798 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3799 return;
3800 }
3801 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 mStartingIconInTransition = true;
3804 wtoken.startingData = new StartingData(
3805 pkg, theme, nonLocalizedLabel,
3806 labelRes, icon);
3807 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3808 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3809 // want to process the message ASAP, before any other queued
3810 // messages.
3811 mH.sendMessageAtFrontOfQueue(m);
3812 }
3813 }
3814
3815 public void setAppWillBeHidden(IBinder token) {
3816 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3817 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003818 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 }
3820
3821 AppWindowToken wtoken;
3822
3823 synchronized(mWindowMap) {
3824 wtoken = findAppWindowToken(token);
3825 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003826 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 -08003827 return;
3828 }
3829 wtoken.willBeHidden = true;
3830 }
3831 }
Romain Guy06882f82009-06-10 13:36:04 -07003832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3834 boolean visible, int transit, boolean performLayout) {
3835 boolean delayed = false;
3836
3837 if (wtoken.clientHidden == visible) {
3838 wtoken.clientHidden = !visible;
3839 wtoken.sendAppVisibilityToClients();
3840 }
Romain Guy06882f82009-06-10 13:36:04 -07003841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 wtoken.willBeHidden = false;
3843 if (wtoken.hidden == visible) {
3844 final int N = wtoken.allAppWindows.size();
3845 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003846 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3848 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003850 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003851
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003852 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 if (wtoken.animation == sDummyAnimation) {
3854 wtoken.animation = null;
3855 }
3856 applyAnimationLocked(wtoken, lp, transit, visible);
3857 changed = true;
3858 if (wtoken.animation != null) {
3859 delayed = runningAppAnimation = true;
3860 }
3861 }
Romain Guy06882f82009-06-10 13:36:04 -07003862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 for (int i=0; i<N; i++) {
3864 WindowState win = wtoken.allAppWindows.get(i);
3865 if (win == wtoken.startingWindow) {
3866 continue;
3867 }
3868
3869 if (win.isAnimating()) {
3870 delayed = true;
3871 }
Romain Guy06882f82009-06-10 13:36:04 -07003872
Joe Onorato8a9b2202010-02-26 18:56:32 -08003873 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 //win.dump(" ");
3875 if (visible) {
3876 if (!win.isVisibleNow()) {
3877 if (!runningAppAnimation) {
3878 applyAnimationLocked(win,
3879 WindowManagerPolicy.TRANSIT_ENTER, true);
3880 }
3881 changed = true;
3882 }
3883 } else if (win.isVisibleNow()) {
3884 if (!runningAppAnimation) {
3885 applyAnimationLocked(win,
3886 WindowManagerPolicy.TRANSIT_EXIT, false);
3887 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 changed = true;
3889 }
3890 }
3891
3892 wtoken.hidden = wtoken.hiddenRequested = !visible;
3893 if (!visible) {
3894 unsetAppFreezingScreenLocked(wtoken, true, true);
3895 } else {
3896 // If we are being set visible, and the starting window is
3897 // not yet displayed, then make sure it doesn't get displayed.
3898 WindowState swin = wtoken.startingWindow;
3899 if (swin != null && (swin.mDrawPending
3900 || swin.mCommitDrawPending)) {
3901 swin.mPolicyVisibility = false;
3902 swin.mPolicyVisibilityAfterAnim = false;
3903 }
3904 }
Romain Guy06882f82009-06-10 13:36:04 -07003905
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3908 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003909
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003910 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003912 if (performLayout) {
3913 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3914 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003915 } else {
3916 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 }
3919 }
3920
3921 if (wtoken.animation != null) {
3922 delayed = true;
3923 }
Romain Guy06882f82009-06-10 13:36:04 -07003924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 return delayed;
3926 }
3927
3928 public void setAppVisibility(IBinder token, boolean visible) {
3929 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3930 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003931 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 }
3933
3934 AppWindowToken wtoken;
3935
3936 synchronized(mWindowMap) {
3937 wtoken = findAppWindowToken(token);
3938 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003939 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 return;
3941 }
3942
3943 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003944 RuntimeException e = null;
3945 if (!HIDE_STACK_CRAWLS) {
3946 e = new RuntimeException();
3947 e.fillInStackTrace();
3948 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003949 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 + "): mNextAppTransition=" + mNextAppTransition
3951 + " hidden=" + wtoken.hidden
3952 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3953 }
Romain Guy06882f82009-06-10 13:36:04 -07003954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 // If we are preparing an app transition, then delay changing
3956 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003957 if (!mDisplayFrozen && mPolicy.isScreenOn()
3958 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959 // Already in requested state, don't do anything more.
3960 if (wtoken.hiddenRequested != visible) {
3961 return;
3962 }
3963 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003964
Joe Onorato8a9b2202010-02-26 18:56:32 -08003965 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 TAG, "Setting dummy animation on: " + wtoken);
3967 wtoken.setDummyAnimation();
3968 mOpeningApps.remove(wtoken);
3969 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003970 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 wtoken.inPendingTransaction = true;
3972 if (visible) {
3973 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974 wtoken.startingDisplayed = false;
3975 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003976
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003977 // If the token is currently hidden (should be the
3978 // common case), then we need to set up to wait for
3979 // its windows to be ready.
3980 if (wtoken.hidden) {
3981 wtoken.allDrawn = false;
3982 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003983
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003984 if (wtoken.clientHidden) {
3985 // In the case where we are making an app visible
3986 // but holding off for a transition, we still need
3987 // to tell the client to make its windows visible so
3988 // they get drawn. Otherwise, we will wait on
3989 // performing the transition until all windows have
3990 // been drawn, they never will be, and we are sad.
3991 wtoken.clientHidden = false;
3992 wtoken.sendAppVisibilityToClients();
3993 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 }
3995 } else {
3996 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003997
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003998 // If the token is currently visible (should be the
3999 // common case), then set up to wait for it to be hidden.
4000 if (!wtoken.hidden) {
4001 wtoken.waitingToHide = true;
4002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 }
4004 return;
4005 }
Romain Guy06882f82009-06-10 13:36:04 -07004006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004008 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 wtoken.updateReportedVisibilityLocked();
4010 Binder.restoreCallingIdentity(origId);
4011 }
4012 }
4013
4014 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4015 boolean unfreezeSurfaceNow, boolean force) {
4016 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004017 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004018 + " force=" + force);
4019 final int N = wtoken.allAppWindows.size();
4020 boolean unfrozeWindows = false;
4021 for (int i=0; i<N; i++) {
4022 WindowState w = wtoken.allAppWindows.get(i);
4023 if (w.mAppFreezing) {
4024 w.mAppFreezing = false;
4025 if (w.mSurface != null && !w.mOrientationChanging) {
4026 w.mOrientationChanging = true;
4027 }
4028 unfrozeWindows = true;
4029 }
4030 }
4031 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004032 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 wtoken.freezingScreen = false;
4034 mAppsFreezingScreen--;
4035 }
4036 if (unfreezeSurfaceNow) {
4037 if (unfrozeWindows) {
4038 mLayoutNeeded = true;
4039 performLayoutAndPlaceSurfacesLocked();
4040 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004041 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004042 }
4043 }
4044 }
Romain Guy06882f82009-06-10 13:36:04 -07004045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004046 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4047 int configChanges) {
4048 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004049 RuntimeException e = null;
4050 if (!HIDE_STACK_CRAWLS) {
4051 e = new RuntimeException();
4052 e.fillInStackTrace();
4053 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004054 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004055 + ": hidden=" + wtoken.hidden + " freezing="
4056 + wtoken.freezingScreen, e);
4057 }
4058 if (!wtoken.hiddenRequested) {
4059 if (!wtoken.freezingScreen) {
4060 wtoken.freezingScreen = true;
4061 mAppsFreezingScreen++;
4062 if (mAppsFreezingScreen == 1) {
4063 startFreezingDisplayLocked();
4064 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4065 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4066 5000);
4067 }
4068 }
4069 final int N = wtoken.allAppWindows.size();
4070 for (int i=0; i<N; i++) {
4071 WindowState w = wtoken.allAppWindows.get(i);
4072 w.mAppFreezing = true;
4073 }
4074 }
4075 }
Romain Guy06882f82009-06-10 13:36:04 -07004076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 public void startAppFreezingScreen(IBinder token, int configChanges) {
4078 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4079 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004080 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 }
4082
4083 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004084 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004085 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 return;
4087 }
Romain Guy06882f82009-06-10 13:36:04 -07004088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004089 AppWindowToken wtoken = findAppWindowToken(token);
4090 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004091 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 return;
4093 }
4094 final long origId = Binder.clearCallingIdentity();
4095 startAppFreezingScreenLocked(wtoken, configChanges);
4096 Binder.restoreCallingIdentity(origId);
4097 }
4098 }
Romain Guy06882f82009-06-10 13:36:04 -07004099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 public void stopAppFreezingScreen(IBinder token, boolean force) {
4101 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4102 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004103 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004104 }
4105
4106 synchronized(mWindowMap) {
4107 AppWindowToken wtoken = findAppWindowToken(token);
4108 if (wtoken == null || wtoken.appToken == null) {
4109 return;
4110 }
4111 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004112 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4114 unsetAppFreezingScreenLocked(wtoken, true, force);
4115 Binder.restoreCallingIdentity(origId);
4116 }
4117 }
Romain Guy06882f82009-06-10 13:36:04 -07004118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 public void removeAppToken(IBinder token) {
4120 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4121 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004122 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 }
4124
4125 AppWindowToken wtoken = null;
4126 AppWindowToken startingToken = null;
4127 boolean delayed = false;
4128
4129 final long origId = Binder.clearCallingIdentity();
4130 synchronized(mWindowMap) {
4131 WindowToken basewtoken = mTokenMap.remove(token);
4132 mTokenList.remove(basewtoken);
4133 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004134 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004135 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 wtoken.inPendingTransaction = false;
4137 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004138 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004139 if (mClosingApps.contains(wtoken)) {
4140 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004141 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004143 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004144 delayed = true;
4145 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004146 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 TAG, "Removing app " + wtoken + " delayed=" + delayed
4148 + " animation=" + wtoken.animation
4149 + " animating=" + wtoken.animating);
4150 if (delayed) {
4151 // set the token aside because it has an active animation to be finished
4152 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004153 } else {
4154 // Make sure there is no animation running on this token,
4155 // so any windows associated with it will be removed as
4156 // soon as their animations are complete
4157 wtoken.animation = null;
4158 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004159 }
4160 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004161 if (mLastEnterAnimToken == wtoken) {
4162 mLastEnterAnimToken = null;
4163 mLastEnterAnimParams = null;
4164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 wtoken.removed = true;
4166 if (wtoken.startingData != null) {
4167 startingToken = wtoken;
4168 }
4169 unsetAppFreezingScreenLocked(wtoken, true, true);
4170 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004171 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 mFocusedApp = null;
4173 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004174 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 }
4176 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004177 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004178 }
Romain Guy06882f82009-06-10 13:36:04 -07004179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 if (!delayed && wtoken != null) {
4181 wtoken.updateReportedVisibilityLocked();
4182 }
4183 }
4184 Binder.restoreCallingIdentity(origId);
4185
4186 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004187 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 + startingToken + ": app token removed");
4189 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4190 mH.sendMessage(m);
4191 }
4192 }
4193
4194 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4195 final int NW = token.windows.size();
4196 for (int i=0; i<NW; i++) {
4197 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004200 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 int j = win.mChildWindows.size();
4202 while (j > 0) {
4203 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004204 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004205 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004206 "Tmp removing child window " + cwin);
4207 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 }
4209 }
4210 return NW > 0;
4211 }
4212
4213 void dumpAppTokensLocked() {
4214 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004215 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 }
4217 }
Romain Guy06882f82009-06-10 13:36:04 -07004218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 void dumpWindowsLocked() {
4220 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004221 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 }
4223 }
Romain Guy06882f82009-06-10 13:36:04 -07004224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 private int findWindowOffsetLocked(int tokenPos) {
4226 final int NW = mWindows.size();
4227
4228 if (tokenPos >= mAppTokens.size()) {
4229 int i = NW;
4230 while (i > 0) {
4231 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004232 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004233 if (win.getAppToken() != null) {
4234 return i+1;
4235 }
4236 }
4237 }
4238
4239 while (tokenPos > 0) {
4240 // Find the first app token below the new position that has
4241 // a window displayed.
4242 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004243 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004245 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004246 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004247 "Skipping token -- currently sending to bottom");
4248 tokenPos--;
4249 continue;
4250 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 int i = wtoken.windows.size();
4252 while (i > 0) {
4253 i--;
4254 WindowState win = wtoken.windows.get(i);
4255 int j = win.mChildWindows.size();
4256 while (j > 0) {
4257 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004258 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004259 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 for (int pos=NW-1; pos>=0; pos--) {
4261 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004262 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004263 "Found child win @" + (pos+1));
4264 return pos+1;
4265 }
4266 }
4267 }
4268 }
4269 for (int pos=NW-1; pos>=0; pos--) {
4270 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004271 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 return pos+1;
4273 }
4274 }
4275 }
4276 tokenPos--;
4277 }
4278
4279 return 0;
4280 }
4281
4282 private final int reAddWindowLocked(int index, WindowState win) {
4283 final int NCW = win.mChildWindows.size();
4284 boolean added = false;
4285 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004286 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004288 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004289 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 mWindows.add(index, win);
4291 index++;
4292 added = true;
4293 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004294 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004295 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 mWindows.add(index, cwin);
4297 index++;
4298 }
4299 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004300 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004301 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 mWindows.add(index, win);
4303 index++;
4304 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004305 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 return index;
4307 }
Romain Guy06882f82009-06-10 13:36:04 -07004308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4310 final int NW = token.windows.size();
4311 for (int i=0; i<NW; i++) {
4312 index = reAddWindowLocked(index, token.windows.get(i));
4313 }
4314 return index;
4315 }
4316
4317 public void moveAppToken(int index, IBinder token) {
4318 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4319 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004320 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 }
4322
4323 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004324 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 if (DEBUG_REORDER) dumpAppTokensLocked();
4326 final AppWindowToken wtoken = findAppWindowToken(token);
4327 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004328 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 + token + " (" + wtoken + ")");
4330 return;
4331 }
4332 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004333 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004337 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004338 if (DEBUG_REORDER) dumpWindowsLocked();
4339 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004340 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004341 if (DEBUG_REORDER) dumpWindowsLocked();
4342 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004343 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 if (DEBUG_REORDER) dumpWindowsLocked();
4345 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 mLayoutNeeded = true;
4347 performLayoutAndPlaceSurfacesLocked();
4348 }
4349 Binder.restoreCallingIdentity(origId);
4350 }
4351 }
4352
4353 private void removeAppTokensLocked(List<IBinder> tokens) {
4354 // XXX This should be done more efficiently!
4355 // (take advantage of the fact that both lists should be
4356 // ordered in the same way.)
4357 int N = tokens.size();
4358 for (int i=0; i<N; i++) {
4359 IBinder token = tokens.get(i);
4360 final AppWindowToken wtoken = findAppWindowToken(token);
4361 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 + token + " (" + wtoken + ")");
4364 i--;
4365 N--;
4366 }
4367 }
4368 }
4369
Dianne Hackborna8f60182009-09-01 19:01:50 -07004370 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4371 boolean updateFocusAndLayout) {
4372 // First remove all of the windows from the list.
4373 tmpRemoveAppWindowsLocked(wtoken);
4374
4375 // Where to start adding?
4376 int pos = findWindowOffsetLocked(tokenPos);
4377
4378 // And now add them back at the correct place.
4379 pos = reAddAppWindowsLocked(pos, wtoken);
4380
4381 if (updateFocusAndLayout) {
4382 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4383 assignLayersLocked();
4384 }
4385 mLayoutNeeded = true;
4386 performLayoutAndPlaceSurfacesLocked();
4387 }
4388 }
4389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4391 // First remove all of the windows from the list.
4392 final int N = tokens.size();
4393 int i;
4394 for (i=0; i<N; i++) {
4395 WindowToken token = mTokenMap.get(tokens.get(i));
4396 if (token != null) {
4397 tmpRemoveAppWindowsLocked(token);
4398 }
4399 }
4400
4401 // Where to start adding?
4402 int pos = findWindowOffsetLocked(tokenPos);
4403
4404 // And now add them back at the correct place.
4405 for (i=0; i<N; i++) {
4406 WindowToken token = mTokenMap.get(tokens.get(i));
4407 if (token != null) {
4408 pos = reAddAppWindowsLocked(pos, token);
4409 }
4410 }
4411
Dianne Hackborna8f60182009-09-01 19:01:50 -07004412 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4413 assignLayersLocked();
4414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 mLayoutNeeded = true;
4416 performLayoutAndPlaceSurfacesLocked();
4417
4418 //dump();
4419 }
4420
4421 public void moveAppTokensToTop(List<IBinder> tokens) {
4422 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4423 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004424 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 }
4426
4427 final long origId = Binder.clearCallingIdentity();
4428 synchronized(mWindowMap) {
4429 removeAppTokensLocked(tokens);
4430 final int N = tokens.size();
4431 for (int i=0; i<N; i++) {
4432 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4433 if (wt != null) {
4434 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004435 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004436 mToTopApps.remove(wt);
4437 mToBottomApps.remove(wt);
4438 mToTopApps.add(wt);
4439 wt.sendingToBottom = false;
4440 wt.sendingToTop = true;
4441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004442 }
4443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004444
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004445 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004446 moveAppWindowsLocked(tokens, mAppTokens.size());
4447 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 }
4449 Binder.restoreCallingIdentity(origId);
4450 }
4451
4452 public void moveAppTokensToBottom(List<IBinder> tokens) {
4453 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4454 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004455 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
4457
4458 final long origId = Binder.clearCallingIdentity();
4459 synchronized(mWindowMap) {
4460 removeAppTokensLocked(tokens);
4461 final int N = tokens.size();
4462 int pos = 0;
4463 for (int i=0; i<N; i++) {
4464 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4465 if (wt != null) {
4466 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004467 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004468 mToTopApps.remove(wt);
4469 mToBottomApps.remove(wt);
4470 mToBottomApps.add(i, wt);
4471 wt.sendingToTop = false;
4472 wt.sendingToBottom = true;
4473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 pos++;
4475 }
4476 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004477
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004478 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004479 moveAppWindowsLocked(tokens, 0);
4480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 }
4482 Binder.restoreCallingIdentity(origId);
4483 }
4484
4485 // -------------------------------------------------------------
4486 // Misc IWindowSession methods
4487 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004488
Jim Miller284b62e2010-06-08 14:27:42 -07004489 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004490 {
Jim Miller284b62e2010-06-08 14:27:42 -07004491 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4492 // called before DevicePolicyManagerService has started.
4493 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4494 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4495 Context.DEVICE_POLICY_SERVICE);
4496 if (dpm != null) {
4497 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4498 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4499 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4500 }
Jim Millerd6b57052010-06-07 17:52:42 -07004501 }
Jim Miller284b62e2010-06-08 14:27:42 -07004502 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004503 }
4504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004506 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 != PackageManager.PERMISSION_GRANTED) {
4508 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4509 }
Jim Millerd6b57052010-06-07 17:52:42 -07004510
Jim Miller284b62e2010-06-08 14:27:42 -07004511 synchronized (mKeyguardTokenWatcher) {
4512 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 }
4515
4516 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004517 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004518 != PackageManager.PERMISSION_GRANTED) {
4519 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521
Jim Miller284b62e2010-06-08 14:27:42 -07004522 synchronized (mKeyguardTokenWatcher) {
4523 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004524
Jim Miller284b62e2010-06-08 14:27:42 -07004525 if (!mKeyguardTokenWatcher.isAcquired()) {
4526 // If we are the last one to reenable the keyguard wait until
4527 // we have actually finished reenabling until returning.
4528 // It is possible that reenableKeyguard() can be called before
4529 // the previous disableKeyguard() is handled, in which case
4530 // neither mKeyguardTokenWatcher.acquired() or released() would
4531 // be called. In that case mKeyguardDisabled will be false here
4532 // and we have nothing to wait for.
4533 while (mKeyguardDisabled) {
4534 try {
4535 mKeyguardTokenWatcher.wait();
4536 } catch (InterruptedException e) {
4537 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 }
4539 }
4540 }
4541 }
4542 }
4543
4544 /**
4545 * @see android.app.KeyguardManager#exitKeyguardSecurely
4546 */
4547 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004548 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004549 != PackageManager.PERMISSION_GRANTED) {
4550 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4551 }
4552 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4553 public void onKeyguardExitResult(boolean success) {
4554 try {
4555 callback.onKeyguardExitResult(success);
4556 } catch (RemoteException e) {
4557 // Client has died, we don't care.
4558 }
4559 }
4560 });
4561 }
4562
4563 public boolean inKeyguardRestrictedInputMode() {
4564 return mPolicy.inKeyguardRestrictedKeyInputMode();
4565 }
Romain Guy06882f82009-06-10 13:36:04 -07004566
Dianne Hackbornffa42482009-09-23 22:20:11 -07004567 public void closeSystemDialogs(String reason) {
4568 synchronized(mWindowMap) {
4569 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004570 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004571 if (w.mSurface != null) {
4572 try {
4573 w.mClient.closeSystemDialogs(reason);
4574 } catch (RemoteException e) {
4575 }
4576 }
4577 }
4578 }
4579 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 static float fixScale(float scale) {
4582 if (scale < 0) scale = 0;
4583 else if (scale > 20) scale = 20;
4584 return Math.abs(scale);
4585 }
Romain Guy06882f82009-06-10 13:36:04 -07004586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004587 public void setAnimationScale(int which, float scale) {
4588 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4589 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004590 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004591 }
4592
4593 if (scale < 0) scale = 0;
4594 else if (scale > 20) scale = 20;
4595 scale = Math.abs(scale);
4596 switch (which) {
4597 case 0: mWindowAnimationScale = fixScale(scale); break;
4598 case 1: mTransitionAnimationScale = fixScale(scale); break;
4599 }
Romain Guy06882f82009-06-10 13:36:04 -07004600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004601 // Persist setting
4602 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4603 }
Romain Guy06882f82009-06-10 13:36:04 -07004604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004605 public void setAnimationScales(float[] scales) {
4606 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4607 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004608 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004609 }
4610
4611 if (scales != null) {
4612 if (scales.length >= 1) {
4613 mWindowAnimationScale = fixScale(scales[0]);
4614 }
4615 if (scales.length >= 2) {
4616 mTransitionAnimationScale = fixScale(scales[1]);
4617 }
4618 }
Romain Guy06882f82009-06-10 13:36:04 -07004619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 // Persist setting
4621 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4622 }
Romain Guy06882f82009-06-10 13:36:04 -07004623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 public float getAnimationScale(int which) {
4625 switch (which) {
4626 case 0: return mWindowAnimationScale;
4627 case 1: return mTransitionAnimationScale;
4628 }
4629 return 0;
4630 }
Romain Guy06882f82009-06-10 13:36:04 -07004631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 public float[] getAnimationScales() {
4633 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4634 }
Romain Guy06882f82009-06-10 13:36:04 -07004635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004636 public int getSwitchState(int sw) {
4637 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4638 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004639 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004641 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 }
Romain Guy06882f82009-06-10 13:36:04 -07004643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004644 public int getSwitchStateForDevice(int devid, int sw) {
4645 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4646 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004647 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004648 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004649 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004650 }
Romain Guy06882f82009-06-10 13:36:04 -07004651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004652 public int getScancodeState(int sw) {
4653 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4654 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004655 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004656 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004657 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 }
Romain Guy06882f82009-06-10 13:36:04 -07004659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 public int getScancodeStateForDevice(int devid, int sw) {
4661 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4662 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004663 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004665 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 }
Romain Guy06882f82009-06-10 13:36:04 -07004667
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004668 public int getTrackballScancodeState(int sw) {
4669 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4670 "getTrackballScancodeState()")) {
4671 throw new SecurityException("Requires READ_INPUT_STATE permission");
4672 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004673 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004674 }
4675
4676 public int getDPadScancodeState(int sw) {
4677 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4678 "getDPadScancodeState()")) {
4679 throw new SecurityException("Requires READ_INPUT_STATE permission");
4680 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004681 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004682 }
4683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 public int getKeycodeState(int sw) {
4685 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4686 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004687 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004689 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004690 }
Romain Guy06882f82009-06-10 13:36:04 -07004691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004692 public int getKeycodeStateForDevice(int devid, int sw) {
4693 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4694 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004695 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004697 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004698 }
Romain Guy06882f82009-06-10 13:36:04 -07004699
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004700 public int getTrackballKeycodeState(int sw) {
4701 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4702 "getTrackballKeycodeState()")) {
4703 throw new SecurityException("Requires READ_INPUT_STATE permission");
4704 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004705 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004706 }
4707
4708 public int getDPadKeycodeState(int sw) {
4709 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4710 "getDPadKeycodeState()")) {
4711 throw new SecurityException("Requires READ_INPUT_STATE permission");
4712 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004713 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004714 }
Jeff Browna41ca772010-08-11 14:46:32 -07004715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004717 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 }
Romain Guy06882f82009-06-10 13:36:04 -07004719
Jeff Browna41ca772010-08-11 14:46:32 -07004720 public InputChannel monitorInput(String inputChannelName) {
4721 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4722 "monitorInput()")) {
4723 throw new SecurityException("Requires READ_INPUT_STATE permission");
4724 }
4725 return mInputManager.monitorInput(inputChannelName);
4726 }
4727
Jeff Brown8d608662010-08-30 03:02:23 -07004728 public InputDevice getInputDevice(int deviceId) {
4729 return mInputManager.getInputDevice(deviceId);
4730 }
4731
4732 public int[] getInputDeviceIds() {
4733 return mInputManager.getInputDeviceIds();
4734 }
4735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004736 public void enableScreenAfterBoot() {
4737 synchronized(mWindowMap) {
4738 if (mSystemBooted) {
4739 return;
4740 }
4741 mSystemBooted = true;
4742 }
Romain Guy06882f82009-06-10 13:36:04 -07004743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004744 performEnableScreen();
4745 }
Romain Guy06882f82009-06-10 13:36:04 -07004746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004747 public void enableScreenIfNeededLocked() {
4748 if (mDisplayEnabled) {
4749 return;
4750 }
4751 if (!mSystemBooted) {
4752 return;
4753 }
4754 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4755 }
Romain Guy06882f82009-06-10 13:36:04 -07004756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004757 public void performEnableScreen() {
4758 synchronized(mWindowMap) {
4759 if (mDisplayEnabled) {
4760 return;
4761 }
4762 if (!mSystemBooted) {
4763 return;
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 // Don't enable the screen until all existing windows
4767 // have been drawn.
4768 final int N = mWindows.size();
4769 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004770 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004771 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004772 return;
4773 }
4774 }
Romain Guy06882f82009-06-10 13:36:04 -07004775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 mDisplayEnabled = true;
4777 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004778 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004779 StringWriter sw = new StringWriter();
4780 PrintWriter pw = new PrintWriter(sw);
4781 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004782 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 }
4784 try {
4785 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4786 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004787 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 Parcel data = Parcel.obtain();
4789 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4790 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4791 data, null, 0);
4792 data.recycle();
4793 }
4794 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004795 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 }
4797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004802 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4803 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 }
Romain Guy06882f82009-06-10 13:36:04 -07004805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004806 public void setInTouchMode(boolean mode) {
4807 synchronized(mWindowMap) {
4808 mInTouchMode = mode;
4809 }
4810 }
4811
Romain Guy06882f82009-06-10 13:36:04 -07004812 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004813 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004814 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004815 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004816 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004817 }
4818
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004819 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820 }
Romain Guy06882f82009-06-10 13:36:04 -07004821
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004822 public void setRotationUnchecked(int rotation,
4823 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004824 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 long origId = Binder.clearCallingIdentity();
4828 boolean changed;
4829 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004830 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 }
Romain Guy06882f82009-06-10 13:36:04 -07004832
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004833 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834 sendNewConfiguration();
4835 }
Romain Guy06882f82009-06-10 13:36:04 -07004836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 Binder.restoreCallingIdentity(origId);
4838 }
Romain Guy06882f82009-06-10 13:36:04 -07004839
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004840 /**
4841 * Apply a new rotation to the screen, respecting the requests of
4842 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4843 * re-evaluate the desired rotation.
4844 *
4845 * Returns null if the rotation has been changed. In this case YOU
4846 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4847 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004848 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849 boolean changed;
4850 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4851 rotation = mRequestedRotation;
4852 } else {
4853 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004854 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004856 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004857 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004858 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004859 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004863 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 "Rotation changed to " + rotation
4865 + " from " + mRotation
4866 + " (forceApp=" + mForcedAppOrientation
4867 + ", req=" + mRequestedRotation + ")");
4868 mRotation = rotation;
4869 mWindowsFreezingScreen = true;
4870 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4871 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4872 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004873 mWaitingForConfig = true;
4874 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004876 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004877 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004878 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004879 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 }
4881 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004882 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 if (w.mSurface != null) {
4884 w.mOrientationChanging = true;
4885 }
4886 }
4887 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4888 try {
4889 mRotationWatchers.get(i).onRotationChanged(rotation);
4890 } catch (RemoteException e) {
4891 }
4892 }
4893 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 return changed;
4896 }
Romain Guy06882f82009-06-10 13:36:04 -07004897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 public int getRotation() {
4899 return mRotation;
4900 }
4901
4902 public int watchRotation(IRotationWatcher watcher) {
4903 final IBinder watcherBinder = watcher.asBinder();
4904 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4905 public void binderDied() {
4906 synchronized (mWindowMap) {
4907 for (int i=0; i<mRotationWatchers.size(); i++) {
4908 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004909 IRotationWatcher removed = mRotationWatchers.remove(i);
4910 if (removed != null) {
4911 removed.asBinder().unlinkToDeath(this, 0);
4912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 i--;
4914 }
4915 }
4916 }
4917 }
4918 };
Romain Guy06882f82009-06-10 13:36:04 -07004919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 synchronized (mWindowMap) {
4921 try {
4922 watcher.asBinder().linkToDeath(dr, 0);
4923 mRotationWatchers.add(watcher);
4924 } catch (RemoteException e) {
4925 // Client died, no cleanup needed.
4926 }
Romain Guy06882f82009-06-10 13:36:04 -07004927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 return mRotation;
4929 }
4930 }
4931
4932 /**
4933 * Starts the view server on the specified port.
4934 *
4935 * @param port The port to listener to.
4936 *
4937 * @return True if the server was successfully started, false otherwise.
4938 *
4939 * @see com.android.server.ViewServer
4940 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4941 */
4942 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004943 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004944 return false;
4945 }
4946
4947 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4948 return false;
4949 }
4950
4951 if (port < 1024) {
4952 return false;
4953 }
4954
4955 if (mViewServer != null) {
4956 if (!mViewServer.isRunning()) {
4957 try {
4958 return mViewServer.start();
4959 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004960 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961 }
4962 }
4963 return false;
4964 }
4965
4966 try {
4967 mViewServer = new ViewServer(this, port);
4968 return mViewServer.start();
4969 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004970 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004971 }
4972 return false;
4973 }
4974
Romain Guy06882f82009-06-10 13:36:04 -07004975 private boolean isSystemSecure() {
4976 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4977 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4978 }
4979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 /**
4981 * Stops the view server if it exists.
4982 *
4983 * @return True if the server stopped, false if it wasn't started or
4984 * couldn't be stopped.
4985 *
4986 * @see com.android.server.ViewServer
4987 */
4988 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004989 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004990 return false;
4991 }
4992
4993 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4994 return false;
4995 }
4996
4997 if (mViewServer != null) {
4998 return mViewServer.stop();
4999 }
5000 return false;
5001 }
5002
5003 /**
5004 * Indicates whether the view server is running.
5005 *
5006 * @return True if the server is running, false otherwise.
5007 *
5008 * @see com.android.server.ViewServer
5009 */
5010 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005011 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005012 return false;
5013 }
5014
5015 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5016 return false;
5017 }
5018
5019 return mViewServer != null && mViewServer.isRunning();
5020 }
5021
5022 /**
5023 * Lists all availble windows in the system. The listing is written in the
5024 * specified Socket's output stream with the following syntax:
5025 * windowHashCodeInHexadecimal windowName
5026 * Each line of the ouput represents a different window.
5027 *
5028 * @param client The remote client to send the listing to.
5029 * @return False if an error occured, true otherwise.
5030 */
5031 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005032 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 return false;
5034 }
5035
5036 boolean result = true;
5037
Jeff Browne33348b2010-07-15 23:54:05 -07005038 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005039 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005040 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005041 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005042 }
5043
5044 BufferedWriter out = null;
5045
5046 // Any uncaught exception will crash the system process
5047 try {
5048 OutputStream clientStream = client.getOutputStream();
5049 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5050
5051 final int count = windows.length;
5052 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005053 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005054 out.write(Integer.toHexString(System.identityHashCode(w)));
5055 out.write(' ');
5056 out.append(w.mAttrs.getTitle());
5057 out.write('\n');
5058 }
5059
5060 out.write("DONE.\n");
5061 out.flush();
5062 } catch (Exception e) {
5063 result = false;
5064 } finally {
5065 if (out != null) {
5066 try {
5067 out.close();
5068 } catch (IOException e) {
5069 result = false;
5070 }
5071 }
5072 }
5073
5074 return result;
5075 }
5076
5077 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005078 * Returns the focused window in the following format:
5079 * windowHashCodeInHexadecimal windowName
5080 *
5081 * @param client The remote client to send the listing to.
5082 * @return False if an error occurred, true otherwise.
5083 */
5084 boolean viewServerGetFocusedWindow(Socket client) {
5085 if (isSystemSecure()) {
5086 return false;
5087 }
5088
5089 boolean result = true;
5090
5091 WindowState focusedWindow = getFocusedWindow();
5092
5093 BufferedWriter out = null;
5094
5095 // Any uncaught exception will crash the system process
5096 try {
5097 OutputStream clientStream = client.getOutputStream();
5098 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5099
5100 if(focusedWindow != null) {
5101 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5102 out.write(' ');
5103 out.append(focusedWindow.mAttrs.getTitle());
5104 }
5105 out.write('\n');
5106 out.flush();
5107 } catch (Exception e) {
5108 result = false;
5109 } finally {
5110 if (out != null) {
5111 try {
5112 out.close();
5113 } catch (IOException e) {
5114 result = false;
5115 }
5116 }
5117 }
5118
5119 return result;
5120 }
5121
5122 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005123 * Sends a command to a target window. The result of the command, if any, will be
5124 * written in the output stream of the specified socket.
5125 *
5126 * The parameters must follow this syntax:
5127 * windowHashcode extra
5128 *
5129 * Where XX is the length in characeters of the windowTitle.
5130 *
5131 * The first parameter is the target window. The window with the specified hashcode
5132 * will be the target. If no target can be found, nothing happens. The extra parameters
5133 * will be delivered to the target window and as parameters to the command itself.
5134 *
5135 * @param client The remote client to sent the result, if any, to.
5136 * @param command The command to execute.
5137 * @param parameters The command parameters.
5138 *
5139 * @return True if the command was successfully delivered, false otherwise. This does
5140 * not indicate whether the command itself was successful.
5141 */
5142 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005143 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005144 return false;
5145 }
5146
5147 boolean success = true;
5148 Parcel data = null;
5149 Parcel reply = null;
5150
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005151 BufferedWriter out = null;
5152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005153 // Any uncaught exception will crash the system process
5154 try {
5155 // Find the hashcode of the window
5156 int index = parameters.indexOf(' ');
5157 if (index == -1) {
5158 index = parameters.length();
5159 }
5160 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005161 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005162
5163 // Extract the command's parameter after the window description
5164 if (index < parameters.length()) {
5165 parameters = parameters.substring(index + 1);
5166 } else {
5167 parameters = "";
5168 }
5169
5170 final WindowManagerService.WindowState window = findWindow(hashCode);
5171 if (window == null) {
5172 return false;
5173 }
5174
5175 data = Parcel.obtain();
5176 data.writeInterfaceToken("android.view.IWindow");
5177 data.writeString(command);
5178 data.writeString(parameters);
5179 data.writeInt(1);
5180 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5181
5182 reply = Parcel.obtain();
5183
5184 final IBinder binder = window.mClient.asBinder();
5185 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5186 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5187
5188 reply.readException();
5189
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005190 if (!client.isOutputShutdown()) {
5191 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5192 out.write("DONE\n");
5193 out.flush();
5194 }
5195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005197 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 success = false;
5199 } finally {
5200 if (data != null) {
5201 data.recycle();
5202 }
5203 if (reply != null) {
5204 reply.recycle();
5205 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005206 if (out != null) {
5207 try {
5208 out.close();
5209 } catch (IOException e) {
5210
5211 }
5212 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005213 }
5214
5215 return success;
5216 }
5217
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005218 public void addWindowChangeListener(WindowChangeListener listener) {
5219 synchronized(mWindowMap) {
5220 mWindowChangeListeners.add(listener);
5221 }
5222 }
5223
5224 public void removeWindowChangeListener(WindowChangeListener listener) {
5225 synchronized(mWindowMap) {
5226 mWindowChangeListeners.remove(listener);
5227 }
5228 }
5229
5230 private void notifyWindowsChanged() {
5231 WindowChangeListener[] windowChangeListeners;
5232 synchronized(mWindowMap) {
5233 if(mWindowChangeListeners.isEmpty()) {
5234 return;
5235 }
5236 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5237 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5238 }
5239 int N = windowChangeListeners.length;
5240 for(int i = 0; i < N; i++) {
5241 windowChangeListeners[i].windowsChanged();
5242 }
5243 }
5244
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005245 private void notifyFocusChanged() {
5246 WindowChangeListener[] windowChangeListeners;
5247 synchronized(mWindowMap) {
5248 if(mWindowChangeListeners.isEmpty()) {
5249 return;
5250 }
5251 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5252 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5253 }
5254 int N = windowChangeListeners.length;
5255 for(int i = 0; i < N; i++) {
5256 windowChangeListeners[i].focusChanged();
5257 }
5258 }
5259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005260 private WindowState findWindow(int hashCode) {
5261 if (hashCode == -1) {
5262 return getFocusedWindow();
5263 }
5264
5265 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005266 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005267 final int count = windows.size();
5268
5269 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005270 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005271 if (System.identityHashCode(w) == hashCode) {
5272 return w;
5273 }
5274 }
5275 }
5276
5277 return null;
5278 }
5279
5280 /*
5281 * Instruct the Activity Manager to fetch the current configuration and broadcast
5282 * that to config-changed listeners if appropriate.
5283 */
5284 void sendNewConfiguration() {
5285 try {
5286 mActivityManager.updateConfiguration(null);
5287 } catch (RemoteException e) {
5288 }
5289 }
Romain Guy06882f82009-06-10 13:36:04 -07005290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 public Configuration computeNewConfiguration() {
5292 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005293 return computeNewConfigurationLocked();
5294 }
5295 }
Romain Guy06882f82009-06-10 13:36:04 -07005296
Dianne Hackbornc485a602009-03-24 22:39:49 -07005297 Configuration computeNewConfigurationLocked() {
5298 Configuration config = new Configuration();
5299 if (!computeNewConfigurationLocked(config)) {
5300 return null;
5301 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005302 return config;
5303 }
Romain Guy06882f82009-06-10 13:36:04 -07005304
Dianne Hackbornc485a602009-03-24 22:39:49 -07005305 boolean computeNewConfigurationLocked(Configuration config) {
5306 if (mDisplay == null) {
5307 return false;
5308 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005309
5310 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005311
5312 // Use the effective "visual" dimensions based on current rotation
5313 final boolean rotated = (mRotation == Surface.ROTATION_90
5314 || mRotation == Surface.ROTATION_270);
5315 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5316 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5317
Dianne Hackbornc485a602009-03-24 22:39:49 -07005318 int orientation = Configuration.ORIENTATION_SQUARE;
5319 if (dw < dh) {
5320 orientation = Configuration.ORIENTATION_PORTRAIT;
5321 } else if (dw > dh) {
5322 orientation = Configuration.ORIENTATION_LANDSCAPE;
5323 }
5324 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005325
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005326 DisplayMetrics dm = new DisplayMetrics();
5327 mDisplay.getMetrics(dm);
5328 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5329
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005330 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005331 // Note we only do this once because at this point we don't
5332 // expect the screen to change in this way at runtime, and want
5333 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005334 int longSize = dw;
5335 int shortSize = dh;
5336 if (longSize < shortSize) {
5337 int tmp = longSize;
5338 longSize = shortSize;
5339 shortSize = tmp;
5340 }
5341 longSize = (int)(longSize/dm.density);
5342 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005343
Dianne Hackborn723738c2009-06-25 19:48:04 -07005344 // These semi-magic numbers define our compatibility modes for
5345 // applications with different screens. Don't change unless you
5346 // make sure to test lots and lots of apps!
5347 if (longSize < 470) {
5348 // This is shorter than an HVGA normal density screen (which
5349 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005350 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5351 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005352 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005353 // What size is this screen screen?
5354 if (longSize >= 800 && shortSize >= 600) {
5355 // SVGA or larger screens at medium density are the point
5356 // at which we consider it to be an extra large screen.
5357 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5358 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005359 // VGA or larger screens at medium density are the point
5360 // at which we consider it to be a large screen.
5361 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5362 } else {
5363 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005364
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005365 // If this screen is wider than normal HVGA, or taller
5366 // than FWVGA, then for old apps we want to run in size
5367 // compatibility mode.
5368 if (shortSize > 321 || longSize > 570) {
5369 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5370 }
5371 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005372
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005373 // Is this a long screen?
5374 if (((longSize*3)/5) >= (shortSize-1)) {
5375 // Anything wider than WVGA (5:3) is considering to be long.
5376 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5377 } else {
5378 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5379 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005380 }
5381 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005382 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005383
Dianne Hackbornc485a602009-03-24 22:39:49 -07005384 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5385 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5386 mPolicy.adjustConfigurationLw(config);
5387 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005388 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005389
5390 // -------------------------------------------------------------
5391 // Drag and drop
5392 // -------------------------------------------------------------
5393
5394 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5395 boolean localOnly, int width, int height, Surface outSurface) {
5396 if (DEBUG_DRAG) {
5397 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5398 + " local=" + localOnly + " win=" + window
5399 + " asbinder=" + window.asBinder());
5400 }
5401
5402 final int callerPid = Binder.getCallingPid();
5403 final long origId = Binder.clearCallingIdentity();
5404 IBinder token = null;
5405
5406 try {
5407 synchronized (mWindowMap) {
5408 try {
5409 // !!! TODO: fail if the given window does not currently have touch focus?
5410
5411 if (mDragState == null) {
5412 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5413 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5414 outSurface.copyFrom(surface);
5415 token = new Binder();
5416 mDragState = new DragState(token, surface, localOnly);
5417 mDragState.mSurface = surface;
5418 mDragState.mLocalOnly = localOnly;
5419 token = mDragState.mToken = new Binder();
5420
5421 // 5 second timeout for this window to actually begin the drag
5422 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5423 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5424 mH.sendMessageDelayed(msg, 5000);
5425 } else {
5426 Slog.w(TAG, "Drag already in progress");
5427 }
5428 } catch (Surface.OutOfResourcesException e) {
5429 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5430 if (mDragState != null) {
5431 mDragState.reset();
5432 mDragState = null;
5433 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005434 }
5435 }
5436 } finally {
5437 Binder.restoreCallingIdentity(origId);
5438 }
5439
5440 return token;
5441 }
5442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005443 // -------------------------------------------------------------
5444 // Input Events and Focus Management
5445 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005446
Jeff Brown349703e2010-06-22 01:27:15 -07005447 InputMonitor mInputMonitor = new InputMonitor();
5448
5449 /* Tracks the progress of input dispatch and ensures that input dispatch state
5450 * is kept in sync with changes in window focus, visibility, registration, and
5451 * other relevant Window Manager state transitions. */
5452 final class InputMonitor {
5453 // Current window with input focus for keys and other non-touch events. May be null.
5454 private WindowState mInputFocus;
5455
5456 // When true, prevents input dispatch from proceeding until set to false again.
5457 private boolean mInputDispatchFrozen;
5458
5459 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5460 private boolean mInputDispatchEnabled = true;
5461
5462 // Temporary list of windows information to provide to the input dispatcher.
5463 private InputWindowList mTempInputWindows = new InputWindowList();
5464
5465 // Temporary input application object to provide to the input dispatcher.
5466 private InputApplication mTempInputApplication = new InputApplication();
5467
5468 /* Notifies the window manager about a broken input channel.
5469 *
5470 * Called by the InputManager.
5471 */
5472 public void notifyInputChannelBroken(InputChannel inputChannel) {
5473 synchronized (mWindowMap) {
5474 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5475 if (windowState == null) {
5476 return; // irrelevant
5477 }
5478
5479 Slog.i(TAG, "WINDOW DIED " + windowState);
5480 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005481 }
5482 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005483
Jeff Brown519e0242010-09-15 15:18:56 -07005484 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005485 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005486 *
5487 * Called by the InputManager.
5488 */
Jeff Brown519e0242010-09-15 15:18:56 -07005489 public long notifyANR(Object token, InputChannel inputChannel) {
5490 AppWindowToken appWindowToken = null;
5491 if (inputChannel != null) {
5492 synchronized (mWindowMap) {
5493 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5494 if (windowState != null) {
5495 Slog.i(TAG, "Input event dispatching timed out sending to "
5496 + windowState.mAttrs.getTitle());
5497 appWindowToken = windowState.mAppToken;
5498 }
Jeff Brown349703e2010-06-22 01:27:15 -07005499 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005500 }
5501
Jeff Brown519e0242010-09-15 15:18:56 -07005502 if (appWindowToken == null && token != null) {
5503 appWindowToken = (AppWindowToken) token;
5504 Slog.i(TAG, "Input event dispatching timed out sending to application "
5505 + appWindowToken.stringName);
5506 }
Jeff Brown349703e2010-06-22 01:27:15 -07005507
Jeff Brown519e0242010-09-15 15:18:56 -07005508 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005509 try {
5510 // Notify the activity manager about the timeout and let it decide whether
5511 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005512 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005513 if (! abort) {
5514 // The activity manager declined to abort dispatching.
5515 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005516 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005517 }
Jeff Brown349703e2010-06-22 01:27:15 -07005518 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005519 }
5520 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005521 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005522 }
5523
Jeff Brown349703e2010-06-22 01:27:15 -07005524 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5525 synchronized (mWindowMap) {
5526 return getWindowStateForInputChannelLocked(inputChannel);
5527 }
5528 }
5529
5530 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5531 int windowCount = mWindows.size();
5532 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005533 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005534 if (windowState.mInputChannel == inputChannel) {
5535 return windowState;
5536 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005537 }
5538
Jeff Brown349703e2010-06-22 01:27:15 -07005539 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005540 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005541
Chris Tatea32dcf72010-10-14 12:13:50 -07005542 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005543 final InputWindow inputWindow = windowList.add();
5544 inputWindow.inputChannel = mDragState.mServerChannel;
5545 inputWindow.name = "drag";
5546 inputWindow.layoutParamsFlags = 0;
5547 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5548 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5549 inputWindow.visible = true;
5550 inputWindow.canReceiveKeys = false;
5551 inputWindow.hasFocus = true;
5552 inputWindow.hasWallpaper = false;
5553 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005554 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005555 inputWindow.ownerPid = Process.myPid();
5556 inputWindow.ownerUid = Process.myUid();
5557
5558 // The drag window covers the entire display
5559 inputWindow.frameLeft = 0;
5560 inputWindow.frameTop = 0;
5561 inputWindow.frameRight = mDisplay.getWidth();
5562 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005563
Christopher Tatea53146c2010-09-07 11:57:52 -07005564 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5565 inputWindow.visibleFrameTop = inputWindow.frameTop;
5566 inputWindow.visibleFrameRight = inputWindow.frameRight;
5567 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5568
5569 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5570 inputWindow.touchableAreaTop = inputWindow.frameTop;
5571 inputWindow.touchableAreaRight = inputWindow.frameRight;
5572 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5573 }
5574
Jeff Brown349703e2010-06-22 01:27:15 -07005575 /* Updates the cached window information provided to the input dispatcher. */
5576 public void updateInputWindowsLw() {
5577 // Populate the input window list with information about all of the windows that
5578 // could potentially receive input.
5579 // As an optimization, we could try to prune the list of windows but this turns
5580 // out to be difficult because only the native code knows for sure which window
5581 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005582 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005583
5584 // If there's a drag in flight, provide a pseudowindow to catch drag input
5585 final boolean inDrag = (mDragState != null);
5586 if (inDrag) {
5587 if (DEBUG_DRAG) {
5588 Log.d(TAG, "Inserting drag window");
5589 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005590 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005591 }
5592
Jeff Brown7fbdc842010-06-17 20:52:56 -07005593 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005594 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005595 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005596 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005597 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005598 continue;
5599 }
5600
Jeff Brown349703e2010-06-22 01:27:15 -07005601 final int flags = child.mAttrs.flags;
5602 final int type = child.mAttrs.type;
5603
5604 final boolean hasFocus = (child == mInputFocus);
5605 final boolean isVisible = child.isVisibleLw();
5606 final boolean hasWallpaper = (child == mWallpaperTarget)
5607 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005608
5609 // If there's a drag in progress and 'child' is a potential drop target,
5610 // make sure it's been told about the drag
5611 if (inDrag && isVisible) {
5612 mDragState.sendDragStartedIfNeededLw(child);
5613 }
5614
Jeff Brown349703e2010-06-22 01:27:15 -07005615 // Add a window to our list of input windows.
5616 final InputWindow inputWindow = mTempInputWindows.add();
5617 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005618 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005619 inputWindow.layoutParamsFlags = flags;
5620 inputWindow.layoutParamsType = type;
5621 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5622 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005623 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005624 inputWindow.hasFocus = hasFocus;
5625 inputWindow.hasWallpaper = hasWallpaper;
5626 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005627 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005628 inputWindow.ownerPid = child.mSession.mPid;
5629 inputWindow.ownerUid = child.mSession.mUid;
5630
5631 final Rect frame = child.mFrame;
5632 inputWindow.frameLeft = frame.left;
5633 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005634 inputWindow.frameRight = frame.right;
5635 inputWindow.frameBottom = frame.bottom;
5636
5637 final Rect visibleFrame = child.mVisibleFrame;
5638 inputWindow.visibleFrameLeft = visibleFrame.left;
5639 inputWindow.visibleFrameTop = visibleFrame.top;
5640 inputWindow.visibleFrameRight = visibleFrame.right;
5641 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005642
5643 switch (child.mTouchableInsets) {
5644 default:
5645 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5646 inputWindow.touchableAreaLeft = frame.left;
5647 inputWindow.touchableAreaTop = frame.top;
5648 inputWindow.touchableAreaRight = frame.right;
5649 inputWindow.touchableAreaBottom = frame.bottom;
5650 break;
5651
5652 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5653 Rect inset = child.mGivenContentInsets;
5654 inputWindow.touchableAreaLeft = frame.left + inset.left;
5655 inputWindow.touchableAreaTop = frame.top + inset.top;
5656 inputWindow.touchableAreaRight = frame.right - inset.right;
5657 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5658 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005659 }
Jeff Brown349703e2010-06-22 01:27:15 -07005660
5661 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5662 Rect inset = child.mGivenVisibleInsets;
5663 inputWindow.touchableAreaLeft = frame.left + inset.left;
5664 inputWindow.touchableAreaTop = frame.top + inset.top;
5665 inputWindow.touchableAreaRight = frame.right - inset.right;
5666 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005667 break;
5668 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005669 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005670 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005671
Jeff Brown349703e2010-06-22 01:27:15 -07005672 // Send windows to native code.
5673 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005674
Jeff Brown349703e2010-06-22 01:27:15 -07005675 // Clear the list in preparation for the next round.
5676 // Also avoids keeping InputChannel objects referenced unnecessarily.
5677 mTempInputWindows.clear();
5678 }
5679
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005680 /* Notifies that the lid switch changed state. */
5681 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5682 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5683 }
5684
Jeff Brown349703e2010-06-22 01:27:15 -07005685 /* Provides an opportunity for the window manager policy to intercept early key
5686 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005687 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5688 int policyFlags, boolean isScreenOn) {
5689 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5690 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005691 }
5692
5693 /* Provides an opportunity for the window manager policy to process a key before
5694 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005695 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5696 int action, int flags, int keyCode, int metaState, int repeatCount,
5697 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005698 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005699 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5700 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005701 }
5702
5703 /* Called when the current input focus changes.
5704 * Layer assignment is assumed to be complete by the time this is called.
5705 */
5706 public void setInputFocusLw(WindowState newWindow) {
5707 if (DEBUG_INPUT) {
5708 Slog.d(TAG, "Input focus has changed to " + newWindow);
5709 }
5710
5711 if (newWindow != mInputFocus) {
5712 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005713 // Displaying a window implicitly causes dispatching to be unpaused.
5714 // This is to protect against bugs if someone pauses dispatching but
5715 // forgets to resume.
5716 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005717 }
Jeff Brown349703e2010-06-22 01:27:15 -07005718
5719 mInputFocus = newWindow;
5720 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005721 }
5722 }
5723
Jeff Brown349703e2010-06-22 01:27:15 -07005724 public void setFocusedAppLw(AppWindowToken newApp) {
5725 // Focused app has changed.
5726 if (newApp == null) {
5727 mInputManager.setFocusedApplication(null);
5728 } else {
5729 mTempInputApplication.name = newApp.toString();
5730 mTempInputApplication.dispatchingTimeoutNanos =
5731 newApp.inputDispatchingTimeoutNanos;
5732 mTempInputApplication.token = newApp;
5733
5734 mInputManager.setFocusedApplication(mTempInputApplication);
5735 }
5736 }
5737
Jeff Brown349703e2010-06-22 01:27:15 -07005738 public void pauseDispatchingLw(WindowToken window) {
5739 if (! window.paused) {
5740 if (DEBUG_INPUT) {
5741 Slog.v(TAG, "Pausing WindowToken " + window);
5742 }
5743
5744 window.paused = true;
5745 updateInputWindowsLw();
5746 }
5747 }
5748
5749 public void resumeDispatchingLw(WindowToken window) {
5750 if (window.paused) {
5751 if (DEBUG_INPUT) {
5752 Slog.v(TAG, "Resuming WindowToken " + window);
5753 }
5754
5755 window.paused = false;
5756 updateInputWindowsLw();
5757 }
5758 }
5759
5760 public void freezeInputDispatchingLw() {
5761 if (! mInputDispatchFrozen) {
5762 if (DEBUG_INPUT) {
5763 Slog.v(TAG, "Freezing input dispatching");
5764 }
5765
5766 mInputDispatchFrozen = true;
5767 updateInputDispatchModeLw();
5768 }
5769 }
5770
5771 public void thawInputDispatchingLw() {
5772 if (mInputDispatchFrozen) {
5773 if (DEBUG_INPUT) {
5774 Slog.v(TAG, "Thawing input dispatching");
5775 }
5776
5777 mInputDispatchFrozen = false;
5778 updateInputDispatchModeLw();
5779 }
5780 }
5781
5782 public void setEventDispatchingLw(boolean enabled) {
5783 if (mInputDispatchEnabled != enabled) {
5784 if (DEBUG_INPUT) {
5785 Slog.v(TAG, "Setting event dispatching to " + enabled);
5786 }
5787
5788 mInputDispatchEnabled = enabled;
5789 updateInputDispatchModeLw();
5790 }
5791 }
5792
5793 private void updateInputDispatchModeLw() {
5794 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5795 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005798 public void pauseKeyDispatching(IBinder _token) {
5799 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5800 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005801 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005802 }
5803
5804 synchronized (mWindowMap) {
5805 WindowToken token = mTokenMap.get(_token);
5806 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005807 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005808 }
5809 }
5810 }
5811
5812 public void resumeKeyDispatching(IBinder _token) {
5813 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5814 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005815 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005816 }
5817
5818 synchronized (mWindowMap) {
5819 WindowToken token = mTokenMap.get(_token);
5820 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005821 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 }
5823 }
5824 }
5825
5826 public void setEventDispatching(boolean enabled) {
5827 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5828 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005829 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 }
5831
5832 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005833 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 }
5835 }
Romain Guy06882f82009-06-10 13:36:04 -07005836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 /**
5838 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005839 * Even when sync is false, this method may block while waiting for current
5840 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005841 *
5842 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005843 * {@link SystemClock#uptimeMillis()} as the timebase.)
5844 * @param sync If true, wait for the event to be completed before returning to the caller.
5845 * @return Returns true if event was dispatched, false if it was dropped for any reason
5846 */
5847 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5848 long downTime = ev.getDownTime();
5849 long eventTime = ev.getEventTime();
5850
5851 int action = ev.getAction();
5852 int code = ev.getKeyCode();
5853 int repeatCount = ev.getRepeatCount();
5854 int metaState = ev.getMetaState();
5855 int deviceId = ev.getDeviceId();
5856 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005857 int source = ev.getSource();
5858
5859 if (source == InputDevice.SOURCE_UNKNOWN) {
5860 source = InputDevice.SOURCE_KEYBOARD;
5861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862
5863 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5864 if (downTime == 0) downTime = eventTime;
5865
5866 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005867 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005868
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005869 final int pid = Binder.getCallingPid();
5870 final int uid = Binder.getCallingUid();
5871 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005872
Jeff Brownbbda99d2010-07-28 15:48:59 -07005873 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5874 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5875 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5876 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005877
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005878 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005879 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 }
5881
5882 /**
5883 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005884 * Even when sync is false, this method may block while waiting for current
5885 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005886 *
5887 * @param ev A motion event describing the pointer (touch) action. (As noted in
5888 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005889 * {@link SystemClock#uptimeMillis()} as the timebase.)
5890 * @param sync If true, wait for the event to be completed before returning to the caller.
5891 * @return Returns true if event was dispatched, false if it was dropped for any reason
5892 */
5893 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005894 final int pid = Binder.getCallingPid();
5895 final int uid = Binder.getCallingUid();
5896 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005897
Jeff Brownc5ed5912010-07-14 18:48:53 -07005898 MotionEvent newEvent = MotionEvent.obtain(ev);
5899 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5900 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5901 }
5902
Jeff Brownbbda99d2010-07-28 15:48:59 -07005903 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5904 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5905 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5906 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005907
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005908 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005909 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005910 }
Romain Guy06882f82009-06-10 13:36:04 -07005911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005912 /**
5913 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005914 * Even when sync is false, this method may block while waiting for current
5915 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005916 *
5917 * @param ev A motion event describing the trackball action. (As noted in
5918 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005919 * {@link SystemClock#uptimeMillis()} as the timebase.)
5920 * @param sync If true, wait for the event to be completed before returning to the caller.
5921 * @return Returns true if event was dispatched, false if it was dropped for any reason
5922 */
5923 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005924 final int pid = Binder.getCallingPid();
5925 final int uid = Binder.getCallingUid();
5926 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005927
Jeff Brownc5ed5912010-07-14 18:48:53 -07005928 MotionEvent newEvent = MotionEvent.obtain(ev);
5929 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5930 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5931 }
5932
Jeff Brownbbda99d2010-07-28 15:48:59 -07005933 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5934 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5935 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5936 INJECTION_TIMEOUT_MILLIS);
5937
5938 Binder.restoreCallingIdentity(ident);
5939 return reportInjectionResult(result);
5940 }
5941
5942 /**
5943 * Inject an input event into the UI without waiting for dispatch to commence.
5944 * This variant is useful for fire-and-forget input event injection. It does not
5945 * block any longer than it takes to enqueue the input event.
5946 *
5947 * @param ev An input event. (Be sure to set the input source correctly.)
5948 * @return Returns true if event was dispatched, false if it was dropped for any reason
5949 */
5950 public boolean injectInputEventNoWait(InputEvent ev) {
5951 final int pid = Binder.getCallingPid();
5952 final int uid = Binder.getCallingUid();
5953 final long ident = Binder.clearCallingIdentity();
5954
5955 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5956 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5957 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005958
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005959 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005960 return reportInjectionResult(result);
5961 }
5962
5963 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005964 switch (result) {
5965 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5966 Slog.w(TAG, "Input event injection permission denied.");
5967 throw new SecurityException(
5968 "Injecting to another application requires INJECT_EVENTS permission");
5969 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005970 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005971 return true;
5972 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5973 Slog.w(TAG, "Input event injection timed out.");
5974 return false;
5975 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5976 default:
5977 Slog.w(TAG, "Input event injection failed.");
5978 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005980 }
Romain Guy06882f82009-06-10 13:36:04 -07005981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005982 private WindowState getFocusedWindow() {
5983 synchronized (mWindowMap) {
5984 return getFocusedWindowLocked();
5985 }
5986 }
5987
5988 private WindowState getFocusedWindowLocked() {
5989 return mCurrentFocus;
5990 }
Romain Guy06882f82009-06-10 13:36:04 -07005991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005992 public boolean detectSafeMode() {
5993 mSafeMode = mPolicy.detectSafeMode();
5994 return mSafeMode;
5995 }
Romain Guy06882f82009-06-10 13:36:04 -07005996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005997 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005998 synchronized(mWindowMap) {
5999 if (mDisplay != null) {
6000 throw new IllegalStateException("Display already initialized");
6001 }
6002 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6003 mDisplay = wm.getDefaultDisplay();
6004 mInitialDisplayWidth = mDisplay.getWidth();
6005 mInitialDisplayHeight = mDisplay.getHeight();
6006 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6007 }
6008
6009 try {
6010 mActivityManager.updateConfiguration(null);
6011 } catch (RemoteException e) {
6012 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006013
6014 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006015 }
6016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 // -------------------------------------------------------------
6018 // Client Session State
6019 // -------------------------------------------------------------
6020
6021 private final class Session extends IWindowSession.Stub
6022 implements IBinder.DeathRecipient {
6023 final IInputMethodClient mClient;
6024 final IInputContext mInputContext;
6025 final int mUid;
6026 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006027 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 SurfaceSession mSurfaceSession;
6029 int mNumWindow = 0;
6030 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006032 public Session(IInputMethodClient client, IInputContext inputContext) {
6033 mClient = client;
6034 mInputContext = inputContext;
6035 mUid = Binder.getCallingUid();
6036 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006037 StringBuilder sb = new StringBuilder();
6038 sb.append("Session{");
6039 sb.append(Integer.toHexString(System.identityHashCode(this)));
6040 sb.append(" uid ");
6041 sb.append(mUid);
6042 sb.append("}");
6043 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 synchronized (mWindowMap) {
6046 if (mInputMethodManager == null && mHaveInputMethods) {
6047 IBinder b = ServiceManager.getService(
6048 Context.INPUT_METHOD_SERVICE);
6049 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6050 }
6051 }
6052 long ident = Binder.clearCallingIdentity();
6053 try {
6054 // Note: it is safe to call in to the input method manager
6055 // here because we are not holding our lock.
6056 if (mInputMethodManager != null) {
6057 mInputMethodManager.addClient(client, inputContext,
6058 mUid, mPid);
6059 } else {
6060 client.setUsingInputMethod(false);
6061 }
6062 client.asBinder().linkToDeath(this, 0);
6063 } catch (RemoteException e) {
6064 // The caller has died, so we can just forget about this.
6065 try {
6066 if (mInputMethodManager != null) {
6067 mInputMethodManager.removeClient(client);
6068 }
6069 } catch (RemoteException ee) {
6070 }
6071 } finally {
6072 Binder.restoreCallingIdentity(ident);
6073 }
6074 }
Romain Guy06882f82009-06-10 13:36:04 -07006075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006076 @Override
6077 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6078 throws RemoteException {
6079 try {
6080 return super.onTransact(code, data, reply, flags);
6081 } catch (RuntimeException e) {
6082 // Log all 'real' exceptions thrown to the caller
6083 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006084 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 }
6086 throw e;
6087 }
6088 }
6089
6090 public void binderDied() {
6091 // Note: it is safe to call in to the input method manager
6092 // here because we are not holding our lock.
6093 try {
6094 if (mInputMethodManager != null) {
6095 mInputMethodManager.removeClient(mClient);
6096 }
6097 } catch (RemoteException e) {
6098 }
6099 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006100 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 mClientDead = true;
6102 killSessionLocked();
6103 }
6104 }
6105
6106 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006107 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6108 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6109 outInputChannel);
6110 }
6111
6112 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006114 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006115 }
Romain Guy06882f82009-06-10 13:36:04 -07006116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 public void remove(IWindow window) {
6118 removeWindow(this, window);
6119 }
Romain Guy06882f82009-06-10 13:36:04 -07006120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006121 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6122 int requestedWidth, int requestedHeight, int viewFlags,
6123 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006124 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006125 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6126 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006127 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006128 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006129 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6130 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006131 }
Romain Guy06882f82009-06-10 13:36:04 -07006132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 public void setTransparentRegion(IWindow window, Region region) {
6134 setTransparentRegionWindow(this, window, region);
6135 }
Romain Guy06882f82009-06-10 13:36:04 -07006136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 public void setInsets(IWindow window, int touchableInsets,
6138 Rect contentInsets, Rect visibleInsets) {
6139 setInsetsWindow(this, window, touchableInsets, contentInsets,
6140 visibleInsets);
6141 }
Romain Guy06882f82009-06-10 13:36:04 -07006142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6144 getWindowDisplayFrame(this, window, outDisplayFrame);
6145 }
Romain Guy06882f82009-06-10 13:36:04 -07006146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006147 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006148 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006149 TAG, "IWindow finishDrawing called for " + window);
6150 finishDrawingWindow(this, window);
6151 }
6152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 public void setInTouchMode(boolean mode) {
6154 synchronized(mWindowMap) {
6155 mInTouchMode = mode;
6156 }
6157 }
6158
6159 public boolean getInTouchMode() {
6160 synchronized(mWindowMap) {
6161 return mInTouchMode;
6162 }
6163 }
6164
6165 public boolean performHapticFeedback(IWindow window, int effectId,
6166 boolean always) {
6167 synchronized(mWindowMap) {
6168 long ident = Binder.clearCallingIdentity();
6169 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006170 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006171 windowForClientLocked(this, window, true),
6172 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006173 } finally {
6174 Binder.restoreCallingIdentity(ident);
6175 }
6176 }
6177 }
Romain Guy06882f82009-06-10 13:36:04 -07006178
Christopher Tatea53146c2010-09-07 11:57:52 -07006179 /* Drag/drop */
6180 public IBinder prepareDrag(IWindow window, boolean localOnly,
6181 int width, int height, Surface outSurface) {
6182 return prepareDragSurface(window, mSurfaceSession, localOnly,
6183 width, height, outSurface);
6184 }
6185
6186 public boolean performDrag(IWindow window, IBinder dragToken,
6187 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6188 ClipData data) {
6189 if (DEBUG_DRAG) {
6190 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6191 }
6192
6193 synchronized (mWindowMap) {
6194 if (mDragState == null) {
6195 Slog.w(TAG, "No drag prepared");
6196 throw new IllegalStateException("performDrag() without prepareDrag()");
6197 }
6198
6199 if (dragToken != mDragState.mToken) {
6200 Slog.w(TAG, "Performing mismatched drag");
6201 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6202 }
6203
6204 WindowState callingWin = windowForClientLocked(null, window, false);
6205 if (callingWin == null) {
6206 Slog.w(TAG, "Bad requesting window " + window);
6207 return false; // !!! TODO: throw here?
6208 }
6209
6210 // !!! TODO: if input is not still focused on the initiating window, fail
6211 // the drag initiation (e.g. an alarm window popped up just as the application
6212 // called performDrag()
6213
6214 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6215
Christopher Tate2c095f32010-10-04 14:13:40 -07006216 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6217 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006218
6219 mDragState.register();
6220 mInputMonitor.updateInputWindowsLw();
6221 mInputManager.transferTouchFocus(callingWin.mInputChannel,
6222 mDragState.mServerChannel);
6223
6224 mDragState.mData = data;
Chris Tateb8203e92010-10-12 14:23:21 -07006225 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006226
6227 // remember the thumb offsets for later
6228 mDragState.mThumbOffsetX = thumbCenterX;
6229 mDragState.mThumbOffsetY = thumbCenterY;
6230
6231 // Make the surface visible at the proper location
6232 final Surface surface = mDragState.mSurface;
6233 surface.openTransaction();
6234 try {
6235 surface.setPosition((int)(touchX - thumbCenterX),
6236 (int)(touchY - thumbCenterY));
6237 surface.setAlpha(.5f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006238 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006239 surface.show();
6240 } finally {
6241 surface.closeTransaction();
6242 }
6243 }
6244
6245 return true; // success!
6246 }
6247
6248 public void dragRecipientEntered(IWindow window) {
6249 if (DEBUG_DRAG) {
6250 Slog.d(TAG, "Drag into new candidate view @ " + window);
6251 }
6252 }
6253
6254 public void dragRecipientExited(IWindow window) {
6255 if (DEBUG_DRAG) {
6256 Slog.d(TAG, "Drag from old candidate view @ " + window);
6257 }
6258 }
6259
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006260 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006261 synchronized(mWindowMap) {
6262 long ident = Binder.clearCallingIdentity();
6263 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006264 setWindowWallpaperPositionLocked(
6265 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006266 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006267 } finally {
6268 Binder.restoreCallingIdentity(ident);
6269 }
6270 }
6271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006272
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006273 public void wallpaperOffsetsComplete(IBinder window) {
6274 WindowManagerService.this.wallpaperOffsetsComplete(window);
6275 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006276
Dianne Hackborn75804932009-10-20 20:15:20 -07006277 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6278 int z, Bundle extras, boolean sync) {
6279 synchronized(mWindowMap) {
6280 long ident = Binder.clearCallingIdentity();
6281 try {
6282 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006283 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006284 action, x, y, z, extras, sync);
6285 } finally {
6286 Binder.restoreCallingIdentity(ident);
6287 }
6288 }
6289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006290
Dianne Hackborn75804932009-10-20 20:15:20 -07006291 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6292 WindowManagerService.this.wallpaperCommandComplete(window, result);
6293 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 void windowAddedLocked() {
6296 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006297 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006298 TAG, "First window added to " + this + ", creating SurfaceSession");
6299 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006300 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006301 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006302 mSessions.add(this);
6303 }
6304 mNumWindow++;
6305 }
6306
6307 void windowRemovedLocked() {
6308 mNumWindow--;
6309 killSessionLocked();
6310 }
Romain Guy06882f82009-06-10 13:36:04 -07006311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006312 void killSessionLocked() {
6313 if (mNumWindow <= 0 && mClientDead) {
6314 mSessions.remove(this);
6315 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006316 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006317 TAG, "Last window removed from " + this
6318 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006319 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006320 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321 try {
6322 mSurfaceSession.kill();
6323 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006324 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006325 + mSurfaceSession + " in session " + this
6326 + ": " + e.toString());
6327 }
6328 mSurfaceSession = null;
6329 }
6330 }
6331 }
Romain Guy06882f82009-06-10 13:36:04 -07006332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006334 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6335 pw.print(" mClientDead="); pw.print(mClientDead);
6336 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006337 }
6338
6339 @Override
6340 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006341 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 }
6343 }
6344
6345 // -------------------------------------------------------------
6346 // Client Window State
6347 // -------------------------------------------------------------
6348
6349 private final class WindowState implements WindowManagerPolicy.WindowState {
6350 final Session mSession;
6351 final IWindow mClient;
6352 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006353 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 AppWindowToken mAppToken;
6355 AppWindowToken mTargetAppToken;
6356 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6357 final DeathRecipient mDeathRecipient;
6358 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006359 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 final int mBaseLayer;
6361 final int mSubLayer;
6362 final boolean mLayoutAttached;
6363 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006364 final boolean mIsWallpaper;
6365 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 int mViewVisibility;
6367 boolean mPolicyVisibility = true;
6368 boolean mPolicyVisibilityAfterAnim = true;
6369 boolean mAppFreezing;
6370 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006371 boolean mReportDestroySurface;
6372 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 boolean mAttachedHidden; // is our parent window hidden?
6374 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006375 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 int mRequestedWidth;
6377 int mRequestedHeight;
6378 int mLastRequestedWidth;
6379 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380 int mLayer;
6381 int mAnimLayer;
6382 int mLastLayer;
6383 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006384 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006385 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006387 int mLayoutSeq = -1;
6388
6389 Configuration mConfiguration = null;
6390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391 // Actual frame shown on-screen (may be modified by animation)
6392 final Rect mShownFrame = new Rect();
6393 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006395 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006396 * Set when we have changed the size of the surface, to know that
6397 * we must tell them application to resize (and thus redraw itself).
6398 */
6399 boolean mSurfaceResized;
6400
6401 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 * Insets that determine the actually visible area
6403 */
6404 final Rect mVisibleInsets = new Rect();
6405 final Rect mLastVisibleInsets = new Rect();
6406 boolean mVisibleInsetsChanged;
6407
6408 /**
6409 * Insets that are covered by system windows
6410 */
6411 final Rect mContentInsets = new Rect();
6412 final Rect mLastContentInsets = new Rect();
6413 boolean mContentInsetsChanged;
6414
6415 /**
6416 * Set to true if we are waiting for this window to receive its
6417 * given internal insets before laying out other windows based on it.
6418 */
6419 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 /**
6422 * These are the content insets that were given during layout for
6423 * this window, to be applied to windows behind it.
6424 */
6425 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 /**
6428 * These are the visible insets that were given during layout for
6429 * this window, to be applied to windows behind it.
6430 */
6431 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 /**
6434 * Flag indicating whether the touchable region should be adjusted by
6435 * the visible insets; if false the area outside the visible insets is
6436 * NOT touchable, so we must use those to adjust the frame during hit
6437 * tests.
6438 */
6439 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 // Current transformation being applied.
6442 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6443 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6444 float mHScale=1, mVScale=1;
6445 float mLastHScale=1, mLastVScale=1;
6446 final Matrix mTmpMatrix = new Matrix();
6447
6448 // "Real" frame that the application sees.
6449 final Rect mFrame = new Rect();
6450 final Rect mLastFrame = new Rect();
6451
6452 final Rect mContainingFrame = new Rect();
6453 final Rect mDisplayFrame = new Rect();
6454 final Rect mContentFrame = new Rect();
6455 final Rect mVisibleFrame = new Rect();
6456
6457 float mShownAlpha = 1;
6458 float mAlpha = 1;
6459 float mLastAlpha = 1;
6460
6461 // Set to true if, when the window gets displayed, it should perform
6462 // an enter animation.
6463 boolean mEnterAnimationPending;
6464
6465 // Currently running animation.
6466 boolean mAnimating;
6467 boolean mLocalAnimating;
6468 Animation mAnimation;
6469 boolean mAnimationIsEntrance;
6470 boolean mHasTransformation;
6471 boolean mHasLocalTransformation;
6472 final Transformation mTransformation = new Transformation();
6473
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006474 // If a window showing a wallpaper: the requested offset for the
6475 // wallpaper; if a wallpaper window: the currently applied offset.
6476 float mWallpaperX = -1;
6477 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006478
6479 // If a window showing a wallpaper: what fraction of the offset
6480 // range corresponds to a full virtual screen.
6481 float mWallpaperXStep = -1;
6482 float mWallpaperYStep = -1;
6483
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006484 // Wallpaper windows: pixels offset based on above variables.
6485 int mXOffset;
6486 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 // This is set after IWindowSession.relayout() has been called at
6489 // least once for the window. It allows us to detect the situation
6490 // where we don't yet have a surface, but should have one soon, so
6491 // we can give the window focus before waiting for the relayout.
6492 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 // This is set after the Surface has been created but before the
6495 // window has been drawn. During this time the surface is hidden.
6496 boolean mDrawPending;
6497
6498 // This is set after the window has finished drawing for the first
6499 // time but before its surface is shown. The surface will be
6500 // displayed when the next layout is run.
6501 boolean mCommitDrawPending;
6502
6503 // This is set during the time after the window's drawing has been
6504 // committed, and before its surface is actually shown. It is used
6505 // to delay showing the surface until all windows in a token are ready
6506 // to be shown.
6507 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006509 // Set when the window has been shown in the screen the first time.
6510 boolean mHasDrawn;
6511
6512 // Currently running an exit animation?
6513 boolean mExiting;
6514
6515 // Currently on the mDestroySurface list?
6516 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006518 // Completely remove from window manager after exit animation?
6519 boolean mRemoveOnExit;
6520
6521 // Set when the orientation is changing and this window has not yet
6522 // been updated for the new orientation.
6523 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 // Is this window now (or just being) removed?
6526 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006527
Dianne Hackborn16064f92010-03-25 00:47:24 -07006528 // For debugging, this is the last information given to the surface flinger.
6529 boolean mSurfaceShown;
6530 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6531 int mSurfaceLayer;
6532 float mSurfaceAlpha;
6533
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006534 // Input channel
6535 InputChannel mInputChannel;
6536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006537 WindowState(Session s, IWindow c, WindowToken token,
6538 WindowState attachedWindow, WindowManager.LayoutParams a,
6539 int viewVisibility) {
6540 mSession = s;
6541 mClient = c;
6542 mToken = token;
6543 mAttrs.copyFrom(a);
6544 mViewVisibility = viewVisibility;
6545 DeathRecipient deathRecipient = new DeathRecipient();
6546 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006547 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 TAG, "Window " + this + " client=" + c.asBinder()
6549 + " token=" + token + " (" + mAttrs.token + ")");
6550 try {
6551 c.asBinder().linkToDeath(deathRecipient, 0);
6552 } catch (RemoteException e) {
6553 mDeathRecipient = null;
6554 mAttachedWindow = null;
6555 mLayoutAttached = false;
6556 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006557 mIsWallpaper = false;
6558 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 mBaseLayer = 0;
6560 mSubLayer = 0;
6561 return;
6562 }
6563 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6566 mAttrs.type <= LAST_SUB_WINDOW)) {
6567 // The multiplier here is to reserve space for multiple
6568 // windows in the same type layer.
6569 mBaseLayer = mPolicy.windowTypeToLayerLw(
6570 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6571 + TYPE_LAYER_OFFSET;
6572 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6573 mAttachedWindow = attachedWindow;
6574 mAttachedWindow.mChildWindows.add(this);
6575 mLayoutAttached = mAttrs.type !=
6576 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6577 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6578 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006579 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6580 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006581 } else {
6582 // The multiplier here is to reserve space for multiple
6583 // windows in the same type layer.
6584 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6585 * TYPE_LAYER_MULTIPLIER
6586 + TYPE_LAYER_OFFSET;
6587 mSubLayer = 0;
6588 mAttachedWindow = null;
6589 mLayoutAttached = false;
6590 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6591 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006592 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6593 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 }
6595
6596 WindowState appWin = this;
6597 while (appWin.mAttachedWindow != null) {
6598 appWin = mAttachedWindow;
6599 }
6600 WindowToken appToken = appWin.mToken;
6601 while (appToken.appWindowToken == null) {
6602 WindowToken parent = mTokenMap.get(appToken.token);
6603 if (parent == null || appToken == parent) {
6604 break;
6605 }
6606 appToken = parent;
6607 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006608 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 mAppToken = appToken.appWindowToken;
6610
6611 mSurface = null;
6612 mRequestedWidth = 0;
6613 mRequestedHeight = 0;
6614 mLastRequestedWidth = 0;
6615 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006616 mXOffset = 0;
6617 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006618 mLayer = 0;
6619 mAnimLayer = 0;
6620 mLastLayer = 0;
6621 }
6622
6623 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006624 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 TAG, "Attaching " + this + " token=" + mToken
6626 + ", list=" + mToken.windows);
6627 mSession.windowAddedLocked();
6628 }
6629
6630 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6631 mHaveFrame = true;
6632
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006633 final Rect container = mContainingFrame;
6634 container.set(pf);
6635
6636 final Rect display = mDisplayFrame;
6637 display.set(df);
6638
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006639 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006640 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006641 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6642 display.intersect(mCompatibleScreenFrame);
6643 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006644 }
6645
6646 final int pw = container.right - container.left;
6647 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006648
6649 int w,h;
6650 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6651 w = mAttrs.width < 0 ? pw : mAttrs.width;
6652 h = mAttrs.height< 0 ? ph : mAttrs.height;
6653 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006654 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6655 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 }
Romain Guy06882f82009-06-10 13:36:04 -07006657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006658 final Rect content = mContentFrame;
6659 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661 final Rect visible = mVisibleFrame;
6662 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006664 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006665 final int fw = frame.width();
6666 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006668 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6669 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6670
6671 Gravity.apply(mAttrs.gravity, w, h, container,
6672 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6673 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6674
6675 //System.out.println("Out: " + mFrame);
6676
6677 // Now make sure the window fits in the overall display.
6678 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006680 // Make sure the content and visible frames are inside of the
6681 // final window frame.
6682 if (content.left < frame.left) content.left = frame.left;
6683 if (content.top < frame.top) content.top = frame.top;
6684 if (content.right > frame.right) content.right = frame.right;
6685 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6686 if (visible.left < frame.left) visible.left = frame.left;
6687 if (visible.top < frame.top) visible.top = frame.top;
6688 if (visible.right > frame.right) visible.right = frame.right;
6689 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 final Rect contentInsets = mContentInsets;
6692 contentInsets.left = content.left-frame.left;
6693 contentInsets.top = content.top-frame.top;
6694 contentInsets.right = frame.right-content.right;
6695 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 final Rect visibleInsets = mVisibleInsets;
6698 visibleInsets.left = visible.left-frame.left;
6699 visibleInsets.top = visible.top-frame.top;
6700 visibleInsets.right = frame.right-visible.right;
6701 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006702
Dianne Hackborn284ac932009-08-28 10:34:25 -07006703 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6704 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006705 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006708 if (localLOGV) {
6709 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6710 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006711 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 + mRequestedWidth + ", mRequestedheight="
6713 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6714 + "): frame=" + mFrame.toShortString()
6715 + " ci=" + contentInsets.toShortString()
6716 + " vi=" + visibleInsets.toShortString());
6717 //}
6718 }
6719 }
Romain Guy06882f82009-06-10 13:36:04 -07006720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006721 public Rect getFrameLw() {
6722 return mFrame;
6723 }
6724
6725 public Rect getShownFrameLw() {
6726 return mShownFrame;
6727 }
6728
6729 public Rect getDisplayFrameLw() {
6730 return mDisplayFrame;
6731 }
6732
6733 public Rect getContentFrameLw() {
6734 return mContentFrame;
6735 }
6736
6737 public Rect getVisibleFrameLw() {
6738 return mVisibleFrame;
6739 }
6740
6741 public boolean getGivenInsetsPendingLw() {
6742 return mGivenInsetsPending;
6743 }
6744
6745 public Rect getGivenContentInsetsLw() {
6746 return mGivenContentInsets;
6747 }
Romain Guy06882f82009-06-10 13:36:04 -07006748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 public Rect getGivenVisibleInsetsLw() {
6750 return mGivenVisibleInsets;
6751 }
Romain Guy06882f82009-06-10 13:36:04 -07006752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 public WindowManager.LayoutParams getAttrs() {
6754 return mAttrs;
6755 }
6756
6757 public int getSurfaceLayer() {
6758 return mLayer;
6759 }
Romain Guy06882f82009-06-10 13:36:04 -07006760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006761 public IApplicationToken getAppToken() {
6762 return mAppToken != null ? mAppToken.appToken : null;
6763 }
Jeff Brown349703e2010-06-22 01:27:15 -07006764
6765 public long getInputDispatchingTimeoutNanos() {
6766 return mAppToken != null
6767 ? mAppToken.inputDispatchingTimeoutNanos
6768 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6769 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006770
6771 public boolean hasAppShownWindows() {
6772 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6773 }
6774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006775 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006776 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006777 TAG, "Setting animation in " + this + ": " + anim);
6778 mAnimating = false;
6779 mLocalAnimating = false;
6780 mAnimation = anim;
6781 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6782 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6783 }
6784
6785 public void clearAnimation() {
6786 if (mAnimation != null) {
6787 mAnimating = true;
6788 mLocalAnimating = false;
6789 mAnimation = null;
6790 }
6791 }
Romain Guy06882f82009-06-10 13:36:04 -07006792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006793 Surface createSurfaceLocked() {
6794 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006795 mReportDestroySurface = false;
6796 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 mDrawPending = true;
6798 mCommitDrawPending = false;
6799 mReadyToShow = false;
6800 if (mAppToken != null) {
6801 mAppToken.allDrawn = false;
6802 }
6803
6804 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006805 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 flags |= Surface.PUSH_BUFFERS;
6807 }
6808
6809 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6810 flags |= Surface.SECURE;
6811 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006812 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006813 TAG, "Creating surface in session "
6814 + mSession.mSurfaceSession + " window " + this
6815 + " w=" + mFrame.width()
6816 + " h=" + mFrame.height() + " format="
6817 + mAttrs.format + " flags=" + flags);
6818
6819 int w = mFrame.width();
6820 int h = mFrame.height();
6821 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6822 // for a scaled surface, we always want the requested
6823 // size.
6824 w = mRequestedWidth;
6825 h = mRequestedHeight;
6826 }
6827
Romain Guy9825ec62009-10-01 00:58:09 -07006828 // Something is wrong and SurfaceFlinger will not like this,
6829 // try to revert to sane values
6830 if (w <= 0) w = 1;
6831 if (h <= 0) h = 1;
6832
Dianne Hackborn16064f92010-03-25 00:47:24 -07006833 mSurfaceShown = false;
6834 mSurfaceLayer = 0;
6835 mSurfaceAlpha = 1;
6836 mSurfaceX = 0;
6837 mSurfaceY = 0;
6838 mSurfaceW = w;
6839 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006841 final boolean isHwAccelerated = (mAttrs.flags &
6842 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6843 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6844 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6845 flags |= Surface.OPAQUE;
6846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006848 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006849 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006850 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006851 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006852 + mSurface + " IN SESSION "
6853 + mSession.mSurfaceSession
6854 + ": pid=" + mSession.mPid + " format="
6855 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006856 + Integer.toHexString(flags)
6857 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006859 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 reclaimSomeSurfaceMemoryLocked(this, "create");
6861 return null;
6862 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006863 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 return null;
6865 }
Romain Guy06882f82009-06-10 13:36:04 -07006866
Joe Onorato8a9b2202010-02-26 18:56:32 -08006867 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006868 TAG, "Got surface: " + mSurface
6869 + ", set left=" + mFrame.left + " top=" + mFrame.top
6870 + ", animLayer=" + mAnimLayer);
6871 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006872 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006873 if (SHOW_TRANSACTIONS) logSurface(this,
6874 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6875 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6876 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 }
6878 Surface.openTransaction();
6879 try {
6880 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006881 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006882 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006883 mSurface.setPosition(mSurfaceX, mSurfaceY);
6884 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006885 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006886 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 mSurface.hide();
6888 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006889 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006890 mSurface.setFlags(Surface.SURFACE_DITHER,
6891 Surface.SURFACE_DITHER);
6892 }
6893 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006894 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006895 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6896 }
6897 mLastHidden = true;
6898 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006899 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006900 Surface.closeTransaction();
6901 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006902 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 TAG, "Created surface " + this);
6904 }
6905 return mSurface;
6906 }
Romain Guy06882f82009-06-10 13:36:04 -07006907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 if (mAppToken != null && this == mAppToken.startingWindow) {
6910 mAppToken.startingDisplayed = false;
6911 }
Romain Guy06882f82009-06-10 13:36:04 -07006912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006913 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006914 mDrawPending = false;
6915 mCommitDrawPending = false;
6916 mReadyToShow = false;
6917
6918 int i = mChildWindows.size();
6919 while (i > 0) {
6920 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006921 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006922 c.mAttachedHidden = true;
6923 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006924
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006925 if (mReportDestroySurface) {
6926 mReportDestroySurface = false;
6927 mSurfacePendingDestroy = true;
6928 try {
6929 mClient.dispatchGetNewSurface();
6930 // We'll really destroy on the next time around.
6931 return;
6932 } catch (RemoteException e) {
6933 }
6934 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006937 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006938 RuntimeException e = null;
6939 if (!HIDE_STACK_CRAWLS) {
6940 e = new RuntimeException();
6941 e.fillInStackTrace();
6942 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006943 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006944 + mSurface + ", session " + mSession, e);
6945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006947 RuntimeException e = null;
6948 if (!HIDE_STACK_CRAWLS) {
6949 e = new RuntimeException();
6950 e.fillInStackTrace();
6951 }
6952 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006954 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006956 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 + " surface " + mSurface + " session " + mSession
6958 + ": " + e.toString());
6959 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006960
Dianne Hackborn16064f92010-03-25 00:47:24 -07006961 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 }
6964 }
6965
6966 boolean finishDrawingLocked() {
6967 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006968 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 TAG, "finishDrawingLocked: " + mSurface);
6970 mCommitDrawPending = true;
6971 mDrawPending = false;
6972 return true;
6973 }
6974 return false;
6975 }
6976
6977 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006978 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006979 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006980 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006981 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006982 }
6983 mCommitDrawPending = false;
6984 mReadyToShow = true;
6985 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6986 final AppWindowToken atoken = mAppToken;
6987 if (atoken == null || atoken.allDrawn || starting) {
6988 performShowLocked();
6989 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006990 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006991 }
6992
6993 // This must be called while inside a transaction.
6994 boolean performShowLocked() {
6995 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006996 RuntimeException e = null;
6997 if (!HIDE_STACK_CRAWLS) {
6998 e = new RuntimeException();
6999 e.fillInStackTrace();
7000 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007001 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007002 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7003 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7004 }
7005 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007006 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7007 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007008 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 + " during animation: policyVis=" + mPolicyVisibility
7010 + " attHidden=" + mAttachedHidden
7011 + " tok.hiddenRequested="
7012 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007013 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 + (mAppToken != null ? mAppToken.hidden : false)
7015 + " animating=" + mAnimating
7016 + " tok animating="
7017 + (mAppToken != null ? mAppToken.animating : false));
7018 if (!showSurfaceRobustlyLocked(this)) {
7019 return false;
7020 }
7021 mLastAlpha = -1;
7022 mHasDrawn = true;
7023 mLastHidden = false;
7024 mReadyToShow = false;
7025 enableScreenIfNeededLocked();
7026
7027 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 int i = mChildWindows.size();
7030 while (i > 0) {
7031 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007032 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007033 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007035 if (c.mSurface != null) {
7036 c.performShowLocked();
7037 // It hadn't been shown, which means layout not
7038 // performed on it, so now we want to make sure to
7039 // do a layout. If called from within the transaction
7040 // loop, this will cause it to restart with a new
7041 // layout.
7042 mLayoutNeeded = true;
7043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 }
7045 }
Romain Guy06882f82009-06-10 13:36:04 -07007046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007047 if (mAttrs.type != TYPE_APPLICATION_STARTING
7048 && mAppToken != null) {
7049 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007050
Dianne Hackborn248b1882009-09-16 16:46:44 -07007051 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007052 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007053 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007055 // If this initial window is animating, stop it -- we
7056 // will do an animation to reveal it from behind the
7057 // starting window, so there is no need for it to also
7058 // be doing its own stuff.
7059 if (mAnimation != null) {
7060 mAnimation = null;
7061 // Make sure we clean up the animation.
7062 mAnimating = true;
7063 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007064 mFinishedStarting.add(mAppToken);
7065 mH.sendEmptyMessage(H.FINISHED_STARTING);
7066 }
7067 mAppToken.updateReportedVisibilityLocked();
7068 }
7069 }
7070 return true;
7071 }
Romain Guy06882f82009-06-10 13:36:04 -07007072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007073 // This must be called while inside a transaction. Returns true if
7074 // there is more animation to run.
7075 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007076 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007077 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7080 mHasTransformation = true;
7081 mHasLocalTransformation = true;
7082 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007083 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 TAG, "Starting animation in " + this +
7085 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7086 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7087 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7088 mAnimation.setStartTime(currentTime);
7089 mLocalAnimating = true;
7090 mAnimating = true;
7091 }
7092 mTransformation.clear();
7093 final boolean more = mAnimation.getTransformation(
7094 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007095 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 TAG, "Stepped animation in " + this +
7097 ": more=" + more + ", xform=" + mTransformation);
7098 if (more) {
7099 // we're not done!
7100 return true;
7101 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007102 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 TAG, "Finished animation in " + this +
7104 " @ " + currentTime);
7105 mAnimation = null;
7106 //WindowManagerService.this.dump();
7107 }
7108 mHasLocalTransformation = false;
7109 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007110 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 // When our app token is animating, we kind-of pretend like
7112 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7113 // part of this check means that we will only do this if
7114 // our window is not currently exiting, or it is not
7115 // locally animating itself. The idea being that one that
7116 // is exiting and doing a local animation should be removed
7117 // once that animation is done.
7118 mAnimating = true;
7119 mHasTransformation = true;
7120 mTransformation.clear();
7121 return false;
7122 } else if (mHasTransformation) {
7123 // Little trick to get through the path below to act like
7124 // we have finished an animation.
7125 mAnimating = true;
7126 } else if (isAnimating()) {
7127 mAnimating = true;
7128 }
7129 } else if (mAnimation != null) {
7130 // If the display is frozen, and there is a pending animation,
7131 // clear it and make sure we run the cleanup code.
7132 mAnimating = true;
7133 mLocalAnimating = true;
7134 mAnimation = null;
7135 }
Romain Guy06882f82009-06-10 13:36:04 -07007136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007137 if (!mAnimating && !mLocalAnimating) {
7138 return false;
7139 }
7140
Joe Onorato8a9b2202010-02-26 18:56:32 -08007141 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007142 TAG, "Animation done in " + this + ": exiting=" + mExiting
7143 + ", reportedVisible="
7144 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007146 mAnimating = false;
7147 mLocalAnimating = false;
7148 mAnimation = null;
7149 mAnimLayer = mLayer;
7150 if (mIsImWindow) {
7151 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007152 } else if (mIsWallpaper) {
7153 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007155 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 + " anim layer: " + mAnimLayer);
7157 mHasTransformation = false;
7158 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007159 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7160 if (DEBUG_VISIBILITY) {
7161 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7162 + mPolicyVisibilityAfterAnim);
7163 }
7164 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7165 if (!mPolicyVisibility) {
7166 if (mCurrentFocus == this) {
7167 mFocusMayChange = true;
7168 }
7169 // Window is no longer visible -- make sure if we were waiting
7170 // for it to be displayed before enabling the display, that
7171 // we allow the display to be enabled now.
7172 enableScreenIfNeededLocked();
7173 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007175 mTransformation.clear();
7176 if (mHasDrawn
7177 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7178 && mAppToken != null
7179 && mAppToken.firstWindowDrawn
7180 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007181 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182 + mToken + ": first real window done animating");
7183 mFinishedStarting.add(mAppToken);
7184 mH.sendEmptyMessage(H.FINISHED_STARTING);
7185 }
Romain Guy06882f82009-06-10 13:36:04 -07007186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007187 finishExit();
7188
7189 if (mAppToken != null) {
7190 mAppToken.updateReportedVisibilityLocked();
7191 }
7192
7193 return false;
7194 }
7195
7196 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007197 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007198 TAG, "finishExit in " + this
7199 + ": exiting=" + mExiting
7200 + " remove=" + mRemoveOnExit
7201 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 final int N = mChildWindows.size();
7204 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007205 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007206 }
Romain Guy06882f82009-06-10 13:36:04 -07007207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007208 if (!mExiting) {
7209 return;
7210 }
Romain Guy06882f82009-06-10 13:36:04 -07007211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007212 if (isWindowAnimating()) {
7213 return;
7214 }
7215
Joe Onorato8a9b2202010-02-26 18:56:32 -08007216 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007217 TAG, "Exit animation finished in " + this
7218 + ": remove=" + mRemoveOnExit);
7219 if (mSurface != null) {
7220 mDestroySurface.add(this);
7221 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007222 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007223 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224 try {
7225 mSurface.hide();
7226 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007227 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 }
7229 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007230 }
7231 mExiting = false;
7232 if (mRemoveOnExit) {
7233 mPendingRemove.add(this);
7234 mRemoveOnExit = false;
7235 }
7236 }
Romain Guy06882f82009-06-10 13:36:04 -07007237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007238 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7239 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7240 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7241 if (dtdx < -.000001f || dtdx > .000001f) return false;
7242 if (dsdy < -.000001f || dsdy > .000001f) return false;
7243 return true;
7244 }
Romain Guy06882f82009-06-10 13:36:04 -07007245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007246 void computeShownFrameLocked() {
7247 final boolean selfTransformation = mHasLocalTransformation;
7248 Transformation attachedTransformation =
7249 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7250 ? mAttachedWindow.mTransformation : null;
7251 Transformation appTransformation =
7252 (mAppToken != null && mAppToken.hasTransformation)
7253 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007254
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007255 // Wallpapers are animated based on the "real" window they
7256 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007257 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007258 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007259 if (mWallpaperTarget.mHasLocalTransformation &&
7260 mWallpaperTarget.mAnimation != null &&
7261 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007262 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007263 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007264 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007265 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007266 }
7267 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007268 mWallpaperTarget.mAppToken.hasTransformation &&
7269 mWallpaperTarget.mAppToken.animation != null &&
7270 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007271 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007272 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007273 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007274 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007275 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007276 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 if (selfTransformation || attachedTransformation != null
7279 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007280 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 final Rect frame = mFrame;
7282 final float tmpFloats[] = mTmpFloats;
7283 final Matrix tmpMatrix = mTmpMatrix;
7284
7285 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007286 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007288 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007290 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007292 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 }
7294 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007295 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007296 }
7297
7298 // "convert" it into SurfaceFlinger's format
7299 // (a 2x2 matrix + an offset)
7300 // Here we must not transform the position of the surface
7301 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007302 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 tmpMatrix.getValues(tmpFloats);
7305 mDsDx = tmpFloats[Matrix.MSCALE_X];
7306 mDtDx = tmpFloats[Matrix.MSKEW_X];
7307 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7308 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007309 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7310 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007311 int w = frame.width();
7312 int h = frame.height();
7313 mShownFrame.set(x, y, x+w, y+h);
7314
7315 // Now set the alpha... but because our current hardware
7316 // can't do alpha transformation on a non-opaque surface,
7317 // turn it off if we are running an animation that is also
7318 // transforming since it is more important to have that
7319 // animation be smooth.
7320 mShownAlpha = mAlpha;
7321 if (!mLimitedAlphaCompositing
7322 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7323 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7324 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007325 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007326 if (selfTransformation) {
7327 mShownAlpha *= mTransformation.getAlpha();
7328 }
7329 if (attachedTransformation != null) {
7330 mShownAlpha *= attachedTransformation.getAlpha();
7331 }
7332 if (appTransformation != null) {
7333 mShownAlpha *= appTransformation.getAlpha();
7334 }
7335 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007336 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007337 }
Romain Guy06882f82009-06-10 13:36:04 -07007338
Joe Onorato8a9b2202010-02-26 18:56:32 -08007339 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 TAG, "Continuing animation in " + this +
7341 ": " + mShownFrame +
7342 ", alpha=" + mTransformation.getAlpha());
7343 return;
7344 }
Romain Guy06882f82009-06-10 13:36:04 -07007345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007347 if (mXOffset != 0 || mYOffset != 0) {
7348 mShownFrame.offset(mXOffset, mYOffset);
7349 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 mShownAlpha = mAlpha;
7351 mDsDx = 1;
7352 mDtDx = 0;
7353 mDsDy = 0;
7354 mDtDy = 1;
7355 }
Romain Guy06882f82009-06-10 13:36:04 -07007356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007357 /**
7358 * Is this window visible? It is not visible if there is no
7359 * surface, or we are in the process of running an exit animation
7360 * that will remove the surface, or its app token has been hidden.
7361 */
7362 public boolean isVisibleLw() {
7363 final AppWindowToken atoken = mAppToken;
7364 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7365 && (atoken == null || !atoken.hiddenRequested)
7366 && !mExiting && !mDestroying;
7367 }
7368
7369 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007370 * Like {@link #isVisibleLw}, but also counts a window that is currently
7371 * "hidden" behind the keyguard as visible. This allows us to apply
7372 * things like window flags that impact the keyguard.
7373 * XXX I am starting to think we need to have ANOTHER visibility flag
7374 * for this "hidden behind keyguard" state rather than overloading
7375 * mPolicyVisibility. Ungh.
7376 */
7377 public boolean isVisibleOrBehindKeyguardLw() {
7378 final AppWindowToken atoken = mAppToken;
7379 return mSurface != null && !mAttachedHidden
7380 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007381 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007382 && !mExiting && !mDestroying;
7383 }
7384
7385 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 * Is this window visible, ignoring its app token? It is not visible
7387 * if there is no surface, or we are in the process of running an exit animation
7388 * that will remove the surface.
7389 */
7390 public boolean isWinVisibleLw() {
7391 final AppWindowToken atoken = mAppToken;
7392 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7393 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7394 && !mExiting && !mDestroying;
7395 }
7396
7397 /**
7398 * The same as isVisible(), but follows the current hidden state of
7399 * the associated app token, not the pending requested hidden state.
7400 */
7401 boolean isVisibleNow() {
7402 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007403 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 }
7405
7406 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007407 * Can this window possibly be a drag/drop target? The test here is
7408 * a combination of the above "visible now" with the check that the
7409 * Input Manager uses when discarding windows from input consideration.
7410 */
7411 boolean isPotentialDragTarget() {
7412 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7413 }
7414
7415 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007416 * Same as isVisible(), but we also count it as visible between the
7417 * call to IWindowSession.add() and the first relayout().
7418 */
7419 boolean isVisibleOrAdding() {
7420 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007421 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7423 && mPolicyVisibility && !mAttachedHidden
7424 && (atoken == null || !atoken.hiddenRequested)
7425 && !mExiting && !mDestroying;
7426 }
7427
7428 /**
7429 * Is this window currently on-screen? It is on-screen either if it
7430 * is visible or it is currently running an animation before no longer
7431 * being visible.
7432 */
7433 boolean isOnScreen() {
7434 final AppWindowToken atoken = mAppToken;
7435 if (atoken != null) {
7436 return mSurface != null && mPolicyVisibility && !mDestroying
7437 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007438 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 } else {
7440 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007441 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 }
7443 }
Romain Guy06882f82009-06-10 13:36:04 -07007444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 /**
7446 * Like isOnScreen(), but we don't return true if the window is part
7447 * of a transition that has not yet been started.
7448 */
7449 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007450 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007451 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007452 return false;
7453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007455 final boolean animating = atoken != null
7456 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007458 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7459 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007460 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 }
7462
7463 /** Is the window or its container currently animating? */
7464 boolean isAnimating() {
7465 final WindowState attached = mAttachedWindow;
7466 final AppWindowToken atoken = mAppToken;
7467 return mAnimation != null
7468 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007469 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 (atoken.animation != null
7471 || atoken.inPendingTransaction));
7472 }
7473
7474 /** Is this window currently animating? */
7475 boolean isWindowAnimating() {
7476 return mAnimation != null;
7477 }
7478
7479 /**
7480 * Like isOnScreen, but returns false if the surface hasn't yet
7481 * been drawn.
7482 */
7483 public boolean isDisplayedLw() {
7484 final AppWindowToken atoken = mAppToken;
7485 return mSurface != null && mPolicyVisibility && !mDestroying
7486 && !mDrawPending && !mCommitDrawPending
7487 && ((!mAttachedHidden &&
7488 (atoken == null || !atoken.hiddenRequested))
7489 || mAnimating);
7490 }
7491
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007492 /**
7493 * Returns true if the window has a surface that it has drawn a
7494 * complete UI in to.
7495 */
7496 public boolean isDrawnLw() {
7497 final AppWindowToken atoken = mAppToken;
7498 return mSurface != null && !mDestroying
7499 && !mDrawPending && !mCommitDrawPending;
7500 }
7501
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007502 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007503 * Return true if the window is opaque and fully drawn. This indicates
7504 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007505 */
7506 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007507 return (mAttrs.format == PixelFormat.OPAQUE
7508 || mAttrs.type == TYPE_WALLPAPER)
7509 && mSurface != null && mAnimation == null
7510 && (mAppToken == null || mAppToken.animation == null)
7511 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007512 }
7513
7514 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7515 return
7516 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007517 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7518 // only if it's visible
7519 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007520 // and only if the application fills the compatible screen
7521 mFrame.left <= mCompatibleScreenFrame.left &&
7522 mFrame.top <= mCompatibleScreenFrame.top &&
7523 mFrame.right >= mCompatibleScreenFrame.right &&
7524 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007525 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007526 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007527 }
7528
7529 boolean isFullscreen(int screenWidth, int screenHeight) {
7530 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007531 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 }
7533
7534 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007535 disposeInputChannel();
7536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 if (mAttachedWindow != null) {
7538 mAttachedWindow.mChildWindows.remove(this);
7539 }
7540 destroySurfaceLocked();
7541 mSession.windowRemovedLocked();
7542 try {
7543 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7544 } catch (RuntimeException e) {
7545 // Ignore if it has already been removed (usually because
7546 // we are doing this as part of processing a death note.)
7547 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007548 }
7549
7550 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007551 if (mInputChannel != null) {
7552 mInputManager.unregisterInputChannel(mInputChannel);
7553
7554 mInputChannel.dispose();
7555 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 }
7558
7559 private class DeathRecipient implements IBinder.DeathRecipient {
7560 public void binderDied() {
7561 try {
7562 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007563 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007564 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 if (win != null) {
7566 removeWindowLocked(mSession, win);
7567 }
7568 }
7569 } catch (IllegalArgumentException ex) {
7570 // This will happen if the window has already been
7571 // removed.
7572 }
7573 }
7574 }
7575
7576 /** Returns true if this window desires key events. */
7577 public final boolean canReceiveKeys() {
7578 return isVisibleOrAdding()
7579 && (mViewVisibility == View.VISIBLE)
7580 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7581 }
7582
7583 public boolean hasDrawnLw() {
7584 return mHasDrawn;
7585 }
7586
7587 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007588 return showLw(doAnimation, true);
7589 }
7590
7591 boolean showLw(boolean doAnimation, boolean requestAnim) {
7592 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7593 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007595 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007596 if (doAnimation) {
7597 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7598 + mPolicyVisibility + " mAnimation=" + mAnimation);
7599 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7600 doAnimation = false;
7601 } else if (mPolicyVisibility && mAnimation == null) {
7602 // Check for the case where we are currently visible and
7603 // not animating; we do not want to do animation at such a
7604 // point to become visible when we already are.
7605 doAnimation = false;
7606 }
7607 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007608 mPolicyVisibility = true;
7609 mPolicyVisibilityAfterAnim = true;
7610 if (doAnimation) {
7611 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7612 }
7613 if (requestAnim) {
7614 requestAnimationLocked(0);
7615 }
7616 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 }
7618
7619 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007620 return hideLw(doAnimation, true);
7621 }
7622
7623 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007624 if (doAnimation) {
7625 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7626 doAnimation = false;
7627 }
7628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7630 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007631 if (!current) {
7632 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007634 if (doAnimation) {
7635 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7636 if (mAnimation == null) {
7637 doAnimation = false;
7638 }
7639 }
7640 if (doAnimation) {
7641 mPolicyVisibilityAfterAnim = false;
7642 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007643 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007644 mPolicyVisibilityAfterAnim = false;
7645 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007646 // Window is no longer visible -- make sure if we were waiting
7647 // for it to be displayed before enabling the display, that
7648 // we allow the display to be enabled now.
7649 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007650 if (mCurrentFocus == this) {
7651 mFocusMayChange = true;
7652 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007653 }
7654 if (requestAnim) {
7655 requestAnimationLocked(0);
7656 }
7657 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007658 }
7659
7660 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007661 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7662 pw.print(" mClient="); pw.println(mClient.asBinder());
7663 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7664 if (mAttachedWindow != null || mLayoutAttached) {
7665 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7666 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7667 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007668 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7669 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7670 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007671 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7672 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007673 }
7674 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7675 pw.print(" mSubLayer="); pw.print(mSubLayer);
7676 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7677 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7678 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7679 pw.print("="); pw.print(mAnimLayer);
7680 pw.print(" mLastLayer="); pw.println(mLastLayer);
7681 if (mSurface != null) {
7682 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007683 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7684 pw.print(" layer="); pw.print(mSurfaceLayer);
7685 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7686 pw.print(" rect=("); pw.print(mSurfaceX);
7687 pw.print(","); pw.print(mSurfaceY);
7688 pw.print(") "); pw.print(mSurfaceW);
7689 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007690 }
7691 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7692 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7693 if (mAppToken != null) {
7694 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7695 }
7696 if (mTargetAppToken != null) {
7697 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7698 }
7699 pw.print(prefix); pw.print("mViewVisibility=0x");
7700 pw.print(Integer.toHexString(mViewVisibility));
7701 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007702 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7703 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007704 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7705 pw.print(prefix); pw.print("mPolicyVisibility=");
7706 pw.print(mPolicyVisibility);
7707 pw.print(" mPolicyVisibilityAfterAnim=");
7708 pw.print(mPolicyVisibilityAfterAnim);
7709 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7710 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007711 if (!mRelayoutCalled) {
7712 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7713 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007714 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007715 pw.print(" h="); pw.print(mRequestedHeight);
7716 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007717 if (mXOffset != 0 || mYOffset != 0) {
7718 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7719 pw.print(" y="); pw.println(mYOffset);
7720 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007721 pw.print(prefix); pw.print("mGivenContentInsets=");
7722 mGivenContentInsets.printShortString(pw);
7723 pw.print(" mGivenVisibleInsets=");
7724 mGivenVisibleInsets.printShortString(pw);
7725 pw.println();
7726 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7727 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7728 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7729 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007730 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007731 pw.print(prefix); pw.print("mShownFrame=");
7732 mShownFrame.printShortString(pw);
7733 pw.print(" last="); mLastShownFrame.printShortString(pw);
7734 pw.println();
7735 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7736 pw.print(" last="); mLastFrame.printShortString(pw);
7737 pw.println();
7738 pw.print(prefix); pw.print("mContainingFrame=");
7739 mContainingFrame.printShortString(pw);
7740 pw.print(" mDisplayFrame=");
7741 mDisplayFrame.printShortString(pw);
7742 pw.println();
7743 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7744 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7745 pw.println();
7746 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7747 pw.print(" last="); mLastContentInsets.printShortString(pw);
7748 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7749 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7750 pw.println();
7751 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7752 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7753 pw.print(" mAlpha="); pw.print(mAlpha);
7754 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7755 }
7756 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7757 || mAnimation != null) {
7758 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7759 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7760 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7761 pw.print(" mAnimation="); pw.println(mAnimation);
7762 }
7763 if (mHasTransformation || mHasLocalTransformation) {
7764 pw.print(prefix); pw.print("XForm: has=");
7765 pw.print(mHasTransformation);
7766 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7767 pw.print(" "); mTransformation.printShortString(pw);
7768 pw.println();
7769 }
7770 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7771 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7772 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7773 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7774 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7775 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7776 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7777 pw.print(" mDestroying="); pw.print(mDestroying);
7778 pw.print(" mRemoved="); pw.println(mRemoved);
7779 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007780 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007781 pw.print(prefix); pw.print("mOrientationChanging=");
7782 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007783 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7784 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007785 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007786 if (mHScale != 1 || mVScale != 1) {
7787 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7788 pw.print(" mVScale="); pw.println(mVScale);
7789 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007790 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007791 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7792 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7793 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007794 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7795 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7796 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007799
7800 String makeInputChannelName() {
7801 return Integer.toHexString(System.identityHashCode(this))
7802 + " " + mAttrs.getTitle();
7803 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007804
7805 @Override
7806 public String toString() {
7807 return "Window{"
7808 + Integer.toHexString(System.identityHashCode(this))
7809 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7810 }
7811 }
Romain Guy06882f82009-06-10 13:36:04 -07007812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007813 // -------------------------------------------------------------
7814 // Window Token State
7815 // -------------------------------------------------------------
7816
7817 class WindowToken {
7818 // The actual token.
7819 final IBinder token;
7820
7821 // The type of window this token is for, as per WindowManager.LayoutParams.
7822 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007824 // Set if this token was explicitly added by a client, so should
7825 // not be removed when all windows are removed.
7826 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007827
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007828 // For printing.
7829 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007831 // If this is an AppWindowToken, this is non-null.
7832 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007834 // All of the windows associated with this token.
7835 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7836
7837 // Is key dispatching paused for this token?
7838 boolean paused = false;
7839
7840 // Should this token's windows be hidden?
7841 boolean hidden;
7842
7843 // Temporary for finding which tokens no longer have visible windows.
7844 boolean hasVisible;
7845
Dianne Hackborna8f60182009-09-01 19:01:50 -07007846 // Set to true when this token is in a pending transaction where it
7847 // will be shown.
7848 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007849
Dianne Hackborna8f60182009-09-01 19:01:50 -07007850 // Set to true when this token is in a pending transaction where it
7851 // will be hidden.
7852 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007853
Dianne Hackborna8f60182009-09-01 19:01:50 -07007854 // Set to true when this token is in a pending transaction where its
7855 // windows will be put to the bottom of the list.
7856 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007857
Dianne Hackborna8f60182009-09-01 19:01:50 -07007858 // Set to true when this token is in a pending transaction where its
7859 // windows will be put to the top of the list.
7860 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 WindowToken(IBinder _token, int type, boolean _explicit) {
7863 token = _token;
7864 windowType = type;
7865 explicit = _explicit;
7866 }
7867
7868 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007869 pw.print(prefix); pw.print("token="); pw.println(token);
7870 pw.print(prefix); pw.print("windows="); pw.println(windows);
7871 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7872 pw.print(" hidden="); pw.print(hidden);
7873 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007874 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7875 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7876 pw.print(" waitingToHide="); pw.print(waitingToHide);
7877 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7878 pw.print(" sendingToTop="); pw.println(sendingToTop);
7879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 }
7881
7882 @Override
7883 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007884 if (stringName == null) {
7885 StringBuilder sb = new StringBuilder();
7886 sb.append("WindowToken{");
7887 sb.append(Integer.toHexString(System.identityHashCode(this)));
7888 sb.append(" token="); sb.append(token); sb.append('}');
7889 stringName = sb.toString();
7890 }
7891 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007892 }
7893 };
7894
7895 class AppWindowToken extends WindowToken {
7896 // Non-null only for application tokens.
7897 final IApplicationToken appToken;
7898
7899 // All of the windows and child windows that are included in this
7900 // application token. Note this list is NOT sorted!
7901 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7902
7903 int groupId = -1;
7904 boolean appFullscreen;
7905 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007906
7907 // The input dispatching timeout for this application token in nanoseconds.
7908 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007910 // These are used for determining when all windows associated with
7911 // an activity have been drawn, so they can be made visible together
7912 // at the same time.
7913 int lastTransactionSequence = mTransactionSequence-1;
7914 int numInterestingWindows;
7915 int numDrawnWindows;
7916 boolean inPendingTransaction;
7917 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 // Is this token going to be hidden in a little while? If so, it
7920 // won't be taken into account for setting the screen orientation.
7921 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007923 // Is this window's surface needed? This is almost like hidden, except
7924 // it will sometimes be true a little earlier: when the token has
7925 // been shown, but is still waiting for its app transition to execute
7926 // before making its windows shown.
7927 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 // Have we told the window clients to hide themselves?
7930 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 // Last visibility state we reported to the app token.
7933 boolean reportedVisible;
7934
7935 // Set to true when the token has been removed from the window mgr.
7936 boolean removed;
7937
7938 // Have we been asked to have this token keep the screen frozen?
7939 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007941 boolean animating;
7942 Animation animation;
7943 boolean hasTransformation;
7944 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007946 // Offset to the window of all layers in the token, for use by
7947 // AppWindowToken animations.
7948 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007950 // Information about an application starting window if displayed.
7951 StartingData startingData;
7952 WindowState startingWindow;
7953 View startingView;
7954 boolean startingDisplayed;
7955 boolean startingMoved;
7956 boolean firstWindowDrawn;
7957
7958 AppWindowToken(IApplicationToken _token) {
7959 super(_token.asBinder(),
7960 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7961 appWindowToken = this;
7962 appToken = _token;
7963 }
Romain Guy06882f82009-06-10 13:36:04 -07007964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007965 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007966 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007967 TAG, "Setting animation in " + this + ": " + anim);
7968 animation = anim;
7969 animating = false;
7970 anim.restrictDuration(MAX_ANIMATION_DURATION);
7971 anim.scaleCurrentDuration(mTransitionAnimationScale);
7972 int zorder = anim.getZAdjustment();
7973 int adj = 0;
7974 if (zorder == Animation.ZORDER_TOP) {
7975 adj = TYPE_LAYER_OFFSET;
7976 } else if (zorder == Animation.ZORDER_BOTTOM) {
7977 adj = -TYPE_LAYER_OFFSET;
7978 }
Romain Guy06882f82009-06-10 13:36:04 -07007979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 if (animLayerAdjustment != adj) {
7981 animLayerAdjustment = adj;
7982 updateLayers();
7983 }
7984 }
Romain Guy06882f82009-06-10 13:36:04 -07007985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007986 public void setDummyAnimation() {
7987 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007988 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007989 TAG, "Setting dummy animation in " + this);
7990 animation = sDummyAnimation;
7991 }
7992 }
7993
7994 public void clearAnimation() {
7995 if (animation != null) {
7996 animation = null;
7997 animating = true;
7998 }
7999 }
Romain Guy06882f82009-06-10 13:36:04 -07008000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 void updateLayers() {
8002 final int N = allAppWindows.size();
8003 final int adj = animLayerAdjustment;
8004 for (int i=0; i<N; i++) {
8005 WindowState w = allAppWindows.get(i);
8006 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008007 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008008 + w.mAnimLayer);
8009 if (w == mInputMethodTarget) {
8010 setInputMethodAnimLayerAdjustment(adj);
8011 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008012 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008013 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008014 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008015 }
8016 }
Romain Guy06882f82009-06-10 13:36:04 -07008017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008018 void sendAppVisibilityToClients() {
8019 final int N = allAppWindows.size();
8020 for (int i=0; i<N; i++) {
8021 WindowState win = allAppWindows.get(i);
8022 if (win == startingWindow && clientHidden) {
8023 // Don't hide the starting window.
8024 continue;
8025 }
8026 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008027 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 "Setting visibility of " + win + ": " + (!clientHidden));
8029 win.mClient.dispatchAppVisibility(!clientHidden);
8030 } catch (RemoteException e) {
8031 }
8032 }
8033 }
Romain Guy06882f82009-06-10 13:36:04 -07008034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 void showAllWindowsLocked() {
8036 final int NW = allAppWindows.size();
8037 for (int i=0; i<NW; i++) {
8038 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008039 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 "performing show on: " + w);
8041 w.performShowLocked();
8042 }
8043 }
Romain Guy06882f82009-06-10 13:36:04 -07008044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008045 // This must be called while inside a transaction.
8046 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008047 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 if (animation == sDummyAnimation) {
8051 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008052 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008053 // when it is really time to animate, this will be set to
8054 // a real animation and the next call will execute normally.
8055 return false;
8056 }
Romain Guy06882f82009-06-10 13:36:04 -07008057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8059 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008060 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008061 TAG, "Starting animation in " + this +
8062 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8063 + " scale=" + mTransitionAnimationScale
8064 + " allDrawn=" + allDrawn + " animating=" + animating);
8065 animation.initialize(dw, dh, dw, dh);
8066 animation.setStartTime(currentTime);
8067 animating = true;
8068 }
8069 transformation.clear();
8070 final boolean more = animation.getTransformation(
8071 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008072 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008073 TAG, "Stepped animation in " + this +
8074 ": more=" + more + ", xform=" + transformation);
8075 if (more) {
8076 // we're done!
8077 hasTransformation = true;
8078 return true;
8079 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008080 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008081 TAG, "Finished animation in " + this +
8082 " @ " + currentTime);
8083 animation = null;
8084 }
8085 } else if (animation != null) {
8086 // If the display is frozen, and there is a pending animation,
8087 // clear it and make sure we run the cleanup code.
8088 animating = true;
8089 animation = null;
8090 }
8091
8092 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 if (!animating) {
8095 return false;
8096 }
8097
8098 clearAnimation();
8099 animating = false;
8100 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8101 moveInputMethodWindowsIfNeededLocked(true);
8102 }
Romain Guy06882f82009-06-10 13:36:04 -07008103
Joe Onorato8a9b2202010-02-26 18:56:32 -08008104 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008105 TAG, "Animation done in " + this
8106 + ": reportedVisible=" + reportedVisible);
8107
8108 transformation.clear();
8109 if (animLayerAdjustment != 0) {
8110 animLayerAdjustment = 0;
8111 updateLayers();
8112 }
Romain Guy06882f82009-06-10 13:36:04 -07008113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 final int N = windows.size();
8115 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008116 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008117 }
8118 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 return false;
8121 }
8122
8123 void updateReportedVisibilityLocked() {
8124 if (appToken == null) {
8125 return;
8126 }
Romain Guy06882f82009-06-10 13:36:04 -07008127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008128 int numInteresting = 0;
8129 int numVisible = 0;
8130 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008131
Joe Onorato8a9b2202010-02-26 18:56:32 -08008132 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 final int N = allAppWindows.size();
8134 for (int i=0; i<N; i++) {
8135 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008136 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008137 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008138 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8139 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 continue;
8141 }
8142 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008143 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008144 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008146 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008147 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 + " pv=" + win.mPolicyVisibility
8149 + " dp=" + win.mDrawPending
8150 + " cdp=" + win.mCommitDrawPending
8151 + " ah=" + win.mAttachedHidden
8152 + " th="
8153 + (win.mAppToken != null
8154 ? win.mAppToken.hiddenRequested : false)
8155 + " a=" + win.mAnimating);
8156 }
8157 }
8158 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008159 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008160 if (!win.isAnimating()) {
8161 numVisible++;
8162 }
8163 nowGone = false;
8164 } else if (win.isAnimating()) {
8165 nowGone = false;
8166 }
8167 }
Romain Guy06882f82009-06-10 13:36:04 -07008168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008169 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008170 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008171 + numInteresting + " visible=" + numVisible);
8172 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008173 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008174 TAG, "Visibility changed in " + this
8175 + ": vis=" + nowVisible);
8176 reportedVisible = nowVisible;
8177 Message m = mH.obtainMessage(
8178 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8179 nowVisible ? 1 : 0,
8180 nowGone ? 1 : 0,
8181 this);
8182 mH.sendMessage(m);
8183 }
8184 }
Romain Guy06882f82009-06-10 13:36:04 -07008185
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008186 WindowState findMainWindow() {
8187 int j = windows.size();
8188 while (j > 0) {
8189 j--;
8190 WindowState win = windows.get(j);
8191 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8192 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8193 return win;
8194 }
8195 }
8196 return null;
8197 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008199 void dump(PrintWriter pw, String prefix) {
8200 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008201 if (appToken != null) {
8202 pw.print(prefix); pw.println("app=true");
8203 }
8204 if (allAppWindows.size() > 0) {
8205 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8206 }
8207 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008208 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008209 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8210 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8211 pw.print(" clientHidden="); pw.print(clientHidden);
8212 pw.print(" willBeHidden="); pw.print(willBeHidden);
8213 pw.print(" reportedVisible="); pw.println(reportedVisible);
8214 if (paused || freezingScreen) {
8215 pw.print(prefix); pw.print("paused="); pw.print(paused);
8216 pw.print(" freezingScreen="); pw.println(freezingScreen);
8217 }
8218 if (numInterestingWindows != 0 || numDrawnWindows != 0
8219 || inPendingTransaction || allDrawn) {
8220 pw.print(prefix); pw.print("numInterestingWindows=");
8221 pw.print(numInterestingWindows);
8222 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8223 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8224 pw.print(" allDrawn="); pw.println(allDrawn);
8225 }
8226 if (animating || animation != null) {
8227 pw.print(prefix); pw.print("animating="); pw.print(animating);
8228 pw.print(" animation="); pw.println(animation);
8229 }
8230 if (animLayerAdjustment != 0) {
8231 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8232 }
8233 if (hasTransformation) {
8234 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8235 pw.print(" transformation="); transformation.printShortString(pw);
8236 pw.println();
8237 }
8238 if (startingData != null || removed || firstWindowDrawn) {
8239 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8240 pw.print(" removed="); pw.print(removed);
8241 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8242 }
8243 if (startingWindow != null || startingView != null
8244 || startingDisplayed || startingMoved) {
8245 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8246 pw.print(" startingView="); pw.print(startingView);
8247 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8248 pw.print(" startingMoved"); pw.println(startingMoved);
8249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 }
8251
8252 @Override
8253 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008254 if (stringName == null) {
8255 StringBuilder sb = new StringBuilder();
8256 sb.append("AppWindowToken{");
8257 sb.append(Integer.toHexString(System.identityHashCode(this)));
8258 sb.append(" token="); sb.append(token); sb.append('}');
8259 stringName = sb.toString();
8260 }
8261 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262 }
8263 }
Romain Guy06882f82009-06-10 13:36:04 -07008264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008265 // -------------------------------------------------------------
8266 // DummyAnimation
8267 // -------------------------------------------------------------
8268
8269 // This is an animation that does nothing: it just immediately finishes
8270 // itself every time it is called. It is used as a stub animation in cases
8271 // where we want to synchronize multiple things that may be animating.
8272 static final class DummyAnimation extends Animation {
8273 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8274 return false;
8275 }
8276 }
8277 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 // -------------------------------------------------------------
8280 // Async Handler
8281 // -------------------------------------------------------------
8282
8283 static final class StartingData {
8284 final String pkg;
8285 final int theme;
8286 final CharSequence nonLocalizedLabel;
8287 final int labelRes;
8288 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008290 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8291 int _labelRes, int _icon) {
8292 pkg = _pkg;
8293 theme = _theme;
8294 nonLocalizedLabel = _nonLocalizedLabel;
8295 labelRes = _labelRes;
8296 icon = _icon;
8297 }
8298 }
8299
8300 private final class H extends Handler {
8301 public static final int REPORT_FOCUS_CHANGE = 2;
8302 public static final int REPORT_LOSING_FOCUS = 3;
8303 public static final int ANIMATE = 4;
8304 public static final int ADD_STARTING = 5;
8305 public static final int REMOVE_STARTING = 6;
8306 public static final int FINISHED_STARTING = 7;
8307 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008308 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8309 public static final int HOLD_SCREEN_CHANGED = 12;
8310 public static final int APP_TRANSITION_TIMEOUT = 13;
8311 public static final int PERSIST_ANIMATION_SCALE = 14;
8312 public static final int FORCE_GC = 15;
8313 public static final int ENABLE_SCREEN = 16;
8314 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008315 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008316 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008317 public static final int DRAG_START_TIMEOUT = 20;
Romain Guy06882f82009-06-10 13:36:04 -07008318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008319 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 public H() {
8322 }
Romain Guy06882f82009-06-10 13:36:04 -07008323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008324 @Override
8325 public void handleMessage(Message msg) {
8326 switch (msg.what) {
8327 case REPORT_FOCUS_CHANGE: {
8328 WindowState lastFocus;
8329 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008331 synchronized(mWindowMap) {
8332 lastFocus = mLastFocus;
8333 newFocus = mCurrentFocus;
8334 if (lastFocus == newFocus) {
8335 // Focus is not changing, so nothing to do.
8336 return;
8337 }
8338 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008339 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 // + " to " + newFocus);
8341 if (newFocus != null && lastFocus != null
8342 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008343 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008344 mLosingFocus.add(lastFocus);
8345 lastFocus = null;
8346 }
8347 }
8348
8349 if (lastFocus != newFocus) {
8350 //System.out.println("Changing focus from " + lastFocus
8351 // + " to " + newFocus);
8352 if (newFocus != null) {
8353 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008354 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008355 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8356 } catch (RemoteException e) {
8357 // Ignore if process has died.
8358 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008359 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 }
8361
8362 if (lastFocus != null) {
8363 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008364 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008365 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8366 } catch (RemoteException e) {
8367 // Ignore if process has died.
8368 }
8369 }
8370 }
8371 } break;
8372
8373 case REPORT_LOSING_FOCUS: {
8374 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008376 synchronized(mWindowMap) {
8377 losers = mLosingFocus;
8378 mLosingFocus = new ArrayList<WindowState>();
8379 }
8380
8381 final int N = losers.size();
8382 for (int i=0; i<N; i++) {
8383 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008384 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008385 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8386 } catch (RemoteException e) {
8387 // Ignore if process has died.
8388 }
8389 }
8390 } break;
8391
8392 case ANIMATE: {
8393 synchronized(mWindowMap) {
8394 mAnimationPending = false;
8395 performLayoutAndPlaceSurfacesLocked();
8396 }
8397 } break;
8398
8399 case ADD_STARTING: {
8400 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8401 final StartingData sd = wtoken.startingData;
8402
8403 if (sd == null) {
8404 // Animation has been canceled... do nothing.
8405 return;
8406 }
Romain Guy06882f82009-06-10 13:36:04 -07008407
Joe Onorato8a9b2202010-02-26 18:56:32 -08008408 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008411 View view = null;
8412 try {
8413 view = mPolicy.addStartingWindow(
8414 wtoken.token, sd.pkg,
8415 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8416 sd.icon);
8417 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008418 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419 }
8420
8421 if (view != null) {
8422 boolean abort = false;
8423
8424 synchronized(mWindowMap) {
8425 if (wtoken.removed || wtoken.startingData == null) {
8426 // If the window was successfully added, then
8427 // we need to remove it.
8428 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008429 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008430 "Aborted starting " + wtoken
8431 + ": removed=" + wtoken.removed
8432 + " startingData=" + wtoken.startingData);
8433 wtoken.startingWindow = null;
8434 wtoken.startingData = null;
8435 abort = true;
8436 }
8437 } else {
8438 wtoken.startingView = view;
8439 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008440 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 "Added starting " + wtoken
8442 + ": startingWindow="
8443 + wtoken.startingWindow + " startingView="
8444 + wtoken.startingView);
8445 }
8446
8447 if (abort) {
8448 try {
8449 mPolicy.removeStartingWindow(wtoken.token, view);
8450 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008451 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 }
8453 }
8454 }
8455 } break;
8456
8457 case REMOVE_STARTING: {
8458 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8459 IBinder token = null;
8460 View view = null;
8461 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008462 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008463 + wtoken + ": startingWindow="
8464 + wtoken.startingWindow + " startingView="
8465 + wtoken.startingView);
8466 if (wtoken.startingWindow != null) {
8467 view = wtoken.startingView;
8468 token = wtoken.token;
8469 wtoken.startingData = null;
8470 wtoken.startingView = null;
8471 wtoken.startingWindow = null;
8472 }
8473 }
8474 if (view != null) {
8475 try {
8476 mPolicy.removeStartingWindow(token, view);
8477 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008478 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 }
8480 }
8481 } break;
8482
8483 case FINISHED_STARTING: {
8484 IBinder token = null;
8485 View view = null;
8486 while (true) {
8487 synchronized (mWindowMap) {
8488 final int N = mFinishedStarting.size();
8489 if (N <= 0) {
8490 break;
8491 }
8492 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8493
Joe Onorato8a9b2202010-02-26 18:56:32 -08008494 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008495 "Finished starting " + wtoken
8496 + ": startingWindow=" + wtoken.startingWindow
8497 + " startingView=" + wtoken.startingView);
8498
8499 if (wtoken.startingWindow == null) {
8500 continue;
8501 }
8502
8503 view = wtoken.startingView;
8504 token = wtoken.token;
8505 wtoken.startingData = null;
8506 wtoken.startingView = null;
8507 wtoken.startingWindow = null;
8508 }
8509
8510 try {
8511 mPolicy.removeStartingWindow(token, view);
8512 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008513 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 }
8515 }
8516 } break;
8517
8518 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8519 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8520
8521 boolean nowVisible = msg.arg1 != 0;
8522 boolean nowGone = msg.arg2 != 0;
8523
8524 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008525 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 TAG, "Reporting visible in " + wtoken
8527 + " visible=" + nowVisible
8528 + " gone=" + nowGone);
8529 if (nowVisible) {
8530 wtoken.appToken.windowsVisible();
8531 } else {
8532 wtoken.appToken.windowsGone();
8533 }
8534 } catch (RemoteException ex) {
8535 }
8536 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 case WINDOW_FREEZE_TIMEOUT: {
8539 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008540 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 int i = mWindows.size();
8542 while (i > 0) {
8543 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008544 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 if (w.mOrientationChanging) {
8546 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008547 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 }
8549 }
8550 performLayoutAndPlaceSurfacesLocked();
8551 }
8552 break;
8553 }
Romain Guy06882f82009-06-10 13:36:04 -07008554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008555 case HOLD_SCREEN_CHANGED: {
8556 Session oldHold;
8557 Session newHold;
8558 synchronized (mWindowMap) {
8559 oldHold = mLastReportedHold;
8560 newHold = (Session)msg.obj;
8561 mLastReportedHold = newHold;
8562 }
Romain Guy06882f82009-06-10 13:36:04 -07008563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008564 if (oldHold != newHold) {
8565 try {
8566 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008567 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 "window",
8569 BatteryStats.WAKE_TYPE_WINDOW);
8570 }
8571 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008572 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573 "window",
8574 BatteryStats.WAKE_TYPE_WINDOW);
8575 }
8576 } catch (RemoteException e) {
8577 }
8578 }
8579 break;
8580 }
Romain Guy06882f82009-06-10 13:36:04 -07008581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 case APP_TRANSITION_TIMEOUT: {
8583 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008584 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008585 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 "*** APP TRANSITION TIMEOUT");
8587 mAppTransitionReady = true;
8588 mAppTransitionTimeout = true;
8589 performLayoutAndPlaceSurfacesLocked();
8590 }
8591 }
8592 break;
8593 }
Romain Guy06882f82009-06-10 13:36:04 -07008594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008595 case PERSIST_ANIMATION_SCALE: {
8596 Settings.System.putFloat(mContext.getContentResolver(),
8597 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8598 Settings.System.putFloat(mContext.getContentResolver(),
8599 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8600 break;
8601 }
Romain Guy06882f82009-06-10 13:36:04 -07008602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603 case FORCE_GC: {
8604 synchronized(mWindowMap) {
8605 if (mAnimationPending) {
8606 // If we are animating, don't do the gc now but
8607 // delay a bit so we don't interrupt the animation.
8608 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8609 2000);
8610 return;
8611 }
8612 // If we are currently rotating the display, it will
8613 // schedule a new message when done.
8614 if (mDisplayFrozen) {
8615 return;
8616 }
8617 mFreezeGcPending = 0;
8618 }
8619 Runtime.getRuntime().gc();
8620 break;
8621 }
Romain Guy06882f82009-06-10 13:36:04 -07008622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 case ENABLE_SCREEN: {
8624 performEnableScreen();
8625 break;
8626 }
Romain Guy06882f82009-06-10 13:36:04 -07008627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 case APP_FREEZE_TIMEOUT: {
8629 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008630 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008631 int i = mAppTokens.size();
8632 while (i > 0) {
8633 i--;
8634 AppWindowToken tok = mAppTokens.get(i);
8635 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008636 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 unsetAppFreezingScreenLocked(tok, true, true);
8638 }
8639 }
8640 }
8641 break;
8642 }
Romain Guy06882f82009-06-10 13:36:04 -07008643
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008644 case SEND_NEW_CONFIGURATION: {
8645 removeMessages(SEND_NEW_CONFIGURATION);
8646 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008647 break;
8648 }
Romain Guy06882f82009-06-10 13:36:04 -07008649
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008650 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008651 if (mWindowsChanged) {
8652 synchronized (mWindowMap) {
8653 mWindowsChanged = false;
8654 }
8655 notifyWindowsChanged();
8656 }
8657 break;
8658 }
8659
Christopher Tatea53146c2010-09-07 11:57:52 -07008660 case DRAG_START_TIMEOUT: {
8661 IBinder win = (IBinder)msg.obj;
8662 if (DEBUG_DRAG) {
8663 Slog.w(TAG, "Timeout starting drag by win " + win);
8664 }
8665 synchronized (mWindowMap) {
8666 // !!! TODO: ANR the app that has failed to start the drag in time
8667 if (mDragState != null) {
8668 mDragState.reset();
8669 mDragState = null;
8670 }
8671 }
8672 }
8673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008674 }
8675 }
8676 }
8677
8678 // -------------------------------------------------------------
8679 // IWindowManager API
8680 // -------------------------------------------------------------
8681
8682 public IWindowSession openSession(IInputMethodClient client,
8683 IInputContext inputContext) {
8684 if (client == null) throw new IllegalArgumentException("null client");
8685 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008686 Session session = new Session(client, inputContext);
8687 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008688 }
8689
8690 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8691 synchronized (mWindowMap) {
8692 // The focus for the client is the window immediately below
8693 // where we would place the input method window.
8694 int idx = findDesiredInputMethodWindowIndexLocked(false);
8695 WindowState imFocus;
8696 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008697 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 if (imFocus != null) {
8699 if (imFocus.mSession.mClient != null &&
8700 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8701 return true;
8702 }
8703 }
8704 }
8705 }
8706 return false;
8707 }
Romain Guy06882f82009-06-10 13:36:04 -07008708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008709 // -------------------------------------------------------------
8710 // Internals
8711 // -------------------------------------------------------------
8712
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008713 final WindowState windowForClientLocked(Session session, IWindow client,
8714 boolean throwOnError) {
8715 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008716 }
Romain Guy06882f82009-06-10 13:36:04 -07008717
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008718 final WindowState windowForClientLocked(Session session, IBinder client,
8719 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008720 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008721 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008722 TAG, "Looking up client " + client + ": " + win);
8723 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008724 RuntimeException ex = new IllegalArgumentException(
8725 "Requested window " + client + " does not exist");
8726 if (throwOnError) {
8727 throw ex;
8728 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008729 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008730 return null;
8731 }
8732 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008733 RuntimeException ex = new IllegalArgumentException(
8734 "Requested window " + client + " is in session " +
8735 win.mSession + ", not " + session);
8736 if (throwOnError) {
8737 throw ex;
8738 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008739 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 return null;
8741 }
8742
8743 return win;
8744 }
8745
Dianne Hackborna8f60182009-09-01 19:01:50 -07008746 final void rebuildAppWindowListLocked() {
8747 int NW = mWindows.size();
8748 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008749 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008750 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008751
Dianne Hackborna8f60182009-09-01 19:01:50 -07008752 // First remove all existing app windows.
8753 i=0;
8754 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008755 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008756 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008757 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008758 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008759 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008760 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008761 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008762 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008763 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008764 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8765 && lastWallpaper == i-1) {
8766 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008767 }
8768 i++;
8769 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008770
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008771 // The wallpaper window(s) typically live at the bottom of the stack,
8772 // so skip them before adding app tokens.
8773 lastWallpaper++;
8774 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008775
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008776 // First add all of the exiting app tokens... these are no longer
8777 // in the main app list, but still have windows shown. We put them
8778 // in the back because now that the animation is over we no longer
8779 // will care about them.
8780 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008781 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008782 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8783 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008784
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008785 // And add in the still active app tokens in Z order.
8786 NT = mAppTokens.size();
8787 for (int j=0; j<NT; j++) {
8788 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008789 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008790
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008791 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008792 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008793 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008794 + " windows but added " + i);
8795 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008796 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008798 private final void assignLayersLocked() {
8799 int N = mWindows.size();
8800 int curBaseLayer = 0;
8801 int curLayer = 0;
8802 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008805 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008806 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8807 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008808 curLayer += WINDOW_LAYER_MULTIPLIER;
8809 w.mLayer = curLayer;
8810 } else {
8811 curBaseLayer = curLayer = w.mBaseLayer;
8812 w.mLayer = curLayer;
8813 }
8814 if (w.mTargetAppToken != null) {
8815 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8816 } else if (w.mAppToken != null) {
8817 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8818 } else {
8819 w.mAnimLayer = w.mLayer;
8820 }
8821 if (w.mIsImWindow) {
8822 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008823 } else if (w.mIsWallpaper) {
8824 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008826 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008827 + w.mAnimLayer);
8828 //System.out.println(
8829 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8830 }
8831 }
8832
8833 private boolean mInLayout = false;
8834 private final void performLayoutAndPlaceSurfacesLocked() {
8835 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008836 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008837 throw new RuntimeException("Recursive call!");
8838 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008839 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008840 return;
8841 }
8842
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008843 if (mWaitingForConfig) {
8844 // Our configuration has changed (most likely rotation), but we
8845 // don't yet have the complete configuration to report to
8846 // applications. Don't do any window layout until we have it.
8847 return;
8848 }
8849
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008850 if (mDisplay == null) {
8851 // Not yet initialized, nothing to do.
8852 return;
8853 }
8854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 boolean recoveringMemory = false;
8856 if (mForceRemoves != null) {
8857 recoveringMemory = true;
8858 // Wait a little it for things to settle down, and off we go.
8859 for (int i=0; i<mForceRemoves.size(); i++) {
8860 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008861 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008862 removeWindowInnerLocked(ws.mSession, ws);
8863 }
8864 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 Object tmp = new Object();
8867 synchronized (tmp) {
8868 try {
8869 tmp.wait(250);
8870 } catch (InterruptedException e) {
8871 }
8872 }
8873 }
Romain Guy06882f82009-06-10 13:36:04 -07008874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 mInLayout = true;
8876 try {
8877 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008879 int i = mPendingRemove.size()-1;
8880 if (i >= 0) {
8881 while (i >= 0) {
8882 WindowState w = mPendingRemove.get(i);
8883 removeWindowInnerLocked(w.mSession, w);
8884 i--;
8885 }
8886 mPendingRemove.clear();
8887
8888 mInLayout = false;
8889 assignLayersLocked();
8890 mLayoutNeeded = true;
8891 performLayoutAndPlaceSurfacesLocked();
8892
8893 } else {
8894 mInLayout = false;
8895 if (mLayoutNeeded) {
8896 requestAnimationLocked(0);
8897 }
8898 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008899 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008900 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8901 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008903 } catch (RuntimeException e) {
8904 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008905 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008906 }
8907 }
8908
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008909 private final int performLayoutLockedInner() {
8910 if (!mLayoutNeeded) {
8911 return 0;
8912 }
8913
8914 mLayoutNeeded = false;
8915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008916 final int dw = mDisplay.getWidth();
8917 final int dh = mDisplay.getHeight();
8918
8919 final int N = mWindows.size();
8920 int i;
8921
Joe Onorato8a9b2202010-02-26 18:56:32 -08008922 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008923 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8924
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008925 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008926
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008927 int seq = mLayoutSeq+1;
8928 if (seq < 0) seq = 0;
8929 mLayoutSeq = seq;
8930
8931 // First perform layout of any root windows (not attached
8932 // to another window).
8933 int topAttached = -1;
8934 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008935 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008936
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008937 // Don't do layout of a window if it is not visible, or
8938 // soon won't be visible, to avoid wasting time and funky
8939 // changes while a window is animating away.
8940 final AppWindowToken atoken = win.mAppToken;
8941 final boolean gone = win.mViewVisibility == View.GONE
8942 || !win.mRelayoutCalled
8943 || win.mRootToken.hidden
8944 || (atoken != null && atoken.hiddenRequested)
8945 || win.mAttachedHidden
8946 || win.mExiting || win.mDestroying;
8947
8948 if (!win.mLayoutAttached) {
8949 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8950 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8951 + " mLayoutAttached=" + win.mLayoutAttached);
8952 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8953 + win.mViewVisibility + " mRelayoutCalled="
8954 + win.mRelayoutCalled + " hidden="
8955 + win.mRootToken.hidden + " hiddenRequested="
8956 + (atoken != null && atoken.hiddenRequested)
8957 + " mAttachedHidden=" + win.mAttachedHidden);
8958 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008959
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008960 // If this view is GONE, then skip it -- keep the current
8961 // frame, and let the caller know so they can ignore it
8962 // if they want. (We do the normal layout for INVISIBLE
8963 // windows, since that means "perform layout as normal,
8964 // just don't display").
8965 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008966 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008967 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8968 win.mLayoutSeq = seq;
8969 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8970 + win.mFrame + " mContainingFrame="
8971 + win.mContainingFrame + " mDisplayFrame="
8972 + win.mDisplayFrame);
8973 } else {
8974 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008975 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008976 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008977 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008978
8979 // Now perform layout of attached windows, which usually
8980 // depend on the position of the window they are attached to.
8981 // XXX does not deal with windows that are attached to windows
8982 // that are themselves attached.
8983 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008984 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008985
8986 // If this view is GONE, then skip it -- keep the current
8987 // frame, and let the caller know so they can ignore it
8988 // if they want. (We do the normal layout for INVISIBLE
8989 // windows, since that means "perform layout as normal,
8990 // just don't display").
8991 if (win.mLayoutAttached) {
8992 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8993 + " mHaveFrame=" + win.mHaveFrame
8994 + " mViewVisibility=" + win.mViewVisibility
8995 + " mRelayoutCalled=" + win.mRelayoutCalled);
8996 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8997 || !win.mHaveFrame) {
8998 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8999 win.mLayoutSeq = seq;
9000 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9001 + win.mFrame + " mContainingFrame="
9002 + win.mContainingFrame + " mDisplayFrame="
9003 + win.mDisplayFrame);
9004 }
9005 }
9006 }
Jeff Brown349703e2010-06-22 01:27:15 -07009007
9008 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009009 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009010
9011 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009012 }
Romain Guy06882f82009-06-10 13:36:04 -07009013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009014 private final void performLayoutAndPlaceSurfacesLockedInner(
9015 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009016 if (mDisplay == null) {
9017 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9018 return;
9019 }
9020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021 final long currentTime = SystemClock.uptimeMillis();
9022 final int dw = mDisplay.getWidth();
9023 final int dh = mDisplay.getHeight();
9024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009025 int i;
9026
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009027 if (mFocusMayChange) {
9028 mFocusMayChange = false;
9029 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9030 }
9031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009032 // Initialize state of exiting tokens.
9033 for (i=mExitingTokens.size()-1; i>=0; i--) {
9034 mExitingTokens.get(i).hasVisible = false;
9035 }
9036
9037 // Initialize state of exiting applications.
9038 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9039 mExitingAppTokens.get(i).hasVisible = false;
9040 }
9041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009042 boolean orientationChangeComplete = true;
9043 Session holdScreen = null;
9044 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009045 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009046 boolean focusDisplayed = false;
9047 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009048 boolean createWatermark = false;
9049
9050 if (mFxSession == null) {
9051 mFxSession = new SurfaceSession();
9052 createWatermark = true;
9053 }
9054
9055 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056
9057 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009058
9059 if (createWatermark) {
9060 createWatermark();
9061 }
9062 if (mWatermark != null) {
9063 mWatermark.positionSurface(dw, dh);
9064 }
9065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009066 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009067 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009068 int repeats = 0;
9069 int changes = 0;
9070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009071 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009072 repeats++;
9073 if (repeats > 6) {
9074 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9075 mLayoutNeeded = false;
9076 break;
9077 }
9078
9079 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9080 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9081 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9082 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9083 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9084 assignLayersLocked();
9085 mLayoutNeeded = true;
9086 }
9087 }
9088 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9089 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9090 if (updateOrientationFromAppTokensLocked()) {
9091 mLayoutNeeded = true;
9092 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9093 }
9094 }
9095 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9096 mLayoutNeeded = true;
9097 }
9098 }
9099
9100 // FIRST LOOP: Perform a layout, if needed.
9101 if (repeats < 4) {
9102 changes = performLayoutLockedInner();
9103 if (changes != 0) {
9104 continue;
9105 }
9106 } else {
9107 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9108 changes = 0;
9109 }
9110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 final int transactionSequence = ++mTransactionSequence;
9112
9113 // Update animations of all applications, including those
9114 // associated with exiting/removed apps
9115 boolean tokensAnimating = false;
9116 final int NAT = mAppTokens.size();
9117 for (i=0; i<NAT; i++) {
9118 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9119 tokensAnimating = true;
9120 }
9121 }
9122 final int NEAT = mExitingAppTokens.size();
9123 for (i=0; i<NEAT; i++) {
9124 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9125 tokensAnimating = true;
9126 }
9127 }
9128
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009129 // SECOND LOOP: Execute animations and update visibility of windows.
9130
Joe Onorato8a9b2202010-02-26 18:56:32 -08009131 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009132 + transactionSequence + " tokensAnimating="
9133 + tokensAnimating);
9134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009135 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009136
9137 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009138 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009139 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009140
9141 mPolicy.beginAnimationLw(dw, dh);
9142
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009143 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009146 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009147
9148 final WindowManager.LayoutParams attrs = w.mAttrs;
9149
9150 if (w.mSurface != null) {
9151 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009152 if (w.commitFinishDrawingLocked(currentTime)) {
9153 if ((w.mAttrs.flags
9154 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009155 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009156 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009157 wallpaperMayChange = true;
9158 }
9159 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009160
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009161 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9163 animating = true;
9164 //w.dump(" ");
9165 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009166 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9167 wallpaperMayChange = true;
9168 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009169
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009170 if (mPolicy.doesForceHide(w, attrs)) {
9171 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009172 if (DEBUG_VISIBILITY) Slog.v(TAG,
9173 "Animation done that could impact force hide: "
9174 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009175 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009176 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009177 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9178 forceHiding = true;
9179 }
9180 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9181 boolean changed;
9182 if (forceHiding) {
9183 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009184 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9185 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009186 } else {
9187 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009188 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9189 "Now policy shown: " + w);
9190 if (changed) {
9191 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009192 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009193 // Assume we will need to animate. If
9194 // we don't (because the wallpaper will
9195 // stay with the lock screen), then we will
9196 // clean up later.
9197 Animation a = mPolicy.createForceHideEnterAnimation();
9198 if (a != null) {
9199 w.setAnimation(a);
9200 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009201 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009202 if (mCurrentFocus == null ||
9203 mCurrentFocus.mLayer < w.mLayer) {
9204 // We are showing on to of the current
9205 // focus, so re-evaluate focus to make
9206 // sure it is correct.
9207 mFocusMayChange = true;
9208 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009209 }
9210 }
9211 if (changed && (attrs.flags
9212 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9213 wallpaperMayChange = true;
9214 }
9215 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217 mPolicy.animatingWindowLw(w, attrs);
9218 }
9219
9220 final AppWindowToken atoken = w.mAppToken;
9221 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9222 if (atoken.lastTransactionSequence != transactionSequence) {
9223 atoken.lastTransactionSequence = transactionSequence;
9224 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9225 atoken.startingDisplayed = false;
9226 }
9227 if ((w.isOnScreen() || w.mAttrs.type
9228 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9229 && !w.mExiting && !w.mDestroying) {
9230 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009231 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009232 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009233 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009234 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009235 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 + " pv=" + w.mPolicyVisibility
9237 + " dp=" + w.mDrawPending
9238 + " cdp=" + w.mCommitDrawPending
9239 + " ah=" + w.mAttachedHidden
9240 + " th=" + atoken.hiddenRequested
9241 + " a=" + w.mAnimating);
9242 }
9243 }
9244 if (w != atoken.startingWindow) {
9245 if (!atoken.freezingScreen || !w.mAppFreezing) {
9246 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009247 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009249 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009250 "tokenMayBeDrawn: " + atoken
9251 + " freezingScreen=" + atoken.freezingScreen
9252 + " mAppFreezing=" + w.mAppFreezing);
9253 tokenMayBeDrawn = true;
9254 }
9255 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009256 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 atoken.startingDisplayed = true;
9258 }
9259 }
9260 } else if (w.mReadyToShow) {
9261 w.performShowLocked();
9262 }
9263 }
9264
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009265 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009266
9267 if (tokenMayBeDrawn) {
9268 // See if any windows have been drawn, so they (and others
9269 // associated with them) can now be shown.
9270 final int NT = mTokenList.size();
9271 for (i=0; i<NT; i++) {
9272 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9273 if (wtoken == null) {
9274 continue;
9275 }
9276 if (wtoken.freezingScreen) {
9277 int numInteresting = wtoken.numInterestingWindows;
9278 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009279 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280 "allDrawn: " + wtoken
9281 + " interesting=" + numInteresting
9282 + " drawn=" + wtoken.numDrawnWindows);
9283 wtoken.showAllWindowsLocked();
9284 unsetAppFreezingScreenLocked(wtoken, false, true);
9285 orientationChangeComplete = true;
9286 }
9287 } else if (!wtoken.allDrawn) {
9288 int numInteresting = wtoken.numInterestingWindows;
9289 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009290 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009291 "allDrawn: " + wtoken
9292 + " interesting=" + numInteresting
9293 + " drawn=" + wtoken.numDrawnWindows);
9294 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009295 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009296
9297 // We can now show all of the drawn windows!
9298 if (!mOpeningApps.contains(wtoken)) {
9299 wtoken.showAllWindowsLocked();
9300 }
9301 }
9302 }
9303 }
9304 }
9305
9306 // If we are ready to perform an app transition, check through
9307 // all of the app tokens to be shown and see if they are ready
9308 // to go.
9309 if (mAppTransitionReady) {
9310 int NN = mOpeningApps.size();
9311 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009312 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009313 "Checking " + NN + " opening apps (frozen="
9314 + mDisplayFrozen + " timeout="
9315 + mAppTransitionTimeout + ")...");
9316 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9317 // If the display isn't frozen, wait to do anything until
9318 // all of the apps are ready. Otherwise just go because
9319 // we'll unfreeze the display when everyone is ready.
9320 for (i=0; i<NN && goodToGo; i++) {
9321 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009322 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 "Check opening app" + wtoken + ": allDrawn="
9324 + wtoken.allDrawn + " startingDisplayed="
9325 + wtoken.startingDisplayed);
9326 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9327 && !wtoken.startingMoved) {
9328 goodToGo = false;
9329 }
9330 }
9331 }
9332 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009333 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009334 int transit = mNextAppTransition;
9335 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009336 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009337 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009338 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009339 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009340 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009341 mAppTransitionTimeout = false;
9342 mStartingIconInTransition = false;
9343 mSkipAppTransitionAnimation = false;
9344
9345 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9346
Dianne Hackborna8f60182009-09-01 19:01:50 -07009347 // If there are applications waiting to come to the
9348 // top of the stack, now is the time to move their windows.
9349 // (Note that we don't do apps going to the bottom
9350 // here -- we want to keep their windows in the old
9351 // Z-order until the animation completes.)
9352 if (mToTopApps.size() > 0) {
9353 NN = mAppTokens.size();
9354 for (i=0; i<NN; i++) {
9355 AppWindowToken wtoken = mAppTokens.get(i);
9356 if (wtoken.sendingToTop) {
9357 wtoken.sendingToTop = false;
9358 moveAppWindowsLocked(wtoken, NN, false);
9359 }
9360 }
9361 mToTopApps.clear();
9362 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009363
Dianne Hackborn25994b42009-09-04 14:21:19 -07009364 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009365
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009366 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009367 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009368
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009369 // The top-most window will supply the layout params,
9370 // and we will determine it below.
9371 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009372 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009373 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009374
Joe Onorato8a9b2202010-02-26 18:56:32 -08009375 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009376 "New wallpaper target=" + mWallpaperTarget
9377 + ", lower target=" + mLowerWallpaperTarget
9378 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009379 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009380 // Do a first pass through the tokens for two
9381 // things:
9382 // (1) Determine if both the closing and opening
9383 // app token sets are wallpaper targets, in which
9384 // case special animations are needed
9385 // (since the wallpaper needs to stay static
9386 // behind them).
9387 // (2) Find the layout params of the top-most
9388 // application window in the tokens, which is
9389 // what will control the animation theme.
9390 final int NC = mClosingApps.size();
9391 NN = NC + mOpeningApps.size();
9392 for (i=0; i<NN; i++) {
9393 AppWindowToken wtoken;
9394 int mode;
9395 if (i < NC) {
9396 wtoken = mClosingApps.get(i);
9397 mode = 1;
9398 } else {
9399 wtoken = mOpeningApps.get(i-NC);
9400 mode = 2;
9401 }
9402 if (mLowerWallpaperTarget != null) {
9403 if (mLowerWallpaperTarget.mAppToken == wtoken
9404 || mUpperWallpaperTarget.mAppToken == wtoken) {
9405 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009406 }
9407 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009408 if (wtoken.appFullscreen) {
9409 WindowState ws = wtoken.findMainWindow();
9410 if (ws != null) {
9411 // If this is a compatibility mode
9412 // window, we will always use its anim.
9413 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9414 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009415 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009416 bestAnimLayer = Integer.MAX_VALUE;
9417 } else if (ws.mLayer > bestAnimLayer) {
9418 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009419 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009420 bestAnimLayer = ws.mLayer;
9421 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009422 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009423 }
9424 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009425
Dianne Hackborn25994b42009-09-04 14:21:19 -07009426 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009427 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009428 "Wallpaper animation!");
9429 switch (transit) {
9430 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9431 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9432 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9433 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9434 break;
9435 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9436 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9437 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9438 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9439 break;
9440 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009441 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009442 "New transit: " + transit);
9443 } else if (oldWallpaper != null) {
9444 // We are transitioning from an activity with
9445 // a wallpaper to one without.
9446 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009447 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009448 "New transit away from wallpaper: " + transit);
9449 } else if (mWallpaperTarget != null) {
9450 // We are transitioning from an activity without
9451 // a wallpaper to now showing the wallpaper
9452 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009453 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009454 "New transit into wallpaper: " + transit);
9455 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009456
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009457 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9458 mLastEnterAnimToken = animToken;
9459 mLastEnterAnimParams = animLp;
9460 } else if (mLastEnterAnimParams != null) {
9461 animLp = mLastEnterAnimParams;
9462 mLastEnterAnimToken = null;
9463 mLastEnterAnimParams = null;
9464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009465
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009466 // If all closing windows are obscured, then there is
9467 // no need to do an animation. This is the case, for
9468 // example, when this transition is being done behind
9469 // the lock screen.
9470 if (!mPolicy.allowAppAnimationsLw()) {
9471 animLp = null;
9472 }
9473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 NN = mOpeningApps.size();
9475 for (i=0; i<NN; i++) {
9476 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009477 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009478 "Now opening app" + wtoken);
9479 wtoken.reportedVisible = false;
9480 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009481 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009482 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009484 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 wtoken.showAllWindowsLocked();
9486 }
9487 NN = mClosingApps.size();
9488 for (i=0; i<NN; i++) {
9489 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009490 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 "Now closing app" + wtoken);
9492 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009493 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009494 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009495 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009496 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 // Force the allDrawn flag, because we want to start
9498 // this guy's animations regardless of whether it's
9499 // gotten drawn.
9500 wtoken.allDrawn = true;
9501 }
9502
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009503 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 mOpeningApps.clear();
9506 mClosingApps.clear();
9507
9508 // This has changed the visibility of windows, so perform
9509 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009510 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009511 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009512 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9513 assignLayersLocked();
9514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009515 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009516 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009517 }
9518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009519
Dianne Hackborn16064f92010-03-25 00:47:24 -07009520 int adjResult = 0;
9521
Dianne Hackborna8f60182009-09-01 19:01:50 -07009522 if (!animating && mAppTransitionRunning) {
9523 // We have finished the animation of an app transition. To do
9524 // this, we have delayed a lot of operations like showing and
9525 // hiding apps, moving apps in Z-order, etc. The app token list
9526 // reflects the correct Z-order, but the window list may now
9527 // be out of sync with it. So here we will just rebuild the
9528 // entire app window list. Fun!
9529 mAppTransitionRunning = false;
9530 // Clear information about apps that were moving.
9531 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009532
Dianne Hackborna8f60182009-09-01 19:01:50 -07009533 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009534 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009535 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009536 moveInputMethodWindowsIfNeededLocked(false);
9537 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009538 // Since the window list has been rebuilt, focus might
9539 // have to be recomputed since the actual order of windows
9540 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009541 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009542 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009543
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009544 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009545 // At this point, there was a window with a wallpaper that
9546 // was force hiding other windows behind it, but now it
9547 // is going away. This may be simple -- just animate
9548 // away the wallpaper and its window -- or it may be
9549 // hard -- the wallpaper now needs to be shown behind
9550 // something that was hidden.
9551 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009552 if (mLowerWallpaperTarget != null
9553 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009554 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009555 "wallpaperForceHiding changed with lower="
9556 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009557 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009558 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9559 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9560 if (mLowerWallpaperTarget.mAppToken.hidden) {
9561 // The lower target has become hidden before we
9562 // actually started the animation... let's completely
9563 // re-evaluate everything.
9564 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009565 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009566 }
9567 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009568 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009569 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009570 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009571 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009572 + " NEW: " + mWallpaperTarget
9573 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009574 if (mLowerWallpaperTarget == null) {
9575 // Whoops, we don't need a special wallpaper animation.
9576 // Clear them out.
9577 forceHiding = false;
9578 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009579 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009580 if (w.mSurface != null) {
9581 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009582 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009583 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009584 forceHiding = true;
9585 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9586 if (!w.mAnimating) {
9587 // We set the animation above so it
9588 // is not yet running.
9589 w.clearAnimation();
9590 }
9591 }
9592 }
9593 }
9594 }
9595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009596
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009597 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009598 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009599 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009600 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009603 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009604 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009605 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009606 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009607 assignLayersLocked();
9608 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009609 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009610 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009611 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009613
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009614 if (mFocusMayChange) {
9615 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009616 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009617 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009618 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009619 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009620 }
9621
9622 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009623 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009624 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009625
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009626 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9627 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009628
Jeff Browne33348b2010-07-15 23:54:05 -07009629 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009630 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009631
9632 // THIRD LOOP: Update the surfaces of all windows.
9633
9634 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9635
9636 boolean obscured = false;
9637 boolean blurring = false;
9638 boolean dimming = false;
9639 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009640 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009641 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009642
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009643 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009646 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009647
9648 boolean displayed = false;
9649 final WindowManager.LayoutParams attrs = w.mAttrs;
9650 final int attrFlags = attrs.flags;
9651
9652 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009653 // XXX NOTE: The logic here could be improved. We have
9654 // the decision about whether to resize a window separated
9655 // from whether to hide the surface. This can cause us to
9656 // resize a surface even if we are going to hide it. You
9657 // can see this by (1) holding device in landscape mode on
9658 // home screen; (2) tapping browser icon (device will rotate
9659 // to landscape; (3) tap home. The wallpaper will be resized
9660 // in step 2 but then immediately hidden, causing us to
9661 // have to resize and then redraw it again in step 3. It
9662 // would be nice to figure out how to avoid this, but it is
9663 // difficult because we do need to resize surfaces in some
9664 // cases while they are hidden such as when first showing a
9665 // window.
9666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009667 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009668 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009669 TAG, "Placing surface #" + i + " " + w.mSurface
9670 + ": new=" + w.mShownFrame + ", old="
9671 + w.mLastShownFrame);
9672
9673 boolean resize;
9674 int width, height;
9675 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9676 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9677 w.mLastRequestedHeight != w.mRequestedHeight;
9678 // for a scaled surface, we just want to use
9679 // the requested size.
9680 width = w.mRequestedWidth;
9681 height = w.mRequestedHeight;
9682 w.mLastRequestedWidth = width;
9683 w.mLastRequestedHeight = height;
9684 w.mLastShownFrame.set(w.mShownFrame);
9685 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009686 if (SHOW_TRANSACTIONS) logSurface(w,
9687 "POS " + w.mShownFrame.left
9688 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009689 w.mSurfaceX = w.mShownFrame.left;
9690 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9692 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009693 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694 if (!recoveringMemory) {
9695 reclaimSomeSurfaceMemoryLocked(w, "position");
9696 }
9697 }
9698 } else {
9699 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9700 width = w.mShownFrame.width();
9701 height = w.mShownFrame.height();
9702 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009703 }
9704
9705 if (resize) {
9706 if (width < 1) width = 1;
9707 if (height < 1) height = 1;
9708 if (w.mSurface != null) {
9709 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009710 if (SHOW_TRANSACTIONS) logSurface(w,
9711 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009712 + w.mShownFrame.top + " SIZE "
9713 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009714 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009715 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009716 w.mSurfaceW = width;
9717 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009718 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009719 w.mSurfaceX = w.mShownFrame.left;
9720 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009721 w.mSurface.setPosition(w.mShownFrame.left,
9722 w.mShownFrame.top);
9723 } catch (RuntimeException e) {
9724 // If something goes wrong with the surface (such
9725 // as running out of memory), don't take down the
9726 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009727 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 + "size=(" + width + "x" + height
9729 + "), pos=(" + w.mShownFrame.left
9730 + "," + w.mShownFrame.top + ")", e);
9731 if (!recoveringMemory) {
9732 reclaimSomeSurfaceMemoryLocked(w, "size");
9733 }
9734 }
9735 }
9736 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009737 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738 w.mContentInsetsChanged =
9739 !w.mLastContentInsets.equals(w.mContentInsets);
9740 w.mVisibleInsetsChanged =
9741 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009742 boolean configChanged =
9743 w.mConfiguration != mCurConfiguration
9744 && (w.mConfiguration == null
9745 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009746 if (DEBUG_CONFIGURATION && configChanged) {
9747 Slog.v(TAG, "Win " + w + " config changed: "
9748 + mCurConfiguration);
9749 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009751 + ": configChanged=" + configChanged
9752 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009753 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009754 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009755 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009756 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009757 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 w.mLastFrame.set(w.mFrame);
9759 w.mLastContentInsets.set(w.mContentInsets);
9760 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009761 // If the screen is currently frozen, then keep
9762 // it frozen until this window draws at its new
9763 // orientation.
9764 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009765 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009766 "Resizing while display frozen: " + w);
9767 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009768 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009769 mWindowsFreezingScreen = true;
9770 // XXX should probably keep timeout from
9771 // when we first froze the display.
9772 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9773 mH.sendMessageDelayed(mH.obtainMessage(
9774 H.WINDOW_FREEZE_TIMEOUT), 2000);
9775 }
9776 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777 // If the orientation is changing, then we need to
9778 // hold off on unfreezing the display until this
9779 // window has been redrawn; to do that, we need
9780 // to go through the process of getting informed
9781 // by the application when it has finished drawing.
9782 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009783 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009784 "Orientation start waiting for draw in "
9785 + w + ", surface " + w.mSurface);
9786 w.mDrawPending = true;
9787 w.mCommitDrawPending = false;
9788 w.mReadyToShow = false;
9789 if (w.mAppToken != null) {
9790 w.mAppToken.allDrawn = false;
9791 }
9792 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009793 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 "Resizing window " + w + " to " + w.mFrame);
9795 mResizingWindows.add(w);
9796 } else if (w.mOrientationChanging) {
9797 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009798 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009799 "Orientation not waiting for draw in "
9800 + w + ", surface " + w.mSurface);
9801 w.mOrientationChanging = false;
9802 }
9803 }
9804 }
9805
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009806 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807 if (!w.mLastHidden) {
9808 //dump();
9809 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009810 if (SHOW_TRANSACTIONS) logSurface(w,
9811 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009813 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009814 try {
9815 w.mSurface.hide();
9816 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009817 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 }
9819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009820 }
9821 // If we are waiting for this window to handle an
9822 // orientation change, well, it is hidden, so
9823 // doesn't really matter. Note that this does
9824 // introduce a potential glitch if the window
9825 // becomes unhidden before it has drawn for the
9826 // new orientation.
9827 if (w.mOrientationChanging) {
9828 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009829 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009830 "Orientation change skips hidden " + w);
9831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009832 } else if (w.mLastLayer != w.mAnimLayer
9833 || w.mLastAlpha != w.mShownAlpha
9834 || w.mLastDsDx != w.mDsDx
9835 || w.mLastDtDx != w.mDtDx
9836 || w.mLastDsDy != w.mDsDy
9837 || w.mLastDtDy != w.mDtDy
9838 || w.mLastHScale != w.mHScale
9839 || w.mLastVScale != w.mVScale
9840 || w.mLastHidden) {
9841 displayed = true;
9842 w.mLastAlpha = w.mShownAlpha;
9843 w.mLastLayer = w.mAnimLayer;
9844 w.mLastDsDx = w.mDsDx;
9845 w.mLastDtDx = w.mDtDx;
9846 w.mLastDsDy = w.mDsDy;
9847 w.mLastDtDy = w.mDtDy;
9848 w.mLastHScale = w.mHScale;
9849 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009850 if (SHOW_TRANSACTIONS) logSurface(w,
9851 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009852 + " matrix=[" + (w.mDsDx*w.mHScale)
9853 + "," + (w.mDtDx*w.mVScale)
9854 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009855 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856 if (w.mSurface != null) {
9857 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009858 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009860 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861 w.mSurface.setLayer(w.mAnimLayer);
9862 w.mSurface.setMatrix(
9863 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9864 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9865 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009866 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867 if (!recoveringMemory) {
9868 reclaimSomeSurfaceMemoryLocked(w, "update");
9869 }
9870 }
9871 }
9872
9873 if (w.mLastHidden && !w.mDrawPending
9874 && !w.mCommitDrawPending
9875 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009876 if (SHOW_TRANSACTIONS) logSurface(w,
9877 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009878 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009879 + " during relayout");
9880 if (showSurfaceRobustlyLocked(w)) {
9881 w.mHasDrawn = true;
9882 w.mLastHidden = false;
9883 } else {
9884 w.mOrientationChanging = false;
9885 }
9886 }
9887 if (w.mSurface != null) {
9888 w.mToken.hasVisible = true;
9889 }
9890 } else {
9891 displayed = true;
9892 }
9893
9894 if (displayed) {
9895 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009896 if (attrs.width == LayoutParams.MATCH_PARENT
9897 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009898 covered = true;
9899 }
9900 }
9901 if (w.mOrientationChanging) {
9902 if (w.mDrawPending || w.mCommitDrawPending) {
9903 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009904 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 "Orientation continue waiting for draw in " + w);
9906 } else {
9907 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009908 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 "Orientation change complete in " + w);
9910 }
9911 }
9912 w.mToken.hasVisible = true;
9913 }
9914 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009915 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009916 "Orientation change skips hidden " + w);
9917 w.mOrientationChanging = false;
9918 }
9919
9920 final boolean canBeSeen = w.isDisplayedLw();
9921
9922 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9923 focusDisplayed = true;
9924 }
9925
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009926 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009928 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009929 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930 if (w.mSurface != null) {
9931 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9932 holdScreen = w.mSession;
9933 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009934 if (!syswin && w.mAttrs.screenBrightness >= 0
9935 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 screenBrightness = w.mAttrs.screenBrightness;
9937 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009938 if (!syswin && w.mAttrs.buttonBrightness >= 0
9939 && buttonBrightness < 0) {
9940 buttonBrightness = w.mAttrs.buttonBrightness;
9941 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009942 if (canBeSeen
9943 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9944 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9945 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009946 syswin = true;
9947 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009948 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009949
Dianne Hackborn25994b42009-09-04 14:21:19 -07009950 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9951 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009952 // This window completely covers everything behind it,
9953 // so we want to leave all of them as unblurred (for
9954 // performance reasons).
9955 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009956 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009957 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009958 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009959 obscured = true;
9960 if (mBackgroundFillerSurface == null) {
9961 try {
9962 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009963 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009964 0, dw, dh,
9965 PixelFormat.OPAQUE,
9966 Surface.FX_SURFACE_NORMAL);
9967 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009968 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009969 }
9970 }
9971 try {
9972 mBackgroundFillerSurface.setPosition(0, 0);
9973 mBackgroundFillerSurface.setSize(dw, dh);
9974 // Using the same layer as Dim because they will never be shown at the
9975 // same time.
9976 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9977 mBackgroundFillerSurface.show();
9978 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009979 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009980 }
9981 backgroundFillerShown = true;
9982 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009983 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009985 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 + ": blurring=" + blurring
9987 + " obscured=" + obscured
9988 + " displayed=" + displayed);
9989 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9990 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009991 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009993 if (mDimAnimator == null) {
9994 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009996 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009997 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009999 }
10000 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10001 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010002 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010005 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 + mBlurSurface + ": CREATE");
10007 try {
Romain Guy06882f82009-06-10 13:36:04 -070010008 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010009 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010010 -1, 16, 16,
10011 PixelFormat.OPAQUE,
10012 Surface.FX_SURFACE_BLUR);
10013 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010014 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010015 }
10016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010017 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010018 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10019 + mBlurSurface + ": pos=(0,0) (" +
10020 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 mBlurSurface.setPosition(0, 0);
10022 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010023 mBlurSurface.setLayer(w.mAnimLayer-2);
10024 if (!mBlurShown) {
10025 try {
10026 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10027 + mBlurSurface + ": SHOW");
10028 mBlurSurface.show();
10029 } catch (RuntimeException e) {
10030 Slog.w(TAG, "Failure showing blur surface", e);
10031 }
10032 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 }
10034 }
10035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036 }
10037 }
10038 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010039
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010040 if (obscuredChanged && mWallpaperTarget == w) {
10041 // This is the wallpaper target and its obscured state
10042 // changed... make sure the current wallaper's visibility
10043 // has been updated accordingly.
10044 updateWallpaperVisibilityLocked();
10045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010047
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010048 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10049 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010050 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010051 try {
10052 mBackgroundFillerSurface.hide();
10053 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010054 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010055 }
10056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010058 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010059 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10060 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010061 }
Romain Guy06882f82009-06-10 13:36:04 -070010062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010064 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010065 + ": HIDE");
10066 try {
10067 mBlurSurface.hide();
10068 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010069 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010070 }
10071 mBlurShown = false;
10072 }
10073
Joe Onorato8a9b2202010-02-26 18:56:32 -080010074 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010076 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 }
10078
Jeff Browne33348b2010-07-15 23:54:05 -070010079 mInputMonitor.updateInputWindowsLw();
10080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010082
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010083 if (mWatermark != null) {
10084 mWatermark.drawIfNeeded();
10085 }
10086
Joe Onorato8a9b2202010-02-26 18:56:32 -080010087 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010088 "With display frozen, orientationChangeComplete="
10089 + orientationChangeComplete);
10090 if (orientationChangeComplete) {
10091 if (mWindowsFreezingScreen) {
10092 mWindowsFreezingScreen = false;
10093 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10094 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010095 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010096 }
Romain Guy06882f82009-06-10 13:36:04 -070010097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098 i = mResizingWindows.size();
10099 if (i > 0) {
10100 do {
10101 i--;
10102 WindowState win = mResizingWindows.get(i);
10103 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010104 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10105 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010106 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010107 boolean configChanged =
10108 win.mConfiguration != mCurConfiguration
10109 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010110 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10111 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10112 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010113 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010114 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010115 + " / " + mCurConfiguration + " / 0x"
10116 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010117 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010118 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010119 win.mClient.resized(win.mFrame.width(),
10120 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010121 win.mLastVisibleInsets, win.mDrawPending,
10122 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 win.mContentInsetsChanged = false;
10124 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010125 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010126 } catch (RemoteException e) {
10127 win.mOrientationChanging = false;
10128 }
10129 } while (i > 0);
10130 mResizingWindows.clear();
10131 }
Romain Guy06882f82009-06-10 13:36:04 -070010132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010133 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010134 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010135 i = mDestroySurface.size();
10136 if (i > 0) {
10137 do {
10138 i--;
10139 WindowState win = mDestroySurface.get(i);
10140 win.mDestroying = false;
10141 if (mInputMethodWindow == win) {
10142 mInputMethodWindow = null;
10143 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010144 if (win == mWallpaperTarget) {
10145 wallpaperDestroyed = true;
10146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010147 win.destroySurfaceLocked();
10148 } while (i > 0);
10149 mDestroySurface.clear();
10150 }
10151
10152 // Time to remove any exiting tokens?
10153 for (i=mExitingTokens.size()-1; i>=0; i--) {
10154 WindowToken token = mExitingTokens.get(i);
10155 if (!token.hasVisible) {
10156 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010157 if (token.windowType == TYPE_WALLPAPER) {
10158 mWallpaperTokens.remove(token);
10159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010160 }
10161 }
10162
10163 // Time to remove any exiting applications?
10164 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10165 AppWindowToken token = mExitingAppTokens.get(i);
10166 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010167 // Make sure there is no animation running on this token,
10168 // so any windows associated with it will be removed as
10169 // soon as their animations are complete
10170 token.animation = null;
10171 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010172 mAppTokens.remove(token);
10173 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010174 if (mLastEnterAnimToken == token) {
10175 mLastEnterAnimToken = null;
10176 mLastEnterAnimParams = null;
10177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010178 }
10179 }
10180
Dianne Hackborna8f60182009-09-01 19:01:50 -070010181 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010182
Dianne Hackborna8f60182009-09-01 19:01:50 -070010183 if (!animating && mAppTransitionRunning) {
10184 // We have finished the animation of an app transition. To do
10185 // this, we have delayed a lot of operations like showing and
10186 // hiding apps, moving apps in Z-order, etc. The app token list
10187 // reflects the correct Z-order, but the window list may now
10188 // be out of sync with it. So here we will just rebuild the
10189 // entire app window list. Fun!
10190 mAppTransitionRunning = false;
10191 needRelayout = true;
10192 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010193 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010194 // Clear information about apps that were moving.
10195 mToBottomApps.clear();
10196 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010198 if (focusDisplayed) {
10199 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10200 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010201 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010202 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010203 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010204 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010205 requestAnimationLocked(0);
10206 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10208 }
Jeff Browneb857f12010-07-16 10:06:33 -070010209
Jeff Browne33348b2010-07-15 23:54:05 -070010210 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010211
Jeff Brown8e03b752010-06-13 19:16:55 -070010212 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010213 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10214 mPowerManager.setScreenBrightnessOverride(-1);
10215 } else {
10216 mPowerManager.setScreenBrightnessOverride((int)
10217 (screenBrightness * Power.BRIGHTNESS_ON));
10218 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010219 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10220 mPowerManager.setButtonBrightnessOverride(-1);
10221 } else {
10222 mPowerManager.setButtonBrightnessOverride((int)
10223 (buttonBrightness * Power.BRIGHTNESS_ON));
10224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010225 if (holdScreen != mHoldingScreenOn) {
10226 mHoldingScreenOn = holdScreen;
10227 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10228 mH.sendMessage(m);
10229 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010230
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010231 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010232 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010233 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10234 LocalPowerManager.BUTTON_EVENT, true);
10235 mTurnOnScreen = false;
10236 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010237
10238 // Check to see if we are now in a state where the screen should
10239 // be enabled, because the window obscured flags have changed.
10240 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010241 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010242
10243 /**
10244 * Must be called with the main window manager lock held.
10245 */
10246 void setHoldScreenLocked(boolean holding) {
10247 boolean state = mHoldingScreenWakeLock.isHeld();
10248 if (holding != state) {
10249 if (holding) {
10250 mHoldingScreenWakeLock.acquire();
10251 } else {
10252 mPolicy.screenOnStoppedLw();
10253 mHoldingScreenWakeLock.release();
10254 }
10255 }
10256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010257
10258 void requestAnimationLocked(long delay) {
10259 if (!mAnimationPending) {
10260 mAnimationPending = true;
10261 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10262 }
10263 }
Romain Guy06882f82009-06-10 13:36:04 -070010264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010265 /**
10266 * Have the surface flinger show a surface, robustly dealing with
10267 * error conditions. In particular, if there is not enough memory
10268 * to show the surface, then we will try to get rid of other surfaces
10269 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010270 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010271 * @return Returns true if the surface was successfully shown.
10272 */
10273 boolean showSurfaceRobustlyLocked(WindowState win) {
10274 try {
10275 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010276 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010278 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010279 if (DEBUG_VISIBILITY) Slog.v(TAG,
10280 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010281 win.mTurnOnScreen = false;
10282 mTurnOnScreen = true;
10283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010284 }
10285 return true;
10286 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010287 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 }
Romain Guy06882f82009-06-10 13:36:04 -070010289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010292 return false;
10293 }
Romain Guy06882f82009-06-10 13:36:04 -070010294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10296 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010297
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010298 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010301 if (mForceRemoves == null) {
10302 mForceRemoves = new ArrayList<WindowState>();
10303 }
Romain Guy06882f82009-06-10 13:36:04 -070010304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010305 long callingIdentity = Binder.clearCallingIdentity();
10306 try {
10307 // There was some problem... first, do a sanity check of the
10308 // window list to make sure we haven't left any dangling surfaces
10309 // around.
10310 int N = mWindows.size();
10311 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010312 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010314 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010315 if (ws.mSurface != null) {
10316 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010317 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010318 + ws + " surface=" + ws.mSurface
10319 + " token=" + win.mToken
10320 + " pid=" + ws.mSession.mPid
10321 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010322 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010323 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 ws.mSurface = null;
10325 mForceRemoves.add(ws);
10326 i--;
10327 N--;
10328 leakedSurface = true;
10329 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010330 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010331 + ws + " surface=" + ws.mSurface
10332 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010333 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010334 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 ws.mSurface = null;
10336 leakedSurface = true;
10337 }
10338 }
10339 }
Romain Guy06882f82009-06-10 13:36:04 -070010340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 boolean killedApps = false;
10342 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010343 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010344 SparseIntArray pidCandidates = new SparseIntArray();
10345 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010346 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 if (ws.mSurface != null) {
10348 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10349 }
10350 }
10351 if (pidCandidates.size() > 0) {
10352 int[] pids = new int[pidCandidates.size()];
10353 for (int i=0; i<pids.length; i++) {
10354 pids[i] = pidCandidates.keyAt(i);
10355 }
10356 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010357 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010358 killedApps = true;
10359 }
10360 } catch (RemoteException e) {
10361 }
10362 }
10363 }
Romain Guy06882f82009-06-10 13:36:04 -070010364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365 if (leakedSurface || killedApps) {
10366 // We managed to reclaim some memory, so get rid of the trouble
10367 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010368 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010369 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010370 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010371 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010372 win.mSurface = null;
10373 }
Romain Guy06882f82009-06-10 13:36:04 -070010374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010375 try {
10376 win.mClient.dispatchGetNewSurface();
10377 } catch (RemoteException e) {
10378 }
10379 }
10380 } finally {
10381 Binder.restoreCallingIdentity(callingIdentity);
10382 }
10383 }
Romain Guy06882f82009-06-10 13:36:04 -070010384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 private boolean updateFocusedWindowLocked(int mode) {
10386 WindowState newFocus = computeFocusedWindowLocked();
10387 if (mCurrentFocus != newFocus) {
10388 // This check makes sure that we don't already have the focus
10389 // change message pending.
10390 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10391 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010392 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10394 final WindowState oldFocus = mCurrentFocus;
10395 mCurrentFocus = newFocus;
10396 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 final WindowState imWindow = mInputMethodWindow;
10399 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010400 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010402 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10403 mLayoutNeeded = true;
10404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010405 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10406 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010407 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10408 // Client will do the layout, but we need to assign layers
10409 // for handleNewWindowLocked() below.
10410 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 }
10412 }
Jeff Brown349703e2010-06-22 01:27:15 -070010413
10414 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10415 // If we defer assigning layers, then the caller is responsible for
10416 // doing this part.
10417 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419 return true;
10420 }
10421 return false;
10422 }
Jeff Brown349703e2010-06-22 01:27:15 -070010423
10424 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010425 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427
10428 private WindowState computeFocusedWindowLocked() {
10429 WindowState result = null;
10430 WindowState win;
10431
10432 int i = mWindows.size() - 1;
10433 int nextAppIndex = mAppTokens.size()-1;
10434 WindowToken nextApp = nextAppIndex >= 0
10435 ? mAppTokens.get(nextAppIndex) : null;
10436
10437 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010438 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010439
Joe Onorato8a9b2202010-02-26 18:56:32 -080010440 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010441 TAG, "Looking for focus: " + i
10442 + " = " + win
10443 + ", flags=" + win.mAttrs.flags
10444 + ", canReceive=" + win.canReceiveKeys());
10445
10446 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 // If this window's application has been removed, just skip it.
10449 if (thisApp != null && thisApp.removed) {
10450 i--;
10451 continue;
10452 }
Romain Guy06882f82009-06-10 13:36:04 -070010453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 // If there is a focused app, don't allow focus to go to any
10455 // windows below it. If this is an application window, step
10456 // through the app tokens until we find its app.
10457 if (thisApp != null && nextApp != null && thisApp != nextApp
10458 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10459 int origAppIndex = nextAppIndex;
10460 while (nextAppIndex > 0) {
10461 if (nextApp == mFocusedApp) {
10462 // Whoops, we are below the focused app... no focus
10463 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010464 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010465 TAG, "Reached focused app: " + mFocusedApp);
10466 return null;
10467 }
10468 nextAppIndex--;
10469 nextApp = mAppTokens.get(nextAppIndex);
10470 if (nextApp == thisApp) {
10471 break;
10472 }
10473 }
10474 if (thisApp != nextApp) {
10475 // Uh oh, the app token doesn't exist! This shouldn't
10476 // happen, but if it does we can get totally hosed...
10477 // so restart at the original app.
10478 nextAppIndex = origAppIndex;
10479 nextApp = mAppTokens.get(nextAppIndex);
10480 }
10481 }
10482
10483 // Dispatch to this window if it is wants key events.
10484 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010485 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010486 TAG, "Found focus @ " + i + " = " + win);
10487 result = win;
10488 break;
10489 }
10490
10491 i--;
10492 }
10493
10494 return result;
10495 }
10496
10497 private void startFreezingDisplayLocked() {
10498 if (mDisplayFrozen) {
10499 return;
10500 }
Romain Guy06882f82009-06-10 13:36:04 -070010501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010505 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 if (mFreezeGcPending != 0) {
10507 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010508 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 mH.removeMessages(H.FORCE_GC);
10510 Runtime.getRuntime().gc();
10511 mFreezeGcPending = now;
10512 }
10513 } else {
10514 mFreezeGcPending = now;
10515 }
Romain Guy06882f82009-06-10 13:36:04 -070010516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010517 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010518
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010519 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010520
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010521 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10522 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010523 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 mAppTransitionReady = true;
10525 }
Romain Guy06882f82009-06-10 13:36:04 -070010526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010527 if (PROFILE_ORIENTATION) {
10528 File file = new File("/data/system/frozen");
10529 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10530 }
10531 Surface.freezeDisplay(0);
10532 }
Romain Guy06882f82009-06-10 13:36:04 -070010533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 private void stopFreezingDisplayLocked() {
10535 if (!mDisplayFrozen) {
10536 return;
10537 }
Romain Guy06882f82009-06-10 13:36:04 -070010538
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010539 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10540 return;
10541 }
10542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010543 mDisplayFrozen = false;
10544 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10545 if (PROFILE_ORIENTATION) {
10546 Debug.stopMethodTracing();
10547 }
10548 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010549
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010550 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551
Christopher Tateb696aee2010-04-02 19:08:30 -070010552 // While the display is frozen we don't re-compute the orientation
10553 // to avoid inconsistent states. However, something interesting
10554 // could have actually changed during that time so re-evaluate it
10555 // now to catch that.
10556 if (updateOrientationFromAppTokensLocked()) {
10557 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10558 }
10559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010560 // A little kludge: a lot could have happened while the
10561 // display was frozen, so now that we are coming back we
10562 // do a gc so that any remote references the system
10563 // processes holds on others can be released if they are
10564 // no longer needed.
10565 mH.removeMessages(H.FORCE_GC);
10566 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10567 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010569 mScreenFrozenLock.release();
10570 }
Romain Guy06882f82009-06-10 13:36:04 -070010571
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010572 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10573 DisplayMetrics dm) {
10574 if (index < tokens.length) {
10575 String str = tokens[index];
10576 if (str != null && str.length() > 0) {
10577 try {
10578 int val = Integer.parseInt(str);
10579 return val;
10580 } catch (Exception e) {
10581 }
10582 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010583 }
10584 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10585 return defDps;
10586 }
10587 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10588 return val;
10589 }
10590
10591 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010592 final String[] mTokens;
10593 final String mText;
10594 final Paint mTextPaint;
10595 final int mTextWidth;
10596 final int mTextHeight;
10597 final int mTextAscent;
10598 final int mTextDescent;
10599 final int mDeltaX;
10600 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010601
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010602 Surface mSurface;
10603 int mLastDW;
10604 int mLastDH;
10605 boolean mDrawNeeded;
10606
10607 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010608 final DisplayMetrics dm = new DisplayMetrics();
10609 mDisplay.getMetrics(dm);
10610
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010611 if (false) {
10612 Log.i(TAG, "*********************** WATERMARK");
10613 for (int i=0; i<tokens.length; i++) {
10614 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10615 }
10616 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010617
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010618 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010619
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010620 StringBuilder builder = new StringBuilder(32);
10621 int len = mTokens[0].length();
10622 len = len & ~1;
10623 for (int i=0; i<len; i+=2) {
10624 int c1 = mTokens[0].charAt(i);
10625 int c2 = mTokens[0].charAt(i+1);
10626 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10627 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10628 else c1 -= '0';
10629 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10630 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10631 else c2 -= '0';
10632 builder.append((char)(255-((c1*16)+c2)));
10633 }
10634 mText = builder.toString();
10635 if (false) {
10636 Log.i(TAG, "Final text: " + mText);
10637 }
10638
10639 int fontSize = getPropertyInt(tokens, 1,
10640 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10641
10642 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10643 mTextPaint.setTextSize(fontSize);
10644 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10645
10646 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10647 mTextWidth = (int)mTextPaint.measureText(mText);
10648 mTextAscent = fm.ascent;
10649 mTextDescent = fm.descent;
10650 mTextHeight = fm.descent - fm.ascent;
10651
10652 mDeltaX = getPropertyInt(tokens, 2,
10653 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10654 mDeltaY = getPropertyInt(tokens, 3,
10655 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10656 int shadowColor = getPropertyInt(tokens, 4,
10657 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10658 int color = getPropertyInt(tokens, 5,
10659 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10660 int shadowRadius = getPropertyInt(tokens, 6,
10661 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10662 int shadowDx = getPropertyInt(tokens, 8,
10663 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10664 int shadowDy = getPropertyInt(tokens, 9,
10665 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10666
10667 mTextPaint.setColor(color);
10668 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010669
10670 try {
10671 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010672 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010673 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010674 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010675 mSurface.show();
10676 } catch (OutOfResourcesException e) {
10677 }
10678 }
10679
10680 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010681 if (mLastDW != dw || mLastDH != dh) {
10682 mLastDW = dw;
10683 mLastDH = dh;
10684 mSurface.setSize(dw, dh);
10685 mDrawNeeded = true;
10686 }
10687 }
10688
10689 void drawIfNeeded() {
10690 if (mDrawNeeded) {
10691 final int dw = mLastDW;
10692 final int dh = mLastDH;
10693
10694 mDrawNeeded = false;
10695 Rect dirty = new Rect(0, 0, dw, dh);
10696 Canvas c = null;
10697 try {
10698 c = mSurface.lockCanvas(dirty);
10699 } catch (IllegalArgumentException e) {
10700 } catch (OutOfResourcesException e) {
10701 }
10702 if (c != null) {
10703 int deltaX = mDeltaX;
10704 int deltaY = mDeltaY;
10705
10706 // deltaX shouldn't be close to a round fraction of our
10707 // x step, or else things will line up too much.
10708 int div = (dw+mTextWidth)/deltaX;
10709 int rem = (dw+mTextWidth) - (div*deltaX);
10710 int qdelta = deltaX/4;
10711 if (rem < qdelta || rem > (deltaX-qdelta)) {
10712 deltaX += deltaX/3;
10713 }
10714
10715 int y = -mTextHeight;
10716 int x = -mTextWidth;
10717 while (y < (dh+mTextHeight)) {
10718 c.drawText(mText, x, y, mTextPaint);
10719 x += deltaX;
10720 if (x >= dw) {
10721 x -= (dw+mTextWidth);
10722 y += deltaY;
10723 }
10724 }
10725 mSurface.unlockCanvasAndPost(c);
10726 }
10727 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010728 }
10729 }
10730
10731 void createWatermark() {
10732 if (mWatermark != null) {
10733 return;
10734 }
10735
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010736 File file = new File("/system/etc/setup.conf");
10737 FileInputStream in = null;
10738 try {
10739 in = new FileInputStream(file);
10740 DataInputStream ind = new DataInputStream(in);
10741 String line = ind.readLine();
10742 if (line != null) {
10743 String[] toks = line.split("%");
10744 if (toks != null && toks.length > 0) {
10745 mWatermark = new Watermark(mFxSession, toks);
10746 }
10747 }
10748 } catch (FileNotFoundException e) {
10749 } catch (IOException e) {
10750 } finally {
10751 if (in != null) {
10752 try {
10753 in.close();
10754 } catch (IOException e) {
10755 }
10756 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010757 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010758 }
10759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010760 @Override
10761 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10762 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10763 != PackageManager.PERMISSION_GRANTED) {
10764 pw.println("Permission Denial: can't dump WindowManager from from pid="
10765 + Binder.getCallingPid()
10766 + ", uid=" + Binder.getCallingUid());
10767 return;
10768 }
Romain Guy06882f82009-06-10 13:36:04 -070010769
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010770 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010771 pw.println(" ");
10772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010773 synchronized(mWindowMap) {
10774 pw.println("Current Window Manager state:");
10775 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010776 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010777 pw.print(" Window #"); pw.print(i); pw.print(' ');
10778 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 w.dump(pw, " ");
10780 }
10781 if (mInputMethodDialogs.size() > 0) {
10782 pw.println(" ");
10783 pw.println(" Input method dialogs:");
10784 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10785 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010786 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010787 }
10788 }
10789 if (mPendingRemove.size() > 0) {
10790 pw.println(" ");
10791 pw.println(" Remove pending for:");
10792 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10793 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010794 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10795 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 w.dump(pw, " ");
10797 }
10798 }
10799 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10800 pw.println(" ");
10801 pw.println(" Windows force removing:");
10802 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10803 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010804 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10805 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 w.dump(pw, " ");
10807 }
10808 }
10809 if (mDestroySurface.size() > 0) {
10810 pw.println(" ");
10811 pw.println(" Windows waiting to destroy their surface:");
10812 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10813 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010814 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10815 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010816 w.dump(pw, " ");
10817 }
10818 }
10819 if (mLosingFocus.size() > 0) {
10820 pw.println(" ");
10821 pw.println(" Windows losing focus:");
10822 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10823 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010824 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10825 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010826 w.dump(pw, " ");
10827 }
10828 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010829 if (mResizingWindows.size() > 0) {
10830 pw.println(" ");
10831 pw.println(" Windows waiting to resize:");
10832 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10833 WindowState w = mResizingWindows.get(i);
10834 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10835 pw.print(w); pw.println(":");
10836 w.dump(pw, " ");
10837 }
10838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010839 if (mSessions.size() > 0) {
10840 pw.println(" ");
10841 pw.println(" All active sessions:");
10842 Iterator<Session> it = mSessions.iterator();
10843 while (it.hasNext()) {
10844 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010845 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010846 s.dump(pw, " ");
10847 }
10848 }
10849 if (mTokenMap.size() > 0) {
10850 pw.println(" ");
10851 pw.println(" All tokens:");
10852 Iterator<WindowToken> it = mTokenMap.values().iterator();
10853 while (it.hasNext()) {
10854 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010855 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856 token.dump(pw, " ");
10857 }
10858 }
10859 if (mTokenList.size() > 0) {
10860 pw.println(" ");
10861 pw.println(" Window token list:");
10862 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010863 pw.print(" #"); pw.print(i); pw.print(": ");
10864 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010865 }
10866 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010867 if (mWallpaperTokens.size() > 0) {
10868 pw.println(" ");
10869 pw.println(" Wallpaper tokens:");
10870 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10871 WindowToken token = mWallpaperTokens.get(i);
10872 pw.print(" Wallpaper #"); pw.print(i);
10873 pw.print(' '); pw.print(token); pw.println(':');
10874 token.dump(pw, " ");
10875 }
10876 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 if (mAppTokens.size() > 0) {
10878 pw.println(" ");
10879 pw.println(" Application tokens in Z order:");
10880 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010881 pw.print(" App #"); pw.print(i); pw.print(": ");
10882 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010883 }
10884 }
10885 if (mFinishedStarting.size() > 0) {
10886 pw.println(" ");
10887 pw.println(" Finishing start of application tokens:");
10888 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10889 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010890 pw.print(" Finished Starting #"); pw.print(i);
10891 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010892 token.dump(pw, " ");
10893 }
10894 }
10895 if (mExitingTokens.size() > 0) {
10896 pw.println(" ");
10897 pw.println(" Exiting tokens:");
10898 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10899 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010900 pw.print(" Exiting #"); pw.print(i);
10901 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 token.dump(pw, " ");
10903 }
10904 }
10905 if (mExitingAppTokens.size() > 0) {
10906 pw.println(" ");
10907 pw.println(" Exiting application tokens:");
10908 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10909 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010910 pw.print(" Exiting App #"); pw.print(i);
10911 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912 token.dump(pw, " ");
10913 }
10914 }
10915 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010916 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10917 pw.print(" mLastFocus="); pw.println(mLastFocus);
10918 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10919 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10920 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010921 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010922 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10923 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10924 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10925 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010926 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10927 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10928 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010929 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10930 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10931 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10932 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010933 if (mDimAnimator != null) {
10934 mDimAnimator.printTo(pw);
10935 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010936 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010937 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010938 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010939 pw.print(mInputMethodAnimLayerAdjustment);
10940 pw.print(" mWallpaperAnimLayerAdjustment=");
10941 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010942 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10943 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010944 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10945 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010946 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10947 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010948 pw.print(" mRotation="); pw.print(mRotation);
10949 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10950 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10951 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10952 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10953 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10954 pw.print(" mNextAppTransition=0x");
10955 pw.print(Integer.toHexString(mNextAppTransition));
10956 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010957 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010958 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010959 if (mNextAppTransitionPackage != null) {
10960 pw.print(" mNextAppTransitionPackage=");
10961 pw.print(mNextAppTransitionPackage);
10962 pw.print(", mNextAppTransitionEnter=0x");
10963 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10964 pw.print(", mNextAppTransitionExit=0x");
10965 pw.print(Integer.toHexString(mNextAppTransitionExit));
10966 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010967 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10968 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010969 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10970 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10971 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10972 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010973 if (mOpeningApps.size() > 0) {
10974 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10975 }
10976 if (mClosingApps.size() > 0) {
10977 pw.print(" mClosingApps="); pw.println(mClosingApps);
10978 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010979 if (mToTopApps.size() > 0) {
10980 pw.print(" mToTopApps="); pw.println(mToTopApps);
10981 }
10982 if (mToBottomApps.size() > 0) {
10983 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10984 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010985 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10986 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 }
10988 }
10989
Jeff Brown349703e2010-06-22 01:27:15 -070010990 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010991 public void monitor() {
10992 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010993 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010994 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010995
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010996 /**
10997 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010998 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010999 */
11000 private static class DimAnimator {
11001 Surface mDimSurface;
11002 boolean mDimShown = false;
11003 float mDimCurrentAlpha;
11004 float mDimTargetAlpha;
11005 float mDimDeltaPerMs;
11006 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011007
11008 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011009
11010 DimAnimator (SurfaceSession session) {
11011 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011012 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011013 + mDimSurface + ": CREATE");
11014 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011015 mDimSurface = new Surface(session, 0,
11016 "DimSurface",
11017 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011018 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011019 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011020 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011021 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011022 }
11023 }
11024 }
11025
11026 /**
11027 * Show the dim surface.
11028 */
11029 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011030 if (!mDimShown) {
11031 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11032 dw + "x" + dh + ")");
11033 mDimShown = true;
11034 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011035 mLastDimWidth = dw;
11036 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011037 mDimSurface.setPosition(0, 0);
11038 mDimSurface.setSize(dw, dh);
11039 mDimSurface.show();
11040 } catch (RuntimeException e) {
11041 Slog.w(TAG, "Failure showing dim surface", e);
11042 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011043 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11044 mLastDimWidth = dw;
11045 mLastDimHeight = dh;
11046 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011047 }
11048 }
11049
11050 /**
11051 * Set's the dim surface's layer and update dim parameters that will be used in
11052 * {@link updateSurface} after all windows are examined.
11053 */
11054 void updateParameters(WindowState w, long currentTime) {
11055 mDimSurface.setLayer(w.mAnimLayer-1);
11056
11057 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011058 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011059 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011060 if (mDimTargetAlpha != target) {
11061 // If the desired dim level has changed, then
11062 // start an animation to it.
11063 mLastDimAnimTime = currentTime;
11064 long duration = (w.mAnimating && w.mAnimation != null)
11065 ? w.mAnimation.computeDurationHint()
11066 : DEFAULT_DIM_DURATION;
11067 if (target > mDimTargetAlpha) {
11068 // This is happening behind the activity UI,
11069 // so we can make it run a little longer to
11070 // give a stronger impression without disrupting
11071 // the user.
11072 duration *= DIM_DURATION_MULTIPLIER;
11073 }
11074 if (duration < 1) {
11075 // Don't divide by zero
11076 duration = 1;
11077 }
11078 mDimTargetAlpha = target;
11079 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11080 }
11081 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011082
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011083 /**
11084 * Updating the surface's alpha. Returns true if the animation continues, or returns
11085 * false when the animation is finished and the dim surface is hidden.
11086 */
11087 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11088 if (!dimming) {
11089 if (mDimTargetAlpha != 0) {
11090 mLastDimAnimTime = currentTime;
11091 mDimTargetAlpha = 0;
11092 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11093 }
11094 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011095
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011096 boolean animating = false;
11097 if (mLastDimAnimTime != 0) {
11098 mDimCurrentAlpha += mDimDeltaPerMs
11099 * (currentTime-mLastDimAnimTime);
11100 boolean more = true;
11101 if (displayFrozen) {
11102 // If the display is frozen, there is no reason to animate.
11103 more = false;
11104 } else if (mDimDeltaPerMs > 0) {
11105 if (mDimCurrentAlpha > mDimTargetAlpha) {
11106 more = false;
11107 }
11108 } else if (mDimDeltaPerMs < 0) {
11109 if (mDimCurrentAlpha < mDimTargetAlpha) {
11110 more = false;
11111 }
11112 } else {
11113 more = false;
11114 }
11115
11116 // Do we need to continue animating?
11117 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011118 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011119 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11120 mLastDimAnimTime = currentTime;
11121 mDimSurface.setAlpha(mDimCurrentAlpha);
11122 animating = true;
11123 } else {
11124 mDimCurrentAlpha = mDimTargetAlpha;
11125 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011126 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011127 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11128 mDimSurface.setAlpha(mDimCurrentAlpha);
11129 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011130 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011131 + ": HIDE");
11132 try {
11133 mDimSurface.hide();
11134 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011135 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011136 }
11137 mDimShown = false;
11138 }
11139 }
11140 }
11141 return animating;
11142 }
11143
11144 public void printTo(PrintWriter pw) {
11145 pw.print(" mDimShown="); pw.print(mDimShown);
11146 pw.print(" current="); pw.print(mDimCurrentAlpha);
11147 pw.print(" target="); pw.print(mDimTargetAlpha);
11148 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11149 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11150 }
11151 }
11152
11153 /**
11154 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11155 * This is used for opening/closing transition for apps in compatible mode.
11156 */
11157 private static class FadeInOutAnimation extends Animation {
11158 int mWidth;
11159 boolean mFadeIn;
11160
11161 public FadeInOutAnimation(boolean fadeIn) {
11162 setInterpolator(new AccelerateInterpolator());
11163 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11164 mFadeIn = fadeIn;
11165 }
11166
11167 @Override
11168 protected void applyTransformation(float interpolatedTime, Transformation t) {
11169 float x = interpolatedTime;
11170 if (!mFadeIn) {
11171 x = 1.0f - x; // reverse the interpolation for fade out
11172 }
11173 if (x < 0.5) {
11174 // move the window out of the screen.
11175 t.getMatrix().setTranslate(mWidth, 0);
11176 } else {
11177 t.getMatrix().setTranslate(0, 0);// show
11178 t.setAlpha((x - 0.5f) * 2);
11179 }
11180 }
11181
11182 @Override
11183 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11184 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11185 mWidth = width;
11186 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011187
11188 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011189 public int getZAdjustment() {
11190 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011191 }
11192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011193}