blob: 9bc24d25278f9c3b6a331e4247c756401d64dddc [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;
Chris Tated4533f142010-10-19 15:15:08 -0700504 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700505 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700506 float mThumbOffsetX, mThumbOffsetY;
507 InputChannel mServerChannel, mClientChannel;
508 WindowState mTargetWindow;
509 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700510 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700511
512 private final Rect tmpRect = new Rect();
513
514 DragState(IBinder token, Surface surface, boolean localOnly) {
515 mToken = token;
516 mSurface = surface;
517 mLocalOnly = localOnly;
518 mNotifiedWindows = new ArrayList<WindowState>();
519 }
520
521 void reset() {
522 if (mSurface != null) {
523 mSurface.destroy();
524 }
525 mSurface = null;
526 mLocalOnly = false;
527 mToken = null;
528 mData = null;
529 mThumbOffsetX = mThumbOffsetY = 0;
530 mNotifiedWindows = null;
531 }
532
533 void register() {
534 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
535 if (mClientChannel != null) {
536 Slog.e(TAG, "Duplicate register of drag input channel");
537 } else {
538 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
539 mServerChannel = channels[0];
540 mClientChannel = channels[1];
541 mInputManager.registerInputChannel(mServerChannel);
542 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
543 mH.getLooper().getQueue());
544 }
545 }
546
547 void unregister() {
548 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
549 if (mClientChannel == null) {
550 Slog.e(TAG, "Unregister of nonexistent drag input channel");
551 } else {
552 mInputManager.unregisterInputChannel(mServerChannel);
553 InputQueue.unregisterInputChannel(mClientChannel);
554 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700555 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700556 mClientChannel = null;
557 mServerChannel = null;
558 }
559 }
560
Chris Tatea32dcf72010-10-14 12:13:50 -0700561 int getDragLayerLw() {
562 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
563 * TYPE_LAYER_MULTIPLIER
564 + TYPE_LAYER_OFFSET;
565 }
566
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 /* call out to each visible window/session informing it about the drag
568 */
Chris Tateb8203e92010-10-12 14:23:21 -0700569 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700570 // Cache a base-class instance of the clip metadata so that parceling
571 // works correctly in calling out to the apps.
572 mDataDescription = new ClipDescription(mData);
573 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700574 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700575
576 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700577 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
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++) {
Chris Tateb478f462010-10-15 16:02:26 -0700582 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 }
585
586 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
587 * designated window is potentially a drop recipient. There are race situations
588 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
589 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700590 *
591 * This method clones the 'event' parameter if it's being delivered to the same
592 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700593 */
Chris Tateb478f462010-10-15 16:02:26 -0700594 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
595 ClipDescription desc) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700596 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700597 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
598 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700599 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700600 try {
601 newWin.mClient.dispatchDragEvent(event);
602 // track each window that we've notified that the drag is starting
603 mNotifiedWindows.add(newWin);
604 } catch (RemoteException e) {
605 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700606 } finally {
607 // if the callee was local, the dispatch has already recycled the event
608 if (Process.myPid() != newWin.mSession.mPid) {
609 event.recycle();
610 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700611 }
612 }
613 }
614
615 /* helper - construct and send a DRAG_STARTED event only if the window has not
616 * previously been notified, i.e. it became visible after the drag operation
617 * was begun. This is a rare case.
618 */
619 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700620 if (mDragInProgress) {
621 // If we have sent the drag-started, we needn't do so again
622 for (WindowState ws : mNotifiedWindows) {
623 if (ws == newWin) {
624 return;
625 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700626 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700627 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700628 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700629 }
Chris Tateb478f462010-10-15 16:02:26 -0700630 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700631 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700632 }
633
Chris Tated4533f142010-10-19 15:15:08 -0700634 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700635 if (DEBUG_DRAG) {
636 Slog.d(TAG, "broadcasting DRAG_ENDED");
637 }
Chris Tated4533f142010-10-19 15:15:08 -0700638 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
639 0, 0, null, null, mDragResult);
640 for (WindowState ws: mNotifiedWindows) {
641 try {
642 ws.mClient.dispatchDragEvent(evt);
643 } catch (RemoteException e) {
644 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700645 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700646 }
Chris Tated4533f142010-10-19 15:15:08 -0700647 mNotifiedWindows.clear();
648 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 evt.recycle();
650 }
651
Chris Tated4533f142010-10-19 15:15:08 -0700652 void endDragLw() {
653 mDragState.broadcastDragEndedLw();
654
655 // stop intercepting input
656 mDragState.unregister();
657 mInputMonitor.updateInputWindowsLw();
658
659 // free our resources and drop all the object references
660 mDragState.reset();
661 mDragState = null;
662 }
663
Christopher Tatea53146c2010-09-07 11:57:52 -0700664 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700665 final int myPid = Process.myPid();
666
667 // Move the surface to the given touch
668 mSurface.openTransaction();
669 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
670 mSurface.closeTransaction();
671
672 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700673 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
674 try {
675 // have we dragged over a new window?
676 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
677 if (DEBUG_DRAG) {
678 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
679 }
680 // force DRAG_EXITED_EVENT if appropriate
681 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700682 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700683 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700684 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700685 if (myPid != mTargetWindow.mSession.mPid) {
686 evt.recycle();
687 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700688 }
689 if (touchedWin != null) {
690 if (DEBUG_DRAG) {
691 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
692 }
693 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700694 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700695 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700696 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700697 if (myPid != touchedWin.mSession.mPid) {
698 evt.recycle();
699 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700700 }
701 } catch (RemoteException e) {
702 Slog.w(TAG, "can't send drag notification to windows");
703 }
704 mTargetWindow = touchedWin;
705 }
706
Chris Tated4533f142010-10-19 15:15:08 -0700707 // Tell the drop target about the data. Returns 'true' if we can immediately
708 // dispatch the global drag-ended message, 'false' if we need to wait for a
709 // result from the recipient.
710 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700711 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700712 if (touchedWin == null) {
713 // "drop" outside a valid window -- no recipient to apply a
714 // timeout to, and we can send the drag-ended message immediately.
715 mDragResult = false;
716 return true;
717 }
718
719 if (DEBUG_DRAG) {
720 Slog.d(TAG, "sending DROP to " + touchedWin);
721 }
722 final int myPid = Process.myPid();
723 final IBinder token = touchedWin.mClient.asBinder();
724 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
725 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
726 null, mData, false);
727 try {
728 touchedWin.mClient.dispatchDragEvent(evt);
729
730 // 5 second timeout for this window to respond to the drop
731 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
732 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
733 mH.sendMessageDelayed(msg, 5000);
734 } catch (RemoteException e) {
735 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
736 return true;
737 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700738 if (myPid != touchedWin.mSession.mPid) {
739 evt.recycle();
740 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700741 }
Chris Tated4533f142010-10-19 15:15:08 -0700742 mToken = token;
743 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700744 }
745
746 // Find the visible, touch-deliverable window under the given point
747 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
748 WindowState touchedWin = null;
749 final int x = (int) xf;
750 final int y = (int) yf;
751 final ArrayList<WindowState> windows = mWindows;
752 final int N = windows.size();
753 for (int i = N - 1; i >= 0; i--) {
754 WindowState child = windows.get(i);
755 final int flags = child.mAttrs.flags;
756 if (!child.isVisibleLw()) {
757 // not visible == don't tell about drags
758 continue;
759 }
760 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
761 // not touchable == don't tell about drags
762 continue;
763 }
764 // account for the window's decor etc
765 tmpRect.set(child.mFrame);
766 if (child.mTouchableInsets == ViewTreeObserver
767 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
768 // The point is inside of the window if it is
769 // inside the frame, AND the content part of that
770 // frame that was given by the application.
771 tmpRect.left += child.mGivenContentInsets.left;
772 tmpRect.top += child.mGivenContentInsets.top;
773 tmpRect.right -= child.mGivenContentInsets.right;
774 tmpRect.bottom -= child.mGivenContentInsets.bottom;
775 } else if (child.mTouchableInsets == ViewTreeObserver
776 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
777 // The point is inside of the window if it is
778 // inside the frame, AND the visible part of that
779 // frame that was given by the application.
780 tmpRect.left += child.mGivenVisibleInsets.left;
781 tmpRect.top += child.mGivenVisibleInsets.top;
782 tmpRect.right -= child.mGivenVisibleInsets.right;
783 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
784 }
785 final int touchFlags = flags &
786 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
787 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
788 if (tmpRect.contains(x, y) || touchFlags == 0) {
789 // Found it
790 touchedWin = child;
791 break;
792 }
793 }
794
795 return touchedWin;
796 }
797 }
798
799 DragState mDragState = null;
800 private final InputHandler mDragInputHandler = new BaseInputHandler() {
801 @Override
802 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
803 boolean endDrag = false;
804 final float newX = event.getRawX();
805 final float newY = event.getRawY();
806
807 try {
808 if (mDragState != null) {
809 switch (event.getAction()) {
810 case MotionEvent.ACTION_DOWN: {
811 if (DEBUG_DRAG) {
812 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
813 }
814 } break;
815
816 case MotionEvent.ACTION_MOVE: {
817 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700818 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700819 mDragState.notifyMoveLw(newX, newY);
820 }
821 } break;
822
823 case MotionEvent.ACTION_UP: {
824 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
825 + newX + "," + newY);
826 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700827 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700828 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700829 } break;
830
831 case MotionEvent.ACTION_CANCEL: {
832 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
833 endDrag = true;
834 } break;
835 }
836
837 if (endDrag) {
838 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
839 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700840 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700841 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700842 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700843 }
844 }
845 } catch (Exception e) {
846 Slog.e(TAG, "Exception caught by drag handleMotion", e);
847 } finally {
848 finishedCallback.run();
849 }
850 }
851 };
852
853 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 * Whether the UI is currently running in touch mode (not showing
855 * navigational focus because the user is directly pressing the screen).
856 */
857 boolean mInTouchMode = false;
858
859 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700860 private ArrayList<WindowChangeListener> mWindowChangeListeners =
861 new ArrayList<WindowChangeListener>();
862 private boolean mWindowsChanged = false;
863
864 public interface WindowChangeListener {
865 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700866 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700867 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868
Dianne Hackbornc485a602009-03-24 22:39:49 -0700869 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700870 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700871
872 // The frame use to limit the size of the app running in compatibility mode.
873 Rect mCompatibleScreenFrame = new Rect();
874 // The surface used to fill the outer rim of the app running in compatibility mode.
875 Surface mBackgroundFillerSurface = null;
876 boolean mBackgroundFillerShown = false;
877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 public static WindowManagerService main(Context context,
879 PowerManagerService pm, boolean haveInputMethods) {
880 WMThread thr = new WMThread(context, pm, haveInputMethods);
881 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 synchronized (thr) {
884 while (thr.mService == null) {
885 try {
886 thr.wait();
887 } catch (InterruptedException e) {
888 }
889 }
890 }
Romain Guy06882f82009-06-10 13:36:04 -0700891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 return thr.mService;
893 }
Romain Guy06882f82009-06-10 13:36:04 -0700894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 static class WMThread extends Thread {
896 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 private final Context mContext;
899 private final PowerManagerService mPM;
900 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 public WMThread(Context context, PowerManagerService pm,
903 boolean haveInputMethods) {
904 super("WindowManager");
905 mContext = context;
906 mPM = pm;
907 mHaveInputMethods = haveInputMethods;
908 }
Romain Guy06882f82009-06-10 13:36:04 -0700909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 public void run() {
911 Looper.prepare();
912 WindowManagerService s = new WindowManagerService(mContext, mPM,
913 mHaveInputMethods);
914 android.os.Process.setThreadPriority(
915 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700916 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 synchronized (this) {
919 mService = s;
920 notifyAll();
921 }
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 Looper.loop();
924 }
925 }
926
927 static class PolicyThread extends Thread {
928 private final WindowManagerPolicy mPolicy;
929 private final WindowManagerService mService;
930 private final Context mContext;
931 private final PowerManagerService mPM;
932 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 public PolicyThread(WindowManagerPolicy policy,
935 WindowManagerService service, Context context,
936 PowerManagerService pm) {
937 super("WindowManagerPolicy");
938 mPolicy = policy;
939 mService = service;
940 mContext = context;
941 mPM = pm;
942 }
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 public void run() {
945 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800946 WindowManagerPolicyThread.set(this, Looper.myLooper());
947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800949 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 android.os.Process.setThreadPriority(
951 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700952 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 synchronized (this) {
956 mRunning = true;
957 notifyAll();
958 }
Romain Guy06882f82009-06-10 13:36:04 -0700959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 Looper.loop();
961 }
962 }
963
964 private WindowManagerService(Context context, PowerManagerService pm,
965 boolean haveInputMethods) {
966 mContext = context;
967 mHaveInputMethods = haveInputMethods;
968 mLimitedAlphaCompositing = context.getResources().getBoolean(
969 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 mPowerManager = pm;
972 mPowerManager.setPolicy(mPolicy);
973 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
974 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
975 "SCREEN_FROZEN");
976 mScreenFrozenLock.setReferenceCounted(false);
977
978 mActivityManager = ActivityManagerNative.getDefault();
979 mBatteryStats = BatteryStatsService.getService();
980
981 // Get persisted window scale setting
982 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
983 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
984 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
985 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700986
Jim Miller284b62e2010-06-08 14:27:42 -0700987 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
988 IntentFilter filter = new IntentFilter();
989 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
990 mContext.registerReceiver(mBroadcastReceiver, filter);
991
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700992 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
993 "KEEP_SCREEN_ON_FLAG");
994 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995
Jeff Browne33348b2010-07-15 23:54:05 -0700996 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
999 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 synchronized (thr) {
1002 while (!thr.mRunning) {
1003 try {
1004 thr.wait();
1005 } catch (InterruptedException e) {
1006 }
1007 }
1008 }
Romain Guy06882f82009-06-10 13:36:04 -07001009
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001010 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 // Add ourself to the Watchdog monitors.
1013 Watchdog.getInstance().addMonitor(this);
1014 }
1015
1016 @Override
1017 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1018 throws RemoteException {
1019 try {
1020 return super.onTransact(code, data, reply, flags);
1021 } catch (RuntimeException e) {
1022 // The window manager only throws security exceptions, so let's
1023 // log all others.
1024 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001025 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 }
1027 throw e;
1028 }
1029 }
1030
Jeff Browne33348b2010-07-15 23:54:05 -07001031 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001033 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 TAG, "Adding window " + window + " at "
1035 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1036 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001037 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 }
1039
Jeff Browne33348b2010-07-15 23:54:05 -07001040 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001042 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 TAG, "Adding window " + window + " at "
1044 + i + " of " + mWindows.size() + " (before " + pos + ")");
1045 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001046 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 }
1048
1049 //This method finds out the index of a window that has the same app token as
1050 //win. used for z ordering the windows in mWindows
1051 private int findIdxBasedOnAppTokens(WindowState win) {
1052 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001053 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 int jmax = localmWindows.size();
1055 if(jmax == 0) {
1056 return -1;
1057 }
1058 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001059 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 if(wentry.mAppToken == win.mAppToken) {
1061 return j;
1062 }
1063 }
1064 return -1;
1065 }
Romain Guy06882f82009-06-10 13:36:04 -07001066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1068 final IWindow client = win.mClient;
1069 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001070 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 final int N = localmWindows.size();
1073 final WindowState attached = win.mAttachedWindow;
1074 int i;
1075 if (attached == null) {
1076 int tokenWindowsPos = token.windows.size();
1077 if (token.appWindowToken != null) {
1078 int index = tokenWindowsPos-1;
1079 if (index >= 0) {
1080 // If this application has existing windows, we
1081 // simply place the new window on top of them... but
1082 // keep the starting window on top.
1083 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1084 // Base windows go behind everything else.
1085 placeWindowBefore(token.windows.get(0), win);
1086 tokenWindowsPos = 0;
1087 } else {
1088 AppWindowToken atoken = win.mAppToken;
1089 if (atoken != null &&
1090 token.windows.get(index) == atoken.startingWindow) {
1091 placeWindowBefore(token.windows.get(index), win);
1092 tokenWindowsPos--;
1093 } else {
1094 int newIdx = findIdxBasedOnAppTokens(win);
1095 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001096 //there is a window above this one associated with the same
1097 //apptoken note that the window could be a floating window
1098 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001101 TAG, "Adding window " + win + " at "
1102 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001104 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
1107 }
1108 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001109 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 TAG, "Figuring out where to add app window "
1111 + client.asBinder() + " (token=" + token + ")");
1112 // Figure out where the window should go, based on the
1113 // order of applications.
1114 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001115 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 for (i=NA-1; i>=0; i--) {
1117 AppWindowToken t = mAppTokens.get(i);
1118 if (t == token) {
1119 i--;
1120 break;
1121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001122
Dianne Hackborna8f60182009-09-01 19:01:50 -07001123 // We haven't reached the token yet; if this token
1124 // is not going to the bottom and has windows, we can
1125 // use it as an anchor for when we do reach the token.
1126 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 pos = t.windows.get(0);
1128 }
1129 }
1130 // We now know the index into the apps. If we found
1131 // an app window above, that gives us the position; else
1132 // we need to look some more.
1133 if (pos != null) {
1134 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001135 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 if (atoken != null) {
1137 final int NC = atoken.windows.size();
1138 if (NC > 0) {
1139 WindowState bottom = atoken.windows.get(0);
1140 if (bottom.mSubLayer < 0) {
1141 pos = bottom;
1142 }
1143 }
1144 }
1145 placeWindowBefore(pos, win);
1146 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001147 // Continue looking down until we find the first
1148 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 while (i >= 0) {
1150 AppWindowToken t = mAppTokens.get(i);
1151 final int NW = t.windows.size();
1152 if (NW > 0) {
1153 pos = t.windows.get(NW-1);
1154 break;
1155 }
1156 i--;
1157 }
1158 if (pos != null) {
1159 // Move in front of any windows attached to this
1160 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001161 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 if (atoken != null) {
1163 final int NC = atoken.windows.size();
1164 if (NC > 0) {
1165 WindowState top = atoken.windows.get(NC-1);
1166 if (top.mSubLayer >= 0) {
1167 pos = top;
1168 }
1169 }
1170 }
1171 placeWindowAfter(pos, win);
1172 } else {
1173 // Just search for the start of this layer.
1174 final int myLayer = win.mBaseLayer;
1175 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001176 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 if (w.mBaseLayer > myLayer) {
1178 break;
1179 }
1180 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001181 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001182 TAG, "Adding window " + win + " at "
1183 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001185 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 }
1187 }
1188 }
1189 } else {
1190 // Figure out where window should go, based on layer.
1191 final int myLayer = win.mBaseLayer;
1192 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001193 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 i++;
1195 break;
1196 }
1197 }
1198 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001199 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001200 TAG, "Adding window " + win + " at "
1201 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001203 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 }
1205 if (addToToken) {
1206 token.windows.add(tokenWindowsPos, win);
1207 }
1208
1209 } else {
1210 // Figure out this window's ordering relative to the window
1211 // it is attached to.
1212 final int NA = token.windows.size();
1213 final int sublayer = win.mSubLayer;
1214 int largestSublayer = Integer.MIN_VALUE;
1215 WindowState windowWithLargestSublayer = null;
1216 for (i=0; i<NA; i++) {
1217 WindowState w = token.windows.get(i);
1218 final int wSublayer = w.mSubLayer;
1219 if (wSublayer >= largestSublayer) {
1220 largestSublayer = wSublayer;
1221 windowWithLargestSublayer = w;
1222 }
1223 if (sublayer < 0) {
1224 // For negative sublayers, we go below all windows
1225 // in the same sublayer.
1226 if (wSublayer >= sublayer) {
1227 if (addToToken) {
1228 token.windows.add(i, win);
1229 }
1230 placeWindowBefore(
1231 wSublayer >= 0 ? attached : w, win);
1232 break;
1233 }
1234 } else {
1235 // For positive sublayers, we go above all windows
1236 // in the same sublayer.
1237 if (wSublayer > sublayer) {
1238 if (addToToken) {
1239 token.windows.add(i, win);
1240 }
1241 placeWindowBefore(w, win);
1242 break;
1243 }
1244 }
1245 }
1246 if (i >= NA) {
1247 if (addToToken) {
1248 token.windows.add(win);
1249 }
1250 if (sublayer < 0) {
1251 placeWindowBefore(attached, win);
1252 } else {
1253 placeWindowAfter(largestSublayer >= 0
1254 ? windowWithLargestSublayer
1255 : attached,
1256 win);
1257 }
1258 }
1259 }
Romain Guy06882f82009-06-10 13:36:04 -07001260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 if (win.mAppToken != null && addToToken) {
1262 win.mAppToken.allAppWindows.add(win);
1263 }
1264 }
Romain Guy06882f82009-06-10 13:36:04 -07001265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 static boolean canBeImeTarget(WindowState w) {
1267 final int fl = w.mAttrs.flags
1268 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1269 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1270 return w.isVisibleOrAdding();
1271 }
1272 return false;
1273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001276 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 final int N = localmWindows.size();
1278 WindowState w = null;
1279 int i = N;
1280 while (i > 0) {
1281 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001282 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001283
Joe Onorato8a9b2202010-02-26 18:56:32 -08001284 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 // + Integer.toHexString(w.mAttrs.flags));
1286 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001287 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 // Yet more tricksyness! If this window is a "starting"
1290 // window, we do actually want to be on top of it, but
1291 // it is not -really- where input will go. So if the caller
1292 // is not actually looking to move the IME, look down below
1293 // for a real window to target...
1294 if (!willMove
1295 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1296 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001297 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1299 i--;
1300 w = wb;
1301 }
1302 }
1303 break;
1304 }
1305 }
Romain Guy06882f82009-06-10 13:36:04 -07001306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001308
Joe Onorato8a9b2202010-02-26 18:56:32 -08001309 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 if (willMove && w != null) {
1313 final WindowState curTarget = mInputMethodTarget;
1314 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 // Now some fun for dealing with window animations that
1317 // modify the Z order. We need to look at all windows below
1318 // the current target that are in this app, finding the highest
1319 // visible one in layering.
1320 AppWindowToken token = curTarget.mAppToken;
1321 WindowState highestTarget = null;
1322 int highestPos = 0;
1323 if (token.animating || token.animation != null) {
1324 int pos = 0;
1325 pos = localmWindows.indexOf(curTarget);
1326 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001327 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 if (win.mAppToken != token) {
1329 break;
1330 }
1331 if (!win.mRemoved) {
1332 if (highestTarget == null || win.mAnimLayer >
1333 highestTarget.mAnimLayer) {
1334 highestTarget = win;
1335 highestPos = pos;
1336 }
1337 }
1338 pos--;
1339 }
1340 }
Romain Guy06882f82009-06-10 13:36:04 -07001341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001343 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 + mNextAppTransition + " " + highestTarget
1345 + " animating=" + highestTarget.isAnimating()
1346 + " layer=" + highestTarget.mAnimLayer
1347 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001348
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001349 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 // If we are currently setting up for an animation,
1351 // hold everything until we can find out what will happen.
1352 mInputMethodTargetWaitingAnim = true;
1353 mInputMethodTarget = highestTarget;
1354 return highestPos + 1;
1355 } else if (highestTarget.isAnimating() &&
1356 highestTarget.mAnimLayer > w.mAnimLayer) {
1357 // If the window we are currently targeting is involved
1358 // with an animation, and it is on top of the next target
1359 // we will be over, then hold off on moving until
1360 // that is done.
1361 mInputMethodTarget = highestTarget;
1362 return highestPos + 1;
1363 }
1364 }
1365 }
1366 }
Romain Guy06882f82009-06-10 13:36:04 -07001367
Joe Onorato8a9b2202010-02-26 18:56:32 -08001368 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 if (w != null) {
1370 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001371 if (DEBUG_INPUT_METHOD) {
1372 RuntimeException e = null;
1373 if (!HIDE_STACK_CRAWLS) {
1374 e = new RuntimeException();
1375 e.fillInStackTrace();
1376 }
1377 Slog.w(TAG, "Moving IM target from "
1378 + mInputMethodTarget + " to " + w, e);
1379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 mInputMethodTarget = w;
1381 if (w.mAppToken != null) {
1382 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1383 } else {
1384 setInputMethodAnimLayerAdjustment(0);
1385 }
1386 }
1387 return i+1;
1388 }
1389 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001390 if (DEBUG_INPUT_METHOD) {
1391 RuntimeException e = null;
1392 if (!HIDE_STACK_CRAWLS) {
1393 e = new RuntimeException();
1394 e.fillInStackTrace();
1395 }
1396 Slog.w(TAG, "Moving IM target from "
1397 + mInputMethodTarget + " to null", e);
1398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 mInputMethodTarget = null;
1400 setInputMethodAnimLayerAdjustment(0);
1401 }
1402 return -1;
1403 }
Romain Guy06882f82009-06-10 13:36:04 -07001404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 void addInputMethodWindowToListLocked(WindowState win) {
1406 int pos = findDesiredInputMethodWindowIndexLocked(true);
1407 if (pos >= 0) {
1408 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001409 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001410 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001412 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 moveInputMethodDialogsLocked(pos+1);
1414 return;
1415 }
1416 win.mTargetAppToken = null;
1417 addWindowToListInOrderLocked(win, true);
1418 moveInputMethodDialogsLocked(pos);
1419 }
Romain Guy06882f82009-06-10 13:36:04 -07001420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001422 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 mInputMethodAnimLayerAdjustment = adj;
1424 WindowState imw = mInputMethodWindow;
1425 if (imw != null) {
1426 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001427 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 + " anim layer: " + imw.mAnimLayer);
1429 int wi = imw.mChildWindows.size();
1430 while (wi > 0) {
1431 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001432 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001434 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 + " anim layer: " + cw.mAnimLayer);
1436 }
1437 }
1438 int di = mInputMethodDialogs.size();
1439 while (di > 0) {
1440 di --;
1441 imw = mInputMethodDialogs.get(di);
1442 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001443 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 + " anim layer: " + imw.mAnimLayer);
1445 }
1446 }
Romain Guy06882f82009-06-10 13:36:04 -07001447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1449 int wpos = mWindows.indexOf(win);
1450 if (wpos >= 0) {
1451 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001452 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001454 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 int NC = win.mChildWindows.size();
1456 while (NC > 0) {
1457 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001458 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 int cpos = mWindows.indexOf(cw);
1460 if (cpos >= 0) {
1461 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001463 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 mWindows.remove(cpos);
1465 }
1466 }
1467 }
1468 return interestingPos;
1469 }
Romain Guy06882f82009-06-10 13:36:04 -07001470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 private void reAddWindowToListInOrderLocked(WindowState win) {
1472 addWindowToListInOrderLocked(win, false);
1473 // This is a hack to get all of the child windows added as well
1474 // at the right position. Child windows should be rare and
1475 // this case should be rare, so it shouldn't be that big a deal.
1476 int wpos = mWindows.indexOf(win);
1477 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001478 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001479 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001481 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 reAddWindowLocked(wpos, win);
1483 }
1484 }
Romain Guy06882f82009-06-10 13:36:04 -07001485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 void logWindowList(String prefix) {
1487 int N = mWindows.size();
1488 while (N > 0) {
1489 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001490 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 }
1492 }
Romain Guy06882f82009-06-10 13:36:04 -07001493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 void moveInputMethodDialogsLocked(int pos) {
1495 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 for (int i=0; i<N; i++) {
1500 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1501 }
1502 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001503 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 logWindowList(" ");
1505 }
Romain Guy06882f82009-06-10 13:36:04 -07001506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 if (pos >= 0) {
1508 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1509 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001510 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 if (wp == mInputMethodWindow) {
1512 pos++;
1513 }
1514 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001515 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 for (int i=0; i<N; i++) {
1517 WindowState win = dialogs.get(i);
1518 win.mTargetAppToken = targetAppToken;
1519 pos = reAddWindowLocked(pos, win);
1520 }
1521 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001522 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 logWindowList(" ");
1524 }
1525 return;
1526 }
1527 for (int i=0; i<N; i++) {
1528 WindowState win = dialogs.get(i);
1529 win.mTargetAppToken = null;
1530 reAddWindowToListInOrderLocked(win);
1531 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001532 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 logWindowList(" ");
1534 }
1535 }
1536 }
Romain Guy06882f82009-06-10 13:36:04 -07001537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1539 final WindowState imWin = mInputMethodWindow;
1540 final int DN = mInputMethodDialogs.size();
1541 if (imWin == null && DN == 0) {
1542 return false;
1543 }
Romain Guy06882f82009-06-10 13:36:04 -07001544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1546 if (imPos >= 0) {
1547 // In this case, the input method windows are to be placed
1548 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 // First check to see if the input method windows are already
1551 // located here, and contiguous.
1552 final int N = mWindows.size();
1553 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001554 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 // Figure out the actual input method window that should be
1557 // at the bottom of their stack.
1558 WindowState baseImWin = imWin != null
1559 ? imWin : mInputMethodDialogs.get(0);
1560 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001561 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 if (cw.mSubLayer < 0) baseImWin = cw;
1563 }
Romain Guy06882f82009-06-10 13:36:04 -07001564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 if (firstImWin == baseImWin) {
1566 // The windows haven't moved... but are they still contiguous?
1567 // First find the top IM window.
1568 int pos = imPos+1;
1569 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001570 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 break;
1572 }
1573 pos++;
1574 }
1575 pos++;
1576 // Now there should be no more input method windows above.
1577 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001578 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 break;
1580 }
1581 pos++;
1582 }
1583 if (pos >= N) {
1584 // All is good!
1585 return false;
1586 }
1587 }
Romain Guy06882f82009-06-10 13:36:04 -07001588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 if (imWin != null) {
1590 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001591 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 logWindowList(" ");
1593 }
1594 imPos = tmpRemoveWindowLocked(imPos, imWin);
1595 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001596 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 logWindowList(" ");
1598 }
1599 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1600 reAddWindowLocked(imPos, imWin);
1601 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 logWindowList(" ");
1604 }
1605 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1606 } else {
1607 moveInputMethodDialogsLocked(imPos);
1608 }
Romain Guy06882f82009-06-10 13:36:04 -07001609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 } else {
1611 // In this case, the input method windows go in a fixed layer,
1612 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001615 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 tmpRemoveWindowLocked(0, imWin);
1617 imWin.mTargetAppToken = null;
1618 reAddWindowToListInOrderLocked(imWin);
1619 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001620 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 logWindowList(" ");
1622 }
1623 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1624 } else {
1625 moveInputMethodDialogsLocked(-1);;
1626 }
Romain Guy06882f82009-06-10 13:36:04 -07001627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
Romain Guy06882f82009-06-10 13:36:04 -07001629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 if (needAssignLayers) {
1631 assignLayersLocked();
1632 }
Romain Guy06882f82009-06-10 13:36:04 -07001633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 return true;
1635 }
Romain Guy06882f82009-06-10 13:36:04 -07001636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 void adjustInputMethodDialogsLocked() {
1638 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1639 }
Romain Guy06882f82009-06-10 13:36:04 -07001640
Dianne Hackborn25994b42009-09-04 14:21:19 -07001641 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001643 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1644 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1645 ? wallpaperTarget.mAppToken.animation : null)
1646 + " upper=" + mUpperWallpaperTarget
1647 + " lower=" + mLowerWallpaperTarget);
1648 return (wallpaperTarget != null
1649 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1650 && wallpaperTarget.mAppToken.animation != null)))
1651 || mUpperWallpaperTarget != null
1652 || mLowerWallpaperTarget != null;
1653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001654
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001655 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1656 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001657
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001658 int adjustWallpaperWindowsLocked() {
1659 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001660
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001661 final int dw = mDisplay.getWidth();
1662 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001663
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001664 // First find top-most window that has asked to be on top of the
1665 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001666 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001667 int N = localmWindows.size();
1668 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001669 WindowState foundW = null;
1670 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001671 WindowState topCurW = null;
1672 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001673 int i = N;
1674 while (i > 0) {
1675 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001676 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001677 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1678 if (topCurW == null) {
1679 topCurW = w;
1680 topCurI = i;
1681 }
1682 continue;
1683 }
1684 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001685 if (w.mAppToken != null) {
1686 // If this window's app token is hidden and not animating,
1687 // it is of no interest to us.
1688 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001689 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001690 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001691 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001692 continue;
1693 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001694 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001695 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001696 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1697 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001698 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001699 && (mWallpaperTarget == w
1700 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001701 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001702 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001703 foundW = w;
1704 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001705 if (w == mWallpaperTarget && ((w.mAppToken != null
1706 && w.mAppToken.animation != null)
1707 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001708 // The current wallpaper target is animating, so we'll
1709 // look behind it for another possible target and figure
1710 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001711 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001712 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001713 continue;
1714 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001715 break;
1716 }
1717 }
1718
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001719 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001720 // If we are currently waiting for an app transition, and either
1721 // the current target or the next target are involved with it,
1722 // then hold off on doing anything with the wallpaper.
1723 // Note that we are checking here for just whether the target
1724 // is part of an app token... which is potentially overly aggressive
1725 // (the app token may not be involved in the transition), but good
1726 // enough (we'll just wait until whatever transition is pending
1727 // executes).
1728 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001729 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001730 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001731 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001732 }
1733 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001734 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001735 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001736 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001737 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001740 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001741 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001742 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001743 + " oldTarget: " + mWallpaperTarget);
1744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 mLowerWallpaperTarget = null;
1747 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001749 WindowState oldW = mWallpaperTarget;
1750 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001751
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001752 // Now what is happening... if the current and new targets are
1753 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001754 if (foundW != null && oldW != null) {
1755 boolean oldAnim = oldW.mAnimation != null
1756 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1757 boolean foundAnim = foundW.mAnimation != null
1758 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001759 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001760 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001761 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001762 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001763 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001764 int oldI = localmWindows.indexOf(oldW);
1765 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001766 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001767 }
1768 if (oldI >= 0) {
1769 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001770 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001771 + "=" + oldW + "; new#" + foundI
1772 + "=" + foundW);
1773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001774
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001775 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001776 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001777 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001778 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001779 }
1780 mWallpaperTarget = oldW;
1781 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001782
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001783 // Now set the upper and lower wallpaper targets
1784 // correctly, and make sure that we are positioning
1785 // the wallpaper below the lower.
1786 if (foundI > oldI) {
1787 // The new target is on top of the old one.
1788 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001789 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001790 }
1791 mUpperWallpaperTarget = foundW;
1792 mLowerWallpaperTarget = oldW;
1793 foundW = oldW;
1794 foundI = oldI;
1795 } else {
1796 // The new target is below the old one.
1797 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001798 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001799 }
1800 mUpperWallpaperTarget = oldW;
1801 mLowerWallpaperTarget = foundW;
1802 }
1803 }
1804 }
1805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001806
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001807 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001808 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001809 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1810 || (mLowerWallpaperTarget.mAppToken != null
1811 && mLowerWallpaperTarget.mAppToken.animation != null);
1812 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1813 || (mUpperWallpaperTarget.mAppToken != null
1814 && mUpperWallpaperTarget.mAppToken.animation != null);
1815 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001817 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 }
1819 mLowerWallpaperTarget = null;
1820 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001821 }
1822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001823
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001824 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001825 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001826 // The window is visible to the compositor... but is it visible
1827 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001828 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001829 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001830
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001831 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001832 // its layer adjustment. Only do this if we are not transfering
1833 // between two wallpaper targets.
1834 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001835 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001836 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001837
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001838 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1839 * TYPE_LAYER_MULTIPLIER
1840 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 // Now w is the window we are supposed to be behind... but we
1843 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001844 // AND any starting window associated with it, AND below the
1845 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001846 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001847 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001848 if (wb.mBaseLayer < maxLayer &&
1849 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001850 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001851 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001852 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001853 // This window is not related to the previous one in any
1854 // interesting way, so stop here.
1855 break;
1856 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001857 foundW = wb;
1858 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001859 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001860 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001861 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001862 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001863
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001864 if (foundW == null && topCurW != null) {
1865 // There is no wallpaper target, so it goes at the bottom.
1866 // We will assume it is the same place as last time, if known.
1867 foundW = topCurW;
1868 foundI = topCurI+1;
1869 } else {
1870 // Okay i is the position immediately above the wallpaper. Look at
1871 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001872 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001873 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001874
Dianne Hackborn284ac932009-08-28 10:34:25 -07001875 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001876 if (mWallpaperTarget.mWallpaperX >= 0) {
1877 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001878 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001879 }
1880 if (mWallpaperTarget.mWallpaperY >= 0) {
1881 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001882 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001883 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001884 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001885
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001886 // Start stepping backwards from here, ensuring that our wallpaper windows
1887 // are correctly placed.
1888 int curTokenIndex = mWallpaperTokens.size();
1889 while (curTokenIndex > 0) {
1890 curTokenIndex--;
1891 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001892 if (token.hidden == visible) {
1893 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1894 token.hidden = !visible;
1895 // Need to do a layout to ensure the wallpaper now has the
1896 // correct size.
1897 mLayoutNeeded = true;
1898 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001899
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001900 int curWallpaperIndex = token.windows.size();
1901 while (curWallpaperIndex > 0) {
1902 curWallpaperIndex--;
1903 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001904
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001905 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001906 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001907 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001908
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001909 // First, make sure the client has the current visibility
1910 // state.
1911 if (wallpaper.mWallpaperVisible != visible) {
1912 wallpaper.mWallpaperVisible = visible;
1913 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001914 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001915 "Setting visibility of wallpaper " + wallpaper
1916 + ": " + visible);
1917 wallpaper.mClient.dispatchAppVisibility(visible);
1918 } catch (RemoteException e) {
1919 }
1920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001921
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001922 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001923 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001924 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001925
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001926 // First, if this window is at the current index, then all
1927 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001928 if (wallpaper == foundW) {
1929 foundI--;
1930 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001931 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001932 continue;
1933 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 // The window didn't match... the current wallpaper window,
1936 // wherever it is, is in the wrong place, so make sure it is
1937 // not in the list.
1938 int oldIndex = localmWindows.indexOf(wallpaper);
1939 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001940 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001941 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001943 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001944 if (oldIndex < foundI) {
1945 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001946 }
1947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001948
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001949 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001950 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001951 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001952 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001954 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001955 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001956 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001957 }
1958 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001959
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001960 return changed;
1961 }
1962
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001963 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001964 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001965 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001966 mWallpaperAnimLayerAdjustment = adj;
1967 int curTokenIndex = mWallpaperTokens.size();
1968 while (curTokenIndex > 0) {
1969 curTokenIndex--;
1970 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1971 int curWallpaperIndex = token.windows.size();
1972 while (curWallpaperIndex > 0) {
1973 curWallpaperIndex--;
1974 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1975 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001976 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001977 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001978 }
1979 }
1980 }
1981
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001982 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1983 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001984 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001985 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001986 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001987 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001988 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1989 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1990 changed = wallpaperWin.mXOffset != offset;
1991 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001992 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001993 + wallpaperWin + " x: " + offset);
1994 wallpaperWin.mXOffset = offset;
1995 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001996 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001997 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001998 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001999 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002001
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002002 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002003 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002004 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2005 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2006 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002007 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002008 + wallpaperWin + " y: " + offset);
2009 changed = true;
2010 wallpaperWin.mYOffset = offset;
2011 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002012 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002013 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002014 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002015 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002016 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002017
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002018 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002019 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002020 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002021 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2022 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002023 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002024 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002025 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002026 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002027 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2028 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002029 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002030 if (mWaitingOnWallpaper != null) {
2031 long start = SystemClock.uptimeMillis();
2032 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2033 < start) {
2034 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002035 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002036 "Waiting for offset complete...");
2037 mWindowMap.wait(WALLPAPER_TIMEOUT);
2038 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002039 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002040 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002041 if ((start+WALLPAPER_TIMEOUT)
2042 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002043 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002044 + wallpaperWin);
2045 mLastWallpaperTimeoutTime = start;
2046 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002047 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002048 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002049 }
2050 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002051 } catch (RemoteException e) {
2052 }
2053 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002054
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002055 return changed;
2056 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002057
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002058 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002059 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002060 if (mWaitingOnWallpaper != null &&
2061 mWaitingOnWallpaper.mClient.asBinder() == window) {
2062 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002063 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002064 }
2065 }
2066 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002067
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002068 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002069 final int dw = mDisplay.getWidth();
2070 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002071
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002072 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002073
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002074 WindowState target = mWallpaperTarget;
2075 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002076 if (target.mWallpaperX >= 0) {
2077 mLastWallpaperX = target.mWallpaperX;
2078 } else if (changingTarget.mWallpaperX >= 0) {
2079 mLastWallpaperX = changingTarget.mWallpaperX;
2080 }
2081 if (target.mWallpaperY >= 0) {
2082 mLastWallpaperY = target.mWallpaperY;
2083 } else if (changingTarget.mWallpaperY >= 0) {
2084 mLastWallpaperY = changingTarget.mWallpaperY;
2085 }
2086 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002087
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 int curTokenIndex = mWallpaperTokens.size();
2089 while (curTokenIndex > 0) {
2090 curTokenIndex--;
2091 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2092 int curWallpaperIndex = token.windows.size();
2093 while (curWallpaperIndex > 0) {
2094 curWallpaperIndex--;
2095 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2096 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2097 wallpaper.computeShownFrameLocked();
2098 changed = true;
2099 // We only want to be synchronous with one wallpaper.
2100 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002101 }
2102 }
2103 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002104
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002105 return changed;
2106 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002107
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002108 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002109 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002110 final int dw = mDisplay.getWidth();
2111 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002112
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002113 int curTokenIndex = mWallpaperTokens.size();
2114 while (curTokenIndex > 0) {
2115 curTokenIndex--;
2116 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002117 if (token.hidden == visible) {
2118 token.hidden = !visible;
2119 // Need to do a layout to ensure the wallpaper now has the
2120 // correct size.
2121 mLayoutNeeded = true;
2122 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002123
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002124 int curWallpaperIndex = token.windows.size();
2125 while (curWallpaperIndex > 0) {
2126 curWallpaperIndex--;
2127 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2128 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002129 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002130 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002131
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002132 if (wallpaper.mWallpaperVisible != visible) {
2133 wallpaper.mWallpaperVisible = visible;
2134 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002136 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002137 + ": " + visible);
2138 wallpaper.mClient.dispatchAppVisibility(visible);
2139 } catch (RemoteException e) {
2140 }
2141 }
2142 }
2143 }
2144 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002146 public int addWindow(Session session, IWindow client,
2147 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002148 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 int res = mPolicy.checkAddPermission(attrs);
2150 if (res != WindowManagerImpl.ADD_OKAY) {
2151 return res;
2152 }
Romain Guy06882f82009-06-10 13:36:04 -07002153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 boolean reportNewConfig = false;
2155 WindowState attachedWindow = null;
2156 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002157 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002161 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 }
Romain Guy06882f82009-06-10 13:36:04 -07002163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002165 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2167 }
2168
2169 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002170 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002172 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 + attrs.token + ". Aborting.");
2174 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2175 }
2176 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2177 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002178 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 + attrs.token + ". Aborting.");
2180 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2181 }
2182 }
2183
2184 boolean addToken = false;
2185 WindowToken token = mTokenMap.get(attrs.token);
2186 if (token == null) {
2187 if (attrs.type >= FIRST_APPLICATION_WINDOW
2188 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002189 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 + attrs.token + ". Aborting.");
2191 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2192 }
2193 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002194 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 + attrs.token + ". Aborting.");
2196 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2197 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002198 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002199 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002200 + attrs.token + ". Aborting.");
2201 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2202 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 token = new WindowToken(attrs.token, -1, false);
2204 addToken = true;
2205 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2206 && attrs.type <= LAST_APPLICATION_WINDOW) {
2207 AppWindowToken atoken = token.appWindowToken;
2208 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002209 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 + token + ". Aborting.");
2211 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2212 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 + token + ". Aborting.");
2215 return WindowManagerImpl.ADD_APP_EXITING;
2216 }
2217 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2218 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002219 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2221 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2222 }
2223 } else if (attrs.type == TYPE_INPUT_METHOD) {
2224 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002225 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 + attrs.token + ". Aborting.");
2227 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2228 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002229 } else if (attrs.type == TYPE_WALLPAPER) {
2230 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002231 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002232 + attrs.token + ". Aborting.");
2233 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 }
2236
2237 win = new WindowState(session, client, token,
2238 attachedWindow, attrs, viewVisibility);
2239 if (win.mDeathRecipient == null) {
2240 // Client has apparently died, so there is no reason to
2241 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002242 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 + " that is dead, aborting.");
2244 return WindowManagerImpl.ADD_APP_EXITING;
2245 }
2246
2247 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 res = mPolicy.prepareAddWindowLw(win, attrs);
2250 if (res != WindowManagerImpl.ADD_OKAY) {
2251 return res;
2252 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002253
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002254 if (outInputChannel != null) {
2255 String name = win.makeInputChannelName();
2256 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2257 win.mInputChannel = inputChannels[0];
2258 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2259
2260 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262
2263 // From now on, no exceptions or errors allowed!
2264
2265 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002266
Dianne Hackborn5132b372010-07-29 12:51:35 -07002267 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 if (addToken) {
2270 mTokenMap.put(attrs.token, token);
2271 mTokenList.add(token);
2272 }
2273 win.attach();
2274 mWindowMap.put(client.asBinder(), win);
2275
2276 if (attrs.type == TYPE_APPLICATION_STARTING &&
2277 token.appWindowToken != null) {
2278 token.appWindowToken.startingWindow = win;
2279 }
2280
2281 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 if (attrs.type == TYPE_INPUT_METHOD) {
2284 mInputMethodWindow = win;
2285 addInputMethodWindowToListLocked(win);
2286 imMayMove = false;
2287 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2288 mInputMethodDialogs.add(win);
2289 addWindowToListInOrderLocked(win, true);
2290 adjustInputMethodDialogsLocked();
2291 imMayMove = false;
2292 } else {
2293 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002294 if (attrs.type == TYPE_WALLPAPER) {
2295 mLastWallpaperTimeoutTime = 0;
2296 adjustWallpaperWindowsLocked();
2297 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002298 adjustWallpaperWindowsLocked();
2299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 }
Romain Guy06882f82009-06-10 13:36:04 -07002301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 if (mInTouchMode) {
2307 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2308 }
2309 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2310 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2311 }
Romain Guy06882f82009-06-10 13:36:04 -07002312
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002313 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002315 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2316 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 imMayMove = false;
2318 }
2319 }
Romain Guy06882f82009-06-10 13:36:04 -07002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002322 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 }
Romain Guy06882f82009-06-10 13:36:04 -07002324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 assignLayersLocked();
2326 // Don't do layout here, the window must call
2327 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 //dump();
2330
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002331 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002332 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002333 }
Jeff Brown349703e2010-06-22 01:27:15 -07002334
Joe Onorato8a9b2202010-02-26 18:56:32 -08002335 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002336 TAG, "New client " + client.asBinder()
2337 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002338
2339 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2340 reportNewConfig = true;
2341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 }
2343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 if (reportNewConfig) {
2345 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 return res;
2351 }
Romain Guy06882f82009-06-10 13:36:04 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 public void removeWindow(Session session, IWindow client) {
2354 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002355 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 if (win == null) {
2357 return;
2358 }
2359 removeWindowLocked(session, win);
2360 }
2361 }
Romain Guy06882f82009-06-10 13:36:04 -07002362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 public void removeWindowLocked(Session session, WindowState win) {
2364
Joe Onorato8a9b2202010-02-26 18:56:32 -08002365 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 TAG, "Remove " + win + " client="
2367 + Integer.toHexString(System.identityHashCode(
2368 win.mClient.asBinder()))
2369 + ", surface=" + win.mSurface);
2370
2371 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002372
2373 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002374
Joe Onorato8a9b2202010-02-26 18:56:32 -08002375 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2377 + " mExiting=" + win.mExiting
2378 + " isAnimating=" + win.isAnimating()
2379 + " app-animation="
2380 + (win.mAppToken != null ? win.mAppToken.animation : null)
2381 + " inPendingTransaction="
2382 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2383 + " mDisplayFrozen=" + mDisplayFrozen);
2384 // Visibility of the removed window. Will be used later to update orientation later on.
2385 boolean wasVisible = false;
2386 // First, see if we need to run an animation. If we do, we have
2387 // to hold off on removing the window until the animation is done.
2388 // If the display is frozen, just remove immediately, since the
2389 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002390 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 // If we are not currently running the exit animation, we
2392 // need to see about starting one.
2393 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2396 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2397 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2398 }
2399 // Try starting an animation.
2400 if (applyAnimationLocked(win, transit, false)) {
2401 win.mExiting = true;
2402 }
2403 }
2404 if (win.mExiting || win.isAnimating()) {
2405 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002406 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 win.mExiting = true;
2408 win.mRemoveOnExit = true;
2409 mLayoutNeeded = true;
2410 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2411 performLayoutAndPlaceSurfacesLocked();
2412 if (win.mAppToken != null) {
2413 win.mAppToken.updateReportedVisibilityLocked();
2414 }
2415 //dump();
2416 Binder.restoreCallingIdentity(origId);
2417 return;
2418 }
2419 }
2420
2421 removeWindowInnerLocked(session, win);
2422 // Removing a visible window will effect the computed orientation
2423 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002424 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002425 != mForcedAppOrientation
2426 && updateOrientationFromAppTokensLocked()) {
2427 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 }
2429 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2430 Binder.restoreCallingIdentity(origId);
2431 }
Romain Guy06882f82009-06-10 13:36:04 -07002432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 if (mInputMethodTarget == win) {
2437 moveInputMethodWindowsIfNeededLocked(false);
2438 }
Romain Guy06882f82009-06-10 13:36:04 -07002439
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002440 if (false) {
2441 RuntimeException e = new RuntimeException("here");
2442 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002443 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 mPolicy.removeWindowLw(win);
2447 win.removeLocked();
2448
2449 mWindowMap.remove(win.mClient.asBinder());
2450 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002451 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002452 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453
2454 if (mInputMethodWindow == win) {
2455 mInputMethodWindow = null;
2456 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2457 mInputMethodDialogs.remove(win);
2458 }
Romain Guy06882f82009-06-10 13:36:04 -07002459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 final WindowToken token = win.mToken;
2461 final AppWindowToken atoken = win.mAppToken;
2462 token.windows.remove(win);
2463 if (atoken != null) {
2464 atoken.allAppWindows.remove(win);
2465 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002466 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 TAG, "**** Removing window " + win + ": count="
2468 + token.windows.size());
2469 if (token.windows.size() == 0) {
2470 if (!token.explicit) {
2471 mTokenMap.remove(token.token);
2472 mTokenList.remove(token);
2473 } else if (atoken != null) {
2474 atoken.firstWindowDrawn = false;
2475 }
2476 }
2477
2478 if (atoken != null) {
2479 if (atoken.startingWindow == win) {
2480 atoken.startingWindow = null;
2481 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2482 // If this is the last window and we had requested a starting
2483 // transition window, well there is no point now.
2484 atoken.startingData = null;
2485 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2486 // If this is the last window except for a starting transition
2487 // window, we need to get rid of the starting transition.
2488 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002489 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 + ": no more real windows");
2491 }
2492 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2493 mH.sendMessage(m);
2494 }
2495 }
Romain Guy06882f82009-06-10 13:36:04 -07002496
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002497 if (win.mAttrs.type == TYPE_WALLPAPER) {
2498 mLastWallpaperTimeoutTime = 0;
2499 adjustWallpaperWindowsLocked();
2500 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002501 adjustWallpaperWindowsLocked();
2502 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 if (!mInLayout) {
2505 assignLayersLocked();
2506 mLayoutNeeded = true;
2507 performLayoutAndPlaceSurfacesLocked();
2508 if (win.mAppToken != null) {
2509 win.mAppToken.updateReportedVisibilityLocked();
2510 }
2511 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002512
2513 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 }
2515
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002516 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2517 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2518 + ": " + msg + " / " + w.mAttrs.getTitle();
2519 if (where != null) {
2520 Slog.i(TAG, str, where);
2521 } else {
2522 Slog.i(TAG, str);
2523 }
2524 }
2525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2527 long origId = Binder.clearCallingIdentity();
2528 try {
2529 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002530 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002532 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 Surface.openTransaction();
2534 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002535 if (SHOW_TRANSACTIONS) logSurface(w,
2536 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 w.mSurface.setTransparentRegionHint(region);
2538 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002539 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 Surface.closeTransaction();
2541 }
2542 }
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(origId);
2546 }
2547 }
2548
2549 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002550 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 Rect visibleInsets) {
2552 long origId = Binder.clearCallingIdentity();
2553 try {
2554 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002555 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 if (w != null) {
2557 w.mGivenInsetsPending = false;
2558 w.mGivenContentInsets.set(contentInsets);
2559 w.mGivenVisibleInsets.set(visibleInsets);
2560 w.mTouchableInsets = touchableInsets;
2561 mLayoutNeeded = true;
2562 performLayoutAndPlaceSurfacesLocked();
2563 }
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(origId);
2567 }
2568 }
Romain Guy06882f82009-06-10 13:36:04 -07002569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 public void getWindowDisplayFrame(Session session, IWindow client,
2571 Rect outDisplayFrame) {
2572 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002573 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 if (win == null) {
2575 outDisplayFrame.setEmpty();
2576 return;
2577 }
2578 outDisplayFrame.set(win.mDisplayFrame);
2579 }
2580 }
2581
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002582 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2583 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002584 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2585 window.mWallpaperX = x;
2586 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002587 window.mWallpaperXStep = xStep;
2588 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002589 if (updateWallpaperOffsetLocked(window, true)) {
2590 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002591 }
2592 }
2593 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002594
Dianne Hackborn75804932009-10-20 20:15:20 -07002595 void wallpaperCommandComplete(IBinder window, Bundle result) {
2596 synchronized (mWindowMap) {
2597 if (mWaitingOnWallpaper != null &&
2598 mWaitingOnWallpaper.mClient.asBinder() == window) {
2599 mWaitingOnWallpaper = null;
2600 mWindowMap.notifyAll();
2601 }
2602 }
2603 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002604
Dianne Hackborn75804932009-10-20 20:15:20 -07002605 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2606 String action, int x, int y, int z, Bundle extras, boolean sync) {
2607 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2608 || window == mUpperWallpaperTarget) {
2609 boolean doWait = sync;
2610 int curTokenIndex = mWallpaperTokens.size();
2611 while (curTokenIndex > 0) {
2612 curTokenIndex--;
2613 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2614 int curWallpaperIndex = token.windows.size();
2615 while (curWallpaperIndex > 0) {
2616 curWallpaperIndex--;
2617 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2618 try {
2619 wallpaper.mClient.dispatchWallpaperCommand(action,
2620 x, y, z, extras, sync);
2621 // We only want to be synchronous with one wallpaper.
2622 sync = false;
2623 } catch (RemoteException e) {
2624 }
2625 }
2626 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002627
Dianne Hackborn75804932009-10-20 20:15:20 -07002628 if (doWait) {
2629 // XXX Need to wait for result.
2630 }
2631 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002632
Dianne Hackborn75804932009-10-20 20:15:20 -07002633 return null;
2634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 public int relayoutWindow(Session session, IWindow client,
2637 WindowManager.LayoutParams attrs, int requestedWidth,
2638 int requestedHeight, int viewVisibility, boolean insetsPending,
2639 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002640 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 boolean displayed = false;
2642 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002643 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002647 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 if (win == null) {
2649 return 0;
2650 }
2651 win.mRequestedWidth = requestedWidth;
2652 win.mRequestedHeight = requestedHeight;
2653
2654 if (attrs != null) {
2655 mPolicy.adjustWindowParamsLw(attrs);
2656 }
Romain Guy06882f82009-06-10 13:36:04 -07002657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 int attrChanges = 0;
2659 int flagChanges = 0;
2660 if (attrs != null) {
2661 flagChanges = win.mAttrs.flags ^= attrs.flags;
2662 attrChanges = win.mAttrs.copyFrom(attrs);
2663 }
2664
Joe Onorato8a9b2202010-02-26 18:56:32 -08002665 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666
2667 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2668 win.mAlpha = attrs.alpha;
2669 }
2670
2671 final boolean scaledWindow =
2672 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2673
2674 if (scaledWindow) {
2675 // requested{Width|Height} Surface's physical size
2676 // attrs.{width|height} Size on screen
2677 win.mHScale = (attrs.width != requestedWidth) ?
2678 (attrs.width / (float)requestedWidth) : 1.0f;
2679 win.mVScale = (attrs.height != requestedHeight) ?
2680 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002681 } else {
2682 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 }
2684
2685 boolean imMayMove = (flagChanges&(
2686 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2687 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 boolean focusMayChange = win.mViewVisibility != viewVisibility
2690 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2691 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002692
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002693 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2694 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 win.mRelayoutCalled = true;
2697 final int oldVisibility = win.mViewVisibility;
2698 win.mViewVisibility = viewVisibility;
2699 if (viewVisibility == View.VISIBLE &&
2700 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2701 displayed = !win.isVisibleLw();
2702 if (win.mExiting) {
2703 win.mExiting = false;
2704 win.mAnimation = null;
2705 }
2706 if (win.mDestroying) {
2707 win.mDestroying = false;
2708 mDestroySurface.remove(win);
2709 }
2710 if (oldVisibility == View.GONE) {
2711 win.mEnterAnimationPending = true;
2712 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002713 if (displayed) {
2714 if (win.mSurface != null && !win.mDrawPending
2715 && !win.mCommitDrawPending && !mDisplayFrozen
2716 && mPolicy.isScreenOn()) {
2717 applyEnterAnimationLocked(win);
2718 }
2719 if ((win.mAttrs.flags
2720 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2721 if (DEBUG_VISIBILITY) Slog.v(TAG,
2722 "Relayout window turning screen on: " + win);
2723 win.mTurnOnScreen = true;
2724 }
2725 int diff = 0;
2726 if (win.mConfiguration != mCurConfiguration
2727 && (win.mConfiguration == null
2728 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2729 win.mConfiguration = mCurConfiguration;
2730 if (DEBUG_CONFIGURATION) {
2731 Slog.i(TAG, "Window " + win + " visible with new config: "
2732 + win.mConfiguration + " / 0x"
2733 + Integer.toHexString(diff));
2734 }
2735 outConfig.setTo(mCurConfiguration);
2736 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002737 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2739 // To change the format, we need to re-build the surface.
2740 win.destroySurfaceLocked();
2741 displayed = true;
2742 }
2743 try {
2744 Surface surface = win.createSurfaceLocked();
2745 if (surface != null) {
2746 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002747 win.mReportDestroySurface = false;
2748 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002749 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002750 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002752 // For some reason there isn't a surface. Clear the
2753 // caller's object so they see the same state.
2754 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 }
2756 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002757 mInputMonitor.updateInputWindowsLw();
2758
Joe Onorato8a9b2202010-02-26 18:56:32 -08002759 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002760 + client + " (" + win.mAttrs.getTitle() + ")",
2761 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 Binder.restoreCallingIdentity(origId);
2763 return 0;
2764 }
2765 if (displayed) {
2766 focusMayChange = true;
2767 }
2768 if (win.mAttrs.type == TYPE_INPUT_METHOD
2769 && mInputMethodWindow == null) {
2770 mInputMethodWindow = win;
2771 imMayMove = true;
2772 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002773 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2774 && win.mAppToken != null
2775 && win.mAppToken.startingWindow != null) {
2776 // Special handling of starting window over the base
2777 // window of the app: propagate lock screen flags to it,
2778 // to provide the correct semantics while starting.
2779 final int mask =
2780 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002781 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2782 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002783 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2784 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 } else {
2787 win.mEnterAnimationPending = false;
2788 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002789 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002790 + ": mExiting=" + win.mExiting
2791 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 // If we are not currently running the exit animation, we
2793 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002794 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 // Try starting an animation; if there isn't one, we
2796 // can destroy the surface right away.
2797 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2798 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2799 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2800 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002801 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002803 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 } else if (win.isAnimating()) {
2806 // Currently in a hide animation... turn this into
2807 // an exit.
2808 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002809 } else if (win == mWallpaperTarget) {
2810 // If the wallpaper is currently behind this
2811 // window, we need to change both of them inside
2812 // of a transaction to avoid artifacts.
2813 win.mExiting = true;
2814 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 } else {
2816 if (mInputMethodWindow == win) {
2817 mInputMethodWindow = null;
2818 }
2819 win.destroySurfaceLocked();
2820 }
2821 }
2822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002823
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002824 if (win.mSurface == null || (win.getAttrs().flags
2825 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2826 || win.mSurfacePendingDestroy) {
2827 // We are being called from a local process, which
2828 // means outSurface holds its current surface. Ensure the
2829 // surface object is cleared, but we don't want it actually
2830 // destroyed at this point.
2831 win.mSurfacePendingDestroy = false;
2832 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002833 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002834 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002835 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002836 "Keeping surface, will report destroy: " + win);
2837 win.mReportDestroySurface = true;
2838 outSurface.copyFrom(win.mSurface);
2839 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 }
2841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 if (focusMayChange) {
2843 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2844 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 imMayMove = false;
2846 }
2847 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2848 }
Romain Guy06882f82009-06-10 13:36:04 -07002849
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002850 // updateFocusedWindowLocked() already assigned layers so we only need to
2851 // reassign them at this point if the IM window state gets shuffled
2852 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002855 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2856 // Little hack here -- we -should- be able to rely on the
2857 // function to return true if the IME has moved and needs
2858 // its layer recomputed. However, if the IME was hidden
2859 // and isn't actually moved in the list, its layer may be
2860 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 assignLayers = true;
2862 }
2863 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002864 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002865 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002866 assignLayers = true;
2867 }
2868 }
Romain Guy06882f82009-06-10 13:36:04 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 mLayoutNeeded = true;
2871 win.mGivenInsetsPending = insetsPending;
2872 if (assignLayers) {
2873 assignLayersLocked();
2874 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002875 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002877 if (displayed && win.mIsWallpaper) {
2878 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002879 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 if (win.mAppToken != null) {
2882 win.mAppToken.updateReportedVisibilityLocked();
2883 }
2884 outFrame.set(win.mFrame);
2885 outContentInsets.set(win.mContentInsets);
2886 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002887 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002889 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 + ", requestedHeight=" + requestedHeight
2891 + ", viewVisibility=" + viewVisibility
2892 + "\nRelayout returning frame=" + outFrame
2893 + ", surface=" + outSurface);
2894
Joe Onorato8a9b2202010-02-26 18:56:32 -08002895 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2897
2898 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002899
2900 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 }
2902
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002903 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 sendNewConfiguration();
2905 }
Romain Guy06882f82009-06-10 13:36:04 -07002906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2910 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2911 }
2912
2913 public void finishDrawingWindow(Session session, IWindow client) {
2914 final long origId = Binder.clearCallingIdentity();
2915 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002916 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002918 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2919 adjustWallpaperWindowsLocked();
2920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 mLayoutNeeded = true;
2922 performLayoutAndPlaceSurfacesLocked();
2923 }
2924 }
2925 Binder.restoreCallingIdentity(origId);
2926 }
2927
2928 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002929 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 + (lp != null ? lp.packageName : null)
2931 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2932 if (lp != null && lp.windowAnimations != 0) {
2933 // If this is a system resource, don't try to load it from the
2934 // application resources. It is nice to avoid loading application
2935 // resources if we can.
2936 String packageName = lp.packageName != null ? lp.packageName : "android";
2937 int resId = lp.windowAnimations;
2938 if ((resId&0xFF000000) == 0x01000000) {
2939 packageName = "android";
2940 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002941 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 + packageName);
2943 return AttributeCache.instance().get(packageName, resId,
2944 com.android.internal.R.styleable.WindowAnimation);
2945 }
2946 return null;
2947 }
Romain Guy06882f82009-06-10 13:36:04 -07002948
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002949 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002950 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002951 + packageName + " resId=0x" + Integer.toHexString(resId));
2952 if (packageName != null) {
2953 if ((resId&0xFF000000) == 0x01000000) {
2954 packageName = "android";
2955 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002956 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002957 + packageName);
2958 return AttributeCache.instance().get(packageName, resId,
2959 com.android.internal.R.styleable.WindowAnimation);
2960 }
2961 return null;
2962 }
2963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 private void applyEnterAnimationLocked(WindowState win) {
2965 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2966 if (win.mEnterAnimationPending) {
2967 win.mEnterAnimationPending = false;
2968 transit = WindowManagerPolicy.TRANSIT_ENTER;
2969 }
2970
2971 applyAnimationLocked(win, transit, true);
2972 }
2973
2974 private boolean applyAnimationLocked(WindowState win,
2975 int transit, boolean isEntrance) {
2976 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2977 // If we are trying to apply an animation, but already running
2978 // an animation of the same type, then just leave that one alone.
2979 return true;
2980 }
Romain Guy06882f82009-06-10 13:36:04 -07002981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 // Only apply an animation if the display isn't frozen. If it is
2983 // frozen, there is no reason to animate and it can cause strange
2984 // artifacts when we unfreeze the display if some different animation
2985 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002986 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 int anim = mPolicy.selectAnimationLw(win, transit);
2988 int attr = -1;
2989 Animation a = null;
2990 if (anim != 0) {
2991 a = AnimationUtils.loadAnimation(mContext, anim);
2992 } else {
2993 switch (transit) {
2994 case WindowManagerPolicy.TRANSIT_ENTER:
2995 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2996 break;
2997 case WindowManagerPolicy.TRANSIT_EXIT:
2998 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2999 break;
3000 case WindowManagerPolicy.TRANSIT_SHOW:
3001 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3002 break;
3003 case WindowManagerPolicy.TRANSIT_HIDE:
3004 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3005 break;
3006 }
3007 if (attr >= 0) {
3008 a = loadAnimation(win.mAttrs, attr);
3009 }
3010 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003011 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3013 + " mAnimation=" + win.mAnimation
3014 + " isEntrance=" + isEntrance);
3015 if (a != null) {
3016 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003017 RuntimeException e = null;
3018 if (!HIDE_STACK_CRAWLS) {
3019 e = new RuntimeException();
3020 e.fillInStackTrace();
3021 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003022 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 }
3024 win.setAnimation(a);
3025 win.mAnimationIsEntrance = isEntrance;
3026 }
3027 } else {
3028 win.clearAnimation();
3029 }
3030
3031 return win.mAnimation != null;
3032 }
3033
3034 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3035 int anim = 0;
3036 Context context = mContext;
3037 if (animAttr >= 0) {
3038 AttributeCache.Entry ent = getCachedAnimations(lp);
3039 if (ent != null) {
3040 context = ent.context;
3041 anim = ent.array.getResourceId(animAttr, 0);
3042 }
3043 }
3044 if (anim != 0) {
3045 return AnimationUtils.loadAnimation(context, anim);
3046 }
3047 return null;
3048 }
Romain Guy06882f82009-06-10 13:36:04 -07003049
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003050 private Animation loadAnimation(String packageName, int resId) {
3051 int anim = 0;
3052 Context context = mContext;
3053 if (resId >= 0) {
3054 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3055 if (ent != null) {
3056 context = ent.context;
3057 anim = resId;
3058 }
3059 }
3060 if (anim != 0) {
3061 return AnimationUtils.loadAnimation(context, anim);
3062 }
3063 return null;
3064 }
3065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 private boolean applyAnimationLocked(AppWindowToken wtoken,
3067 WindowManager.LayoutParams lp, int transit, boolean enter) {
3068 // Only apply an animation if the display isn't frozen. If it is
3069 // frozen, there is no reason to animate and it can cause strange
3070 // artifacts when we unfreeze the display if some different animation
3071 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003072 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003073 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003074 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003075 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003076 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003077 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003078 } else if (mNextAppTransitionPackage != null) {
3079 a = loadAnimation(mNextAppTransitionPackage, enter ?
3080 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003081 } else {
3082 int animAttr = 0;
3083 switch (transit) {
3084 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3085 animAttr = enter
3086 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3087 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3088 break;
3089 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3090 animAttr = enter
3091 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3092 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3093 break;
3094 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3095 animAttr = enter
3096 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3097 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3098 break;
3099 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3100 animAttr = enter
3101 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3102 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3103 break;
3104 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3105 animAttr = enter
3106 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3107 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3108 break;
3109 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3110 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003111 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003112 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3113 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003114 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003115 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003116 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3117 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003118 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003119 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003120 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003121 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3122 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3123 break;
3124 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3125 animAttr = enter
3126 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3127 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3128 break;
3129 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3130 animAttr = enter
3131 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3132 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003133 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003134 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003135 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003136 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003137 + " anim=" + a
3138 + " animAttr=0x" + Integer.toHexString(animAttr)
3139 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 if (a != null) {
3142 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003143 RuntimeException e = null;
3144 if (!HIDE_STACK_CRAWLS) {
3145 e = new RuntimeException();
3146 e.fillInStackTrace();
3147 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003148 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 }
3150 wtoken.setAnimation(a);
3151 }
3152 } else {
3153 wtoken.clearAnimation();
3154 }
3155
3156 return wtoken.animation != null;
3157 }
3158
3159 // -------------------------------------------------------------
3160 // Application Window Tokens
3161 // -------------------------------------------------------------
3162
3163 public void validateAppTokens(List tokens) {
3164 int v = tokens.size()-1;
3165 int m = mAppTokens.size()-1;
3166 while (v >= 0 && m >= 0) {
3167 AppWindowToken wtoken = mAppTokens.get(m);
3168 if (wtoken.removed) {
3169 m--;
3170 continue;
3171 }
3172 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003173 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3175 }
3176 v--;
3177 m--;
3178 }
3179 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003180 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 v--;
3182 }
3183 while (m >= 0) {
3184 AppWindowToken wtoken = mAppTokens.get(m);
3185 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003186 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 }
3188 m--;
3189 }
3190 }
3191
3192 boolean checkCallingPermission(String permission, String func) {
3193 // Quick check: if the calling permission is me, it's all okay.
3194 if (Binder.getCallingPid() == Process.myPid()) {
3195 return true;
3196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 if (mContext.checkCallingPermission(permission)
3199 == PackageManager.PERMISSION_GRANTED) {
3200 return true;
3201 }
3202 String msg = "Permission Denial: " + func + " from pid="
3203 + Binder.getCallingPid()
3204 + ", uid=" + Binder.getCallingUid()
3205 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003206 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 return false;
3208 }
Romain Guy06882f82009-06-10 13:36:04 -07003209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 AppWindowToken findAppWindowToken(IBinder token) {
3211 WindowToken wtoken = mTokenMap.get(token);
3212 if (wtoken == null) {
3213 return null;
3214 }
3215 return wtoken.appWindowToken;
3216 }
Romain Guy06882f82009-06-10 13:36:04 -07003217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 public void addWindowToken(IBinder token, int type) {
3219 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3220 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003221 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 }
Romain Guy06882f82009-06-10 13:36:04 -07003223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 synchronized(mWindowMap) {
3225 WindowToken wtoken = mTokenMap.get(token);
3226 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003227 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 return;
3229 }
3230 wtoken = new WindowToken(token, type, true);
3231 mTokenMap.put(token, wtoken);
3232 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003233 if (type == TYPE_WALLPAPER) {
3234 mWallpaperTokens.add(wtoken);
3235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 }
3237 }
Romain Guy06882f82009-06-10 13:36:04 -07003238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 public void removeWindowToken(IBinder token) {
3240 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3241 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003242 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 }
3244
3245 final long origId = Binder.clearCallingIdentity();
3246 synchronized(mWindowMap) {
3247 WindowToken wtoken = mTokenMap.remove(token);
3248 mTokenList.remove(wtoken);
3249 if (wtoken != null) {
3250 boolean delayed = false;
3251 if (!wtoken.hidden) {
3252 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 final int N = wtoken.windows.size();
3255 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 for (int i=0; i<N; i++) {
3258 WindowState win = wtoken.windows.get(i);
3259
3260 if (win.isAnimating()) {
3261 delayed = true;
3262 }
Romain Guy06882f82009-06-10 13:36:04 -07003263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 if (win.isVisibleNow()) {
3265 applyAnimationLocked(win,
3266 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 changed = true;
3268 }
3269 }
3270
3271 if (changed) {
3272 mLayoutNeeded = true;
3273 performLayoutAndPlaceSurfacesLocked();
3274 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3275 }
Romain Guy06882f82009-06-10 13:36:04 -07003276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 if (delayed) {
3278 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003279 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3280 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 }
3282 }
Romain Guy06882f82009-06-10 13:36:04 -07003283
Jeff Brownc5ed5912010-07-14 18:48:53 -07003284 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003286 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003287 }
3288 }
3289 Binder.restoreCallingIdentity(origId);
3290 }
3291
3292 public void addAppToken(int addPos, IApplicationToken token,
3293 int groupId, int requestedOrientation, boolean fullscreen) {
3294 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3295 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003296 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
Jeff Brown349703e2010-06-22 01:27:15 -07003298
3299 // Get the dispatching timeout here while we are not holding any locks so that it
3300 // can be cached by the AppWindowToken. The timeout value is used later by the
3301 // input dispatcher in code that does hold locks. If we did not cache the value
3302 // here we would run the chance of introducing a deadlock between the window manager
3303 // (which holds locks while updating the input dispatcher state) and the activity manager
3304 // (which holds locks while querying the application token).
3305 long inputDispatchingTimeoutNanos;
3306 try {
3307 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3308 } catch (RemoteException ex) {
3309 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3310 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3311 }
Romain Guy06882f82009-06-10 13:36:04 -07003312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003313 synchronized(mWindowMap) {
3314 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3315 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003316 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 return;
3318 }
3319 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003320 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 wtoken.groupId = groupId;
3322 wtoken.appFullscreen = fullscreen;
3323 wtoken.requestedOrientation = requestedOrientation;
3324 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003325 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 mTokenMap.put(token.asBinder(), wtoken);
3327 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 // Application tokens start out hidden.
3330 wtoken.hidden = true;
3331 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 //dump();
3334 }
3335 }
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 public void setAppGroupId(IBinder token, int groupId) {
3338 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3339 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003340 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 }
3342
3343 synchronized(mWindowMap) {
3344 AppWindowToken wtoken = findAppWindowToken(token);
3345 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003346 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 return;
3348 }
3349 wtoken.groupId = groupId;
3350 }
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 public int getOrientationFromWindowsLocked() {
3354 int pos = mWindows.size() - 1;
3355 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003356 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 pos--;
3358 if (wtoken.mAppToken != null) {
3359 // We hit an application window. so the orientation will be determined by the
3360 // app window. No point in continuing further.
3361 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3362 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003363 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 continue;
3365 }
3366 int req = wtoken.mAttrs.screenOrientation;
3367 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3368 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3369 continue;
3370 } else {
3371 return req;
3372 }
3373 }
3374 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3375 }
Romain Guy06882f82009-06-10 13:36:04 -07003376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003378 int pos = mAppTokens.size() - 1;
3379 int curGroup = 0;
3380 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3381 boolean findingBehind = false;
3382 boolean haveGroup = false;
3383 boolean lastFullscreen = false;
3384 while (pos >= 0) {
3385 AppWindowToken wtoken = mAppTokens.get(pos);
3386 pos--;
3387 // if we're about to tear down this window and not seek for
3388 // the behind activity, don't use it for orientation
3389 if (!findingBehind
3390 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3391 continue;
3392 }
3393
3394 if (!haveGroup) {
3395 // We ignore any hidden applications on the top.
3396 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003397 continue;
3398 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003399 haveGroup = true;
3400 curGroup = wtoken.groupId;
3401 lastOrientation = wtoken.requestedOrientation;
3402 } else if (curGroup != wtoken.groupId) {
3403 // If we have hit a new application group, and the bottom
3404 // of the previous group didn't explicitly say to use
3405 // the orientation behind it, and the last app was
3406 // full screen, then we'll stick with the
3407 // user's orientation.
3408 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3409 && lastFullscreen) {
3410 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003413 int or = wtoken.requestedOrientation;
3414 // If this application is fullscreen, and didn't explicitly say
3415 // to use the orientation behind it, then just take whatever
3416 // orientation it has and ignores whatever is under it.
3417 lastFullscreen = wtoken.appFullscreen;
3418 if (lastFullscreen
3419 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3420 return or;
3421 }
3422 // If this application has requested an explicit orientation,
3423 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003424 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3425 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003426 return or;
3427 }
3428 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3429 }
3430 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 }
Romain Guy06882f82009-06-10 13:36:04 -07003432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003434 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003435 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3436 "updateOrientationFromAppTokens()")) {
3437 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3438 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003439
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003440 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003442
3443 synchronized(mWindowMap) {
3444 if (updateOrientationFromAppTokensLocked()) {
3445 if (freezeThisOneIfNeeded != null) {
3446 AppWindowToken wtoken = findAppWindowToken(
3447 freezeThisOneIfNeeded);
3448 if (wtoken != null) {
3449 startAppFreezingScreenLocked(wtoken,
3450 ActivityInfo.CONFIG_ORIENTATION);
3451 }
3452 }
3453 config = computeNewConfigurationLocked();
3454
3455 } else if (currentConfig != null) {
3456 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003457 // state mismatches the activity manager's, update it,
3458 // disregarding font scale, which should remain set to
3459 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003460 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003461 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003462 if (computeNewConfigurationLocked(mTempConfiguration)) {
3463 if (currentConfig.diff(mTempConfiguration) != 0) {
3464 mWaitingForConfig = true;
3465 mLayoutNeeded = true;
3466 startFreezingDisplayLocked();
3467 config = new Configuration(mTempConfiguration);
3468 }
3469 }
3470 }
3471 }
3472
Dianne Hackborncfaef692009-06-15 14:24:44 -07003473 Binder.restoreCallingIdentity(ident);
3474 return config;
3475 }
3476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003477 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003478 * Determine the new desired orientation of the display, returning
3479 * a non-null new Configuration if it has changed from the current
3480 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3481 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3482 * SCREEN. This will typically be done for you if you call
3483 * sendNewConfiguration().
3484 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 * The orientation is computed from non-application windows first. If none of
3486 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003487 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3489 * android.os.IBinder)
3490 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003491 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003492 if (mDisplayFrozen) {
3493 // If the display is frozen, some activities may be in the middle
3494 // of restarting, and thus have removed their old window. If the
3495 // window has the flag to hide the lock screen, then the lock screen
3496 // can re-appear and inflict its own orientation on us. Keep the
3497 // orientation stable until this all settles down.
3498 return false;
3499 }
3500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 long ident = Binder.clearCallingIdentity();
3503 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003504 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 mForcedAppOrientation = req;
3508 //send a message to Policy indicating orientation change to take
3509 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003510 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003511 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3512 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3513 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 }
3515 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003516
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003517 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 } finally {
3519 Binder.restoreCallingIdentity(ident);
3520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 }
Romain Guy06882f82009-06-10 13:36:04 -07003522
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003523 int computeForcedAppOrientationLocked() {
3524 int req = getOrientationFromWindowsLocked();
3525 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3526 req = getOrientationFromAppTokensLocked();
3527 }
3528 return req;
3529 }
Romain Guy06882f82009-06-10 13:36:04 -07003530
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003531 public void setNewConfiguration(Configuration config) {
3532 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3533 "setNewConfiguration()")) {
3534 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3535 }
3536
3537 synchronized(mWindowMap) {
3538 mCurConfiguration = new Configuration(config);
3539 mWaitingForConfig = false;
3540 performLayoutAndPlaceSurfacesLocked();
3541 }
3542 }
3543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3545 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3546 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003547 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 }
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 synchronized(mWindowMap) {
3551 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3552 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003553 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 return;
3555 }
Romain Guy06882f82009-06-10 13:36:04 -07003556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 wtoken.requestedOrientation = requestedOrientation;
3558 }
3559 }
Romain Guy06882f82009-06-10 13:36:04 -07003560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 public int getAppOrientation(IApplicationToken token) {
3562 synchronized(mWindowMap) {
3563 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3564 if (wtoken == null) {
3565 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3566 }
Romain Guy06882f82009-06-10 13:36:04 -07003567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 return wtoken.requestedOrientation;
3569 }
3570 }
Romain Guy06882f82009-06-10 13:36:04 -07003571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3573 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3574 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003575 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 }
3577
3578 synchronized(mWindowMap) {
3579 boolean changed = false;
3580 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003581 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 changed = mFocusedApp != null;
3583 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003584 if (changed) {
3585 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 } else {
3588 AppWindowToken newFocus = findAppWindowToken(token);
3589 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003590 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 return;
3592 }
3593 changed = mFocusedApp != newFocus;
3594 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003595 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003596 if (changed) {
3597 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 }
3600
3601 if (moveFocusNow && changed) {
3602 final long origId = Binder.clearCallingIdentity();
3603 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3604 Binder.restoreCallingIdentity(origId);
3605 }
3606 }
3607 }
3608
3609 public void prepareAppTransition(int transit) {
3610 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3611 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003612 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 }
Romain Guy06882f82009-06-10 13:36:04 -07003614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003616 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 TAG, "Prepare app transition: transit=" + transit
3618 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003619 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003620 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3621 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003623 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3624 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3625 // Opening a new task always supersedes a close for the anim.
3626 mNextAppTransition = transit;
3627 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3628 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3629 // Opening a new activity always supersedes a close for the anim.
3630 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 }
3632 mAppTransitionReady = false;
3633 mAppTransitionTimeout = false;
3634 mStartingIconInTransition = false;
3635 mSkipAppTransitionAnimation = false;
3636 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3637 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3638 5000);
3639 }
3640 }
3641 }
3642
3643 public int getPendingAppTransition() {
3644 return mNextAppTransition;
3645 }
Romain Guy06882f82009-06-10 13:36:04 -07003646
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003647 public void overridePendingAppTransition(String packageName,
3648 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003649 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003650 mNextAppTransitionPackage = packageName;
3651 mNextAppTransitionEnter = enterAnim;
3652 mNextAppTransitionExit = exitAnim;
3653 }
3654 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 public void executeAppTransition() {
3657 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3658 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003659 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 }
Romain Guy06882f82009-06-10 13:36:04 -07003661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003663 if (DEBUG_APP_TRANSITIONS) {
3664 RuntimeException e = new RuntimeException("here");
3665 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003666 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003667 + mNextAppTransition, e);
3668 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003669 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 mAppTransitionReady = true;
3671 final long origId = Binder.clearCallingIdentity();
3672 performLayoutAndPlaceSurfacesLocked();
3673 Binder.restoreCallingIdentity(origId);
3674 }
3675 }
3676 }
3677
3678 public void setAppStartingWindow(IBinder token, String pkg,
3679 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3680 IBinder transferFrom, boolean createIfNeeded) {
3681 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3682 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003683 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 }
3685
3686 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003687 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3689 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 AppWindowToken wtoken = findAppWindowToken(token);
3692 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003693 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 return;
3695 }
3696
3697 // If the display is frozen, we won't do anything until the
3698 // actual window is displayed so there is no reason to put in
3699 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003700 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 return;
3702 }
Romain Guy06882f82009-06-10 13:36:04 -07003703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 if (wtoken.startingData != null) {
3705 return;
3706 }
Romain Guy06882f82009-06-10 13:36:04 -07003707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 if (transferFrom != null) {
3709 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3710 if (ttoken != null) {
3711 WindowState startingWindow = ttoken.startingWindow;
3712 if (startingWindow != null) {
3713 if (mStartingIconInTransition) {
3714 // In this case, the starting icon has already
3715 // been displayed, so start letting windows get
3716 // shown immediately without any more transitions.
3717 mSkipAppTransitionAnimation = true;
3718 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003719 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 "Moving existing starting from " + ttoken
3721 + " to " + wtoken);
3722 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 // Transfer the starting window over to the new
3725 // token.
3726 wtoken.startingData = ttoken.startingData;
3727 wtoken.startingView = ttoken.startingView;
3728 wtoken.startingWindow = startingWindow;
3729 ttoken.startingData = null;
3730 ttoken.startingView = null;
3731 ttoken.startingWindow = null;
3732 ttoken.startingMoved = true;
3733 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003734 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003736 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003737 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003739 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 ttoken.windows.remove(startingWindow);
3741 ttoken.allAppWindows.remove(startingWindow);
3742 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 // Propagate other interesting state between the
3745 // tokens. If the old token is displayed, we should
3746 // immediately force the new one to be displayed. If
3747 // it is animating, we need to move that animation to
3748 // the new one.
3749 if (ttoken.allDrawn) {
3750 wtoken.allDrawn = true;
3751 }
3752 if (ttoken.firstWindowDrawn) {
3753 wtoken.firstWindowDrawn = true;
3754 }
3755 if (!ttoken.hidden) {
3756 wtoken.hidden = false;
3757 wtoken.hiddenRequested = false;
3758 wtoken.willBeHidden = false;
3759 }
3760 if (wtoken.clientHidden != ttoken.clientHidden) {
3761 wtoken.clientHidden = ttoken.clientHidden;
3762 wtoken.sendAppVisibilityToClients();
3763 }
3764 if (ttoken.animation != null) {
3765 wtoken.animation = ttoken.animation;
3766 wtoken.animating = ttoken.animating;
3767 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3768 ttoken.animation = null;
3769 ttoken.animLayerAdjustment = 0;
3770 wtoken.updateLayers();
3771 ttoken.updateLayers();
3772 }
Romain Guy06882f82009-06-10 13:36:04 -07003773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 mLayoutNeeded = true;
3776 performLayoutAndPlaceSurfacesLocked();
3777 Binder.restoreCallingIdentity(origId);
3778 return;
3779 } else if (ttoken.startingData != null) {
3780 // The previous app was getting ready to show a
3781 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003782 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 "Moving pending starting from " + ttoken
3784 + " to " + wtoken);
3785 wtoken.startingData = ttoken.startingData;
3786 ttoken.startingData = null;
3787 ttoken.startingMoved = true;
3788 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3789 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3790 // want to process the message ASAP, before any other queued
3791 // messages.
3792 mH.sendMessageAtFrontOfQueue(m);
3793 return;
3794 }
3795 }
3796 }
3797
3798 // There is no existing starting window, and the caller doesn't
3799 // want us to create one, so that's it!
3800 if (!createIfNeeded) {
3801 return;
3802 }
Romain Guy06882f82009-06-10 13:36:04 -07003803
Dianne Hackborn284ac932009-08-28 10:34:25 -07003804 // If this is a translucent or wallpaper window, then don't
3805 // show a starting window -- the current effect (a full-screen
3806 // opaque starting window that fades away to the real contents
3807 // when it is ready) does not work for this.
3808 if (theme != 0) {
3809 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3810 com.android.internal.R.styleable.Window);
3811 if (ent.array.getBoolean(
3812 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3813 return;
3814 }
3815 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003816 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3817 return;
3818 }
3819 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003820 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3821 return;
3822 }
3823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 mStartingIconInTransition = true;
3826 wtoken.startingData = new StartingData(
3827 pkg, theme, nonLocalizedLabel,
3828 labelRes, icon);
3829 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3830 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3831 // want to process the message ASAP, before any other queued
3832 // messages.
3833 mH.sendMessageAtFrontOfQueue(m);
3834 }
3835 }
3836
3837 public void setAppWillBeHidden(IBinder token) {
3838 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3839 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003840 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 }
3842
3843 AppWindowToken wtoken;
3844
3845 synchronized(mWindowMap) {
3846 wtoken = findAppWindowToken(token);
3847 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003848 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 -08003849 return;
3850 }
3851 wtoken.willBeHidden = true;
3852 }
3853 }
Romain Guy06882f82009-06-10 13:36:04 -07003854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3856 boolean visible, int transit, boolean performLayout) {
3857 boolean delayed = false;
3858
3859 if (wtoken.clientHidden == visible) {
3860 wtoken.clientHidden = !visible;
3861 wtoken.sendAppVisibilityToClients();
3862 }
Romain Guy06882f82009-06-10 13:36:04 -07003863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 wtoken.willBeHidden = false;
3865 if (wtoken.hidden == visible) {
3866 final int N = wtoken.allAppWindows.size();
3867 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003868 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3870 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003873
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003874 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 if (wtoken.animation == sDummyAnimation) {
3876 wtoken.animation = null;
3877 }
3878 applyAnimationLocked(wtoken, lp, transit, visible);
3879 changed = true;
3880 if (wtoken.animation != null) {
3881 delayed = runningAppAnimation = true;
3882 }
3883 }
Romain Guy06882f82009-06-10 13:36:04 -07003884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 for (int i=0; i<N; i++) {
3886 WindowState win = wtoken.allAppWindows.get(i);
3887 if (win == wtoken.startingWindow) {
3888 continue;
3889 }
3890
3891 if (win.isAnimating()) {
3892 delayed = true;
3893 }
Romain Guy06882f82009-06-10 13:36:04 -07003894
Joe Onorato8a9b2202010-02-26 18:56:32 -08003895 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 //win.dump(" ");
3897 if (visible) {
3898 if (!win.isVisibleNow()) {
3899 if (!runningAppAnimation) {
3900 applyAnimationLocked(win,
3901 WindowManagerPolicy.TRANSIT_ENTER, true);
3902 }
3903 changed = true;
3904 }
3905 } else if (win.isVisibleNow()) {
3906 if (!runningAppAnimation) {
3907 applyAnimationLocked(win,
3908 WindowManagerPolicy.TRANSIT_EXIT, false);
3909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 changed = true;
3911 }
3912 }
3913
3914 wtoken.hidden = wtoken.hiddenRequested = !visible;
3915 if (!visible) {
3916 unsetAppFreezingScreenLocked(wtoken, true, true);
3917 } else {
3918 // If we are being set visible, and the starting window is
3919 // not yet displayed, then make sure it doesn't get displayed.
3920 WindowState swin = wtoken.startingWindow;
3921 if (swin != null && (swin.mDrawPending
3922 || swin.mCommitDrawPending)) {
3923 swin.mPolicyVisibility = false;
3924 swin.mPolicyVisibilityAfterAnim = false;
3925 }
3926 }
Romain Guy06882f82009-06-10 13:36:04 -07003927
Joe Onorato8a9b2202010-02-26 18:56:32 -08003928 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3930 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003931
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003932 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003934 if (performLayout) {
3935 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3936 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003937 } else {
3938 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 }
3941 }
3942
3943 if (wtoken.animation != null) {
3944 delayed = true;
3945 }
Romain Guy06882f82009-06-10 13:36:04 -07003946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003947 return delayed;
3948 }
3949
3950 public void setAppVisibility(IBinder token, boolean visible) {
3951 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3952 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003953 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 }
3955
3956 AppWindowToken wtoken;
3957
3958 synchronized(mWindowMap) {
3959 wtoken = findAppWindowToken(token);
3960 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003961 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 return;
3963 }
3964
3965 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003966 RuntimeException e = null;
3967 if (!HIDE_STACK_CRAWLS) {
3968 e = new RuntimeException();
3969 e.fillInStackTrace();
3970 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003971 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 + "): mNextAppTransition=" + mNextAppTransition
3973 + " hidden=" + wtoken.hidden
3974 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3975 }
Romain Guy06882f82009-06-10 13:36:04 -07003976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 // If we are preparing an app transition, then delay changing
3978 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003979 if (!mDisplayFrozen && mPolicy.isScreenOn()
3980 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 // Already in requested state, don't do anything more.
3982 if (wtoken.hiddenRequested != visible) {
3983 return;
3984 }
3985 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003986
Joe Onorato8a9b2202010-02-26 18:56:32 -08003987 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 TAG, "Setting dummy animation on: " + wtoken);
3989 wtoken.setDummyAnimation();
3990 mOpeningApps.remove(wtoken);
3991 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003992 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 wtoken.inPendingTransaction = true;
3994 if (visible) {
3995 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 wtoken.startingDisplayed = false;
3997 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003998
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003999 // If the token is currently hidden (should be the
4000 // common case), then we need to set up to wait for
4001 // its windows to be ready.
4002 if (wtoken.hidden) {
4003 wtoken.allDrawn = false;
4004 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004005
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004006 if (wtoken.clientHidden) {
4007 // In the case where we are making an app visible
4008 // but holding off for a transition, we still need
4009 // to tell the client to make its windows visible so
4010 // they get drawn. Otherwise, we will wait on
4011 // performing the transition until all windows have
4012 // been drawn, they never will be, and we are sad.
4013 wtoken.clientHidden = false;
4014 wtoken.sendAppVisibilityToClients();
4015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 }
4017 } else {
4018 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004019
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004020 // If the token is currently visible (should be the
4021 // common case), then set up to wait for it to be hidden.
4022 if (!wtoken.hidden) {
4023 wtoken.waitingToHide = true;
4024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004025 }
4026 return;
4027 }
Romain Guy06882f82009-06-10 13:36:04 -07004028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004030 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 wtoken.updateReportedVisibilityLocked();
4032 Binder.restoreCallingIdentity(origId);
4033 }
4034 }
4035
4036 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4037 boolean unfreezeSurfaceNow, boolean force) {
4038 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004039 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 + " force=" + force);
4041 final int N = wtoken.allAppWindows.size();
4042 boolean unfrozeWindows = false;
4043 for (int i=0; i<N; i++) {
4044 WindowState w = wtoken.allAppWindows.get(i);
4045 if (w.mAppFreezing) {
4046 w.mAppFreezing = false;
4047 if (w.mSurface != null && !w.mOrientationChanging) {
4048 w.mOrientationChanging = true;
4049 }
4050 unfrozeWindows = true;
4051 }
4052 }
4053 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004054 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004055 wtoken.freezingScreen = false;
4056 mAppsFreezingScreen--;
4057 }
4058 if (unfreezeSurfaceNow) {
4059 if (unfrozeWindows) {
4060 mLayoutNeeded = true;
4061 performLayoutAndPlaceSurfacesLocked();
4062 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004063 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 }
4065 }
4066 }
Romain Guy06882f82009-06-10 13:36:04 -07004067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4069 int configChanges) {
4070 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004071 RuntimeException e = null;
4072 if (!HIDE_STACK_CRAWLS) {
4073 e = new RuntimeException();
4074 e.fillInStackTrace();
4075 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004076 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 + ": hidden=" + wtoken.hidden + " freezing="
4078 + wtoken.freezingScreen, e);
4079 }
4080 if (!wtoken.hiddenRequested) {
4081 if (!wtoken.freezingScreen) {
4082 wtoken.freezingScreen = true;
4083 mAppsFreezingScreen++;
4084 if (mAppsFreezingScreen == 1) {
4085 startFreezingDisplayLocked();
4086 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4087 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4088 5000);
4089 }
4090 }
4091 final int N = wtoken.allAppWindows.size();
4092 for (int i=0; i<N; i++) {
4093 WindowState w = wtoken.allAppWindows.get(i);
4094 w.mAppFreezing = true;
4095 }
4096 }
4097 }
Romain Guy06882f82009-06-10 13:36:04 -07004098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 public void startAppFreezingScreen(IBinder token, int configChanges) {
4100 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4101 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004102 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 }
4104
4105 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004106 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004107 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 return;
4109 }
Romain Guy06882f82009-06-10 13:36:04 -07004110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 AppWindowToken wtoken = findAppWindowToken(token);
4112 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004113 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 return;
4115 }
4116 final long origId = Binder.clearCallingIdentity();
4117 startAppFreezingScreenLocked(wtoken, configChanges);
4118 Binder.restoreCallingIdentity(origId);
4119 }
4120 }
Romain Guy06882f82009-06-10 13:36:04 -07004121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004122 public void stopAppFreezingScreen(IBinder token, boolean force) {
4123 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4124 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004125 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126 }
4127
4128 synchronized(mWindowMap) {
4129 AppWindowToken wtoken = findAppWindowToken(token);
4130 if (wtoken == null || wtoken.appToken == null) {
4131 return;
4132 }
4133 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004134 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4136 unsetAppFreezingScreenLocked(wtoken, true, force);
4137 Binder.restoreCallingIdentity(origId);
4138 }
4139 }
Romain Guy06882f82009-06-10 13:36:04 -07004140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 public void removeAppToken(IBinder token) {
4142 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4143 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004144 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 }
4146
4147 AppWindowToken wtoken = null;
4148 AppWindowToken startingToken = null;
4149 boolean delayed = false;
4150
4151 final long origId = Binder.clearCallingIdentity();
4152 synchronized(mWindowMap) {
4153 WindowToken basewtoken = mTokenMap.remove(token);
4154 mTokenList.remove(basewtoken);
4155 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004156 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004157 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 wtoken.inPendingTransaction = false;
4159 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004160 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 if (mClosingApps.contains(wtoken)) {
4162 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004163 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004165 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 delayed = true;
4167 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004168 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 TAG, "Removing app " + wtoken + " delayed=" + delayed
4170 + " animation=" + wtoken.animation
4171 + " animating=" + wtoken.animating);
4172 if (delayed) {
4173 // set the token aside because it has an active animation to be finished
4174 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004175 } else {
4176 // Make sure there is no animation running on this token,
4177 // so any windows associated with it will be removed as
4178 // soon as their animations are complete
4179 wtoken.animation = null;
4180 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 }
4182 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004183 if (mLastEnterAnimToken == wtoken) {
4184 mLastEnterAnimToken = null;
4185 mLastEnterAnimParams = null;
4186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 wtoken.removed = true;
4188 if (wtoken.startingData != null) {
4189 startingToken = wtoken;
4190 }
4191 unsetAppFreezingScreenLocked(wtoken, true, true);
4192 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004193 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 mFocusedApp = null;
4195 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004196 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 }
4198 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004199 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 }
Romain Guy06882f82009-06-10 13:36:04 -07004201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 if (!delayed && wtoken != null) {
4203 wtoken.updateReportedVisibilityLocked();
4204 }
4205 }
4206 Binder.restoreCallingIdentity(origId);
4207
4208 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004209 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 + startingToken + ": app token removed");
4211 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4212 mH.sendMessage(m);
4213 }
4214 }
4215
4216 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4217 final int NW = token.windows.size();
4218 for (int i=0; i<NW; i++) {
4219 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004220 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004222 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 int j = win.mChildWindows.size();
4224 while (j > 0) {
4225 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004226 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004227 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004228 "Tmp removing child window " + cwin);
4229 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004230 }
4231 }
4232 return NW > 0;
4233 }
4234
4235 void dumpAppTokensLocked() {
4236 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004237 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 }
4239 }
Romain Guy06882f82009-06-10 13:36:04 -07004240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004241 void dumpWindowsLocked() {
4242 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004243 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 }
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 private int findWindowOffsetLocked(int tokenPos) {
4248 final int NW = mWindows.size();
4249
4250 if (tokenPos >= mAppTokens.size()) {
4251 int i = NW;
4252 while (i > 0) {
4253 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004254 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 if (win.getAppToken() != null) {
4256 return i+1;
4257 }
4258 }
4259 }
4260
4261 while (tokenPos > 0) {
4262 // Find the first app token below the new position that has
4263 // a window displayed.
4264 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004265 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004267 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004268 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004269 "Skipping token -- currently sending to bottom");
4270 tokenPos--;
4271 continue;
4272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 int i = wtoken.windows.size();
4274 while (i > 0) {
4275 i--;
4276 WindowState win = wtoken.windows.get(i);
4277 int j = win.mChildWindows.size();
4278 while (j > 0) {
4279 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004280 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004281 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 for (int pos=NW-1; pos>=0; pos--) {
4283 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004284 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 "Found child win @" + (pos+1));
4286 return pos+1;
4287 }
4288 }
4289 }
4290 }
4291 for (int pos=NW-1; pos>=0; pos--) {
4292 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004293 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 return pos+1;
4295 }
4296 }
4297 }
4298 tokenPos--;
4299 }
4300
4301 return 0;
4302 }
4303
4304 private final int reAddWindowLocked(int index, WindowState win) {
4305 final int NCW = win.mChildWindows.size();
4306 boolean added = false;
4307 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004308 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004310 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004311 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 mWindows.add(index, win);
4313 index++;
4314 added = true;
4315 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004316 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004317 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 mWindows.add(index, cwin);
4319 index++;
4320 }
4321 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004322 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004323 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 mWindows.add(index, win);
4325 index++;
4326 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004327 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 return index;
4329 }
Romain Guy06882f82009-06-10 13:36:04 -07004330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4332 final int NW = token.windows.size();
4333 for (int i=0; i<NW; i++) {
4334 index = reAddWindowLocked(index, token.windows.get(i));
4335 }
4336 return index;
4337 }
4338
4339 public void moveAppToken(int index, IBinder token) {
4340 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4341 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004342 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 }
4344
4345 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004346 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 if (DEBUG_REORDER) dumpAppTokensLocked();
4348 final AppWindowToken wtoken = findAppWindowToken(token);
4349 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004350 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 + token + " (" + wtoken + ")");
4352 return;
4353 }
4354 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004355 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004359 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 if (DEBUG_REORDER) dumpWindowsLocked();
4361 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 if (DEBUG_REORDER) dumpWindowsLocked();
4364 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004365 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 if (DEBUG_REORDER) dumpWindowsLocked();
4367 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 mLayoutNeeded = true;
4369 performLayoutAndPlaceSurfacesLocked();
4370 }
4371 Binder.restoreCallingIdentity(origId);
4372 }
4373 }
4374
4375 private void removeAppTokensLocked(List<IBinder> tokens) {
4376 // XXX This should be done more efficiently!
4377 // (take advantage of the fact that both lists should be
4378 // ordered in the same way.)
4379 int N = tokens.size();
4380 for (int i=0; i<N; i++) {
4381 IBinder token = tokens.get(i);
4382 final AppWindowToken wtoken = findAppWindowToken(token);
4383 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004384 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 + token + " (" + wtoken + ")");
4386 i--;
4387 N--;
4388 }
4389 }
4390 }
4391
Dianne Hackborna8f60182009-09-01 19:01:50 -07004392 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4393 boolean updateFocusAndLayout) {
4394 // First remove all of the windows from the list.
4395 tmpRemoveAppWindowsLocked(wtoken);
4396
4397 // Where to start adding?
4398 int pos = findWindowOffsetLocked(tokenPos);
4399
4400 // And now add them back at the correct place.
4401 pos = reAddAppWindowsLocked(pos, wtoken);
4402
4403 if (updateFocusAndLayout) {
4404 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4405 assignLayersLocked();
4406 }
4407 mLayoutNeeded = true;
4408 performLayoutAndPlaceSurfacesLocked();
4409 }
4410 }
4411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004412 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4413 // First remove all of the windows from the list.
4414 final int N = tokens.size();
4415 int i;
4416 for (i=0; i<N; i++) {
4417 WindowToken token = mTokenMap.get(tokens.get(i));
4418 if (token != null) {
4419 tmpRemoveAppWindowsLocked(token);
4420 }
4421 }
4422
4423 // Where to start adding?
4424 int pos = findWindowOffsetLocked(tokenPos);
4425
4426 // And now add them back at the correct place.
4427 for (i=0; i<N; i++) {
4428 WindowToken token = mTokenMap.get(tokens.get(i));
4429 if (token != null) {
4430 pos = reAddAppWindowsLocked(pos, token);
4431 }
4432 }
4433
Dianne Hackborna8f60182009-09-01 19:01:50 -07004434 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4435 assignLayersLocked();
4436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 mLayoutNeeded = true;
4438 performLayoutAndPlaceSurfacesLocked();
4439
4440 //dump();
4441 }
4442
4443 public void moveAppTokensToTop(List<IBinder> tokens) {
4444 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4445 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004446 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 }
4448
4449 final long origId = Binder.clearCallingIdentity();
4450 synchronized(mWindowMap) {
4451 removeAppTokensLocked(tokens);
4452 final int N = tokens.size();
4453 for (int i=0; i<N; i++) {
4454 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4455 if (wt != null) {
4456 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004457 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004458 mToTopApps.remove(wt);
4459 mToBottomApps.remove(wt);
4460 mToTopApps.add(wt);
4461 wt.sendingToBottom = false;
4462 wt.sendingToTop = true;
4463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 }
4465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004466
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004467 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004468 moveAppWindowsLocked(tokens, mAppTokens.size());
4469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 }
4471 Binder.restoreCallingIdentity(origId);
4472 }
4473
4474 public void moveAppTokensToBottom(List<IBinder> tokens) {
4475 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4476 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004477 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 }
4479
4480 final long origId = Binder.clearCallingIdentity();
4481 synchronized(mWindowMap) {
4482 removeAppTokensLocked(tokens);
4483 final int N = tokens.size();
4484 int pos = 0;
4485 for (int i=0; i<N; i++) {
4486 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4487 if (wt != null) {
4488 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004489 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004490 mToTopApps.remove(wt);
4491 mToBottomApps.remove(wt);
4492 mToBottomApps.add(i, wt);
4493 wt.sendingToTop = false;
4494 wt.sendingToBottom = true;
4495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 pos++;
4497 }
4498 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004499
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004500 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004501 moveAppWindowsLocked(tokens, 0);
4502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503 }
4504 Binder.restoreCallingIdentity(origId);
4505 }
4506
4507 // -------------------------------------------------------------
4508 // Misc IWindowSession methods
4509 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004510
Jim Miller284b62e2010-06-08 14:27:42 -07004511 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004512 {
Jim Miller284b62e2010-06-08 14:27:42 -07004513 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4514 // called before DevicePolicyManagerService has started.
4515 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4516 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4517 Context.DEVICE_POLICY_SERVICE);
4518 if (dpm != null) {
4519 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4520 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4521 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4522 }
Jim Millerd6b57052010-06-07 17:52:42 -07004523 }
Jim Miller284b62e2010-06-08 14:27:42 -07004524 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004525 }
4526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004528 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 != PackageManager.PERMISSION_GRANTED) {
4530 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4531 }
Jim Millerd6b57052010-06-07 17:52:42 -07004532
Jim Miller284b62e2010-06-08 14:27:42 -07004533 synchronized (mKeyguardTokenWatcher) {
4534 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004536 }
4537
4538 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004539 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 != PackageManager.PERMISSION_GRANTED) {
4541 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4542 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543
Jim Miller284b62e2010-06-08 14:27:42 -07004544 synchronized (mKeyguardTokenWatcher) {
4545 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004546
Jim Miller284b62e2010-06-08 14:27:42 -07004547 if (!mKeyguardTokenWatcher.isAcquired()) {
4548 // If we are the last one to reenable the keyguard wait until
4549 // we have actually finished reenabling until returning.
4550 // It is possible that reenableKeyguard() can be called before
4551 // the previous disableKeyguard() is handled, in which case
4552 // neither mKeyguardTokenWatcher.acquired() or released() would
4553 // be called. In that case mKeyguardDisabled will be false here
4554 // and we have nothing to wait for.
4555 while (mKeyguardDisabled) {
4556 try {
4557 mKeyguardTokenWatcher.wait();
4558 } catch (InterruptedException e) {
4559 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004560 }
4561 }
4562 }
4563 }
4564 }
4565
4566 /**
4567 * @see android.app.KeyguardManager#exitKeyguardSecurely
4568 */
4569 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004570 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 != PackageManager.PERMISSION_GRANTED) {
4572 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4573 }
4574 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4575 public void onKeyguardExitResult(boolean success) {
4576 try {
4577 callback.onKeyguardExitResult(success);
4578 } catch (RemoteException e) {
4579 // Client has died, we don't care.
4580 }
4581 }
4582 });
4583 }
4584
4585 public boolean inKeyguardRestrictedInputMode() {
4586 return mPolicy.inKeyguardRestrictedKeyInputMode();
4587 }
Romain Guy06882f82009-06-10 13:36:04 -07004588
Dianne Hackbornffa42482009-09-23 22:20:11 -07004589 public void closeSystemDialogs(String reason) {
4590 synchronized(mWindowMap) {
4591 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004592 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004593 if (w.mSurface != null) {
4594 try {
4595 w.mClient.closeSystemDialogs(reason);
4596 } catch (RemoteException e) {
4597 }
4598 }
4599 }
4600 }
4601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004603 static float fixScale(float scale) {
4604 if (scale < 0) scale = 0;
4605 else if (scale > 20) scale = 20;
4606 return Math.abs(scale);
4607 }
Romain Guy06882f82009-06-10 13:36:04 -07004608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004609 public void setAnimationScale(int which, float scale) {
4610 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4611 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004612 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 }
4614
4615 if (scale < 0) scale = 0;
4616 else if (scale > 20) scale = 20;
4617 scale = Math.abs(scale);
4618 switch (which) {
4619 case 0: mWindowAnimationScale = fixScale(scale); break;
4620 case 1: mTransitionAnimationScale = fixScale(scale); break;
4621 }
Romain Guy06882f82009-06-10 13:36:04 -07004622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 // Persist setting
4624 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4625 }
Romain Guy06882f82009-06-10 13:36:04 -07004626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 public void setAnimationScales(float[] scales) {
4628 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4629 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004630 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 }
4632
4633 if (scales != null) {
4634 if (scales.length >= 1) {
4635 mWindowAnimationScale = fixScale(scales[0]);
4636 }
4637 if (scales.length >= 2) {
4638 mTransitionAnimationScale = fixScale(scales[1]);
4639 }
4640 }
Romain Guy06882f82009-06-10 13:36:04 -07004641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 // Persist setting
4643 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4644 }
Romain Guy06882f82009-06-10 13:36:04 -07004645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 public float getAnimationScale(int which) {
4647 switch (which) {
4648 case 0: return mWindowAnimationScale;
4649 case 1: return mTransitionAnimationScale;
4650 }
4651 return 0;
4652 }
Romain Guy06882f82009-06-10 13:36:04 -07004653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004654 public float[] getAnimationScales() {
4655 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4656 }
Romain Guy06882f82009-06-10 13:36:04 -07004657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 public int getSwitchState(int sw) {
4659 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4660 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004661 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004663 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 }
Romain Guy06882f82009-06-10 13:36:04 -07004665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 public int getSwitchStateForDevice(int devid, int sw) {
4667 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4668 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004669 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004671 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 }
Romain Guy06882f82009-06-10 13:36:04 -07004673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004674 public int getScancodeState(int sw) {
4675 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4676 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004677 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004679 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 }
Romain Guy06882f82009-06-10 13:36:04 -07004681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 public int getScancodeStateForDevice(int devid, int sw) {
4683 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4684 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004685 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004687 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 }
Romain Guy06882f82009-06-10 13:36:04 -07004689
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004690 public int getTrackballScancodeState(int sw) {
4691 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4692 "getTrackballScancodeState()")) {
4693 throw new SecurityException("Requires READ_INPUT_STATE permission");
4694 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004695 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004696 }
4697
4698 public int getDPadScancodeState(int sw) {
4699 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4700 "getDPadScancodeState()")) {
4701 throw new SecurityException("Requires READ_INPUT_STATE permission");
4702 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004703 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004704 }
4705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 public int getKeycodeState(int sw) {
4707 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4708 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004709 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004711 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 }
Romain Guy06882f82009-06-10 13:36:04 -07004713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 public int getKeycodeStateForDevice(int devid, int sw) {
4715 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4716 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004717 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004719 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 }
Romain Guy06882f82009-06-10 13:36:04 -07004721
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004722 public int getTrackballKeycodeState(int sw) {
4723 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4724 "getTrackballKeycodeState()")) {
4725 throw new SecurityException("Requires READ_INPUT_STATE permission");
4726 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004727 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004728 }
4729
4730 public int getDPadKeycodeState(int sw) {
4731 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4732 "getDPadKeycodeState()")) {
4733 throw new SecurityException("Requires READ_INPUT_STATE permission");
4734 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004735 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004736 }
Jeff Browna41ca772010-08-11 14:46:32 -07004737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004739 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004740 }
Romain Guy06882f82009-06-10 13:36:04 -07004741
Jeff Browna41ca772010-08-11 14:46:32 -07004742 public InputChannel monitorInput(String inputChannelName) {
4743 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4744 "monitorInput()")) {
4745 throw new SecurityException("Requires READ_INPUT_STATE permission");
4746 }
4747 return mInputManager.monitorInput(inputChannelName);
4748 }
4749
Jeff Brown8d608662010-08-30 03:02:23 -07004750 public InputDevice getInputDevice(int deviceId) {
4751 return mInputManager.getInputDevice(deviceId);
4752 }
4753
4754 public int[] getInputDeviceIds() {
4755 return mInputManager.getInputDeviceIds();
4756 }
4757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004758 public void enableScreenAfterBoot() {
4759 synchronized(mWindowMap) {
4760 if (mSystemBooted) {
4761 return;
4762 }
4763 mSystemBooted = true;
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 performEnableScreen();
4767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 public void enableScreenIfNeededLocked() {
4770 if (mDisplayEnabled) {
4771 return;
4772 }
4773 if (!mSystemBooted) {
4774 return;
4775 }
4776 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4777 }
Romain Guy06882f82009-06-10 13:36:04 -07004778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004779 public void performEnableScreen() {
4780 synchronized(mWindowMap) {
4781 if (mDisplayEnabled) {
4782 return;
4783 }
4784 if (!mSystemBooted) {
4785 return;
4786 }
Romain Guy06882f82009-06-10 13:36:04 -07004787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 // Don't enable the screen until all existing windows
4789 // have been drawn.
4790 final int N = mWindows.size();
4791 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004792 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004793 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 return;
4795 }
4796 }
Romain Guy06882f82009-06-10 13:36:04 -07004797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 mDisplayEnabled = true;
4799 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004800 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 StringWriter sw = new StringWriter();
4802 PrintWriter pw = new PrintWriter(sw);
4803 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004804 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 }
4806 try {
4807 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4808 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004809 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 Parcel data = Parcel.obtain();
4811 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4812 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4813 data, null, 0);
4814 data.recycle();
4815 }
4816 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004817 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 }
4819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004824 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4825 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004826 }
Romain Guy06882f82009-06-10 13:36:04 -07004827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004828 public void setInTouchMode(boolean mode) {
4829 synchronized(mWindowMap) {
4830 mInTouchMode = mode;
4831 }
4832 }
4833
Romain Guy06882f82009-06-10 13:36:04 -07004834 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004835 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004836 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004837 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004838 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 }
4840
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004841 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 }
Romain Guy06882f82009-06-10 13:36:04 -07004843
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004844 public void setRotationUnchecked(int rotation,
4845 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004846 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004847 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849 long origId = Binder.clearCallingIdentity();
4850 boolean changed;
4851 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004852 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 }
Romain Guy06882f82009-06-10 13:36:04 -07004854
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004855 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 sendNewConfiguration();
4857 }
Romain Guy06882f82009-06-10 13:36:04 -07004858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 Binder.restoreCallingIdentity(origId);
4860 }
Romain Guy06882f82009-06-10 13:36:04 -07004861
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004862 /**
4863 * Apply a new rotation to the screen, respecting the requests of
4864 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4865 * re-evaluate the desired rotation.
4866 *
4867 * Returns null if the rotation has been changed. In this case YOU
4868 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4869 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004870 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 boolean changed;
4872 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4873 rotation = mRequestedRotation;
4874 } else {
4875 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004876 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004877 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004878 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004879 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004881 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004882 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004885 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886 "Rotation changed to " + rotation
4887 + " from " + mRotation
4888 + " (forceApp=" + mForcedAppOrientation
4889 + ", req=" + mRequestedRotation + ")");
4890 mRotation = rotation;
4891 mWindowsFreezingScreen = true;
4892 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4893 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4894 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004895 mWaitingForConfig = true;
4896 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004898 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004899 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004901 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 }
4903 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004904 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 if (w.mSurface != null) {
4906 w.mOrientationChanging = true;
4907 }
4908 }
4909 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4910 try {
4911 mRotationWatchers.get(i).onRotationChanged(rotation);
4912 } catch (RemoteException e) {
4913 }
4914 }
4915 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 return changed;
4918 }
Romain Guy06882f82009-06-10 13:36:04 -07004919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 public int getRotation() {
4921 return mRotation;
4922 }
4923
4924 public int watchRotation(IRotationWatcher watcher) {
4925 final IBinder watcherBinder = watcher.asBinder();
4926 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4927 public void binderDied() {
4928 synchronized (mWindowMap) {
4929 for (int i=0; i<mRotationWatchers.size(); i++) {
4930 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004931 IRotationWatcher removed = mRotationWatchers.remove(i);
4932 if (removed != null) {
4933 removed.asBinder().unlinkToDeath(this, 0);
4934 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 i--;
4936 }
4937 }
4938 }
4939 }
4940 };
Romain Guy06882f82009-06-10 13:36:04 -07004941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 synchronized (mWindowMap) {
4943 try {
4944 watcher.asBinder().linkToDeath(dr, 0);
4945 mRotationWatchers.add(watcher);
4946 } catch (RemoteException e) {
4947 // Client died, no cleanup needed.
4948 }
Romain Guy06882f82009-06-10 13:36:04 -07004949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 return mRotation;
4951 }
4952 }
4953
4954 /**
4955 * Starts the view server on the specified port.
4956 *
4957 * @param port The port to listener to.
4958 *
4959 * @return True if the server was successfully started, false otherwise.
4960 *
4961 * @see com.android.server.ViewServer
4962 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4963 */
4964 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004965 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004966 return false;
4967 }
4968
4969 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4970 return false;
4971 }
4972
4973 if (port < 1024) {
4974 return false;
4975 }
4976
4977 if (mViewServer != null) {
4978 if (!mViewServer.isRunning()) {
4979 try {
4980 return mViewServer.start();
4981 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004982 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 }
4984 }
4985 return false;
4986 }
4987
4988 try {
4989 mViewServer = new ViewServer(this, port);
4990 return mViewServer.start();
4991 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004992 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004993 }
4994 return false;
4995 }
4996
Romain Guy06882f82009-06-10 13:36:04 -07004997 private boolean isSystemSecure() {
4998 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4999 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5000 }
5001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005002 /**
5003 * Stops the view server if it exists.
5004 *
5005 * @return True if the server stopped, false if it wasn't started or
5006 * couldn't be stopped.
5007 *
5008 * @see com.android.server.ViewServer
5009 */
5010 public boolean stopViewServer() {
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, "stopViewServer")) {
5016 return false;
5017 }
5018
5019 if (mViewServer != null) {
5020 return mViewServer.stop();
5021 }
5022 return false;
5023 }
5024
5025 /**
5026 * Indicates whether the view server is running.
5027 *
5028 * @return True if the server is running, false otherwise.
5029 *
5030 * @see com.android.server.ViewServer
5031 */
5032 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005033 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005034 return false;
5035 }
5036
5037 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5038 return false;
5039 }
5040
5041 return mViewServer != null && mViewServer.isRunning();
5042 }
5043
5044 /**
5045 * Lists all availble windows in the system. The listing is written in the
5046 * specified Socket's output stream with the following syntax:
5047 * windowHashCodeInHexadecimal windowName
5048 * Each line of the ouput represents a different window.
5049 *
5050 * @param client The remote client to send the listing to.
5051 * @return False if an error occured, true otherwise.
5052 */
5053 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005054 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 return false;
5056 }
5057
5058 boolean result = true;
5059
Jeff Browne33348b2010-07-15 23:54:05 -07005060 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005061 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005062 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005063 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005064 }
5065
5066 BufferedWriter out = null;
5067
5068 // Any uncaught exception will crash the system process
5069 try {
5070 OutputStream clientStream = client.getOutputStream();
5071 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5072
5073 final int count = windows.length;
5074 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005075 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005076 out.write(Integer.toHexString(System.identityHashCode(w)));
5077 out.write(' ');
5078 out.append(w.mAttrs.getTitle());
5079 out.write('\n');
5080 }
5081
5082 out.write("DONE.\n");
5083 out.flush();
5084 } catch (Exception e) {
5085 result = false;
5086 } finally {
5087 if (out != null) {
5088 try {
5089 out.close();
5090 } catch (IOException e) {
5091 result = false;
5092 }
5093 }
5094 }
5095
5096 return result;
5097 }
5098
5099 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005100 * Returns the focused window in the following format:
5101 * windowHashCodeInHexadecimal windowName
5102 *
5103 * @param client The remote client to send the listing to.
5104 * @return False if an error occurred, true otherwise.
5105 */
5106 boolean viewServerGetFocusedWindow(Socket client) {
5107 if (isSystemSecure()) {
5108 return false;
5109 }
5110
5111 boolean result = true;
5112
5113 WindowState focusedWindow = getFocusedWindow();
5114
5115 BufferedWriter out = null;
5116
5117 // Any uncaught exception will crash the system process
5118 try {
5119 OutputStream clientStream = client.getOutputStream();
5120 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5121
5122 if(focusedWindow != null) {
5123 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5124 out.write(' ');
5125 out.append(focusedWindow.mAttrs.getTitle());
5126 }
5127 out.write('\n');
5128 out.flush();
5129 } catch (Exception e) {
5130 result = false;
5131 } finally {
5132 if (out != null) {
5133 try {
5134 out.close();
5135 } catch (IOException e) {
5136 result = false;
5137 }
5138 }
5139 }
5140
5141 return result;
5142 }
5143
5144 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005145 * Sends a command to a target window. The result of the command, if any, will be
5146 * written in the output stream of the specified socket.
5147 *
5148 * The parameters must follow this syntax:
5149 * windowHashcode extra
5150 *
5151 * Where XX is the length in characeters of the windowTitle.
5152 *
5153 * The first parameter is the target window. The window with the specified hashcode
5154 * will be the target. If no target can be found, nothing happens. The extra parameters
5155 * will be delivered to the target window and as parameters to the command itself.
5156 *
5157 * @param client The remote client to sent the result, if any, to.
5158 * @param command The command to execute.
5159 * @param parameters The command parameters.
5160 *
5161 * @return True if the command was successfully delivered, false otherwise. This does
5162 * not indicate whether the command itself was successful.
5163 */
5164 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005165 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005166 return false;
5167 }
5168
5169 boolean success = true;
5170 Parcel data = null;
5171 Parcel reply = null;
5172
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005173 BufferedWriter out = null;
5174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005175 // Any uncaught exception will crash the system process
5176 try {
5177 // Find the hashcode of the window
5178 int index = parameters.indexOf(' ');
5179 if (index == -1) {
5180 index = parameters.length();
5181 }
5182 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005183 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184
5185 // Extract the command's parameter after the window description
5186 if (index < parameters.length()) {
5187 parameters = parameters.substring(index + 1);
5188 } else {
5189 parameters = "";
5190 }
5191
5192 final WindowManagerService.WindowState window = findWindow(hashCode);
5193 if (window == null) {
5194 return false;
5195 }
5196
5197 data = Parcel.obtain();
5198 data.writeInterfaceToken("android.view.IWindow");
5199 data.writeString(command);
5200 data.writeString(parameters);
5201 data.writeInt(1);
5202 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5203
5204 reply = Parcel.obtain();
5205
5206 final IBinder binder = window.mClient.asBinder();
5207 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5208 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5209
5210 reply.readException();
5211
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005212 if (!client.isOutputShutdown()) {
5213 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5214 out.write("DONE\n");
5215 out.flush();
5216 }
5217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005218 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005219 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220 success = false;
5221 } finally {
5222 if (data != null) {
5223 data.recycle();
5224 }
5225 if (reply != null) {
5226 reply.recycle();
5227 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005228 if (out != null) {
5229 try {
5230 out.close();
5231 } catch (IOException e) {
5232
5233 }
5234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005235 }
5236
5237 return success;
5238 }
5239
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005240 public void addWindowChangeListener(WindowChangeListener listener) {
5241 synchronized(mWindowMap) {
5242 mWindowChangeListeners.add(listener);
5243 }
5244 }
5245
5246 public void removeWindowChangeListener(WindowChangeListener listener) {
5247 synchronized(mWindowMap) {
5248 mWindowChangeListeners.remove(listener);
5249 }
5250 }
5251
5252 private void notifyWindowsChanged() {
5253 WindowChangeListener[] windowChangeListeners;
5254 synchronized(mWindowMap) {
5255 if(mWindowChangeListeners.isEmpty()) {
5256 return;
5257 }
5258 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5259 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5260 }
5261 int N = windowChangeListeners.length;
5262 for(int i = 0; i < N; i++) {
5263 windowChangeListeners[i].windowsChanged();
5264 }
5265 }
5266
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005267 private void notifyFocusChanged() {
5268 WindowChangeListener[] windowChangeListeners;
5269 synchronized(mWindowMap) {
5270 if(mWindowChangeListeners.isEmpty()) {
5271 return;
5272 }
5273 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5274 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5275 }
5276 int N = windowChangeListeners.length;
5277 for(int i = 0; i < N; i++) {
5278 windowChangeListeners[i].focusChanged();
5279 }
5280 }
5281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282 private WindowState findWindow(int hashCode) {
5283 if (hashCode == -1) {
5284 return getFocusedWindow();
5285 }
5286
5287 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005288 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005289 final int count = windows.size();
5290
5291 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005292 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005293 if (System.identityHashCode(w) == hashCode) {
5294 return w;
5295 }
5296 }
5297 }
5298
5299 return null;
5300 }
5301
5302 /*
5303 * Instruct the Activity Manager to fetch the current configuration and broadcast
5304 * that to config-changed listeners if appropriate.
5305 */
5306 void sendNewConfiguration() {
5307 try {
5308 mActivityManager.updateConfiguration(null);
5309 } catch (RemoteException e) {
5310 }
5311 }
Romain Guy06882f82009-06-10 13:36:04 -07005312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 public Configuration computeNewConfiguration() {
5314 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005315 return computeNewConfigurationLocked();
5316 }
5317 }
Romain Guy06882f82009-06-10 13:36:04 -07005318
Dianne Hackbornc485a602009-03-24 22:39:49 -07005319 Configuration computeNewConfigurationLocked() {
5320 Configuration config = new Configuration();
5321 if (!computeNewConfigurationLocked(config)) {
5322 return null;
5323 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005324 return config;
5325 }
Romain Guy06882f82009-06-10 13:36:04 -07005326
Dianne Hackbornc485a602009-03-24 22:39:49 -07005327 boolean computeNewConfigurationLocked(Configuration config) {
5328 if (mDisplay == null) {
5329 return false;
5330 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005331
5332 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005333
5334 // Use the effective "visual" dimensions based on current rotation
5335 final boolean rotated = (mRotation == Surface.ROTATION_90
5336 || mRotation == Surface.ROTATION_270);
5337 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5338 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5339
Dianne Hackbornc485a602009-03-24 22:39:49 -07005340 int orientation = Configuration.ORIENTATION_SQUARE;
5341 if (dw < dh) {
5342 orientation = Configuration.ORIENTATION_PORTRAIT;
5343 } else if (dw > dh) {
5344 orientation = Configuration.ORIENTATION_LANDSCAPE;
5345 }
5346 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005347
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005348 DisplayMetrics dm = new DisplayMetrics();
5349 mDisplay.getMetrics(dm);
5350 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5351
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005352 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005353 // Note we only do this once because at this point we don't
5354 // expect the screen to change in this way at runtime, and want
5355 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005356 int longSize = dw;
5357 int shortSize = dh;
5358 if (longSize < shortSize) {
5359 int tmp = longSize;
5360 longSize = shortSize;
5361 shortSize = tmp;
5362 }
5363 longSize = (int)(longSize/dm.density);
5364 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005365
Dianne Hackborn723738c2009-06-25 19:48:04 -07005366 // These semi-magic numbers define our compatibility modes for
5367 // applications with different screens. Don't change unless you
5368 // make sure to test lots and lots of apps!
5369 if (longSize < 470) {
5370 // This is shorter than an HVGA normal density screen (which
5371 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005372 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5373 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005374 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005375 // What size is this screen screen?
5376 if (longSize >= 800 && shortSize >= 600) {
5377 // SVGA or larger screens at medium density are the point
5378 // at which we consider it to be an extra large screen.
5379 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005380 } else if (longSize >= 530 && shortSize >= 400) {
5381 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005382 // at which we consider it to be a large screen.
5383 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5384 } else {
5385 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005386
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005387 // If this screen is wider than normal HVGA, or taller
5388 // than FWVGA, then for old apps we want to run in size
5389 // compatibility mode.
5390 if (shortSize > 321 || longSize > 570) {
5391 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5392 }
5393 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005394
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005395 // Is this a long screen?
5396 if (((longSize*3)/5) >= (shortSize-1)) {
5397 // Anything wider than WVGA (5:3) is considering to be long.
5398 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5399 } else {
5400 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5401 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005402 }
5403 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005404 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005405
Dianne Hackbornc485a602009-03-24 22:39:49 -07005406 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5407 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5408 mPolicy.adjustConfigurationLw(config);
5409 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005410 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005411
5412 // -------------------------------------------------------------
5413 // Drag and drop
5414 // -------------------------------------------------------------
5415
5416 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5417 boolean localOnly, int width, int height, Surface outSurface) {
5418 if (DEBUG_DRAG) {
5419 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5420 + " local=" + localOnly + " win=" + window
5421 + " asbinder=" + window.asBinder());
5422 }
5423
5424 final int callerPid = Binder.getCallingPid();
5425 final long origId = Binder.clearCallingIdentity();
5426 IBinder token = null;
5427
5428 try {
5429 synchronized (mWindowMap) {
5430 try {
5431 // !!! TODO: fail if the given window does not currently have touch focus?
5432
5433 if (mDragState == null) {
5434 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5435 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5436 outSurface.copyFrom(surface);
5437 token = new Binder();
5438 mDragState = new DragState(token, surface, localOnly);
5439 mDragState.mSurface = surface;
5440 mDragState.mLocalOnly = localOnly;
5441 token = mDragState.mToken = new Binder();
5442
5443 // 5 second timeout for this window to actually begin the drag
5444 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5445 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5446 mH.sendMessageDelayed(msg, 5000);
5447 } else {
5448 Slog.w(TAG, "Drag already in progress");
5449 }
5450 } catch (Surface.OutOfResourcesException e) {
5451 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5452 if (mDragState != null) {
5453 mDragState.reset();
5454 mDragState = null;
5455 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005456 }
5457 }
5458 } finally {
5459 Binder.restoreCallingIdentity(origId);
5460 }
5461
5462 return token;
5463 }
5464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005465 // -------------------------------------------------------------
5466 // Input Events and Focus Management
5467 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005468
Jeff Brown349703e2010-06-22 01:27:15 -07005469 InputMonitor mInputMonitor = new InputMonitor();
5470
5471 /* Tracks the progress of input dispatch and ensures that input dispatch state
5472 * is kept in sync with changes in window focus, visibility, registration, and
5473 * other relevant Window Manager state transitions. */
5474 final class InputMonitor {
5475 // Current window with input focus for keys and other non-touch events. May be null.
5476 private WindowState mInputFocus;
5477
5478 // When true, prevents input dispatch from proceeding until set to false again.
5479 private boolean mInputDispatchFrozen;
5480
5481 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5482 private boolean mInputDispatchEnabled = true;
5483
5484 // Temporary list of windows information to provide to the input dispatcher.
5485 private InputWindowList mTempInputWindows = new InputWindowList();
5486
5487 // Temporary input application object to provide to the input dispatcher.
5488 private InputApplication mTempInputApplication = new InputApplication();
5489
5490 /* Notifies the window manager about a broken input channel.
5491 *
5492 * Called by the InputManager.
5493 */
5494 public void notifyInputChannelBroken(InputChannel inputChannel) {
5495 synchronized (mWindowMap) {
5496 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5497 if (windowState == null) {
5498 return; // irrelevant
5499 }
5500
5501 Slog.i(TAG, "WINDOW DIED " + windowState);
5502 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005503 }
5504 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005505
Jeff Brown519e0242010-09-15 15:18:56 -07005506 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005507 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005508 *
5509 * Called by the InputManager.
5510 */
Jeff Brown519e0242010-09-15 15:18:56 -07005511 public long notifyANR(Object token, InputChannel inputChannel) {
5512 AppWindowToken appWindowToken = null;
5513 if (inputChannel != null) {
5514 synchronized (mWindowMap) {
5515 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5516 if (windowState != null) {
5517 Slog.i(TAG, "Input event dispatching timed out sending to "
5518 + windowState.mAttrs.getTitle());
5519 appWindowToken = windowState.mAppToken;
5520 }
Jeff Brown349703e2010-06-22 01:27:15 -07005521 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005522 }
5523
Jeff Brown519e0242010-09-15 15:18:56 -07005524 if (appWindowToken == null && token != null) {
5525 appWindowToken = (AppWindowToken) token;
5526 Slog.i(TAG, "Input event dispatching timed out sending to application "
5527 + appWindowToken.stringName);
5528 }
Jeff Brown349703e2010-06-22 01:27:15 -07005529
Jeff Brown519e0242010-09-15 15:18:56 -07005530 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005531 try {
5532 // Notify the activity manager about the timeout and let it decide whether
5533 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005534 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005535 if (! abort) {
5536 // The activity manager declined to abort dispatching.
5537 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005538 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005539 }
Jeff Brown349703e2010-06-22 01:27:15 -07005540 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005541 }
5542 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005543 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005544 }
5545
Jeff Brown349703e2010-06-22 01:27:15 -07005546 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5547 synchronized (mWindowMap) {
5548 return getWindowStateForInputChannelLocked(inputChannel);
5549 }
5550 }
5551
5552 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5553 int windowCount = mWindows.size();
5554 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005555 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005556 if (windowState.mInputChannel == inputChannel) {
5557 return windowState;
5558 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005559 }
5560
Jeff Brown349703e2010-06-22 01:27:15 -07005561 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005562 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005563
Chris Tatea32dcf72010-10-14 12:13:50 -07005564 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005565 final InputWindow inputWindow = windowList.add();
5566 inputWindow.inputChannel = mDragState.mServerChannel;
5567 inputWindow.name = "drag";
5568 inputWindow.layoutParamsFlags = 0;
5569 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5570 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5571 inputWindow.visible = true;
5572 inputWindow.canReceiveKeys = false;
5573 inputWindow.hasFocus = true;
5574 inputWindow.hasWallpaper = false;
5575 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005576 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005577 inputWindow.ownerPid = Process.myPid();
5578 inputWindow.ownerUid = Process.myUid();
5579
5580 // The drag window covers the entire display
5581 inputWindow.frameLeft = 0;
5582 inputWindow.frameTop = 0;
5583 inputWindow.frameRight = mDisplay.getWidth();
5584 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005585
Christopher Tatea53146c2010-09-07 11:57:52 -07005586 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5587 inputWindow.visibleFrameTop = inputWindow.frameTop;
5588 inputWindow.visibleFrameRight = inputWindow.frameRight;
5589 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5590
5591 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5592 inputWindow.touchableAreaTop = inputWindow.frameTop;
5593 inputWindow.touchableAreaRight = inputWindow.frameRight;
5594 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5595 }
5596
Jeff Brown349703e2010-06-22 01:27:15 -07005597 /* Updates the cached window information provided to the input dispatcher. */
5598 public void updateInputWindowsLw() {
5599 // Populate the input window list with information about all of the windows that
5600 // could potentially receive input.
5601 // As an optimization, we could try to prune the list of windows but this turns
5602 // out to be difficult because only the native code knows for sure which window
5603 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005604 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005605
5606 // If there's a drag in flight, provide a pseudowindow to catch drag input
5607 final boolean inDrag = (mDragState != null);
5608 if (inDrag) {
5609 if (DEBUG_DRAG) {
5610 Log.d(TAG, "Inserting drag window");
5611 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005612 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005613 }
5614
Jeff Brown7fbdc842010-06-17 20:52:56 -07005615 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005616 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005617 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005618 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005619 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005620 continue;
5621 }
5622
Jeff Brown349703e2010-06-22 01:27:15 -07005623 final int flags = child.mAttrs.flags;
5624 final int type = child.mAttrs.type;
5625
5626 final boolean hasFocus = (child == mInputFocus);
5627 final boolean isVisible = child.isVisibleLw();
5628 final boolean hasWallpaper = (child == mWallpaperTarget)
5629 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005630
5631 // If there's a drag in progress and 'child' is a potential drop target,
5632 // make sure it's been told about the drag
5633 if (inDrag && isVisible) {
5634 mDragState.sendDragStartedIfNeededLw(child);
5635 }
5636
Jeff Brown349703e2010-06-22 01:27:15 -07005637 // Add a window to our list of input windows.
5638 final InputWindow inputWindow = mTempInputWindows.add();
5639 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005640 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005641 inputWindow.layoutParamsFlags = flags;
5642 inputWindow.layoutParamsType = type;
5643 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5644 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005645 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005646 inputWindow.hasFocus = hasFocus;
5647 inputWindow.hasWallpaper = hasWallpaper;
5648 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005649 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005650 inputWindow.ownerPid = child.mSession.mPid;
5651 inputWindow.ownerUid = child.mSession.mUid;
5652
5653 final Rect frame = child.mFrame;
5654 inputWindow.frameLeft = frame.left;
5655 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005656 inputWindow.frameRight = frame.right;
5657 inputWindow.frameBottom = frame.bottom;
5658
5659 final Rect visibleFrame = child.mVisibleFrame;
5660 inputWindow.visibleFrameLeft = visibleFrame.left;
5661 inputWindow.visibleFrameTop = visibleFrame.top;
5662 inputWindow.visibleFrameRight = visibleFrame.right;
5663 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005664
5665 switch (child.mTouchableInsets) {
5666 default:
5667 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5668 inputWindow.touchableAreaLeft = frame.left;
5669 inputWindow.touchableAreaTop = frame.top;
5670 inputWindow.touchableAreaRight = frame.right;
5671 inputWindow.touchableAreaBottom = frame.bottom;
5672 break;
5673
5674 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5675 Rect inset = child.mGivenContentInsets;
5676 inputWindow.touchableAreaLeft = frame.left + inset.left;
5677 inputWindow.touchableAreaTop = frame.top + inset.top;
5678 inputWindow.touchableAreaRight = frame.right - inset.right;
5679 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5680 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005681 }
Jeff Brown349703e2010-06-22 01:27:15 -07005682
5683 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5684 Rect inset = child.mGivenVisibleInsets;
5685 inputWindow.touchableAreaLeft = frame.left + inset.left;
5686 inputWindow.touchableAreaTop = frame.top + inset.top;
5687 inputWindow.touchableAreaRight = frame.right - inset.right;
5688 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005689 break;
5690 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005691 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005692 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005693
Jeff Brown349703e2010-06-22 01:27:15 -07005694 // Send windows to native code.
5695 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005696
Jeff Brown349703e2010-06-22 01:27:15 -07005697 // Clear the list in preparation for the next round.
5698 // Also avoids keeping InputChannel objects referenced unnecessarily.
5699 mTempInputWindows.clear();
5700 }
5701
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005702 /* Notifies that the lid switch changed state. */
5703 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5704 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5705 }
5706
Jeff Brown349703e2010-06-22 01:27:15 -07005707 /* Provides an opportunity for the window manager policy to intercept early key
5708 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005709 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5710 int policyFlags, boolean isScreenOn) {
5711 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5712 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005713 }
5714
5715 /* Provides an opportunity for the window manager policy to process a key before
5716 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005717 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5718 int action, int flags, int keyCode, int metaState, int repeatCount,
5719 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005720 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005721 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5722 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005723 }
5724
5725 /* Called when the current input focus changes.
5726 * Layer assignment is assumed to be complete by the time this is called.
5727 */
5728 public void setInputFocusLw(WindowState newWindow) {
5729 if (DEBUG_INPUT) {
5730 Slog.d(TAG, "Input focus has changed to " + newWindow);
5731 }
5732
5733 if (newWindow != mInputFocus) {
5734 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005735 // Displaying a window implicitly causes dispatching to be unpaused.
5736 // This is to protect against bugs if someone pauses dispatching but
5737 // forgets to resume.
5738 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005739 }
Jeff Brown349703e2010-06-22 01:27:15 -07005740
5741 mInputFocus = newWindow;
5742 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005743 }
5744 }
5745
Jeff Brown349703e2010-06-22 01:27:15 -07005746 public void setFocusedAppLw(AppWindowToken newApp) {
5747 // Focused app has changed.
5748 if (newApp == null) {
5749 mInputManager.setFocusedApplication(null);
5750 } else {
5751 mTempInputApplication.name = newApp.toString();
5752 mTempInputApplication.dispatchingTimeoutNanos =
5753 newApp.inputDispatchingTimeoutNanos;
5754 mTempInputApplication.token = newApp;
5755
5756 mInputManager.setFocusedApplication(mTempInputApplication);
5757 }
5758 }
5759
Jeff Brown349703e2010-06-22 01:27:15 -07005760 public void pauseDispatchingLw(WindowToken window) {
5761 if (! window.paused) {
5762 if (DEBUG_INPUT) {
5763 Slog.v(TAG, "Pausing WindowToken " + window);
5764 }
5765
5766 window.paused = true;
5767 updateInputWindowsLw();
5768 }
5769 }
5770
5771 public void resumeDispatchingLw(WindowToken window) {
5772 if (window.paused) {
5773 if (DEBUG_INPUT) {
5774 Slog.v(TAG, "Resuming WindowToken " + window);
5775 }
5776
5777 window.paused = false;
5778 updateInputWindowsLw();
5779 }
5780 }
5781
5782 public void freezeInputDispatchingLw() {
5783 if (! mInputDispatchFrozen) {
5784 if (DEBUG_INPUT) {
5785 Slog.v(TAG, "Freezing input dispatching");
5786 }
5787
5788 mInputDispatchFrozen = true;
5789 updateInputDispatchModeLw();
5790 }
5791 }
5792
5793 public void thawInputDispatchingLw() {
5794 if (mInputDispatchFrozen) {
5795 if (DEBUG_INPUT) {
5796 Slog.v(TAG, "Thawing input dispatching");
5797 }
5798
5799 mInputDispatchFrozen = false;
5800 updateInputDispatchModeLw();
5801 }
5802 }
5803
5804 public void setEventDispatchingLw(boolean enabled) {
5805 if (mInputDispatchEnabled != enabled) {
5806 if (DEBUG_INPUT) {
5807 Slog.v(TAG, "Setting event dispatching to " + enabled);
5808 }
5809
5810 mInputDispatchEnabled = enabled;
5811 updateInputDispatchModeLw();
5812 }
5813 }
5814
5815 private void updateInputDispatchModeLw() {
5816 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5817 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005820 public void pauseKeyDispatching(IBinder _token) {
5821 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5822 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005823 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005824 }
5825
5826 synchronized (mWindowMap) {
5827 WindowToken token = mTokenMap.get(_token);
5828 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005829 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 }
5831 }
5832 }
5833
5834 public void resumeKeyDispatching(IBinder _token) {
5835 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5836 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005837 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 }
5839
5840 synchronized (mWindowMap) {
5841 WindowToken token = mTokenMap.get(_token);
5842 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005843 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 }
5845 }
5846 }
5847
5848 public void setEventDispatching(boolean enabled) {
5849 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5850 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005851 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005852 }
5853
5854 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005855 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005856 }
5857 }
Romain Guy06882f82009-06-10 13:36:04 -07005858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005859 /**
5860 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005861 * Even when sync is false, this method may block while waiting for current
5862 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005863 *
5864 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865 * {@link SystemClock#uptimeMillis()} as the timebase.)
5866 * @param sync If true, wait for the event to be completed before returning to the caller.
5867 * @return Returns true if event was dispatched, false if it was dropped for any reason
5868 */
5869 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5870 long downTime = ev.getDownTime();
5871 long eventTime = ev.getEventTime();
5872
5873 int action = ev.getAction();
5874 int code = ev.getKeyCode();
5875 int repeatCount = ev.getRepeatCount();
5876 int metaState = ev.getMetaState();
5877 int deviceId = ev.getDeviceId();
5878 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005879 int source = ev.getSource();
5880
5881 if (source == InputDevice.SOURCE_UNKNOWN) {
5882 source = InputDevice.SOURCE_KEYBOARD;
5883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005884
5885 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5886 if (downTime == 0) downTime = eventTime;
5887
5888 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005889 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005890
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005891 final int pid = Binder.getCallingPid();
5892 final int uid = Binder.getCallingUid();
5893 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005894
Jeff Brownbbda99d2010-07-28 15:48:59 -07005895 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5896 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5897 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5898 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005899
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005900 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005901 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 }
5903
5904 /**
5905 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005906 * Even when sync is false, this method may block while waiting for current
5907 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005908 *
5909 * @param ev A motion event describing the pointer (touch) action. (As noted in
5910 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 * {@link SystemClock#uptimeMillis()} as the timebase.)
5912 * @param sync If true, wait for the event to be completed before returning to the caller.
5913 * @return Returns true if event was dispatched, false if it was dropped for any reason
5914 */
5915 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005916 final int pid = Binder.getCallingPid();
5917 final int uid = Binder.getCallingUid();
5918 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005919
Jeff Brownc5ed5912010-07-14 18:48:53 -07005920 MotionEvent newEvent = MotionEvent.obtain(ev);
5921 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5922 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5923 }
5924
Jeff Brownbbda99d2010-07-28 15:48:59 -07005925 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5926 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5927 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5928 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005929
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005930 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005931 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005932 }
Romain Guy06882f82009-06-10 13:36:04 -07005933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005934 /**
5935 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005936 * Even when sync is false, this method may block while waiting for current
5937 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005938 *
5939 * @param ev A motion event describing the trackball action. (As noted in
5940 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 * {@link SystemClock#uptimeMillis()} as the timebase.)
5942 * @param sync If true, wait for the event to be completed before returning to the caller.
5943 * @return Returns true if event was dispatched, false if it was dropped for any reason
5944 */
5945 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005946 final int pid = Binder.getCallingPid();
5947 final int uid = Binder.getCallingUid();
5948 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005949
Jeff Brownc5ed5912010-07-14 18:48:53 -07005950 MotionEvent newEvent = MotionEvent.obtain(ev);
5951 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5952 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5953 }
5954
Jeff Brownbbda99d2010-07-28 15:48:59 -07005955 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5956 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5957 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5958 INJECTION_TIMEOUT_MILLIS);
5959
5960 Binder.restoreCallingIdentity(ident);
5961 return reportInjectionResult(result);
5962 }
5963
5964 /**
5965 * Inject an input event into the UI without waiting for dispatch to commence.
5966 * This variant is useful for fire-and-forget input event injection. It does not
5967 * block any longer than it takes to enqueue the input event.
5968 *
5969 * @param ev An input event. (Be sure to set the input source correctly.)
5970 * @return Returns true if event was dispatched, false if it was dropped for any reason
5971 */
5972 public boolean injectInputEventNoWait(InputEvent ev) {
5973 final int pid = Binder.getCallingPid();
5974 final int uid = Binder.getCallingUid();
5975 final long ident = Binder.clearCallingIdentity();
5976
5977 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5978 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5979 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005980
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005981 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005982 return reportInjectionResult(result);
5983 }
5984
5985 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005986 switch (result) {
5987 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5988 Slog.w(TAG, "Input event injection permission denied.");
5989 throw new SecurityException(
5990 "Injecting to another application requires INJECT_EVENTS permission");
5991 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005992 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005993 return true;
5994 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5995 Slog.w(TAG, "Input event injection timed out.");
5996 return false;
5997 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5998 default:
5999 Slog.w(TAG, "Input event injection failed.");
6000 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006001 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006002 }
Romain Guy06882f82009-06-10 13:36:04 -07006003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 private WindowState getFocusedWindow() {
6005 synchronized (mWindowMap) {
6006 return getFocusedWindowLocked();
6007 }
6008 }
6009
6010 private WindowState getFocusedWindowLocked() {
6011 return mCurrentFocus;
6012 }
Romain Guy06882f82009-06-10 13:36:04 -07006013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006014 public boolean detectSafeMode() {
6015 mSafeMode = mPolicy.detectSafeMode();
6016 return mSafeMode;
6017 }
Romain Guy06882f82009-06-10 13:36:04 -07006018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006019 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006020 synchronized(mWindowMap) {
6021 if (mDisplay != null) {
6022 throw new IllegalStateException("Display already initialized");
6023 }
6024 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6025 mDisplay = wm.getDefaultDisplay();
6026 mInitialDisplayWidth = mDisplay.getWidth();
6027 mInitialDisplayHeight = mDisplay.getHeight();
6028 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6029 }
6030
6031 try {
6032 mActivityManager.updateConfiguration(null);
6033 } catch (RemoteException e) {
6034 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006035
6036 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006037 }
6038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006039 // -------------------------------------------------------------
6040 // Client Session State
6041 // -------------------------------------------------------------
6042
6043 private final class Session extends IWindowSession.Stub
6044 implements IBinder.DeathRecipient {
6045 final IInputMethodClient mClient;
6046 final IInputContext mInputContext;
6047 final int mUid;
6048 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006049 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006050 SurfaceSession mSurfaceSession;
6051 int mNumWindow = 0;
6052 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006054 public Session(IInputMethodClient client, IInputContext inputContext) {
6055 mClient = client;
6056 mInputContext = inputContext;
6057 mUid = Binder.getCallingUid();
6058 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006059 StringBuilder sb = new StringBuilder();
6060 sb.append("Session{");
6061 sb.append(Integer.toHexString(System.identityHashCode(this)));
6062 sb.append(" uid ");
6063 sb.append(mUid);
6064 sb.append("}");
6065 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006067 synchronized (mWindowMap) {
6068 if (mInputMethodManager == null && mHaveInputMethods) {
6069 IBinder b = ServiceManager.getService(
6070 Context.INPUT_METHOD_SERVICE);
6071 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6072 }
6073 }
6074 long ident = Binder.clearCallingIdentity();
6075 try {
6076 // Note: it is safe to call in to the input method manager
6077 // here because we are not holding our lock.
6078 if (mInputMethodManager != null) {
6079 mInputMethodManager.addClient(client, inputContext,
6080 mUid, mPid);
6081 } else {
6082 client.setUsingInputMethod(false);
6083 }
6084 client.asBinder().linkToDeath(this, 0);
6085 } catch (RemoteException e) {
6086 // The caller has died, so we can just forget about this.
6087 try {
6088 if (mInputMethodManager != null) {
6089 mInputMethodManager.removeClient(client);
6090 }
6091 } catch (RemoteException ee) {
6092 }
6093 } finally {
6094 Binder.restoreCallingIdentity(ident);
6095 }
6096 }
Romain Guy06882f82009-06-10 13:36:04 -07006097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 @Override
6099 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6100 throws RemoteException {
6101 try {
6102 return super.onTransact(code, data, reply, flags);
6103 } catch (RuntimeException e) {
6104 // Log all 'real' exceptions thrown to the caller
6105 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006106 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 }
6108 throw e;
6109 }
6110 }
6111
6112 public void binderDied() {
6113 // Note: it is safe to call in to the input method manager
6114 // here because we are not holding our lock.
6115 try {
6116 if (mInputMethodManager != null) {
6117 mInputMethodManager.removeClient(mClient);
6118 }
6119 } catch (RemoteException e) {
6120 }
6121 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006122 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 mClientDead = true;
6124 killSessionLocked();
6125 }
6126 }
6127
6128 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006129 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6130 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6131 outInputChannel);
6132 }
6133
6134 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006135 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006136 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 }
Romain Guy06882f82009-06-10 13:36:04 -07006138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006139 public void remove(IWindow window) {
6140 removeWindow(this, window);
6141 }
Romain Guy06882f82009-06-10 13:36:04 -07006142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6144 int requestedWidth, int requestedHeight, int viewFlags,
6145 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006146 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006147 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6148 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006149 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006150 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006151 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6152 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 }
Romain Guy06882f82009-06-10 13:36:04 -07006154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 public void setTransparentRegion(IWindow window, Region region) {
6156 setTransparentRegionWindow(this, window, region);
6157 }
Romain Guy06882f82009-06-10 13:36:04 -07006158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 public void setInsets(IWindow window, int touchableInsets,
6160 Rect contentInsets, Rect visibleInsets) {
6161 setInsetsWindow(this, window, touchableInsets, contentInsets,
6162 visibleInsets);
6163 }
Romain Guy06882f82009-06-10 13:36:04 -07006164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006165 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6166 getWindowDisplayFrame(this, window, outDisplayFrame);
6167 }
Romain Guy06882f82009-06-10 13:36:04 -07006168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006169 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006170 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006171 TAG, "IWindow finishDrawing called for " + window);
6172 finishDrawingWindow(this, window);
6173 }
6174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006175 public void setInTouchMode(boolean mode) {
6176 synchronized(mWindowMap) {
6177 mInTouchMode = mode;
6178 }
6179 }
6180
6181 public boolean getInTouchMode() {
6182 synchronized(mWindowMap) {
6183 return mInTouchMode;
6184 }
6185 }
6186
6187 public boolean performHapticFeedback(IWindow window, int effectId,
6188 boolean always) {
6189 synchronized(mWindowMap) {
6190 long ident = Binder.clearCallingIdentity();
6191 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006192 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006193 windowForClientLocked(this, window, true),
6194 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006195 } finally {
6196 Binder.restoreCallingIdentity(ident);
6197 }
6198 }
6199 }
Romain Guy06882f82009-06-10 13:36:04 -07006200
Christopher Tatea53146c2010-09-07 11:57:52 -07006201 /* Drag/drop */
6202 public IBinder prepareDrag(IWindow window, boolean localOnly,
6203 int width, int height, Surface outSurface) {
6204 return prepareDragSurface(window, mSurfaceSession, localOnly,
6205 width, height, outSurface);
6206 }
6207
6208 public boolean performDrag(IWindow window, IBinder dragToken,
6209 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6210 ClipData data) {
6211 if (DEBUG_DRAG) {
6212 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6213 }
6214
6215 synchronized (mWindowMap) {
6216 if (mDragState == null) {
6217 Slog.w(TAG, "No drag prepared");
6218 throw new IllegalStateException("performDrag() without prepareDrag()");
6219 }
6220
6221 if (dragToken != mDragState.mToken) {
6222 Slog.w(TAG, "Performing mismatched drag");
6223 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6224 }
6225
6226 WindowState callingWin = windowForClientLocked(null, window, false);
6227 if (callingWin == null) {
6228 Slog.w(TAG, "Bad requesting window " + window);
6229 return false; // !!! TODO: throw here?
6230 }
6231
6232 // !!! TODO: if input is not still focused on the initiating window, fail
6233 // the drag initiation (e.g. an alarm window popped up just as the application
6234 // called performDrag()
6235
6236 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6237
Christopher Tate2c095f32010-10-04 14:13:40 -07006238 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6239 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006240
Chris Tateb478f462010-10-15 16:02:26 -07006241 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6242 // the actual drag event dispatch stuff in the dragstate
6243
Christopher Tatea53146c2010-09-07 11:57:52 -07006244 mDragState.register();
6245 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006246 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6247 mDragState.mServerChannel)) {
6248 Slog.e(TAG, "Unable to transfer touch focus");
6249 mDragState.unregister();
6250 mDragState = null;
6251 mInputMonitor.updateInputWindowsLw();
6252 return false;
6253 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006254
6255 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006256 mDragState.mCurrentX = touchX;
6257 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006258 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006259
6260 // remember the thumb offsets for later
6261 mDragState.mThumbOffsetX = thumbCenterX;
6262 mDragState.mThumbOffsetY = thumbCenterY;
6263
6264 // Make the surface visible at the proper location
6265 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006266 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006267 try {
6268 surface.setPosition((int)(touchX - thumbCenterX),
6269 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006270 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006271 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006272 surface.show();
6273 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006274 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006275 }
6276 }
6277
6278 return true; // success!
6279 }
6280
Chris Tated4533f142010-10-19 15:15:08 -07006281 public void reportDropResult(IWindow window, boolean consumed) {
6282 IBinder token = window.asBinder();
6283 if (DEBUG_DRAG) {
6284 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6285 }
6286
6287 synchronized (mWindowMap) {
6288 if (mDragState.mToken != token) {
6289 Slog.w(TAG, "Invalid drop-result claim by " + window);
6290 throw new IllegalStateException("reportDropResult() by non-recipient");
6291 }
6292
6293 // The right window has responded, even if it's no longer around,
6294 // so be sure to halt the timeout even if the later WindowState
6295 // lookup fails.
6296 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6297
6298 WindowState callingWin = windowForClientLocked(null, window, false);
6299 if (callingWin == null) {
6300 Slog.w(TAG, "Bad result-reporting window " + window);
6301 return; // !!! TODO: throw here?
6302 }
6303
6304 mDragState.mDragResult = consumed;
6305 mDragState.endDragLw();
6306 }
6307 }
6308
Christopher Tatea53146c2010-09-07 11:57:52 -07006309 public void dragRecipientEntered(IWindow window) {
6310 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006311 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006312 }
6313 }
6314
6315 public void dragRecipientExited(IWindow window) {
6316 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006317 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006318 }
6319 }
6320
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006321 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006322 synchronized(mWindowMap) {
6323 long ident = Binder.clearCallingIdentity();
6324 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006325 setWindowWallpaperPositionLocked(
6326 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006327 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006328 } finally {
6329 Binder.restoreCallingIdentity(ident);
6330 }
6331 }
6332 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006333
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006334 public void wallpaperOffsetsComplete(IBinder window) {
6335 WindowManagerService.this.wallpaperOffsetsComplete(window);
6336 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006337
Dianne Hackborn75804932009-10-20 20:15:20 -07006338 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6339 int z, Bundle extras, boolean sync) {
6340 synchronized(mWindowMap) {
6341 long ident = Binder.clearCallingIdentity();
6342 try {
6343 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006344 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006345 action, x, y, z, extras, sync);
6346 } finally {
6347 Binder.restoreCallingIdentity(ident);
6348 }
6349 }
6350 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006351
Dianne Hackborn75804932009-10-20 20:15:20 -07006352 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6353 WindowManagerService.this.wallpaperCommandComplete(window, result);
6354 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 void windowAddedLocked() {
6357 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006358 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 TAG, "First window added to " + this + ", creating SurfaceSession");
6360 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006361 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006362 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006363 mSessions.add(this);
6364 }
6365 mNumWindow++;
6366 }
6367
6368 void windowRemovedLocked() {
6369 mNumWindow--;
6370 killSessionLocked();
6371 }
Romain Guy06882f82009-06-10 13:36:04 -07006372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 void killSessionLocked() {
6374 if (mNumWindow <= 0 && mClientDead) {
6375 mSessions.remove(this);
6376 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006377 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 TAG, "Last window removed from " + this
6379 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006380 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006381 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 try {
6383 mSurfaceSession.kill();
6384 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006385 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 + mSurfaceSession + " in session " + this
6387 + ": " + e.toString());
6388 }
6389 mSurfaceSession = null;
6390 }
6391 }
6392 }
Romain Guy06882f82009-06-10 13:36:04 -07006393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006395 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6396 pw.print(" mClientDead="); pw.print(mClientDead);
6397 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 }
6399
6400 @Override
6401 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006402 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006403 }
6404 }
6405
6406 // -------------------------------------------------------------
6407 // Client Window State
6408 // -------------------------------------------------------------
6409
6410 private final class WindowState implements WindowManagerPolicy.WindowState {
6411 final Session mSession;
6412 final IWindow mClient;
6413 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006414 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 AppWindowToken mAppToken;
6416 AppWindowToken mTargetAppToken;
6417 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6418 final DeathRecipient mDeathRecipient;
6419 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006420 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 final int mBaseLayer;
6422 final int mSubLayer;
6423 final boolean mLayoutAttached;
6424 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006425 final boolean mIsWallpaper;
6426 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 int mViewVisibility;
6428 boolean mPolicyVisibility = true;
6429 boolean mPolicyVisibilityAfterAnim = true;
6430 boolean mAppFreezing;
6431 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006432 boolean mReportDestroySurface;
6433 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006434 boolean mAttachedHidden; // is our parent window hidden?
6435 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006436 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006437 int mRequestedWidth;
6438 int mRequestedHeight;
6439 int mLastRequestedWidth;
6440 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 int mLayer;
6442 int mAnimLayer;
6443 int mLastLayer;
6444 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006445 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006446 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006448 int mLayoutSeq = -1;
6449
6450 Configuration mConfiguration = null;
6451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 // Actual frame shown on-screen (may be modified by animation)
6453 final Rect mShownFrame = new Rect();
6454 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006457 * Set when we have changed the size of the surface, to know that
6458 * we must tell them application to resize (and thus redraw itself).
6459 */
6460 boolean mSurfaceResized;
6461
6462 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006463 * Insets that determine the actually visible area
6464 */
6465 final Rect mVisibleInsets = new Rect();
6466 final Rect mLastVisibleInsets = new Rect();
6467 boolean mVisibleInsetsChanged;
6468
6469 /**
6470 * Insets that are covered by system windows
6471 */
6472 final Rect mContentInsets = new Rect();
6473 final Rect mLastContentInsets = new Rect();
6474 boolean mContentInsetsChanged;
6475
6476 /**
6477 * Set to true if we are waiting for this window to receive its
6478 * given internal insets before laying out other windows based on it.
6479 */
6480 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 /**
6483 * These are the content insets that were given during layout for
6484 * this window, to be applied to windows behind it.
6485 */
6486 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 /**
6489 * These are the visible insets that were given during layout for
6490 * this window, to be applied to windows behind it.
6491 */
6492 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 /**
6495 * Flag indicating whether the touchable region should be adjusted by
6496 * the visible insets; if false the area outside the visible insets is
6497 * NOT touchable, so we must use those to adjust the frame during hit
6498 * tests.
6499 */
6500 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 // Current transformation being applied.
6503 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6504 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6505 float mHScale=1, mVScale=1;
6506 float mLastHScale=1, mLastVScale=1;
6507 final Matrix mTmpMatrix = new Matrix();
6508
6509 // "Real" frame that the application sees.
6510 final Rect mFrame = new Rect();
6511 final Rect mLastFrame = new Rect();
6512
6513 final Rect mContainingFrame = new Rect();
6514 final Rect mDisplayFrame = new Rect();
6515 final Rect mContentFrame = new Rect();
6516 final Rect mVisibleFrame = new Rect();
6517
6518 float mShownAlpha = 1;
6519 float mAlpha = 1;
6520 float mLastAlpha = 1;
6521
6522 // Set to true if, when the window gets displayed, it should perform
6523 // an enter animation.
6524 boolean mEnterAnimationPending;
6525
6526 // Currently running animation.
6527 boolean mAnimating;
6528 boolean mLocalAnimating;
6529 Animation mAnimation;
6530 boolean mAnimationIsEntrance;
6531 boolean mHasTransformation;
6532 boolean mHasLocalTransformation;
6533 final Transformation mTransformation = new Transformation();
6534
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006535 // If a window showing a wallpaper: the requested offset for the
6536 // wallpaper; if a wallpaper window: the currently applied offset.
6537 float mWallpaperX = -1;
6538 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006539
6540 // If a window showing a wallpaper: what fraction of the offset
6541 // range corresponds to a full virtual screen.
6542 float mWallpaperXStep = -1;
6543 float mWallpaperYStep = -1;
6544
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006545 // Wallpaper windows: pixels offset based on above variables.
6546 int mXOffset;
6547 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006549 // This is set after IWindowSession.relayout() has been called at
6550 // least once for the window. It allows us to detect the situation
6551 // where we don't yet have a surface, but should have one soon, so
6552 // we can give the window focus before waiting for the relayout.
6553 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006555 // This is set after the Surface has been created but before the
6556 // window has been drawn. During this time the surface is hidden.
6557 boolean mDrawPending;
6558
6559 // This is set after the window has finished drawing for the first
6560 // time but before its surface is shown. The surface will be
6561 // displayed when the next layout is run.
6562 boolean mCommitDrawPending;
6563
6564 // This is set during the time after the window's drawing has been
6565 // committed, and before its surface is actually shown. It is used
6566 // to delay showing the surface until all windows in a token are ready
6567 // to be shown.
6568 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 // Set when the window has been shown in the screen the first time.
6571 boolean mHasDrawn;
6572
6573 // Currently running an exit animation?
6574 boolean mExiting;
6575
6576 // Currently on the mDestroySurface list?
6577 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006579 // Completely remove from window manager after exit animation?
6580 boolean mRemoveOnExit;
6581
6582 // Set when the orientation is changing and this window has not yet
6583 // been updated for the new orientation.
6584 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006586 // Is this window now (or just being) removed?
6587 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006588
Dianne Hackborn16064f92010-03-25 00:47:24 -07006589 // For debugging, this is the last information given to the surface flinger.
6590 boolean mSurfaceShown;
6591 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6592 int mSurfaceLayer;
6593 float mSurfaceAlpha;
6594
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006595 // Input channel
6596 InputChannel mInputChannel;
6597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006598 WindowState(Session s, IWindow c, WindowToken token,
6599 WindowState attachedWindow, WindowManager.LayoutParams a,
6600 int viewVisibility) {
6601 mSession = s;
6602 mClient = c;
6603 mToken = token;
6604 mAttrs.copyFrom(a);
6605 mViewVisibility = viewVisibility;
6606 DeathRecipient deathRecipient = new DeathRecipient();
6607 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006608 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 TAG, "Window " + this + " client=" + c.asBinder()
6610 + " token=" + token + " (" + mAttrs.token + ")");
6611 try {
6612 c.asBinder().linkToDeath(deathRecipient, 0);
6613 } catch (RemoteException e) {
6614 mDeathRecipient = null;
6615 mAttachedWindow = null;
6616 mLayoutAttached = false;
6617 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006618 mIsWallpaper = false;
6619 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 mBaseLayer = 0;
6621 mSubLayer = 0;
6622 return;
6623 }
6624 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6627 mAttrs.type <= LAST_SUB_WINDOW)) {
6628 // The multiplier here is to reserve space for multiple
6629 // windows in the same type layer.
6630 mBaseLayer = mPolicy.windowTypeToLayerLw(
6631 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6632 + TYPE_LAYER_OFFSET;
6633 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6634 mAttachedWindow = attachedWindow;
6635 mAttachedWindow.mChildWindows.add(this);
6636 mLayoutAttached = mAttrs.type !=
6637 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6638 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6639 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006640 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6641 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642 } else {
6643 // The multiplier here is to reserve space for multiple
6644 // windows in the same type layer.
6645 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6646 * TYPE_LAYER_MULTIPLIER
6647 + TYPE_LAYER_OFFSET;
6648 mSubLayer = 0;
6649 mAttachedWindow = null;
6650 mLayoutAttached = false;
6651 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6652 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006653 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6654 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 }
6656
6657 WindowState appWin = this;
6658 while (appWin.mAttachedWindow != null) {
6659 appWin = mAttachedWindow;
6660 }
6661 WindowToken appToken = appWin.mToken;
6662 while (appToken.appWindowToken == null) {
6663 WindowToken parent = mTokenMap.get(appToken.token);
6664 if (parent == null || appToken == parent) {
6665 break;
6666 }
6667 appToken = parent;
6668 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006669 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006670 mAppToken = appToken.appWindowToken;
6671
6672 mSurface = null;
6673 mRequestedWidth = 0;
6674 mRequestedHeight = 0;
6675 mLastRequestedWidth = 0;
6676 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006677 mXOffset = 0;
6678 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006679 mLayer = 0;
6680 mAnimLayer = 0;
6681 mLastLayer = 0;
6682 }
6683
6684 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006685 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 TAG, "Attaching " + this + " token=" + mToken
6687 + ", list=" + mToken.windows);
6688 mSession.windowAddedLocked();
6689 }
6690
6691 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6692 mHaveFrame = true;
6693
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006694 final Rect container = mContainingFrame;
6695 container.set(pf);
6696
6697 final Rect display = mDisplayFrame;
6698 display.set(df);
6699
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006700 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006701 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006702 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6703 display.intersect(mCompatibleScreenFrame);
6704 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006705 }
6706
6707 final int pw = container.right - container.left;
6708 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709
6710 int w,h;
6711 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6712 w = mAttrs.width < 0 ? pw : mAttrs.width;
6713 h = mAttrs.height< 0 ? ph : mAttrs.height;
6714 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006715 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6716 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 }
Romain Guy06882f82009-06-10 13:36:04 -07006718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006719 final Rect content = mContentFrame;
6720 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 final Rect visible = mVisibleFrame;
6723 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006726 final int fw = frame.width();
6727 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6730 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6731
6732 Gravity.apply(mAttrs.gravity, w, h, container,
6733 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6734 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6735
6736 //System.out.println("Out: " + mFrame);
6737
6738 // Now make sure the window fits in the overall display.
6739 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006741 // Make sure the content and visible frames are inside of the
6742 // final window frame.
6743 if (content.left < frame.left) content.left = frame.left;
6744 if (content.top < frame.top) content.top = frame.top;
6745 if (content.right > frame.right) content.right = frame.right;
6746 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6747 if (visible.left < frame.left) visible.left = frame.left;
6748 if (visible.top < frame.top) visible.top = frame.top;
6749 if (visible.right > frame.right) visible.right = frame.right;
6750 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 final Rect contentInsets = mContentInsets;
6753 contentInsets.left = content.left-frame.left;
6754 contentInsets.top = content.top-frame.top;
6755 contentInsets.right = frame.right-content.right;
6756 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 final Rect visibleInsets = mVisibleInsets;
6759 visibleInsets.left = visible.left-frame.left;
6760 visibleInsets.top = visible.top-frame.top;
6761 visibleInsets.right = frame.right-visible.right;
6762 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006763
Dianne Hackborn284ac932009-08-28 10:34:25 -07006764 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6765 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006766 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 if (localLOGV) {
6770 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6771 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006772 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 + mRequestedWidth + ", mRequestedheight="
6774 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6775 + "): frame=" + mFrame.toShortString()
6776 + " ci=" + contentInsets.toShortString()
6777 + " vi=" + visibleInsets.toShortString());
6778 //}
6779 }
6780 }
Romain Guy06882f82009-06-10 13:36:04 -07006781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006782 public Rect getFrameLw() {
6783 return mFrame;
6784 }
6785
6786 public Rect getShownFrameLw() {
6787 return mShownFrame;
6788 }
6789
6790 public Rect getDisplayFrameLw() {
6791 return mDisplayFrame;
6792 }
6793
6794 public Rect getContentFrameLw() {
6795 return mContentFrame;
6796 }
6797
6798 public Rect getVisibleFrameLw() {
6799 return mVisibleFrame;
6800 }
6801
6802 public boolean getGivenInsetsPendingLw() {
6803 return mGivenInsetsPending;
6804 }
6805
6806 public Rect getGivenContentInsetsLw() {
6807 return mGivenContentInsets;
6808 }
Romain Guy06882f82009-06-10 13:36:04 -07006809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 public Rect getGivenVisibleInsetsLw() {
6811 return mGivenVisibleInsets;
6812 }
Romain Guy06882f82009-06-10 13:36:04 -07006813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 public WindowManager.LayoutParams getAttrs() {
6815 return mAttrs;
6816 }
6817
6818 public int getSurfaceLayer() {
6819 return mLayer;
6820 }
Romain Guy06882f82009-06-10 13:36:04 -07006821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 public IApplicationToken getAppToken() {
6823 return mAppToken != null ? mAppToken.appToken : null;
6824 }
Jeff Brown349703e2010-06-22 01:27:15 -07006825
6826 public long getInputDispatchingTimeoutNanos() {
6827 return mAppToken != null
6828 ? mAppToken.inputDispatchingTimeoutNanos
6829 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831
6832 public boolean hasAppShownWindows() {
6833 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6834 }
6835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006837 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 TAG, "Setting animation in " + this + ": " + anim);
6839 mAnimating = false;
6840 mLocalAnimating = false;
6841 mAnimation = anim;
6842 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6843 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6844 }
6845
6846 public void clearAnimation() {
6847 if (mAnimation != null) {
6848 mAnimating = true;
6849 mLocalAnimating = false;
6850 mAnimation = null;
6851 }
6852 }
Romain Guy06882f82009-06-10 13:36:04 -07006853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 Surface createSurfaceLocked() {
6855 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006856 mReportDestroySurface = false;
6857 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 mDrawPending = true;
6859 mCommitDrawPending = false;
6860 mReadyToShow = false;
6861 if (mAppToken != null) {
6862 mAppToken.allDrawn = false;
6863 }
6864
6865 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006866 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 flags |= Surface.PUSH_BUFFERS;
6868 }
6869
6870 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6871 flags |= Surface.SECURE;
6872 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006873 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 TAG, "Creating surface in session "
6875 + mSession.mSurfaceSession + " window " + this
6876 + " w=" + mFrame.width()
6877 + " h=" + mFrame.height() + " format="
6878 + mAttrs.format + " flags=" + flags);
6879
6880 int w = mFrame.width();
6881 int h = mFrame.height();
6882 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6883 // for a scaled surface, we always want the requested
6884 // size.
6885 w = mRequestedWidth;
6886 h = mRequestedHeight;
6887 }
6888
Romain Guy9825ec62009-10-01 00:58:09 -07006889 // Something is wrong and SurfaceFlinger will not like this,
6890 // try to revert to sane values
6891 if (w <= 0) w = 1;
6892 if (h <= 0) h = 1;
6893
Dianne Hackborn16064f92010-03-25 00:47:24 -07006894 mSurfaceShown = false;
6895 mSurfaceLayer = 0;
6896 mSurfaceAlpha = 1;
6897 mSurfaceX = 0;
6898 mSurfaceY = 0;
6899 mSurfaceW = w;
6900 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006902 final boolean isHwAccelerated = (mAttrs.flags &
6903 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6904 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6905 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6906 flags |= Surface.OPAQUE;
6907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006909 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006910 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006911 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006912 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006913 + mSurface + " IN SESSION "
6914 + mSession.mSurfaceSession
6915 + ": pid=" + mSession.mPid + " format="
6916 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006917 + Integer.toHexString(flags)
6918 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006920 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 reclaimSomeSurfaceMemoryLocked(this, "create");
6922 return null;
6923 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006924 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006925 return null;
6926 }
Romain Guy06882f82009-06-10 13:36:04 -07006927
Joe Onorato8a9b2202010-02-26 18:56:32 -08006928 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006929 TAG, "Got surface: " + mSurface
6930 + ", set left=" + mFrame.left + " top=" + mFrame.top
6931 + ", animLayer=" + mAnimLayer);
6932 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006933 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006934 if (SHOW_TRANSACTIONS) logSurface(this,
6935 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6936 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6937 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 }
6939 Surface.openTransaction();
6940 try {
6941 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006942 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006943 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006944 mSurface.setPosition(mSurfaceX, mSurfaceY);
6945 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006947 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 mSurface.hide();
6949 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006950 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 mSurface.setFlags(Surface.SURFACE_DITHER,
6952 Surface.SURFACE_DITHER);
6953 }
6954 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006955 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6957 }
6958 mLastHidden = true;
6959 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006960 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006961 Surface.closeTransaction();
6962 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006963 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 TAG, "Created surface " + this);
6965 }
6966 return mSurface;
6967 }
Romain Guy06882f82009-06-10 13:36:04 -07006968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006970 if (mAppToken != null && this == mAppToken.startingWindow) {
6971 mAppToken.startingDisplayed = false;
6972 }
Romain Guy06882f82009-06-10 13:36:04 -07006973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006975 mDrawPending = false;
6976 mCommitDrawPending = false;
6977 mReadyToShow = false;
6978
6979 int i = mChildWindows.size();
6980 while (i > 0) {
6981 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006982 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006983 c.mAttachedHidden = true;
6984 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006985
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006986 if (mReportDestroySurface) {
6987 mReportDestroySurface = false;
6988 mSurfacePendingDestroy = true;
6989 try {
6990 mClient.dispatchGetNewSurface();
6991 // We'll really destroy on the next time around.
6992 return;
6993 } catch (RemoteException e) {
6994 }
6995 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006997 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006998 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006999 RuntimeException e = null;
7000 if (!HIDE_STACK_CRAWLS) {
7001 e = new RuntimeException();
7002 e.fillInStackTrace();
7003 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007004 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007005 + mSurface + ", session " + mSession, e);
7006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007007 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007008 RuntimeException e = null;
7009 if (!HIDE_STACK_CRAWLS) {
7010 e = new RuntimeException();
7011 e.fillInStackTrace();
7012 }
7013 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007015 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007017 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 + " surface " + mSurface + " session " + mSession
7019 + ": " + e.toString());
7020 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007021
Dianne Hackborn16064f92010-03-25 00:47:24 -07007022 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007023 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007024 }
7025 }
7026
7027 boolean finishDrawingLocked() {
7028 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007029 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 TAG, "finishDrawingLocked: " + mSurface);
7031 mCommitDrawPending = true;
7032 mDrawPending = false;
7033 return true;
7034 }
7035 return false;
7036 }
7037
7038 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007039 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007040 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007041 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007042 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 }
7044 mCommitDrawPending = false;
7045 mReadyToShow = true;
7046 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7047 final AppWindowToken atoken = mAppToken;
7048 if (atoken == null || atoken.allDrawn || starting) {
7049 performShowLocked();
7050 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007051 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007052 }
7053
7054 // This must be called while inside a transaction.
7055 boolean performShowLocked() {
7056 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007057 RuntimeException e = null;
7058 if (!HIDE_STACK_CRAWLS) {
7059 e = new RuntimeException();
7060 e.fillInStackTrace();
7061 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007062 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7064 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7065 }
7066 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007067 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7068 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007069 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 + " during animation: policyVis=" + mPolicyVisibility
7071 + " attHidden=" + mAttachedHidden
7072 + " tok.hiddenRequested="
7073 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007074 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007075 + (mAppToken != null ? mAppToken.hidden : false)
7076 + " animating=" + mAnimating
7077 + " tok animating="
7078 + (mAppToken != null ? mAppToken.animating : false));
7079 if (!showSurfaceRobustlyLocked(this)) {
7080 return false;
7081 }
7082 mLastAlpha = -1;
7083 mHasDrawn = true;
7084 mLastHidden = false;
7085 mReadyToShow = false;
7086 enableScreenIfNeededLocked();
7087
7088 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 int i = mChildWindows.size();
7091 while (i > 0) {
7092 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007093 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007094 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007096 if (c.mSurface != null) {
7097 c.performShowLocked();
7098 // It hadn't been shown, which means layout not
7099 // performed on it, so now we want to make sure to
7100 // do a layout. If called from within the transaction
7101 // loop, this will cause it to restart with a new
7102 // layout.
7103 mLayoutNeeded = true;
7104 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007105 }
7106 }
Romain Guy06882f82009-06-10 13:36:04 -07007107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 if (mAttrs.type != TYPE_APPLICATION_STARTING
7109 && mAppToken != null) {
7110 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007111
Dianne Hackborn248b1882009-09-16 16:46:44 -07007112 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007113 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007114 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007116 // If this initial window is animating, stop it -- we
7117 // will do an animation to reveal it from behind the
7118 // starting window, so there is no need for it to also
7119 // be doing its own stuff.
7120 if (mAnimation != null) {
7121 mAnimation = null;
7122 // Make sure we clean up the animation.
7123 mAnimating = true;
7124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007125 mFinishedStarting.add(mAppToken);
7126 mH.sendEmptyMessage(H.FINISHED_STARTING);
7127 }
7128 mAppToken.updateReportedVisibilityLocked();
7129 }
7130 }
7131 return true;
7132 }
Romain Guy06882f82009-06-10 13:36:04 -07007133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007134 // This must be called while inside a transaction. Returns true if
7135 // there is more animation to run.
7136 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007137 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007138 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007140 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7141 mHasTransformation = true;
7142 mHasLocalTransformation = true;
7143 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007144 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 TAG, "Starting animation in " + this +
7146 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7147 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7148 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7149 mAnimation.setStartTime(currentTime);
7150 mLocalAnimating = true;
7151 mAnimating = true;
7152 }
7153 mTransformation.clear();
7154 final boolean more = mAnimation.getTransformation(
7155 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007156 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007157 TAG, "Stepped animation in " + this +
7158 ": more=" + more + ", xform=" + mTransformation);
7159 if (more) {
7160 // we're not done!
7161 return true;
7162 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007163 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007164 TAG, "Finished animation in " + this +
7165 " @ " + currentTime);
7166 mAnimation = null;
7167 //WindowManagerService.this.dump();
7168 }
7169 mHasLocalTransformation = false;
7170 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007171 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172 // When our app token is animating, we kind-of pretend like
7173 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7174 // part of this check means that we will only do this if
7175 // our window is not currently exiting, or it is not
7176 // locally animating itself. The idea being that one that
7177 // is exiting and doing a local animation should be removed
7178 // once that animation is done.
7179 mAnimating = true;
7180 mHasTransformation = true;
7181 mTransformation.clear();
7182 return false;
7183 } else if (mHasTransformation) {
7184 // Little trick to get through the path below to act like
7185 // we have finished an animation.
7186 mAnimating = true;
7187 } else if (isAnimating()) {
7188 mAnimating = true;
7189 }
7190 } else if (mAnimation != null) {
7191 // If the display is frozen, and there is a pending animation,
7192 // clear it and make sure we run the cleanup code.
7193 mAnimating = true;
7194 mLocalAnimating = true;
7195 mAnimation = null;
7196 }
Romain Guy06882f82009-06-10 13:36:04 -07007197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007198 if (!mAnimating && !mLocalAnimating) {
7199 return false;
7200 }
7201
Joe Onorato8a9b2202010-02-26 18:56:32 -08007202 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 TAG, "Animation done in " + this + ": exiting=" + mExiting
7204 + ", reportedVisible="
7205 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007207 mAnimating = false;
7208 mLocalAnimating = false;
7209 mAnimation = null;
7210 mAnimLayer = mLayer;
7211 if (mIsImWindow) {
7212 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007213 } else if (mIsWallpaper) {
7214 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007216 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007217 + " anim layer: " + mAnimLayer);
7218 mHasTransformation = false;
7219 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007220 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7221 if (DEBUG_VISIBILITY) {
7222 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7223 + mPolicyVisibilityAfterAnim);
7224 }
7225 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7226 if (!mPolicyVisibility) {
7227 if (mCurrentFocus == this) {
7228 mFocusMayChange = true;
7229 }
7230 // Window is no longer visible -- make sure if we were waiting
7231 // for it to be displayed before enabling the display, that
7232 // we allow the display to be enabled now.
7233 enableScreenIfNeededLocked();
7234 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 mTransformation.clear();
7237 if (mHasDrawn
7238 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7239 && mAppToken != null
7240 && mAppToken.firstWindowDrawn
7241 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007242 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007243 + mToken + ": first real window done animating");
7244 mFinishedStarting.add(mAppToken);
7245 mH.sendEmptyMessage(H.FINISHED_STARTING);
7246 }
Romain Guy06882f82009-06-10 13:36:04 -07007247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 finishExit();
7249
7250 if (mAppToken != null) {
7251 mAppToken.updateReportedVisibilityLocked();
7252 }
7253
7254 return false;
7255 }
7256
7257 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007258 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 TAG, "finishExit in " + this
7260 + ": exiting=" + mExiting
7261 + " remove=" + mRemoveOnExit
7262 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007264 final int N = mChildWindows.size();
7265 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007266 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007267 }
Romain Guy06882f82009-06-10 13:36:04 -07007268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007269 if (!mExiting) {
7270 return;
7271 }
Romain Guy06882f82009-06-10 13:36:04 -07007272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007273 if (isWindowAnimating()) {
7274 return;
7275 }
7276
Joe Onorato8a9b2202010-02-26 18:56:32 -08007277 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 TAG, "Exit animation finished in " + this
7279 + ": remove=" + mRemoveOnExit);
7280 if (mSurface != null) {
7281 mDestroySurface.add(this);
7282 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007283 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007284 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007285 try {
7286 mSurface.hide();
7287 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007288 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 }
7290 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 }
7292 mExiting = false;
7293 if (mRemoveOnExit) {
7294 mPendingRemove.add(this);
7295 mRemoveOnExit = false;
7296 }
7297 }
Romain Guy06882f82009-06-10 13:36:04 -07007298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7300 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7301 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7302 if (dtdx < -.000001f || dtdx > .000001f) return false;
7303 if (dsdy < -.000001f || dsdy > .000001f) return false;
7304 return true;
7305 }
Romain Guy06882f82009-06-10 13:36:04 -07007306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007307 void computeShownFrameLocked() {
7308 final boolean selfTransformation = mHasLocalTransformation;
7309 Transformation attachedTransformation =
7310 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7311 ? mAttachedWindow.mTransformation : null;
7312 Transformation appTransformation =
7313 (mAppToken != null && mAppToken.hasTransformation)
7314 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007315
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007316 // Wallpapers are animated based on the "real" window they
7317 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007318 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007319 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007320 if (mWallpaperTarget.mHasLocalTransformation &&
7321 mWallpaperTarget.mAnimation != null &&
7322 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007323 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007324 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007325 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007326 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007327 }
7328 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007329 mWallpaperTarget.mAppToken.hasTransformation &&
7330 mWallpaperTarget.mAppToken.animation != null &&
7331 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007332 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007333 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007334 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007335 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007336 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007337 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 if (selfTransformation || attachedTransformation != null
7340 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007341 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 final Rect frame = mFrame;
7343 final float tmpFloats[] = mTmpFloats;
7344 final Matrix tmpMatrix = mTmpMatrix;
7345
7346 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007347 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007348 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007349 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007351 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007353 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 }
7355 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007356 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007357 }
7358
7359 // "convert" it into SurfaceFlinger's format
7360 // (a 2x2 matrix + an offset)
7361 // Here we must not transform the position of the surface
7362 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007363 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 tmpMatrix.getValues(tmpFloats);
7366 mDsDx = tmpFloats[Matrix.MSCALE_X];
7367 mDtDx = tmpFloats[Matrix.MSKEW_X];
7368 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7369 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007370 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7371 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 int w = frame.width();
7373 int h = frame.height();
7374 mShownFrame.set(x, y, x+w, y+h);
7375
7376 // Now set the alpha... but because our current hardware
7377 // can't do alpha transformation on a non-opaque surface,
7378 // turn it off if we are running an animation that is also
7379 // transforming since it is more important to have that
7380 // animation be smooth.
7381 mShownAlpha = mAlpha;
7382 if (!mLimitedAlphaCompositing
7383 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7384 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7385 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007386 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 if (selfTransformation) {
7388 mShownAlpha *= mTransformation.getAlpha();
7389 }
7390 if (attachedTransformation != null) {
7391 mShownAlpha *= attachedTransformation.getAlpha();
7392 }
7393 if (appTransformation != null) {
7394 mShownAlpha *= appTransformation.getAlpha();
7395 }
7396 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007397 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007398 }
Romain Guy06882f82009-06-10 13:36:04 -07007399
Joe Onorato8a9b2202010-02-26 18:56:32 -08007400 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 TAG, "Continuing animation in " + this +
7402 ": " + mShownFrame +
7403 ", alpha=" + mTransformation.getAlpha());
7404 return;
7405 }
Romain Guy06882f82009-06-10 13:36:04 -07007406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007408 if (mXOffset != 0 || mYOffset != 0) {
7409 mShownFrame.offset(mXOffset, mYOffset);
7410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007411 mShownAlpha = mAlpha;
7412 mDsDx = 1;
7413 mDtDx = 0;
7414 mDsDy = 0;
7415 mDtDy = 1;
7416 }
Romain Guy06882f82009-06-10 13:36:04 -07007417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 /**
7419 * Is this window visible? It is not visible if there is no
7420 * surface, or we are in the process of running an exit animation
7421 * that will remove the surface, or its app token has been hidden.
7422 */
7423 public boolean isVisibleLw() {
7424 final AppWindowToken atoken = mAppToken;
7425 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7426 && (atoken == null || !atoken.hiddenRequested)
7427 && !mExiting && !mDestroying;
7428 }
7429
7430 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007431 * Like {@link #isVisibleLw}, but also counts a window that is currently
7432 * "hidden" behind the keyguard as visible. This allows us to apply
7433 * things like window flags that impact the keyguard.
7434 * XXX I am starting to think we need to have ANOTHER visibility flag
7435 * for this "hidden behind keyguard" state rather than overloading
7436 * mPolicyVisibility. Ungh.
7437 */
7438 public boolean isVisibleOrBehindKeyguardLw() {
7439 final AppWindowToken atoken = mAppToken;
7440 return mSurface != null && !mAttachedHidden
7441 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007442 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007443 && !mExiting && !mDestroying;
7444 }
7445
7446 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 * Is this window visible, ignoring its app token? It is not visible
7448 * if there is no surface, or we are in the process of running an exit animation
7449 * that will remove the surface.
7450 */
7451 public boolean isWinVisibleLw() {
7452 final AppWindowToken atoken = mAppToken;
7453 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7454 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7455 && !mExiting && !mDestroying;
7456 }
7457
7458 /**
7459 * The same as isVisible(), but follows the current hidden state of
7460 * the associated app token, not the pending requested hidden state.
7461 */
7462 boolean isVisibleNow() {
7463 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007464 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 }
7466
7467 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007468 * Can this window possibly be a drag/drop target? The test here is
7469 * a combination of the above "visible now" with the check that the
7470 * Input Manager uses when discarding windows from input consideration.
7471 */
7472 boolean isPotentialDragTarget() {
7473 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7474 }
7475
7476 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 * Same as isVisible(), but we also count it as visible between the
7478 * call to IWindowSession.add() and the first relayout().
7479 */
7480 boolean isVisibleOrAdding() {
7481 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007482 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7484 && mPolicyVisibility && !mAttachedHidden
7485 && (atoken == null || !atoken.hiddenRequested)
7486 && !mExiting && !mDestroying;
7487 }
7488
7489 /**
7490 * Is this window currently on-screen? It is on-screen either if it
7491 * is visible or it is currently running an animation before no longer
7492 * being visible.
7493 */
7494 boolean isOnScreen() {
7495 final AppWindowToken atoken = mAppToken;
7496 if (atoken != null) {
7497 return mSurface != null && mPolicyVisibility && !mDestroying
7498 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007499 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 } else {
7501 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007502 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 }
7504 }
Romain Guy06882f82009-06-10 13:36:04 -07007505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007506 /**
7507 * Like isOnScreen(), but we don't return true if the window is part
7508 * of a transition that has not yet been started.
7509 */
7510 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007511 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007512 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007513 return false;
7514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007516 final boolean animating = atoken != null
7517 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007519 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7520 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007521 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 }
7523
7524 /** Is the window or its container currently animating? */
7525 boolean isAnimating() {
7526 final WindowState attached = mAttachedWindow;
7527 final AppWindowToken atoken = mAppToken;
7528 return mAnimation != null
7529 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007530 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 (atoken.animation != null
7532 || atoken.inPendingTransaction));
7533 }
7534
7535 /** Is this window currently animating? */
7536 boolean isWindowAnimating() {
7537 return mAnimation != null;
7538 }
7539
7540 /**
7541 * Like isOnScreen, but returns false if the surface hasn't yet
7542 * been drawn.
7543 */
7544 public boolean isDisplayedLw() {
7545 final AppWindowToken atoken = mAppToken;
7546 return mSurface != null && mPolicyVisibility && !mDestroying
7547 && !mDrawPending && !mCommitDrawPending
7548 && ((!mAttachedHidden &&
7549 (atoken == null || !atoken.hiddenRequested))
7550 || mAnimating);
7551 }
7552
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007553 /**
7554 * Returns true if the window has a surface that it has drawn a
7555 * complete UI in to.
7556 */
7557 public boolean isDrawnLw() {
7558 final AppWindowToken atoken = mAppToken;
7559 return mSurface != null && !mDestroying
7560 && !mDrawPending && !mCommitDrawPending;
7561 }
7562
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007563 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007564 * Return true if the window is opaque and fully drawn. This indicates
7565 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007566 */
7567 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007568 return (mAttrs.format == PixelFormat.OPAQUE
7569 || mAttrs.type == TYPE_WALLPAPER)
7570 && mSurface != null && mAnimation == null
7571 && (mAppToken == null || mAppToken.animation == null)
7572 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007573 }
7574
7575 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7576 return
7577 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007578 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7579 // only if it's visible
7580 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007581 // and only if the application fills the compatible screen
7582 mFrame.left <= mCompatibleScreenFrame.left &&
7583 mFrame.top <= mCompatibleScreenFrame.top &&
7584 mFrame.right >= mCompatibleScreenFrame.right &&
7585 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007586 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007587 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007588 }
7589
7590 boolean isFullscreen(int screenWidth, int screenHeight) {
7591 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007592 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 }
7594
7595 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007596 disposeInputChannel();
7597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598 if (mAttachedWindow != null) {
7599 mAttachedWindow.mChildWindows.remove(this);
7600 }
7601 destroySurfaceLocked();
7602 mSession.windowRemovedLocked();
7603 try {
7604 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7605 } catch (RuntimeException e) {
7606 // Ignore if it has already been removed (usually because
7607 // we are doing this as part of processing a death note.)
7608 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007609 }
7610
7611 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007612 if (mInputChannel != null) {
7613 mInputManager.unregisterInputChannel(mInputChannel);
7614
7615 mInputChannel.dispose();
7616 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007617 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 }
7619
7620 private class DeathRecipient implements IBinder.DeathRecipient {
7621 public void binderDied() {
7622 try {
7623 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007624 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007625 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 if (win != null) {
7627 removeWindowLocked(mSession, win);
7628 }
7629 }
7630 } catch (IllegalArgumentException ex) {
7631 // This will happen if the window has already been
7632 // removed.
7633 }
7634 }
7635 }
7636
7637 /** Returns true if this window desires key events. */
7638 public final boolean canReceiveKeys() {
7639 return isVisibleOrAdding()
7640 && (mViewVisibility == View.VISIBLE)
7641 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7642 }
7643
7644 public boolean hasDrawnLw() {
7645 return mHasDrawn;
7646 }
7647
7648 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007649 return showLw(doAnimation, true);
7650 }
7651
7652 boolean showLw(boolean doAnimation, boolean requestAnim) {
7653 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7654 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007655 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007656 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007657 if (doAnimation) {
7658 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7659 + mPolicyVisibility + " mAnimation=" + mAnimation);
7660 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7661 doAnimation = false;
7662 } else if (mPolicyVisibility && mAnimation == null) {
7663 // Check for the case where we are currently visible and
7664 // not animating; we do not want to do animation at such a
7665 // point to become visible when we already are.
7666 doAnimation = false;
7667 }
7668 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007669 mPolicyVisibility = true;
7670 mPolicyVisibilityAfterAnim = true;
7671 if (doAnimation) {
7672 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7673 }
7674 if (requestAnim) {
7675 requestAnimationLocked(0);
7676 }
7677 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 }
7679
7680 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007681 return hideLw(doAnimation, true);
7682 }
7683
7684 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007685 if (doAnimation) {
7686 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7687 doAnimation = false;
7688 }
7689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7691 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007692 if (!current) {
7693 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007695 if (doAnimation) {
7696 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7697 if (mAnimation == null) {
7698 doAnimation = false;
7699 }
7700 }
7701 if (doAnimation) {
7702 mPolicyVisibilityAfterAnim = false;
7703 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007704 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007705 mPolicyVisibilityAfterAnim = false;
7706 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007707 // Window is no longer visible -- make sure if we were waiting
7708 // for it to be displayed before enabling the display, that
7709 // we allow the display to be enabled now.
7710 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007711 if (mCurrentFocus == this) {
7712 mFocusMayChange = true;
7713 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007714 }
7715 if (requestAnim) {
7716 requestAnimationLocked(0);
7717 }
7718 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 }
7720
7721 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007722 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7723 pw.print(" mClient="); pw.println(mClient.asBinder());
7724 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7725 if (mAttachedWindow != null || mLayoutAttached) {
7726 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7727 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7728 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007729 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7730 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7731 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007732 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7733 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007734 }
7735 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7736 pw.print(" mSubLayer="); pw.print(mSubLayer);
7737 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7738 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7739 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7740 pw.print("="); pw.print(mAnimLayer);
7741 pw.print(" mLastLayer="); pw.println(mLastLayer);
7742 if (mSurface != null) {
7743 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007744 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7745 pw.print(" layer="); pw.print(mSurfaceLayer);
7746 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7747 pw.print(" rect=("); pw.print(mSurfaceX);
7748 pw.print(","); pw.print(mSurfaceY);
7749 pw.print(") "); pw.print(mSurfaceW);
7750 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007751 }
7752 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7753 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7754 if (mAppToken != null) {
7755 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7756 }
7757 if (mTargetAppToken != null) {
7758 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7759 }
7760 pw.print(prefix); pw.print("mViewVisibility=0x");
7761 pw.print(Integer.toHexString(mViewVisibility));
7762 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007763 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7764 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007765 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7766 pw.print(prefix); pw.print("mPolicyVisibility=");
7767 pw.print(mPolicyVisibility);
7768 pw.print(" mPolicyVisibilityAfterAnim=");
7769 pw.print(mPolicyVisibilityAfterAnim);
7770 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7771 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007772 if (!mRelayoutCalled) {
7773 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7774 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007775 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007776 pw.print(" h="); pw.print(mRequestedHeight);
7777 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007778 if (mXOffset != 0 || mYOffset != 0) {
7779 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7780 pw.print(" y="); pw.println(mYOffset);
7781 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007782 pw.print(prefix); pw.print("mGivenContentInsets=");
7783 mGivenContentInsets.printShortString(pw);
7784 pw.print(" mGivenVisibleInsets=");
7785 mGivenVisibleInsets.printShortString(pw);
7786 pw.println();
7787 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7788 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7789 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7790 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007791 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007792 pw.print(prefix); pw.print("mShownFrame=");
7793 mShownFrame.printShortString(pw);
7794 pw.print(" last="); mLastShownFrame.printShortString(pw);
7795 pw.println();
7796 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7797 pw.print(" last="); mLastFrame.printShortString(pw);
7798 pw.println();
7799 pw.print(prefix); pw.print("mContainingFrame=");
7800 mContainingFrame.printShortString(pw);
7801 pw.print(" mDisplayFrame=");
7802 mDisplayFrame.printShortString(pw);
7803 pw.println();
7804 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7805 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7806 pw.println();
7807 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7808 pw.print(" last="); mLastContentInsets.printShortString(pw);
7809 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7810 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7811 pw.println();
7812 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7813 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7814 pw.print(" mAlpha="); pw.print(mAlpha);
7815 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7816 }
7817 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7818 || mAnimation != null) {
7819 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7820 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7821 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7822 pw.print(" mAnimation="); pw.println(mAnimation);
7823 }
7824 if (mHasTransformation || mHasLocalTransformation) {
7825 pw.print(prefix); pw.print("XForm: has=");
7826 pw.print(mHasTransformation);
7827 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7828 pw.print(" "); mTransformation.printShortString(pw);
7829 pw.println();
7830 }
7831 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7832 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7833 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7834 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7835 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7836 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7837 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7838 pw.print(" mDestroying="); pw.print(mDestroying);
7839 pw.print(" mRemoved="); pw.println(mRemoved);
7840 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007841 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007842 pw.print(prefix); pw.print("mOrientationChanging=");
7843 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007844 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7845 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007846 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007847 if (mHScale != 1 || mVScale != 1) {
7848 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7849 pw.print(" mVScale="); pw.println(mVScale);
7850 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007851 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007852 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7853 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7854 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007855 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7856 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7857 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7858 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007859 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007860
7861 String makeInputChannelName() {
7862 return Integer.toHexString(System.identityHashCode(this))
7863 + " " + mAttrs.getTitle();
7864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007865
7866 @Override
7867 public String toString() {
7868 return "Window{"
7869 + Integer.toHexString(System.identityHashCode(this))
7870 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7871 }
7872 }
Romain Guy06882f82009-06-10 13:36:04 -07007873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007874 // -------------------------------------------------------------
7875 // Window Token State
7876 // -------------------------------------------------------------
7877
7878 class WindowToken {
7879 // The actual token.
7880 final IBinder token;
7881
7882 // The type of window this token is for, as per WindowManager.LayoutParams.
7883 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 // Set if this token was explicitly added by a client, so should
7886 // not be removed when all windows are removed.
7887 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007888
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007889 // For printing.
7890 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007892 // If this is an AppWindowToken, this is non-null.
7893 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 // All of the windows associated with this token.
7896 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7897
7898 // Is key dispatching paused for this token?
7899 boolean paused = false;
7900
7901 // Should this token's windows be hidden?
7902 boolean hidden;
7903
7904 // Temporary for finding which tokens no longer have visible windows.
7905 boolean hasVisible;
7906
Dianne Hackborna8f60182009-09-01 19:01:50 -07007907 // Set to true when this token is in a pending transaction where it
7908 // will be shown.
7909 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007910
Dianne Hackborna8f60182009-09-01 19:01:50 -07007911 // Set to true when this token is in a pending transaction where it
7912 // will be hidden.
7913 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007914
Dianne Hackborna8f60182009-09-01 19:01:50 -07007915 // Set to true when this token is in a pending transaction where its
7916 // windows will be put to the bottom of the list.
7917 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007918
Dianne Hackborna8f60182009-09-01 19:01:50 -07007919 // Set to true when this token is in a pending transaction where its
7920 // windows will be put to the top of the list.
7921 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007923 WindowToken(IBinder _token, int type, boolean _explicit) {
7924 token = _token;
7925 windowType = type;
7926 explicit = _explicit;
7927 }
7928
7929 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007930 pw.print(prefix); pw.print("token="); pw.println(token);
7931 pw.print(prefix); pw.print("windows="); pw.println(windows);
7932 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7933 pw.print(" hidden="); pw.print(hidden);
7934 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007935 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7936 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7937 pw.print(" waitingToHide="); pw.print(waitingToHide);
7938 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7939 pw.print(" sendingToTop="); pw.println(sendingToTop);
7940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007941 }
7942
7943 @Override
7944 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007945 if (stringName == null) {
7946 StringBuilder sb = new StringBuilder();
7947 sb.append("WindowToken{");
7948 sb.append(Integer.toHexString(System.identityHashCode(this)));
7949 sb.append(" token="); sb.append(token); sb.append('}');
7950 stringName = sb.toString();
7951 }
7952 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 }
7954 };
7955
7956 class AppWindowToken extends WindowToken {
7957 // Non-null only for application tokens.
7958 final IApplicationToken appToken;
7959
7960 // All of the windows and child windows that are included in this
7961 // application token. Note this list is NOT sorted!
7962 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7963
7964 int groupId = -1;
7965 boolean appFullscreen;
7966 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007967
7968 // The input dispatching timeout for this application token in nanoseconds.
7969 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007971 // These are used for determining when all windows associated with
7972 // an activity have been drawn, so they can be made visible together
7973 // at the same time.
7974 int lastTransactionSequence = mTransactionSequence-1;
7975 int numInterestingWindows;
7976 int numDrawnWindows;
7977 boolean inPendingTransaction;
7978 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 // Is this token going to be hidden in a little while? If so, it
7981 // won't be taken into account for setting the screen orientation.
7982 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007984 // Is this window's surface needed? This is almost like hidden, except
7985 // it will sometimes be true a little earlier: when the token has
7986 // been shown, but is still waiting for its app transition to execute
7987 // before making its windows shown.
7988 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007990 // Have we told the window clients to hide themselves?
7991 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007993 // Last visibility state we reported to the app token.
7994 boolean reportedVisible;
7995
7996 // Set to true when the token has been removed from the window mgr.
7997 boolean removed;
7998
7999 // Have we been asked to have this token keep the screen frozen?
8000 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008002 boolean animating;
8003 Animation animation;
8004 boolean hasTransformation;
8005 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008007 // Offset to the window of all layers in the token, for use by
8008 // AppWindowToken animations.
8009 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011 // Information about an application starting window if displayed.
8012 StartingData startingData;
8013 WindowState startingWindow;
8014 View startingView;
8015 boolean startingDisplayed;
8016 boolean startingMoved;
8017 boolean firstWindowDrawn;
8018
8019 AppWindowToken(IApplicationToken _token) {
8020 super(_token.asBinder(),
8021 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8022 appWindowToken = this;
8023 appToken = _token;
8024 }
Romain Guy06882f82009-06-10 13:36:04 -07008025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008026 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008027 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 TAG, "Setting animation in " + this + ": " + anim);
8029 animation = anim;
8030 animating = false;
8031 anim.restrictDuration(MAX_ANIMATION_DURATION);
8032 anim.scaleCurrentDuration(mTransitionAnimationScale);
8033 int zorder = anim.getZAdjustment();
8034 int adj = 0;
8035 if (zorder == Animation.ZORDER_TOP) {
8036 adj = TYPE_LAYER_OFFSET;
8037 } else if (zorder == Animation.ZORDER_BOTTOM) {
8038 adj = -TYPE_LAYER_OFFSET;
8039 }
Romain Guy06882f82009-06-10 13:36:04 -07008040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008041 if (animLayerAdjustment != adj) {
8042 animLayerAdjustment = adj;
8043 updateLayers();
8044 }
8045 }
Romain Guy06882f82009-06-10 13:36:04 -07008046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 public void setDummyAnimation() {
8048 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008049 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 TAG, "Setting dummy animation in " + this);
8051 animation = sDummyAnimation;
8052 }
8053 }
8054
8055 public void clearAnimation() {
8056 if (animation != null) {
8057 animation = null;
8058 animating = true;
8059 }
8060 }
Romain Guy06882f82009-06-10 13:36:04 -07008061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 void updateLayers() {
8063 final int N = allAppWindows.size();
8064 final int adj = animLayerAdjustment;
8065 for (int i=0; i<N; i++) {
8066 WindowState w = allAppWindows.get(i);
8067 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008068 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 + w.mAnimLayer);
8070 if (w == mInputMethodTarget) {
8071 setInputMethodAnimLayerAdjustment(adj);
8072 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008073 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008074 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008075 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 }
8077 }
Romain Guy06882f82009-06-10 13:36:04 -07008078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008079 void sendAppVisibilityToClients() {
8080 final int N = allAppWindows.size();
8081 for (int i=0; i<N; i++) {
8082 WindowState win = allAppWindows.get(i);
8083 if (win == startingWindow && clientHidden) {
8084 // Don't hide the starting window.
8085 continue;
8086 }
8087 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008088 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 "Setting visibility of " + win + ": " + (!clientHidden));
8090 win.mClient.dispatchAppVisibility(!clientHidden);
8091 } catch (RemoteException e) {
8092 }
8093 }
8094 }
Romain Guy06882f82009-06-10 13:36:04 -07008095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008096 void showAllWindowsLocked() {
8097 final int NW = allAppWindows.size();
8098 for (int i=0; i<NW; i++) {
8099 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008100 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008101 "performing show on: " + w);
8102 w.performShowLocked();
8103 }
8104 }
Romain Guy06882f82009-06-10 13:36:04 -07008105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008106 // This must be called while inside a transaction.
8107 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008108 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008109 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 if (animation == sDummyAnimation) {
8112 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008113 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 // when it is really time to animate, this will be set to
8115 // a real animation and the next call will execute normally.
8116 return false;
8117 }
Romain Guy06882f82009-06-10 13:36:04 -07008118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8120 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008121 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008122 TAG, "Starting animation in " + this +
8123 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8124 + " scale=" + mTransitionAnimationScale
8125 + " allDrawn=" + allDrawn + " animating=" + animating);
8126 animation.initialize(dw, dh, dw, dh);
8127 animation.setStartTime(currentTime);
8128 animating = true;
8129 }
8130 transformation.clear();
8131 final boolean more = animation.getTransformation(
8132 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008133 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 TAG, "Stepped animation in " + this +
8135 ": more=" + more + ", xform=" + transformation);
8136 if (more) {
8137 // we're done!
8138 hasTransformation = true;
8139 return true;
8140 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008141 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008142 TAG, "Finished animation in " + this +
8143 " @ " + currentTime);
8144 animation = null;
8145 }
8146 } else if (animation != null) {
8147 // If the display is frozen, and there is a pending animation,
8148 // clear it and make sure we run the cleanup code.
8149 animating = true;
8150 animation = null;
8151 }
8152
8153 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008155 if (!animating) {
8156 return false;
8157 }
8158
8159 clearAnimation();
8160 animating = false;
8161 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8162 moveInputMethodWindowsIfNeededLocked(true);
8163 }
Romain Guy06882f82009-06-10 13:36:04 -07008164
Joe Onorato8a9b2202010-02-26 18:56:32 -08008165 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008166 TAG, "Animation done in " + this
8167 + ": reportedVisible=" + reportedVisible);
8168
8169 transformation.clear();
8170 if (animLayerAdjustment != 0) {
8171 animLayerAdjustment = 0;
8172 updateLayers();
8173 }
Romain Guy06882f82009-06-10 13:36:04 -07008174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 final int N = windows.size();
8176 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008177 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008178 }
8179 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008181 return false;
8182 }
8183
8184 void updateReportedVisibilityLocked() {
8185 if (appToken == null) {
8186 return;
8187 }
Romain Guy06882f82009-06-10 13:36:04 -07008188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 int numInteresting = 0;
8190 int numVisible = 0;
8191 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008192
Joe Onorato8a9b2202010-02-26 18:56:32 -08008193 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 final int N = allAppWindows.size();
8195 for (int i=0; i<N; i++) {
8196 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008197 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008198 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008199 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8200 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008201 continue;
8202 }
8203 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008204 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008205 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008207 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008208 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008209 + " pv=" + win.mPolicyVisibility
8210 + " dp=" + win.mDrawPending
8211 + " cdp=" + win.mCommitDrawPending
8212 + " ah=" + win.mAttachedHidden
8213 + " th="
8214 + (win.mAppToken != null
8215 ? win.mAppToken.hiddenRequested : false)
8216 + " a=" + win.mAnimating);
8217 }
8218 }
8219 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008220 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008221 if (!win.isAnimating()) {
8222 numVisible++;
8223 }
8224 nowGone = false;
8225 } else if (win.isAnimating()) {
8226 nowGone = false;
8227 }
8228 }
Romain Guy06882f82009-06-10 13:36:04 -07008229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008230 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008231 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008232 + numInteresting + " visible=" + numVisible);
8233 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008234 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008235 TAG, "Visibility changed in " + this
8236 + ": vis=" + nowVisible);
8237 reportedVisible = nowVisible;
8238 Message m = mH.obtainMessage(
8239 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8240 nowVisible ? 1 : 0,
8241 nowGone ? 1 : 0,
8242 this);
8243 mH.sendMessage(m);
8244 }
8245 }
Romain Guy06882f82009-06-10 13:36:04 -07008246
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008247 WindowState findMainWindow() {
8248 int j = windows.size();
8249 while (j > 0) {
8250 j--;
8251 WindowState win = windows.get(j);
8252 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8253 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8254 return win;
8255 }
8256 }
8257 return null;
8258 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008260 void dump(PrintWriter pw, String prefix) {
8261 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008262 if (appToken != null) {
8263 pw.print(prefix); pw.println("app=true");
8264 }
8265 if (allAppWindows.size() > 0) {
8266 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8267 }
8268 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008269 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008270 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8271 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8272 pw.print(" clientHidden="); pw.print(clientHidden);
8273 pw.print(" willBeHidden="); pw.print(willBeHidden);
8274 pw.print(" reportedVisible="); pw.println(reportedVisible);
8275 if (paused || freezingScreen) {
8276 pw.print(prefix); pw.print("paused="); pw.print(paused);
8277 pw.print(" freezingScreen="); pw.println(freezingScreen);
8278 }
8279 if (numInterestingWindows != 0 || numDrawnWindows != 0
8280 || inPendingTransaction || allDrawn) {
8281 pw.print(prefix); pw.print("numInterestingWindows=");
8282 pw.print(numInterestingWindows);
8283 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8284 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8285 pw.print(" allDrawn="); pw.println(allDrawn);
8286 }
8287 if (animating || animation != null) {
8288 pw.print(prefix); pw.print("animating="); pw.print(animating);
8289 pw.print(" animation="); pw.println(animation);
8290 }
8291 if (animLayerAdjustment != 0) {
8292 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8293 }
8294 if (hasTransformation) {
8295 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8296 pw.print(" transformation="); transformation.printShortString(pw);
8297 pw.println();
8298 }
8299 if (startingData != null || removed || firstWindowDrawn) {
8300 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8301 pw.print(" removed="); pw.print(removed);
8302 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8303 }
8304 if (startingWindow != null || startingView != null
8305 || startingDisplayed || startingMoved) {
8306 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8307 pw.print(" startingView="); pw.print(startingView);
8308 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8309 pw.print(" startingMoved"); pw.println(startingMoved);
8310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008311 }
8312
8313 @Override
8314 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008315 if (stringName == null) {
8316 StringBuilder sb = new StringBuilder();
8317 sb.append("AppWindowToken{");
8318 sb.append(Integer.toHexString(System.identityHashCode(this)));
8319 sb.append(" token="); sb.append(token); sb.append('}');
8320 stringName = sb.toString();
8321 }
8322 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008323 }
8324 }
Romain Guy06882f82009-06-10 13:36:04 -07008325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008326 // -------------------------------------------------------------
8327 // DummyAnimation
8328 // -------------------------------------------------------------
8329
8330 // This is an animation that does nothing: it just immediately finishes
8331 // itself every time it is called. It is used as a stub animation in cases
8332 // where we want to synchronize multiple things that may be animating.
8333 static final class DummyAnimation extends Animation {
8334 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8335 return false;
8336 }
8337 }
8338 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 // -------------------------------------------------------------
8341 // Async Handler
8342 // -------------------------------------------------------------
8343
8344 static final class StartingData {
8345 final String pkg;
8346 final int theme;
8347 final CharSequence nonLocalizedLabel;
8348 final int labelRes;
8349 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008351 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8352 int _labelRes, int _icon) {
8353 pkg = _pkg;
8354 theme = _theme;
8355 nonLocalizedLabel = _nonLocalizedLabel;
8356 labelRes = _labelRes;
8357 icon = _icon;
8358 }
8359 }
8360
8361 private final class H extends Handler {
8362 public static final int REPORT_FOCUS_CHANGE = 2;
8363 public static final int REPORT_LOSING_FOCUS = 3;
8364 public static final int ANIMATE = 4;
8365 public static final int ADD_STARTING = 5;
8366 public static final int REMOVE_STARTING = 6;
8367 public static final int FINISHED_STARTING = 7;
8368 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008369 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8370 public static final int HOLD_SCREEN_CHANGED = 12;
8371 public static final int APP_TRANSITION_TIMEOUT = 13;
8372 public static final int PERSIST_ANIMATION_SCALE = 14;
8373 public static final int FORCE_GC = 15;
8374 public static final int ENABLE_SCREEN = 16;
8375 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008376 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008377 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008378 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008379 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008381 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008383 public H() {
8384 }
Romain Guy06882f82009-06-10 13:36:04 -07008385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008386 @Override
8387 public void handleMessage(Message msg) {
8388 switch (msg.what) {
8389 case REPORT_FOCUS_CHANGE: {
8390 WindowState lastFocus;
8391 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008393 synchronized(mWindowMap) {
8394 lastFocus = mLastFocus;
8395 newFocus = mCurrentFocus;
8396 if (lastFocus == newFocus) {
8397 // Focus is not changing, so nothing to do.
8398 return;
8399 }
8400 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008401 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008402 // + " to " + newFocus);
8403 if (newFocus != null && lastFocus != null
8404 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008405 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 mLosingFocus.add(lastFocus);
8407 lastFocus = null;
8408 }
8409 }
8410
8411 if (lastFocus != newFocus) {
8412 //System.out.println("Changing focus from " + lastFocus
8413 // + " to " + newFocus);
8414 if (newFocus != null) {
8415 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008416 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8418 } catch (RemoteException e) {
8419 // Ignore if process has died.
8420 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008421 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008422 }
8423
8424 if (lastFocus != null) {
8425 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008426 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8428 } catch (RemoteException e) {
8429 // Ignore if process has died.
8430 }
8431 }
8432 }
8433 } break;
8434
8435 case REPORT_LOSING_FOCUS: {
8436 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438 synchronized(mWindowMap) {
8439 losers = mLosingFocus;
8440 mLosingFocus = new ArrayList<WindowState>();
8441 }
8442
8443 final int N = losers.size();
8444 for (int i=0; i<N; i++) {
8445 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008446 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8448 } catch (RemoteException e) {
8449 // Ignore if process has died.
8450 }
8451 }
8452 } break;
8453
8454 case ANIMATE: {
8455 synchronized(mWindowMap) {
8456 mAnimationPending = false;
8457 performLayoutAndPlaceSurfacesLocked();
8458 }
8459 } break;
8460
8461 case ADD_STARTING: {
8462 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8463 final StartingData sd = wtoken.startingData;
8464
8465 if (sd == null) {
8466 // Animation has been canceled... do nothing.
8467 return;
8468 }
Romain Guy06882f82009-06-10 13:36:04 -07008469
Joe Onorato8a9b2202010-02-26 18:56:32 -08008470 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008471 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008473 View view = null;
8474 try {
8475 view = mPolicy.addStartingWindow(
8476 wtoken.token, sd.pkg,
8477 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8478 sd.icon);
8479 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008480 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008481 }
8482
8483 if (view != null) {
8484 boolean abort = false;
8485
8486 synchronized(mWindowMap) {
8487 if (wtoken.removed || wtoken.startingData == null) {
8488 // If the window was successfully added, then
8489 // we need to remove it.
8490 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008491 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008492 "Aborted starting " + wtoken
8493 + ": removed=" + wtoken.removed
8494 + " startingData=" + wtoken.startingData);
8495 wtoken.startingWindow = null;
8496 wtoken.startingData = null;
8497 abort = true;
8498 }
8499 } else {
8500 wtoken.startingView = view;
8501 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008502 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 "Added starting " + wtoken
8504 + ": startingWindow="
8505 + wtoken.startingWindow + " startingView="
8506 + wtoken.startingView);
8507 }
8508
8509 if (abort) {
8510 try {
8511 mPolicy.removeStartingWindow(wtoken.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 }
8517 } break;
8518
8519 case REMOVE_STARTING: {
8520 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8521 IBinder token = null;
8522 View view = null;
8523 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008524 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 + wtoken + ": startingWindow="
8526 + wtoken.startingWindow + " startingView="
8527 + wtoken.startingView);
8528 if (wtoken.startingWindow != null) {
8529 view = wtoken.startingView;
8530 token = wtoken.token;
8531 wtoken.startingData = null;
8532 wtoken.startingView = null;
8533 wtoken.startingWindow = null;
8534 }
8535 }
8536 if (view != null) {
8537 try {
8538 mPolicy.removeStartingWindow(token, view);
8539 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008540 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 }
8542 }
8543 } break;
8544
8545 case FINISHED_STARTING: {
8546 IBinder token = null;
8547 View view = null;
8548 while (true) {
8549 synchronized (mWindowMap) {
8550 final int N = mFinishedStarting.size();
8551 if (N <= 0) {
8552 break;
8553 }
8554 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8555
Joe Onorato8a9b2202010-02-26 18:56:32 -08008556 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 "Finished starting " + wtoken
8558 + ": startingWindow=" + wtoken.startingWindow
8559 + " startingView=" + wtoken.startingView);
8560
8561 if (wtoken.startingWindow == null) {
8562 continue;
8563 }
8564
8565 view = wtoken.startingView;
8566 token = wtoken.token;
8567 wtoken.startingData = null;
8568 wtoken.startingView = null;
8569 wtoken.startingWindow = null;
8570 }
8571
8572 try {
8573 mPolicy.removeStartingWindow(token, view);
8574 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008575 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008576 }
8577 }
8578 } break;
8579
8580 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8581 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8582
8583 boolean nowVisible = msg.arg1 != 0;
8584 boolean nowGone = msg.arg2 != 0;
8585
8586 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008587 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 TAG, "Reporting visible in " + wtoken
8589 + " visible=" + nowVisible
8590 + " gone=" + nowGone);
8591 if (nowVisible) {
8592 wtoken.appToken.windowsVisible();
8593 } else {
8594 wtoken.appToken.windowsGone();
8595 }
8596 } catch (RemoteException ex) {
8597 }
8598 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008600 case WINDOW_FREEZE_TIMEOUT: {
8601 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008602 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603 int i = mWindows.size();
8604 while (i > 0) {
8605 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008606 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 if (w.mOrientationChanging) {
8608 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008609 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008610 }
8611 }
8612 performLayoutAndPlaceSurfacesLocked();
8613 }
8614 break;
8615 }
Romain Guy06882f82009-06-10 13:36:04 -07008616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617 case HOLD_SCREEN_CHANGED: {
8618 Session oldHold;
8619 Session newHold;
8620 synchronized (mWindowMap) {
8621 oldHold = mLastReportedHold;
8622 newHold = (Session)msg.obj;
8623 mLastReportedHold = newHold;
8624 }
Romain Guy06882f82009-06-10 13:36:04 -07008625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 if (oldHold != newHold) {
8627 try {
8628 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008629 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 "window",
8631 BatteryStats.WAKE_TYPE_WINDOW);
8632 }
8633 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008634 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008635 "window",
8636 BatteryStats.WAKE_TYPE_WINDOW);
8637 }
8638 } catch (RemoteException e) {
8639 }
8640 }
8641 break;
8642 }
Romain Guy06882f82009-06-10 13:36:04 -07008643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 case APP_TRANSITION_TIMEOUT: {
8645 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008646 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008647 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 "*** APP TRANSITION TIMEOUT");
8649 mAppTransitionReady = true;
8650 mAppTransitionTimeout = true;
8651 performLayoutAndPlaceSurfacesLocked();
8652 }
8653 }
8654 break;
8655 }
Romain Guy06882f82009-06-10 13:36:04 -07008656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008657 case PERSIST_ANIMATION_SCALE: {
8658 Settings.System.putFloat(mContext.getContentResolver(),
8659 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8660 Settings.System.putFloat(mContext.getContentResolver(),
8661 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8662 break;
8663 }
Romain Guy06882f82009-06-10 13:36:04 -07008664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008665 case FORCE_GC: {
8666 synchronized(mWindowMap) {
8667 if (mAnimationPending) {
8668 // If we are animating, don't do the gc now but
8669 // delay a bit so we don't interrupt the animation.
8670 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8671 2000);
8672 return;
8673 }
8674 // If we are currently rotating the display, it will
8675 // schedule a new message when done.
8676 if (mDisplayFrozen) {
8677 return;
8678 }
8679 mFreezeGcPending = 0;
8680 }
8681 Runtime.getRuntime().gc();
8682 break;
8683 }
Romain Guy06882f82009-06-10 13:36:04 -07008684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008685 case ENABLE_SCREEN: {
8686 performEnableScreen();
8687 break;
8688 }
Romain Guy06882f82009-06-10 13:36:04 -07008689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008690 case APP_FREEZE_TIMEOUT: {
8691 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008692 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 int i = mAppTokens.size();
8694 while (i > 0) {
8695 i--;
8696 AppWindowToken tok = mAppTokens.get(i);
8697 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008698 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008699 unsetAppFreezingScreenLocked(tok, true, true);
8700 }
8701 }
8702 }
8703 break;
8704 }
Romain Guy06882f82009-06-10 13:36:04 -07008705
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008706 case SEND_NEW_CONFIGURATION: {
8707 removeMessages(SEND_NEW_CONFIGURATION);
8708 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008709 break;
8710 }
Romain Guy06882f82009-06-10 13:36:04 -07008711
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008712 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008713 if (mWindowsChanged) {
8714 synchronized (mWindowMap) {
8715 mWindowsChanged = false;
8716 }
8717 notifyWindowsChanged();
8718 }
8719 break;
8720 }
8721
Christopher Tatea53146c2010-09-07 11:57:52 -07008722 case DRAG_START_TIMEOUT: {
8723 IBinder win = (IBinder)msg.obj;
8724 if (DEBUG_DRAG) {
8725 Slog.w(TAG, "Timeout starting drag by win " + win);
8726 }
8727 synchronized (mWindowMap) {
8728 // !!! TODO: ANR the app that has failed to start the drag in time
8729 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008730 mDragState.unregister();
8731 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008732 mDragState.reset();
8733 mDragState = null;
8734 }
8735 }
Chris Tated4533f142010-10-19 15:15:08 -07008736 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008737 }
8738
Chris Tated4533f142010-10-19 15:15:08 -07008739 case DRAG_END_TIMEOUT: {
8740 IBinder win = (IBinder)msg.obj;
8741 if (DEBUG_DRAG) {
8742 Slog.w(TAG, "Timeout ending drag to win " + win);
8743 }
8744 synchronized (mWindowMap) {
8745 // !!! TODO: ANR the drag-receiving app
8746 mDragState.mDragResult = false;
8747 mDragState.endDragLw();
8748 }
8749 break;
8750 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008751 }
8752 }
8753 }
8754
8755 // -------------------------------------------------------------
8756 // IWindowManager API
8757 // -------------------------------------------------------------
8758
8759 public IWindowSession openSession(IInputMethodClient client,
8760 IInputContext inputContext) {
8761 if (client == null) throw new IllegalArgumentException("null client");
8762 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008763 Session session = new Session(client, inputContext);
8764 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008765 }
8766
8767 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8768 synchronized (mWindowMap) {
8769 // The focus for the client is the window immediately below
8770 // where we would place the input method window.
8771 int idx = findDesiredInputMethodWindowIndexLocked(false);
8772 WindowState imFocus;
8773 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008774 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008775 if (imFocus != null) {
8776 if (imFocus.mSession.mClient != null &&
8777 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8778 return true;
8779 }
8780 }
8781 }
8782 }
8783 return false;
8784 }
Romain Guy06882f82009-06-10 13:36:04 -07008785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 // -------------------------------------------------------------
8787 // Internals
8788 // -------------------------------------------------------------
8789
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008790 final WindowState windowForClientLocked(Session session, IWindow client,
8791 boolean throwOnError) {
8792 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 }
Romain Guy06882f82009-06-10 13:36:04 -07008794
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008795 final WindowState windowForClientLocked(Session session, IBinder client,
8796 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008798 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008799 TAG, "Looking up client " + client + ": " + win);
8800 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008801 RuntimeException ex = new IllegalArgumentException(
8802 "Requested window " + client + " does not exist");
8803 if (throwOnError) {
8804 throw ex;
8805 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008806 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008807 return null;
8808 }
8809 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008810 RuntimeException ex = new IllegalArgumentException(
8811 "Requested window " + client + " is in session " +
8812 win.mSession + ", not " + session);
8813 if (throwOnError) {
8814 throw ex;
8815 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008816 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008817 return null;
8818 }
8819
8820 return win;
8821 }
8822
Dianne Hackborna8f60182009-09-01 19:01:50 -07008823 final void rebuildAppWindowListLocked() {
8824 int NW = mWindows.size();
8825 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008826 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008827 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008828
Dianne Hackborna8f60182009-09-01 19:01:50 -07008829 // First remove all existing app windows.
8830 i=0;
8831 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008832 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008833 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008834 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008835 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008836 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008837 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008838 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008839 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008840 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008841 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8842 && lastWallpaper == i-1) {
8843 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008844 }
8845 i++;
8846 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008847
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008848 // The wallpaper window(s) typically live at the bottom of the stack,
8849 // so skip them before adding app tokens.
8850 lastWallpaper++;
8851 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008852
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008853 // First add all of the exiting app tokens... these are no longer
8854 // in the main app list, but still have windows shown. We put them
8855 // in the back because now that the animation is over we no longer
8856 // will care about them.
8857 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008858 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008859 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8860 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008861
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008862 // And add in the still active app tokens in Z order.
8863 NT = mAppTokens.size();
8864 for (int j=0; j<NT; j++) {
8865 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008867
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008868 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008869 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008870 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008871 + " windows but added " + i);
8872 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008873 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 private final void assignLayersLocked() {
8876 int N = mWindows.size();
8877 int curBaseLayer = 0;
8878 int curLayer = 0;
8879 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008881 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008882 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008883 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8884 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 curLayer += WINDOW_LAYER_MULTIPLIER;
8886 w.mLayer = curLayer;
8887 } else {
8888 curBaseLayer = curLayer = w.mBaseLayer;
8889 w.mLayer = curLayer;
8890 }
8891 if (w.mTargetAppToken != null) {
8892 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8893 } else if (w.mAppToken != null) {
8894 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8895 } else {
8896 w.mAnimLayer = w.mLayer;
8897 }
8898 if (w.mIsImWindow) {
8899 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008900 } else if (w.mIsWallpaper) {
8901 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008902 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008903 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008904 + w.mAnimLayer);
8905 //System.out.println(
8906 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8907 }
8908 }
8909
8910 private boolean mInLayout = false;
8911 private final void performLayoutAndPlaceSurfacesLocked() {
8912 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008913 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008914 throw new RuntimeException("Recursive call!");
8915 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008916 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008917 return;
8918 }
8919
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008920 if (mWaitingForConfig) {
8921 // Our configuration has changed (most likely rotation), but we
8922 // don't yet have the complete configuration to report to
8923 // applications. Don't do any window layout until we have it.
8924 return;
8925 }
8926
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008927 if (mDisplay == null) {
8928 // Not yet initialized, nothing to do.
8929 return;
8930 }
8931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 boolean recoveringMemory = false;
8933 if (mForceRemoves != null) {
8934 recoveringMemory = true;
8935 // Wait a little it for things to settle down, and off we go.
8936 for (int i=0; i<mForceRemoves.size(); i++) {
8937 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008938 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008939 removeWindowInnerLocked(ws.mSession, ws);
8940 }
8941 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008942 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 Object tmp = new Object();
8944 synchronized (tmp) {
8945 try {
8946 tmp.wait(250);
8947 } catch (InterruptedException e) {
8948 }
8949 }
8950 }
Romain Guy06882f82009-06-10 13:36:04 -07008951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008952 mInLayout = true;
8953 try {
8954 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008956 int i = mPendingRemove.size()-1;
8957 if (i >= 0) {
8958 while (i >= 0) {
8959 WindowState w = mPendingRemove.get(i);
8960 removeWindowInnerLocked(w.mSession, w);
8961 i--;
8962 }
8963 mPendingRemove.clear();
8964
8965 mInLayout = false;
8966 assignLayersLocked();
8967 mLayoutNeeded = true;
8968 performLayoutAndPlaceSurfacesLocked();
8969
8970 } else {
8971 mInLayout = false;
8972 if (mLayoutNeeded) {
8973 requestAnimationLocked(0);
8974 }
8975 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008976 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008977 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8978 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008980 } catch (RuntimeException e) {
8981 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008982 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008983 }
8984 }
8985
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008986 private final int performLayoutLockedInner() {
8987 if (!mLayoutNeeded) {
8988 return 0;
8989 }
8990
8991 mLayoutNeeded = false;
8992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008993 final int dw = mDisplay.getWidth();
8994 final int dh = mDisplay.getHeight();
8995
8996 final int N = mWindows.size();
8997 int i;
8998
Joe Onorato8a9b2202010-02-26 18:56:32 -08008999 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009000 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9001
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009002 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009003
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009004 int seq = mLayoutSeq+1;
9005 if (seq < 0) seq = 0;
9006 mLayoutSeq = seq;
9007
9008 // First perform layout of any root windows (not attached
9009 // to another window).
9010 int topAttached = -1;
9011 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009012 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009013
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009014 // Don't do layout of a window if it is not visible, or
9015 // soon won't be visible, to avoid wasting time and funky
9016 // changes while a window is animating away.
9017 final AppWindowToken atoken = win.mAppToken;
9018 final boolean gone = win.mViewVisibility == View.GONE
9019 || !win.mRelayoutCalled
9020 || win.mRootToken.hidden
9021 || (atoken != null && atoken.hiddenRequested)
9022 || win.mAttachedHidden
9023 || win.mExiting || win.mDestroying;
9024
9025 if (!win.mLayoutAttached) {
9026 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9027 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9028 + " mLayoutAttached=" + win.mLayoutAttached);
9029 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9030 + win.mViewVisibility + " mRelayoutCalled="
9031 + win.mRelayoutCalled + " hidden="
9032 + win.mRootToken.hidden + " hiddenRequested="
9033 + (atoken != null && atoken.hiddenRequested)
9034 + " mAttachedHidden=" + win.mAttachedHidden);
9035 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009036
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009037 // If this view is GONE, then skip it -- keep the current
9038 // frame, and let the caller know so they can ignore it
9039 // if they want. (We do the normal layout for INVISIBLE
9040 // windows, since that means "perform layout as normal,
9041 // just don't display").
9042 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009043 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009044 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9045 win.mLayoutSeq = seq;
9046 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9047 + win.mFrame + " mContainingFrame="
9048 + win.mContainingFrame + " mDisplayFrame="
9049 + win.mDisplayFrame);
9050 } else {
9051 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009052 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009053 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009055
9056 // Now perform layout of attached windows, which usually
9057 // depend on the position of the window they are attached to.
9058 // XXX does not deal with windows that are attached to windows
9059 // that are themselves attached.
9060 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009061 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009062
9063 // If this view is GONE, then skip it -- keep the current
9064 // frame, and let the caller know so they can ignore it
9065 // if they want. (We do the normal layout for INVISIBLE
9066 // windows, since that means "perform layout as normal,
9067 // just don't display").
9068 if (win.mLayoutAttached) {
9069 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9070 + " mHaveFrame=" + win.mHaveFrame
9071 + " mViewVisibility=" + win.mViewVisibility
9072 + " mRelayoutCalled=" + win.mRelayoutCalled);
9073 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9074 || !win.mHaveFrame) {
9075 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9076 win.mLayoutSeq = seq;
9077 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9078 + win.mFrame + " mContainingFrame="
9079 + win.mContainingFrame + " mDisplayFrame="
9080 + win.mDisplayFrame);
9081 }
9082 }
9083 }
Jeff Brown349703e2010-06-22 01:27:15 -07009084
9085 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009086 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009087
9088 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009089 }
Romain Guy06882f82009-06-10 13:36:04 -07009090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009091 private final void performLayoutAndPlaceSurfacesLockedInner(
9092 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009093 if (mDisplay == null) {
9094 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9095 return;
9096 }
9097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009098 final long currentTime = SystemClock.uptimeMillis();
9099 final int dw = mDisplay.getWidth();
9100 final int dh = mDisplay.getHeight();
9101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009102 int i;
9103
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009104 if (mFocusMayChange) {
9105 mFocusMayChange = false;
9106 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9107 }
9108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 // Initialize state of exiting tokens.
9110 for (i=mExitingTokens.size()-1; i>=0; i--) {
9111 mExitingTokens.get(i).hasVisible = false;
9112 }
9113
9114 // Initialize state of exiting applications.
9115 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9116 mExitingAppTokens.get(i).hasVisible = false;
9117 }
9118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009119 boolean orientationChangeComplete = true;
9120 Session holdScreen = null;
9121 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009122 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123 boolean focusDisplayed = false;
9124 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009125 boolean createWatermark = false;
9126
9127 if (mFxSession == null) {
9128 mFxSession = new SurfaceSession();
9129 createWatermark = true;
9130 }
9131
9132 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133
9134 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009135
9136 if (createWatermark) {
9137 createWatermark();
9138 }
9139 if (mWatermark != null) {
9140 mWatermark.positionSurface(dw, dh);
9141 }
9142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009144 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009145 int repeats = 0;
9146 int changes = 0;
9147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009148 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009149 repeats++;
9150 if (repeats > 6) {
9151 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9152 mLayoutNeeded = false;
9153 break;
9154 }
9155
9156 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9157 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9158 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9159 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9160 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9161 assignLayersLocked();
9162 mLayoutNeeded = true;
9163 }
9164 }
9165 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9166 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9167 if (updateOrientationFromAppTokensLocked()) {
9168 mLayoutNeeded = true;
9169 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9170 }
9171 }
9172 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9173 mLayoutNeeded = true;
9174 }
9175 }
9176
9177 // FIRST LOOP: Perform a layout, if needed.
9178 if (repeats < 4) {
9179 changes = performLayoutLockedInner();
9180 if (changes != 0) {
9181 continue;
9182 }
9183 } else {
9184 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9185 changes = 0;
9186 }
9187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009188 final int transactionSequence = ++mTransactionSequence;
9189
9190 // Update animations of all applications, including those
9191 // associated with exiting/removed apps
9192 boolean tokensAnimating = false;
9193 final int NAT = mAppTokens.size();
9194 for (i=0; i<NAT; i++) {
9195 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9196 tokensAnimating = true;
9197 }
9198 }
9199 final int NEAT = mExitingAppTokens.size();
9200 for (i=0; i<NEAT; i++) {
9201 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9202 tokensAnimating = true;
9203 }
9204 }
9205
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009206 // SECOND LOOP: Execute animations and update visibility of windows.
9207
Joe Onorato8a9b2202010-02-26 18:56:32 -08009208 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009209 + transactionSequence + " tokensAnimating="
9210 + tokensAnimating);
9211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009213
9214 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009215 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009216 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217
9218 mPolicy.beginAnimationLw(dw, dh);
9219
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009220 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009223 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224
9225 final WindowManager.LayoutParams attrs = w.mAttrs;
9226
9227 if (w.mSurface != null) {
9228 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009229 if (w.commitFinishDrawingLocked(currentTime)) {
9230 if ((w.mAttrs.flags
9231 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009232 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009233 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009234 wallpaperMayChange = true;
9235 }
9236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009237
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009238 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9240 animating = true;
9241 //w.dump(" ");
9242 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009243 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9244 wallpaperMayChange = true;
9245 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009246
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009247 if (mPolicy.doesForceHide(w, attrs)) {
9248 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009249 if (DEBUG_VISIBILITY) Slog.v(TAG,
9250 "Animation done that could impact force hide: "
9251 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009252 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009253 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009254 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9255 forceHiding = true;
9256 }
9257 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9258 boolean changed;
9259 if (forceHiding) {
9260 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009261 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9262 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009263 } else {
9264 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009265 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9266 "Now policy shown: " + w);
9267 if (changed) {
9268 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009269 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009270 // Assume we will need to animate. If
9271 // we don't (because the wallpaper will
9272 // stay with the lock screen), then we will
9273 // clean up later.
9274 Animation a = mPolicy.createForceHideEnterAnimation();
9275 if (a != null) {
9276 w.setAnimation(a);
9277 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009278 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009279 if (mCurrentFocus == null ||
9280 mCurrentFocus.mLayer < w.mLayer) {
9281 // We are showing on to of the current
9282 // focus, so re-evaluate focus to make
9283 // sure it is correct.
9284 mFocusMayChange = true;
9285 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009286 }
9287 }
9288 if (changed && (attrs.flags
9289 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9290 wallpaperMayChange = true;
9291 }
9292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009294 mPolicy.animatingWindowLw(w, attrs);
9295 }
9296
9297 final AppWindowToken atoken = w.mAppToken;
9298 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9299 if (atoken.lastTransactionSequence != transactionSequence) {
9300 atoken.lastTransactionSequence = transactionSequence;
9301 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9302 atoken.startingDisplayed = false;
9303 }
9304 if ((w.isOnScreen() || w.mAttrs.type
9305 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9306 && !w.mExiting && !w.mDestroying) {
9307 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009308 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009309 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009310 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009311 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009312 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009313 + " pv=" + w.mPolicyVisibility
9314 + " dp=" + w.mDrawPending
9315 + " cdp=" + w.mCommitDrawPending
9316 + " ah=" + w.mAttachedHidden
9317 + " th=" + atoken.hiddenRequested
9318 + " a=" + w.mAnimating);
9319 }
9320 }
9321 if (w != atoken.startingWindow) {
9322 if (!atoken.freezingScreen || !w.mAppFreezing) {
9323 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009324 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009325 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009326 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 "tokenMayBeDrawn: " + atoken
9328 + " freezingScreen=" + atoken.freezingScreen
9329 + " mAppFreezing=" + w.mAppFreezing);
9330 tokenMayBeDrawn = true;
9331 }
9332 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009333 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009334 atoken.startingDisplayed = true;
9335 }
9336 }
9337 } else if (w.mReadyToShow) {
9338 w.performShowLocked();
9339 }
9340 }
9341
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009342 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009343
9344 if (tokenMayBeDrawn) {
9345 // See if any windows have been drawn, so they (and others
9346 // associated with them) can now be shown.
9347 final int NT = mTokenList.size();
9348 for (i=0; i<NT; i++) {
9349 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9350 if (wtoken == null) {
9351 continue;
9352 }
9353 if (wtoken.freezingScreen) {
9354 int numInteresting = wtoken.numInterestingWindows;
9355 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009356 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009357 "allDrawn: " + wtoken
9358 + " interesting=" + numInteresting
9359 + " drawn=" + wtoken.numDrawnWindows);
9360 wtoken.showAllWindowsLocked();
9361 unsetAppFreezingScreenLocked(wtoken, false, true);
9362 orientationChangeComplete = true;
9363 }
9364 } else if (!wtoken.allDrawn) {
9365 int numInteresting = wtoken.numInterestingWindows;
9366 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009367 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009368 "allDrawn: " + wtoken
9369 + " interesting=" + numInteresting
9370 + " drawn=" + wtoken.numDrawnWindows);
9371 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009372 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009373
9374 // We can now show all of the drawn windows!
9375 if (!mOpeningApps.contains(wtoken)) {
9376 wtoken.showAllWindowsLocked();
9377 }
9378 }
9379 }
9380 }
9381 }
9382
9383 // If we are ready to perform an app transition, check through
9384 // all of the app tokens to be shown and see if they are ready
9385 // to go.
9386 if (mAppTransitionReady) {
9387 int NN = mOpeningApps.size();
9388 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009389 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 "Checking " + NN + " opening apps (frozen="
9391 + mDisplayFrozen + " timeout="
9392 + mAppTransitionTimeout + ")...");
9393 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9394 // If the display isn't frozen, wait to do anything until
9395 // all of the apps are ready. Otherwise just go because
9396 // we'll unfreeze the display when everyone is ready.
9397 for (i=0; i<NN && goodToGo; i++) {
9398 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009399 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009400 "Check opening app" + wtoken + ": allDrawn="
9401 + wtoken.allDrawn + " startingDisplayed="
9402 + wtoken.startingDisplayed);
9403 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9404 && !wtoken.startingMoved) {
9405 goodToGo = false;
9406 }
9407 }
9408 }
9409 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009410 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 int transit = mNextAppTransition;
9412 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009413 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009414 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009415 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009416 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009417 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009418 mAppTransitionTimeout = false;
9419 mStartingIconInTransition = false;
9420 mSkipAppTransitionAnimation = false;
9421
9422 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9423
Dianne Hackborna8f60182009-09-01 19:01:50 -07009424 // If there are applications waiting to come to the
9425 // top of the stack, now is the time to move their windows.
9426 // (Note that we don't do apps going to the bottom
9427 // here -- we want to keep their windows in the old
9428 // Z-order until the animation completes.)
9429 if (mToTopApps.size() > 0) {
9430 NN = mAppTokens.size();
9431 for (i=0; i<NN; i++) {
9432 AppWindowToken wtoken = mAppTokens.get(i);
9433 if (wtoken.sendingToTop) {
9434 wtoken.sendingToTop = false;
9435 moveAppWindowsLocked(wtoken, NN, false);
9436 }
9437 }
9438 mToTopApps.clear();
9439 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009440
Dianne Hackborn25994b42009-09-04 14:21:19 -07009441 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009442
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009443 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009444 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009445
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009446 // The top-most window will supply the layout params,
9447 // and we will determine it below.
9448 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009449 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009450 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009451
Joe Onorato8a9b2202010-02-26 18:56:32 -08009452 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009453 "New wallpaper target=" + mWallpaperTarget
9454 + ", lower target=" + mLowerWallpaperTarget
9455 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009456 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009457 // Do a first pass through the tokens for two
9458 // things:
9459 // (1) Determine if both the closing and opening
9460 // app token sets are wallpaper targets, in which
9461 // case special animations are needed
9462 // (since the wallpaper needs to stay static
9463 // behind them).
9464 // (2) Find the layout params of the top-most
9465 // application window in the tokens, which is
9466 // what will control the animation theme.
9467 final int NC = mClosingApps.size();
9468 NN = NC + mOpeningApps.size();
9469 for (i=0; i<NN; i++) {
9470 AppWindowToken wtoken;
9471 int mode;
9472 if (i < NC) {
9473 wtoken = mClosingApps.get(i);
9474 mode = 1;
9475 } else {
9476 wtoken = mOpeningApps.get(i-NC);
9477 mode = 2;
9478 }
9479 if (mLowerWallpaperTarget != null) {
9480 if (mLowerWallpaperTarget.mAppToken == wtoken
9481 || mUpperWallpaperTarget.mAppToken == wtoken) {
9482 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009483 }
9484 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009485 if (wtoken.appFullscreen) {
9486 WindowState ws = wtoken.findMainWindow();
9487 if (ws != null) {
9488 // If this is a compatibility mode
9489 // window, we will always use its anim.
9490 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9491 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009492 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009493 bestAnimLayer = Integer.MAX_VALUE;
9494 } else if (ws.mLayer > bestAnimLayer) {
9495 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009496 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009497 bestAnimLayer = ws.mLayer;
9498 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009499 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009500 }
9501 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009502
Dianne Hackborn25994b42009-09-04 14:21:19 -07009503 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009504 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009505 "Wallpaper animation!");
9506 switch (transit) {
9507 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9508 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9509 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9510 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9511 break;
9512 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9513 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9514 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9515 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9516 break;
9517 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009518 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009519 "New transit: " + transit);
9520 } else if (oldWallpaper != null) {
9521 // We are transitioning from an activity with
9522 // a wallpaper to one without.
9523 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009524 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009525 "New transit away from wallpaper: " + transit);
9526 } else if (mWallpaperTarget != null) {
9527 // We are transitioning from an activity without
9528 // a wallpaper to now showing the wallpaper
9529 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009530 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009531 "New transit into wallpaper: " + transit);
9532 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009533
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009534 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9535 mLastEnterAnimToken = animToken;
9536 mLastEnterAnimParams = animLp;
9537 } else if (mLastEnterAnimParams != null) {
9538 animLp = mLastEnterAnimParams;
9539 mLastEnterAnimToken = null;
9540 mLastEnterAnimParams = null;
9541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009542
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009543 // If all closing windows are obscured, then there is
9544 // no need to do an animation. This is the case, for
9545 // example, when this transition is being done behind
9546 // the lock screen.
9547 if (!mPolicy.allowAppAnimationsLw()) {
9548 animLp = null;
9549 }
9550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 NN = mOpeningApps.size();
9552 for (i=0; i<NN; i++) {
9553 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009554 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 "Now opening app" + wtoken);
9556 wtoken.reportedVisible = false;
9557 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009558 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009559 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009561 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562 wtoken.showAllWindowsLocked();
9563 }
9564 NN = mClosingApps.size();
9565 for (i=0; i<NN; i++) {
9566 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009567 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009568 "Now closing app" + wtoken);
9569 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009570 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009571 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009573 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009574 // Force the allDrawn flag, because we want to start
9575 // this guy's animations regardless of whether it's
9576 // gotten drawn.
9577 wtoken.allDrawn = true;
9578 }
9579
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009580 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009582 mOpeningApps.clear();
9583 mClosingApps.clear();
9584
9585 // This has changed the visibility of windows, so perform
9586 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009587 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009589 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9590 assignLayersLocked();
9591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009592 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009593 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594 }
9595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009596
Dianne Hackborn16064f92010-03-25 00:47:24 -07009597 int adjResult = 0;
9598
Dianne Hackborna8f60182009-09-01 19:01:50 -07009599 if (!animating && mAppTransitionRunning) {
9600 // We have finished the animation of an app transition. To do
9601 // this, we have delayed a lot of operations like showing and
9602 // hiding apps, moving apps in Z-order, etc. The app token list
9603 // reflects the correct Z-order, but the window list may now
9604 // be out of sync with it. So here we will just rebuild the
9605 // entire app window list. Fun!
9606 mAppTransitionRunning = false;
9607 // Clear information about apps that were moving.
9608 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009609
Dianne Hackborna8f60182009-09-01 19:01:50 -07009610 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009611 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009612 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009613 moveInputMethodWindowsIfNeededLocked(false);
9614 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009615 // Since the window list has been rebuilt, focus might
9616 // have to be recomputed since the actual order of windows
9617 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009618 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009620
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009621 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009622 // At this point, there was a window with a wallpaper that
9623 // was force hiding other windows behind it, but now it
9624 // is going away. This may be simple -- just animate
9625 // away the wallpaper and its window -- or it may be
9626 // hard -- the wallpaper now needs to be shown behind
9627 // something that was hidden.
9628 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009629 if (mLowerWallpaperTarget != null
9630 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009631 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009632 "wallpaperForceHiding changed with lower="
9633 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009634 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009635 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9636 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9637 if (mLowerWallpaperTarget.mAppToken.hidden) {
9638 // The lower target has become hidden before we
9639 // actually started the animation... let's completely
9640 // re-evaluate everything.
9641 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009642 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009643 }
9644 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009645 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009646 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009647 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009648 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009649 + " NEW: " + mWallpaperTarget
9650 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009651 if (mLowerWallpaperTarget == null) {
9652 // Whoops, we don't need a special wallpaper animation.
9653 // Clear them out.
9654 forceHiding = false;
9655 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009656 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009657 if (w.mSurface != null) {
9658 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009659 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009660 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009661 forceHiding = true;
9662 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9663 if (!w.mAnimating) {
9664 // We set the animation above so it
9665 // is not yet running.
9666 w.clearAnimation();
9667 }
9668 }
9669 }
9670 }
9671 }
9672 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009673
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009674 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009675 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009676 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009677 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009679
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009680 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009681 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009682 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009683 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009684 assignLayersLocked();
9685 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009686 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009687 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009688 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009689 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009690
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009691 if (mFocusMayChange) {
9692 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009693 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009694 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009695 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009696 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009697 }
9698
9699 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009700 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009702
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009703 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9704 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009705
Jeff Browne33348b2010-07-15 23:54:05 -07009706 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009707 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009708
9709 // THIRD LOOP: Update the surfaces of all windows.
9710
9711 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9712
9713 boolean obscured = false;
9714 boolean blurring = false;
9715 boolean dimming = false;
9716 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009717 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009718 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009720 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009722 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009723 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009724
9725 boolean displayed = false;
9726 final WindowManager.LayoutParams attrs = w.mAttrs;
9727 final int attrFlags = attrs.flags;
9728
9729 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009730 // XXX NOTE: The logic here could be improved. We have
9731 // the decision about whether to resize a window separated
9732 // from whether to hide the surface. This can cause us to
9733 // resize a surface even if we are going to hide it. You
9734 // can see this by (1) holding device in landscape mode on
9735 // home screen; (2) tapping browser icon (device will rotate
9736 // to landscape; (3) tap home. The wallpaper will be resized
9737 // in step 2 but then immediately hidden, causing us to
9738 // have to resize and then redraw it again in step 3. It
9739 // would be nice to figure out how to avoid this, but it is
9740 // difficult because we do need to resize surfaces in some
9741 // cases while they are hidden such as when first showing a
9742 // window.
9743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009744 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009745 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 TAG, "Placing surface #" + i + " " + w.mSurface
9747 + ": new=" + w.mShownFrame + ", old="
9748 + w.mLastShownFrame);
9749
9750 boolean resize;
9751 int width, height;
9752 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9753 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9754 w.mLastRequestedHeight != w.mRequestedHeight;
9755 // for a scaled surface, we just want to use
9756 // the requested size.
9757 width = w.mRequestedWidth;
9758 height = w.mRequestedHeight;
9759 w.mLastRequestedWidth = width;
9760 w.mLastRequestedHeight = height;
9761 w.mLastShownFrame.set(w.mShownFrame);
9762 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009763 if (SHOW_TRANSACTIONS) logSurface(w,
9764 "POS " + w.mShownFrame.left
9765 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009766 w.mSurfaceX = w.mShownFrame.left;
9767 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009768 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9769 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009770 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009771 if (!recoveringMemory) {
9772 reclaimSomeSurfaceMemoryLocked(w, "position");
9773 }
9774 }
9775 } else {
9776 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9777 width = w.mShownFrame.width();
9778 height = w.mShownFrame.height();
9779 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009780 }
9781
9782 if (resize) {
9783 if (width < 1) width = 1;
9784 if (height < 1) height = 1;
9785 if (w.mSurface != null) {
9786 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009787 if (SHOW_TRANSACTIONS) logSurface(w,
9788 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009789 + w.mShownFrame.top + " SIZE "
9790 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009791 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009792 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009793 w.mSurfaceW = width;
9794 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009796 w.mSurfaceX = w.mShownFrame.left;
9797 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009798 w.mSurface.setPosition(w.mShownFrame.left,
9799 w.mShownFrame.top);
9800 } catch (RuntimeException e) {
9801 // If something goes wrong with the surface (such
9802 // as running out of memory), don't take down the
9803 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009804 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 + "size=(" + width + "x" + height
9806 + "), pos=(" + w.mShownFrame.left
9807 + "," + w.mShownFrame.top + ")", e);
9808 if (!recoveringMemory) {
9809 reclaimSomeSurfaceMemoryLocked(w, "size");
9810 }
9811 }
9812 }
9813 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009814 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 w.mContentInsetsChanged =
9816 !w.mLastContentInsets.equals(w.mContentInsets);
9817 w.mVisibleInsetsChanged =
9818 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009819 boolean configChanged =
9820 w.mConfiguration != mCurConfiguration
9821 && (w.mConfiguration == null
9822 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009823 if (DEBUG_CONFIGURATION && configChanged) {
9824 Slog.v(TAG, "Win " + w + " config changed: "
9825 + mCurConfiguration);
9826 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009827 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009828 + ": configChanged=" + configChanged
9829 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009830 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009831 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009832 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009833 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009834 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009835 w.mLastFrame.set(w.mFrame);
9836 w.mLastContentInsets.set(w.mContentInsets);
9837 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009838 // If the screen is currently frozen, then keep
9839 // it frozen until this window draws at its new
9840 // orientation.
9841 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009842 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009843 "Resizing while display frozen: " + w);
9844 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009845 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009846 mWindowsFreezingScreen = true;
9847 // XXX should probably keep timeout from
9848 // when we first froze the display.
9849 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9850 mH.sendMessageDelayed(mH.obtainMessage(
9851 H.WINDOW_FREEZE_TIMEOUT), 2000);
9852 }
9853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009854 // If the orientation is changing, then we need to
9855 // hold off on unfreezing the display until this
9856 // window has been redrawn; to do that, we need
9857 // to go through the process of getting informed
9858 // by the application when it has finished drawing.
9859 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009860 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861 "Orientation start waiting for draw in "
9862 + w + ", surface " + w.mSurface);
9863 w.mDrawPending = true;
9864 w.mCommitDrawPending = false;
9865 w.mReadyToShow = false;
9866 if (w.mAppToken != null) {
9867 w.mAppToken.allDrawn = false;
9868 }
9869 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009870 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009871 "Resizing window " + w + " to " + w.mFrame);
9872 mResizingWindows.add(w);
9873 } else if (w.mOrientationChanging) {
9874 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009875 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876 "Orientation not waiting for draw in "
9877 + w + ", surface " + w.mSurface);
9878 w.mOrientationChanging = false;
9879 }
9880 }
9881 }
9882
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009883 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009884 if (!w.mLastHidden) {
9885 //dump();
9886 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009887 if (SHOW_TRANSACTIONS) logSurface(w,
9888 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009890 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891 try {
9892 w.mSurface.hide();
9893 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009894 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009895 }
9896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009897 }
9898 // If we are waiting for this window to handle an
9899 // orientation change, well, it is hidden, so
9900 // doesn't really matter. Note that this does
9901 // introduce a potential glitch if the window
9902 // becomes unhidden before it has drawn for the
9903 // new orientation.
9904 if (w.mOrientationChanging) {
9905 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009906 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009907 "Orientation change skips hidden " + w);
9908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 } else if (w.mLastLayer != w.mAnimLayer
9910 || w.mLastAlpha != w.mShownAlpha
9911 || w.mLastDsDx != w.mDsDx
9912 || w.mLastDtDx != w.mDtDx
9913 || w.mLastDsDy != w.mDsDy
9914 || w.mLastDtDy != w.mDtDy
9915 || w.mLastHScale != w.mHScale
9916 || w.mLastVScale != w.mVScale
9917 || w.mLastHidden) {
9918 displayed = true;
9919 w.mLastAlpha = w.mShownAlpha;
9920 w.mLastLayer = w.mAnimLayer;
9921 w.mLastDsDx = w.mDsDx;
9922 w.mLastDtDx = w.mDtDx;
9923 w.mLastDsDy = w.mDsDy;
9924 w.mLastDtDy = w.mDtDy;
9925 w.mLastHScale = w.mHScale;
9926 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009927 if (SHOW_TRANSACTIONS) logSurface(w,
9928 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009929 + " matrix=[" + (w.mDsDx*w.mHScale)
9930 + "," + (w.mDtDx*w.mVScale)
9931 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009932 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 if (w.mSurface != null) {
9934 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009935 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009937 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009938 w.mSurface.setLayer(w.mAnimLayer);
9939 w.mSurface.setMatrix(
9940 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9941 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9942 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009943 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 if (!recoveringMemory) {
9945 reclaimSomeSurfaceMemoryLocked(w, "update");
9946 }
9947 }
9948 }
9949
9950 if (w.mLastHidden && !w.mDrawPending
9951 && !w.mCommitDrawPending
9952 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009953 if (SHOW_TRANSACTIONS) logSurface(w,
9954 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009955 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009956 + " during relayout");
9957 if (showSurfaceRobustlyLocked(w)) {
9958 w.mHasDrawn = true;
9959 w.mLastHidden = false;
9960 } else {
9961 w.mOrientationChanging = false;
9962 }
9963 }
9964 if (w.mSurface != null) {
9965 w.mToken.hasVisible = true;
9966 }
9967 } else {
9968 displayed = true;
9969 }
9970
9971 if (displayed) {
9972 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009973 if (attrs.width == LayoutParams.MATCH_PARENT
9974 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 covered = true;
9976 }
9977 }
9978 if (w.mOrientationChanging) {
9979 if (w.mDrawPending || w.mCommitDrawPending) {
9980 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009981 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009982 "Orientation continue waiting for draw in " + w);
9983 } else {
9984 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009985 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 "Orientation change complete in " + w);
9987 }
9988 }
9989 w.mToken.hasVisible = true;
9990 }
9991 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009992 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 "Orientation change skips hidden " + w);
9994 w.mOrientationChanging = false;
9995 }
9996
9997 final boolean canBeSeen = w.isDisplayedLw();
9998
9999 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10000 focusDisplayed = true;
10001 }
10002
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010003 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010006 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 if (w.mSurface != null) {
10008 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10009 holdScreen = w.mSession;
10010 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010011 if (!syswin && w.mAttrs.screenBrightness >= 0
10012 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 screenBrightness = w.mAttrs.screenBrightness;
10014 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010015 if (!syswin && w.mAttrs.buttonBrightness >= 0
10016 && buttonBrightness < 0) {
10017 buttonBrightness = w.mAttrs.buttonBrightness;
10018 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010019 if (canBeSeen
10020 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10021 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10022 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010023 syswin = true;
10024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010026
Dianne Hackborn25994b42009-09-04 14:21:19 -070010027 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10028 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010029 // This window completely covers everything behind it,
10030 // so we want to leave all of them as unblurred (for
10031 // performance reasons).
10032 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010033 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010034 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010035 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010036 obscured = true;
10037 if (mBackgroundFillerSurface == null) {
10038 try {
10039 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010040 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010041 0, dw, dh,
10042 PixelFormat.OPAQUE,
10043 Surface.FX_SURFACE_NORMAL);
10044 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010045 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010046 }
10047 }
10048 try {
10049 mBackgroundFillerSurface.setPosition(0, 0);
10050 mBackgroundFillerSurface.setSize(dw, dh);
10051 // Using the same layer as Dim because they will never be shown at the
10052 // same time.
10053 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10054 mBackgroundFillerSurface.show();
10055 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010056 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010057 }
10058 backgroundFillerShown = true;
10059 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010060 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010061 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010062 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 + ": blurring=" + blurring
10064 + " obscured=" + obscured
10065 + " displayed=" + displayed);
10066 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10067 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010068 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010070 if (mDimAnimator == null) {
10071 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010072 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010073 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010074 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076 }
10077 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10078 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010079 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010080 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010082 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010083 + mBlurSurface + ": CREATE");
10084 try {
Romain Guy06882f82009-06-10 13:36:04 -070010085 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010086 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 -1, 16, 16,
10088 PixelFormat.OPAQUE,
10089 Surface.FX_SURFACE_BLUR);
10090 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010091 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010092 }
10093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010094 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010095 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10096 + mBlurSurface + ": pos=(0,0) (" +
10097 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098 mBlurSurface.setPosition(0, 0);
10099 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010100 mBlurSurface.setLayer(w.mAnimLayer-2);
10101 if (!mBlurShown) {
10102 try {
10103 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10104 + mBlurSurface + ": SHOW");
10105 mBlurSurface.show();
10106 } catch (RuntimeException e) {
10107 Slog.w(TAG, "Failure showing blur surface", e);
10108 }
10109 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010110 }
10111 }
10112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010113 }
10114 }
10115 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010116
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010117 if (obscuredChanged && mWallpaperTarget == w) {
10118 // This is the wallpaper target and its obscured state
10119 // changed... make sure the current wallaper's visibility
10120 // has been updated accordingly.
10121 updateWallpaperVisibilityLocked();
10122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010124
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010125 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10126 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010127 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010128 try {
10129 mBackgroundFillerSurface.hide();
10130 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010131 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010132 }
10133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010134
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010135 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010136 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10137 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010138 }
Romain Guy06882f82009-06-10 13:36:04 -070010139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010140 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010141 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010142 + ": HIDE");
10143 try {
10144 mBlurSurface.hide();
10145 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010146 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010147 }
10148 mBlurShown = false;
10149 }
10150
Joe Onorato8a9b2202010-02-26 18:56:32 -080010151 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010152 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010153 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154 }
10155
Jeff Browne33348b2010-07-15 23:54:05 -070010156 mInputMonitor.updateInputWindowsLw();
10157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010159
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010160 if (mWatermark != null) {
10161 mWatermark.drawIfNeeded();
10162 }
10163
Joe Onorato8a9b2202010-02-26 18:56:32 -080010164 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010165 "With display frozen, orientationChangeComplete="
10166 + orientationChangeComplete);
10167 if (orientationChangeComplete) {
10168 if (mWindowsFreezingScreen) {
10169 mWindowsFreezingScreen = false;
10170 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10171 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010172 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010173 }
Romain Guy06882f82009-06-10 13:36:04 -070010174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010175 i = mResizingWindows.size();
10176 if (i > 0) {
10177 do {
10178 i--;
10179 WindowState win = mResizingWindows.get(i);
10180 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010181 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10182 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010183 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010184 boolean configChanged =
10185 win.mConfiguration != mCurConfiguration
10186 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010187 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10188 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10189 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010190 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010191 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010192 + " / " + mCurConfiguration + " / 0x"
10193 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010194 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010195 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 win.mClient.resized(win.mFrame.width(),
10197 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010198 win.mLastVisibleInsets, win.mDrawPending,
10199 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010200 win.mContentInsetsChanged = false;
10201 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010202 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010203 } catch (RemoteException e) {
10204 win.mOrientationChanging = false;
10205 }
10206 } while (i > 0);
10207 mResizingWindows.clear();
10208 }
Romain Guy06882f82009-06-10 13:36:04 -070010209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010210 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010211 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010212 i = mDestroySurface.size();
10213 if (i > 0) {
10214 do {
10215 i--;
10216 WindowState win = mDestroySurface.get(i);
10217 win.mDestroying = false;
10218 if (mInputMethodWindow == win) {
10219 mInputMethodWindow = null;
10220 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010221 if (win == mWallpaperTarget) {
10222 wallpaperDestroyed = true;
10223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010224 win.destroySurfaceLocked();
10225 } while (i > 0);
10226 mDestroySurface.clear();
10227 }
10228
10229 // Time to remove any exiting tokens?
10230 for (i=mExitingTokens.size()-1; i>=0; i--) {
10231 WindowToken token = mExitingTokens.get(i);
10232 if (!token.hasVisible) {
10233 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010234 if (token.windowType == TYPE_WALLPAPER) {
10235 mWallpaperTokens.remove(token);
10236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237 }
10238 }
10239
10240 // Time to remove any exiting applications?
10241 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10242 AppWindowToken token = mExitingAppTokens.get(i);
10243 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010244 // Make sure there is no animation running on this token,
10245 // so any windows associated with it will be removed as
10246 // soon as their animations are complete
10247 token.animation = null;
10248 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010249 mAppTokens.remove(token);
10250 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010251 if (mLastEnterAnimToken == token) {
10252 mLastEnterAnimToken = null;
10253 mLastEnterAnimParams = null;
10254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010255 }
10256 }
10257
Dianne Hackborna8f60182009-09-01 19:01:50 -070010258 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010259
Dianne Hackborna8f60182009-09-01 19:01:50 -070010260 if (!animating && mAppTransitionRunning) {
10261 // We have finished the animation of an app transition. To do
10262 // this, we have delayed a lot of operations like showing and
10263 // hiding apps, moving apps in Z-order, etc. The app token list
10264 // reflects the correct Z-order, but the window list may now
10265 // be out of sync with it. So here we will just rebuild the
10266 // entire app window list. Fun!
10267 mAppTransitionRunning = false;
10268 needRelayout = true;
10269 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010270 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010271 // Clear information about apps that were moving.
10272 mToBottomApps.clear();
10273 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275 if (focusDisplayed) {
10276 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10277 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010278 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010279 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010280 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010281 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010282 requestAnimationLocked(0);
10283 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010284 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10285 }
Jeff Browneb857f12010-07-16 10:06:33 -070010286
Jeff Browne33348b2010-07-15 23:54:05 -070010287 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010288
Jeff Brown8e03b752010-06-13 19:16:55 -070010289 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10291 mPowerManager.setScreenBrightnessOverride(-1);
10292 } else {
10293 mPowerManager.setScreenBrightnessOverride((int)
10294 (screenBrightness * Power.BRIGHTNESS_ON));
10295 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010296 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10297 mPowerManager.setButtonBrightnessOverride(-1);
10298 } else {
10299 mPowerManager.setButtonBrightnessOverride((int)
10300 (buttonBrightness * Power.BRIGHTNESS_ON));
10301 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010302 if (holdScreen != mHoldingScreenOn) {
10303 mHoldingScreenOn = holdScreen;
10304 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10305 mH.sendMessage(m);
10306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010307
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010308 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010309 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010310 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10311 LocalPowerManager.BUTTON_EVENT, true);
10312 mTurnOnScreen = false;
10313 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010314
10315 // Check to see if we are now in a state where the screen should
10316 // be enabled, because the window obscured flags have changed.
10317 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010318 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010319
10320 /**
10321 * Must be called with the main window manager lock held.
10322 */
10323 void setHoldScreenLocked(boolean holding) {
10324 boolean state = mHoldingScreenWakeLock.isHeld();
10325 if (holding != state) {
10326 if (holding) {
10327 mHoldingScreenWakeLock.acquire();
10328 } else {
10329 mPolicy.screenOnStoppedLw();
10330 mHoldingScreenWakeLock.release();
10331 }
10332 }
10333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010334
10335 void requestAnimationLocked(long delay) {
10336 if (!mAnimationPending) {
10337 mAnimationPending = true;
10338 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10339 }
10340 }
Romain Guy06882f82009-06-10 13:36:04 -070010341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010342 /**
10343 * Have the surface flinger show a surface, robustly dealing with
10344 * error conditions. In particular, if there is not enough memory
10345 * to show the surface, then we will try to get rid of other surfaces
10346 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010347 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010348 * @return Returns true if the surface was successfully shown.
10349 */
10350 boolean showSurfaceRobustlyLocked(WindowState win) {
10351 try {
10352 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010353 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010355 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010356 if (DEBUG_VISIBILITY) Slog.v(TAG,
10357 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010358 win.mTurnOnScreen = false;
10359 mTurnOnScreen = true;
10360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010361 }
10362 return true;
10363 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010364 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365 }
Romain Guy06882f82009-06-10 13:36:04 -070010366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010369 return false;
10370 }
Romain Guy06882f82009-06-10 13:36:04 -070010371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010372 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10373 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010374
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010375 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010376 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010378 if (mForceRemoves == null) {
10379 mForceRemoves = new ArrayList<WindowState>();
10380 }
Romain Guy06882f82009-06-10 13:36:04 -070010381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010382 long callingIdentity = Binder.clearCallingIdentity();
10383 try {
10384 // There was some problem... first, do a sanity check of the
10385 // window list to make sure we haven't left any dangling surfaces
10386 // around.
10387 int N = mWindows.size();
10388 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010389 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010390 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010391 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010392 if (ws.mSurface != null) {
10393 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010394 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010395 + ws + " surface=" + ws.mSurface
10396 + " token=" + win.mToken
10397 + " pid=" + ws.mSession.mPid
10398 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010399 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010400 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 ws.mSurface = null;
10402 mForceRemoves.add(ws);
10403 i--;
10404 N--;
10405 leakedSurface = true;
10406 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010407 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408 + ws + " surface=" + ws.mSurface
10409 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010410 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010411 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 ws.mSurface = null;
10413 leakedSurface = true;
10414 }
10415 }
10416 }
Romain Guy06882f82009-06-10 13:36:04 -070010417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010418 boolean killedApps = false;
10419 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010420 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 SparseIntArray pidCandidates = new SparseIntArray();
10422 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010423 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424 if (ws.mSurface != null) {
10425 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10426 }
10427 }
10428 if (pidCandidates.size() > 0) {
10429 int[] pids = new int[pidCandidates.size()];
10430 for (int i=0; i<pids.length; i++) {
10431 pids[i] = pidCandidates.keyAt(i);
10432 }
10433 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010434 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 killedApps = true;
10436 }
10437 } catch (RemoteException e) {
10438 }
10439 }
10440 }
Romain Guy06882f82009-06-10 13:36:04 -070010441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 if (leakedSurface || killedApps) {
10443 // We managed to reclaim some memory, so get rid of the trouble
10444 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010445 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010447 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010448 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010449 win.mSurface = null;
10450 }
Romain Guy06882f82009-06-10 13:36:04 -070010451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 try {
10453 win.mClient.dispatchGetNewSurface();
10454 } catch (RemoteException e) {
10455 }
10456 }
10457 } finally {
10458 Binder.restoreCallingIdentity(callingIdentity);
10459 }
10460 }
Romain Guy06882f82009-06-10 13:36:04 -070010461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010462 private boolean updateFocusedWindowLocked(int mode) {
10463 WindowState newFocus = computeFocusedWindowLocked();
10464 if (mCurrentFocus != newFocus) {
10465 // This check makes sure that we don't already have the focus
10466 // change message pending.
10467 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10468 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010469 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010470 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10471 final WindowState oldFocus = mCurrentFocus;
10472 mCurrentFocus = newFocus;
10473 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 final WindowState imWindow = mInputMethodWindow;
10476 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010477 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010479 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10480 mLayoutNeeded = true;
10481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010482 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10483 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010484 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10485 // Client will do the layout, but we need to assign layers
10486 // for handleNewWindowLocked() below.
10487 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 }
10489 }
Jeff Brown349703e2010-06-22 01:27:15 -070010490
10491 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10492 // If we defer assigning layers, then the caller is responsible for
10493 // doing this part.
10494 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010496 return true;
10497 }
10498 return false;
10499 }
Jeff Brown349703e2010-06-22 01:27:15 -070010500
10501 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010502 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504
10505 private WindowState computeFocusedWindowLocked() {
10506 WindowState result = null;
10507 WindowState win;
10508
10509 int i = mWindows.size() - 1;
10510 int nextAppIndex = mAppTokens.size()-1;
10511 WindowToken nextApp = nextAppIndex >= 0
10512 ? mAppTokens.get(nextAppIndex) : null;
10513
10514 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010515 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516
Joe Onorato8a9b2202010-02-26 18:56:32 -080010517 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 TAG, "Looking for focus: " + i
10519 + " = " + win
10520 + ", flags=" + win.mAttrs.flags
10521 + ", canReceive=" + win.canReceiveKeys());
10522
10523 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 // If this window's application has been removed, just skip it.
10526 if (thisApp != null && thisApp.removed) {
10527 i--;
10528 continue;
10529 }
Romain Guy06882f82009-06-10 13:36:04 -070010530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 // If there is a focused app, don't allow focus to go to any
10532 // windows below it. If this is an application window, step
10533 // through the app tokens until we find its app.
10534 if (thisApp != null && nextApp != null && thisApp != nextApp
10535 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10536 int origAppIndex = nextAppIndex;
10537 while (nextAppIndex > 0) {
10538 if (nextApp == mFocusedApp) {
10539 // Whoops, we are below the focused app... no focus
10540 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010541 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 TAG, "Reached focused app: " + mFocusedApp);
10543 return null;
10544 }
10545 nextAppIndex--;
10546 nextApp = mAppTokens.get(nextAppIndex);
10547 if (nextApp == thisApp) {
10548 break;
10549 }
10550 }
10551 if (thisApp != nextApp) {
10552 // Uh oh, the app token doesn't exist! This shouldn't
10553 // happen, but if it does we can get totally hosed...
10554 // so restart at the original app.
10555 nextAppIndex = origAppIndex;
10556 nextApp = mAppTokens.get(nextAppIndex);
10557 }
10558 }
10559
10560 // Dispatch to this window if it is wants key events.
10561 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010562 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010563 TAG, "Found focus @ " + i + " = " + win);
10564 result = win;
10565 break;
10566 }
10567
10568 i--;
10569 }
10570
10571 return result;
10572 }
10573
10574 private void startFreezingDisplayLocked() {
10575 if (mDisplayFrozen) {
10576 return;
10577 }
Romain Guy06882f82009-06-10 13:36:04 -070010578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010582 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010583 if (mFreezeGcPending != 0) {
10584 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010585 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010586 mH.removeMessages(H.FORCE_GC);
10587 Runtime.getRuntime().gc();
10588 mFreezeGcPending = now;
10589 }
10590 } else {
10591 mFreezeGcPending = now;
10592 }
Romain Guy06882f82009-06-10 13:36:04 -070010593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010595
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010596 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010597
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010598 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10599 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010600 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 mAppTransitionReady = true;
10602 }
Romain Guy06882f82009-06-10 13:36:04 -070010603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010604 if (PROFILE_ORIENTATION) {
10605 File file = new File("/data/system/frozen");
10606 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10607 }
10608 Surface.freezeDisplay(0);
10609 }
Romain Guy06882f82009-06-10 13:36:04 -070010610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 private void stopFreezingDisplayLocked() {
10612 if (!mDisplayFrozen) {
10613 return;
10614 }
Romain Guy06882f82009-06-10 13:36:04 -070010615
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010616 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10617 return;
10618 }
10619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 mDisplayFrozen = false;
10621 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10622 if (PROFILE_ORIENTATION) {
10623 Debug.stopMethodTracing();
10624 }
10625 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010626
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010627 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010628
Christopher Tateb696aee2010-04-02 19:08:30 -070010629 // While the display is frozen we don't re-compute the orientation
10630 // to avoid inconsistent states. However, something interesting
10631 // could have actually changed during that time so re-evaluate it
10632 // now to catch that.
10633 if (updateOrientationFromAppTokensLocked()) {
10634 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10635 }
10636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 // A little kludge: a lot could have happened while the
10638 // display was frozen, so now that we are coming back we
10639 // do a gc so that any remote references the system
10640 // processes holds on others can be released if they are
10641 // no longer needed.
10642 mH.removeMessages(H.FORCE_GC);
10643 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10644 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010646 mScreenFrozenLock.release();
10647 }
Romain Guy06882f82009-06-10 13:36:04 -070010648
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010649 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10650 DisplayMetrics dm) {
10651 if (index < tokens.length) {
10652 String str = tokens[index];
10653 if (str != null && str.length() > 0) {
10654 try {
10655 int val = Integer.parseInt(str);
10656 return val;
10657 } catch (Exception e) {
10658 }
10659 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010660 }
10661 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10662 return defDps;
10663 }
10664 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10665 return val;
10666 }
10667
10668 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010669 final String[] mTokens;
10670 final String mText;
10671 final Paint mTextPaint;
10672 final int mTextWidth;
10673 final int mTextHeight;
10674 final int mTextAscent;
10675 final int mTextDescent;
10676 final int mDeltaX;
10677 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010678
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010679 Surface mSurface;
10680 int mLastDW;
10681 int mLastDH;
10682 boolean mDrawNeeded;
10683
10684 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010685 final DisplayMetrics dm = new DisplayMetrics();
10686 mDisplay.getMetrics(dm);
10687
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010688 if (false) {
10689 Log.i(TAG, "*********************** WATERMARK");
10690 for (int i=0; i<tokens.length; i++) {
10691 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10692 }
10693 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010694
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010695 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010696
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010697 StringBuilder builder = new StringBuilder(32);
10698 int len = mTokens[0].length();
10699 len = len & ~1;
10700 for (int i=0; i<len; i+=2) {
10701 int c1 = mTokens[0].charAt(i);
10702 int c2 = mTokens[0].charAt(i+1);
10703 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10704 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10705 else c1 -= '0';
10706 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10707 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10708 else c2 -= '0';
10709 builder.append((char)(255-((c1*16)+c2)));
10710 }
10711 mText = builder.toString();
10712 if (false) {
10713 Log.i(TAG, "Final text: " + mText);
10714 }
10715
10716 int fontSize = getPropertyInt(tokens, 1,
10717 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10718
10719 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10720 mTextPaint.setTextSize(fontSize);
10721 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10722
10723 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10724 mTextWidth = (int)mTextPaint.measureText(mText);
10725 mTextAscent = fm.ascent;
10726 mTextDescent = fm.descent;
10727 mTextHeight = fm.descent - fm.ascent;
10728
10729 mDeltaX = getPropertyInt(tokens, 2,
10730 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10731 mDeltaY = getPropertyInt(tokens, 3,
10732 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10733 int shadowColor = getPropertyInt(tokens, 4,
10734 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10735 int color = getPropertyInt(tokens, 5,
10736 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10737 int shadowRadius = getPropertyInt(tokens, 6,
10738 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10739 int shadowDx = getPropertyInt(tokens, 8,
10740 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10741 int shadowDy = getPropertyInt(tokens, 9,
10742 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10743
10744 mTextPaint.setColor(color);
10745 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010746
10747 try {
10748 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010749 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010750 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010751 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010752 mSurface.show();
10753 } catch (OutOfResourcesException e) {
10754 }
10755 }
10756
10757 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010758 if (mLastDW != dw || mLastDH != dh) {
10759 mLastDW = dw;
10760 mLastDH = dh;
10761 mSurface.setSize(dw, dh);
10762 mDrawNeeded = true;
10763 }
10764 }
10765
10766 void drawIfNeeded() {
10767 if (mDrawNeeded) {
10768 final int dw = mLastDW;
10769 final int dh = mLastDH;
10770
10771 mDrawNeeded = false;
10772 Rect dirty = new Rect(0, 0, dw, dh);
10773 Canvas c = null;
10774 try {
10775 c = mSurface.lockCanvas(dirty);
10776 } catch (IllegalArgumentException e) {
10777 } catch (OutOfResourcesException e) {
10778 }
10779 if (c != null) {
10780 int deltaX = mDeltaX;
10781 int deltaY = mDeltaY;
10782
10783 // deltaX shouldn't be close to a round fraction of our
10784 // x step, or else things will line up too much.
10785 int div = (dw+mTextWidth)/deltaX;
10786 int rem = (dw+mTextWidth) - (div*deltaX);
10787 int qdelta = deltaX/4;
10788 if (rem < qdelta || rem > (deltaX-qdelta)) {
10789 deltaX += deltaX/3;
10790 }
10791
10792 int y = -mTextHeight;
10793 int x = -mTextWidth;
10794 while (y < (dh+mTextHeight)) {
10795 c.drawText(mText, x, y, mTextPaint);
10796 x += deltaX;
10797 if (x >= dw) {
10798 x -= (dw+mTextWidth);
10799 y += deltaY;
10800 }
10801 }
10802 mSurface.unlockCanvasAndPost(c);
10803 }
10804 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010805 }
10806 }
10807
10808 void createWatermark() {
10809 if (mWatermark != null) {
10810 return;
10811 }
10812
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010813 File file = new File("/system/etc/setup.conf");
10814 FileInputStream in = null;
10815 try {
10816 in = new FileInputStream(file);
10817 DataInputStream ind = new DataInputStream(in);
10818 String line = ind.readLine();
10819 if (line != null) {
10820 String[] toks = line.split("%");
10821 if (toks != null && toks.length > 0) {
10822 mWatermark = new Watermark(mFxSession, toks);
10823 }
10824 }
10825 } catch (FileNotFoundException e) {
10826 } catch (IOException e) {
10827 } finally {
10828 if (in != null) {
10829 try {
10830 in.close();
10831 } catch (IOException e) {
10832 }
10833 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010834 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010835 }
10836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010837 @Override
10838 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10839 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10840 != PackageManager.PERMISSION_GRANTED) {
10841 pw.println("Permission Denial: can't dump WindowManager from from pid="
10842 + Binder.getCallingPid()
10843 + ", uid=" + Binder.getCallingUid());
10844 return;
10845 }
Romain Guy06882f82009-06-10 13:36:04 -070010846
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010847 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010848 pw.println(" ");
10849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010850 synchronized(mWindowMap) {
10851 pw.println("Current Window Manager state:");
10852 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010853 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010854 pw.print(" Window #"); pw.print(i); pw.print(' ');
10855 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856 w.dump(pw, " ");
10857 }
10858 if (mInputMethodDialogs.size() > 0) {
10859 pw.println(" ");
10860 pw.println(" Input method dialogs:");
10861 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10862 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010863 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010864 }
10865 }
10866 if (mPendingRemove.size() > 0) {
10867 pw.println(" ");
10868 pw.println(" Remove pending for:");
10869 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10870 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010871 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10872 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873 w.dump(pw, " ");
10874 }
10875 }
10876 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10877 pw.println(" ");
10878 pw.println(" Windows force removing:");
10879 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10880 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010881 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10882 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010883 w.dump(pw, " ");
10884 }
10885 }
10886 if (mDestroySurface.size() > 0) {
10887 pw.println(" ");
10888 pw.println(" Windows waiting to destroy their surface:");
10889 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10890 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010891 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10892 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010893 w.dump(pw, " ");
10894 }
10895 }
10896 if (mLosingFocus.size() > 0) {
10897 pw.println(" ");
10898 pw.println(" Windows losing focus:");
10899 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10900 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010901 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10902 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010903 w.dump(pw, " ");
10904 }
10905 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010906 if (mResizingWindows.size() > 0) {
10907 pw.println(" ");
10908 pw.println(" Windows waiting to resize:");
10909 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10910 WindowState w = mResizingWindows.get(i);
10911 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10912 pw.print(w); pw.println(":");
10913 w.dump(pw, " ");
10914 }
10915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010916 if (mSessions.size() > 0) {
10917 pw.println(" ");
10918 pw.println(" All active sessions:");
10919 Iterator<Session> it = mSessions.iterator();
10920 while (it.hasNext()) {
10921 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010922 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010923 s.dump(pw, " ");
10924 }
10925 }
10926 if (mTokenMap.size() > 0) {
10927 pw.println(" ");
10928 pw.println(" All tokens:");
10929 Iterator<WindowToken> it = mTokenMap.values().iterator();
10930 while (it.hasNext()) {
10931 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010932 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010933 token.dump(pw, " ");
10934 }
10935 }
10936 if (mTokenList.size() > 0) {
10937 pw.println(" ");
10938 pw.println(" Window token list:");
10939 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010940 pw.print(" #"); pw.print(i); pw.print(": ");
10941 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010942 }
10943 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010944 if (mWallpaperTokens.size() > 0) {
10945 pw.println(" ");
10946 pw.println(" Wallpaper tokens:");
10947 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10948 WindowToken token = mWallpaperTokens.get(i);
10949 pw.print(" Wallpaper #"); pw.print(i);
10950 pw.print(' '); pw.print(token); pw.println(':');
10951 token.dump(pw, " ");
10952 }
10953 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010954 if (mAppTokens.size() > 0) {
10955 pw.println(" ");
10956 pw.println(" Application tokens in Z order:");
10957 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010958 pw.print(" App #"); pw.print(i); pw.print(": ");
10959 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010960 }
10961 }
10962 if (mFinishedStarting.size() > 0) {
10963 pw.println(" ");
10964 pw.println(" Finishing start of application tokens:");
10965 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10966 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010967 pw.print(" Finished Starting #"); pw.print(i);
10968 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010969 token.dump(pw, " ");
10970 }
10971 }
10972 if (mExitingTokens.size() > 0) {
10973 pw.println(" ");
10974 pw.println(" Exiting tokens:");
10975 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10976 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010977 pw.print(" Exiting #"); pw.print(i);
10978 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010979 token.dump(pw, " ");
10980 }
10981 }
10982 if (mExitingAppTokens.size() > 0) {
10983 pw.println(" ");
10984 pw.println(" Exiting application tokens:");
10985 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10986 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010987 pw.print(" Exiting App #"); pw.print(i);
10988 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010989 token.dump(pw, " ");
10990 }
10991 }
10992 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010993 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10994 pw.print(" mLastFocus="); pw.println(mLastFocus);
10995 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10996 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10997 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010998 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010999 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11000 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11001 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11002 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011003 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11004 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11005 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011006 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11007 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11008 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11009 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011010 if (mDimAnimator != null) {
11011 mDimAnimator.printTo(pw);
11012 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011013 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011014 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011015 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011016 pw.print(mInputMethodAnimLayerAdjustment);
11017 pw.print(" mWallpaperAnimLayerAdjustment=");
11018 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011019 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11020 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011021 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11022 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011023 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11024 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011025 pw.print(" mRotation="); pw.print(mRotation);
11026 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11027 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11028 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11029 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11030 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11031 pw.print(" mNextAppTransition=0x");
11032 pw.print(Integer.toHexString(mNextAppTransition));
11033 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011034 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011035 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011036 if (mNextAppTransitionPackage != null) {
11037 pw.print(" mNextAppTransitionPackage=");
11038 pw.print(mNextAppTransitionPackage);
11039 pw.print(", mNextAppTransitionEnter=0x");
11040 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11041 pw.print(", mNextAppTransitionExit=0x");
11042 pw.print(Integer.toHexString(mNextAppTransitionExit));
11043 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011044 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11045 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011046 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11047 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11048 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11049 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011050 if (mOpeningApps.size() > 0) {
11051 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11052 }
11053 if (mClosingApps.size() > 0) {
11054 pw.print(" mClosingApps="); pw.println(mClosingApps);
11055 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011056 if (mToTopApps.size() > 0) {
11057 pw.print(" mToTopApps="); pw.println(mToTopApps);
11058 }
11059 if (mToBottomApps.size() > 0) {
11060 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11061 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011062 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11063 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011064 }
11065 }
11066
Jeff Brown349703e2010-06-22 01:27:15 -070011067 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011068 public void monitor() {
11069 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011070 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011071 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011072
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011073 /**
11074 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011075 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011076 */
11077 private static class DimAnimator {
11078 Surface mDimSurface;
11079 boolean mDimShown = false;
11080 float mDimCurrentAlpha;
11081 float mDimTargetAlpha;
11082 float mDimDeltaPerMs;
11083 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011084
11085 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011086
11087 DimAnimator (SurfaceSession session) {
11088 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011089 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011090 + mDimSurface + ": CREATE");
11091 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011092 mDimSurface = new Surface(session, 0,
11093 "DimSurface",
11094 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011095 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011096 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011097 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011098 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011099 }
11100 }
11101 }
11102
11103 /**
11104 * Show the dim surface.
11105 */
11106 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011107 if (!mDimShown) {
11108 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11109 dw + "x" + dh + ")");
11110 mDimShown = true;
11111 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011112 mLastDimWidth = dw;
11113 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011114 mDimSurface.setPosition(0, 0);
11115 mDimSurface.setSize(dw, dh);
11116 mDimSurface.show();
11117 } catch (RuntimeException e) {
11118 Slog.w(TAG, "Failure showing dim surface", e);
11119 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011120 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11121 mLastDimWidth = dw;
11122 mLastDimHeight = dh;
11123 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011124 }
11125 }
11126
11127 /**
11128 * Set's the dim surface's layer and update dim parameters that will be used in
11129 * {@link updateSurface} after all windows are examined.
11130 */
11131 void updateParameters(WindowState w, long currentTime) {
11132 mDimSurface.setLayer(w.mAnimLayer-1);
11133
11134 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011135 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011136 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011137 if (mDimTargetAlpha != target) {
11138 // If the desired dim level has changed, then
11139 // start an animation to it.
11140 mLastDimAnimTime = currentTime;
11141 long duration = (w.mAnimating && w.mAnimation != null)
11142 ? w.mAnimation.computeDurationHint()
11143 : DEFAULT_DIM_DURATION;
11144 if (target > mDimTargetAlpha) {
11145 // This is happening behind the activity UI,
11146 // so we can make it run a little longer to
11147 // give a stronger impression without disrupting
11148 // the user.
11149 duration *= DIM_DURATION_MULTIPLIER;
11150 }
11151 if (duration < 1) {
11152 // Don't divide by zero
11153 duration = 1;
11154 }
11155 mDimTargetAlpha = target;
11156 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11157 }
11158 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011159
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011160 /**
11161 * Updating the surface's alpha. Returns true if the animation continues, or returns
11162 * false when the animation is finished and the dim surface is hidden.
11163 */
11164 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11165 if (!dimming) {
11166 if (mDimTargetAlpha != 0) {
11167 mLastDimAnimTime = currentTime;
11168 mDimTargetAlpha = 0;
11169 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11170 }
11171 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011172
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011173 boolean animating = false;
11174 if (mLastDimAnimTime != 0) {
11175 mDimCurrentAlpha += mDimDeltaPerMs
11176 * (currentTime-mLastDimAnimTime);
11177 boolean more = true;
11178 if (displayFrozen) {
11179 // If the display is frozen, there is no reason to animate.
11180 more = false;
11181 } else if (mDimDeltaPerMs > 0) {
11182 if (mDimCurrentAlpha > mDimTargetAlpha) {
11183 more = false;
11184 }
11185 } else if (mDimDeltaPerMs < 0) {
11186 if (mDimCurrentAlpha < mDimTargetAlpha) {
11187 more = false;
11188 }
11189 } else {
11190 more = false;
11191 }
11192
11193 // Do we need to continue animating?
11194 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011195 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011196 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11197 mLastDimAnimTime = currentTime;
11198 mDimSurface.setAlpha(mDimCurrentAlpha);
11199 animating = true;
11200 } else {
11201 mDimCurrentAlpha = mDimTargetAlpha;
11202 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011203 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011204 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11205 mDimSurface.setAlpha(mDimCurrentAlpha);
11206 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011207 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011208 + ": HIDE");
11209 try {
11210 mDimSurface.hide();
11211 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011212 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011213 }
11214 mDimShown = false;
11215 }
11216 }
11217 }
11218 return animating;
11219 }
11220
11221 public void printTo(PrintWriter pw) {
11222 pw.print(" mDimShown="); pw.print(mDimShown);
11223 pw.print(" current="); pw.print(mDimCurrentAlpha);
11224 pw.print(" target="); pw.print(mDimTargetAlpha);
11225 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11226 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11227 }
11228 }
11229
11230 /**
11231 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11232 * This is used for opening/closing transition for apps in compatible mode.
11233 */
11234 private static class FadeInOutAnimation extends Animation {
11235 int mWidth;
11236 boolean mFadeIn;
11237
11238 public FadeInOutAnimation(boolean fadeIn) {
11239 setInterpolator(new AccelerateInterpolator());
11240 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11241 mFadeIn = fadeIn;
11242 }
11243
11244 @Override
11245 protected void applyTransformation(float interpolatedTime, Transformation t) {
11246 float x = interpolatedTime;
11247 if (!mFadeIn) {
11248 x = 1.0f - x; // reverse the interpolation for fade out
11249 }
11250 if (x < 0.5) {
11251 // move the window out of the screen.
11252 t.getMatrix().setTranslate(mWidth, 0);
11253 } else {
11254 t.getMatrix().setTranslate(0, 0);// show
11255 t.setAlpha((x - 0.5f) * 2);
11256 }
11257 }
11258
11259 @Override
11260 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11261 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11262 mWidth = width;
11263 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011264
11265 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011266 public int getZAdjustment() {
11267 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011268 }
11269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011270}