blob: af2fece2a7951aa67b115c774792d6c6b6a1c9fe [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 Tateb478f462010-10-15 16:02:26 -0700504 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700505 float mThumbOffsetX, mThumbOffsetY;
506 InputChannel mServerChannel, mClientChannel;
507 WindowState mTargetWindow;
508 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700509 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700510
511 private final Rect tmpRect = new Rect();
512
513 DragState(IBinder token, Surface surface, boolean localOnly) {
514 mToken = token;
515 mSurface = surface;
516 mLocalOnly = localOnly;
517 mNotifiedWindows = new ArrayList<WindowState>();
518 }
519
520 void reset() {
521 if (mSurface != null) {
522 mSurface.destroy();
523 }
524 mSurface = null;
525 mLocalOnly = false;
526 mToken = null;
527 mData = null;
528 mThumbOffsetX = mThumbOffsetY = 0;
529 mNotifiedWindows = null;
530 }
531
532 void register() {
533 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
534 if (mClientChannel != null) {
535 Slog.e(TAG, "Duplicate register of drag input channel");
536 } else {
537 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
538 mServerChannel = channels[0];
539 mClientChannel = channels[1];
540 mInputManager.registerInputChannel(mServerChannel);
541 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
542 mH.getLooper().getQueue());
543 }
544 }
545
546 void unregister() {
547 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
548 if (mClientChannel == null) {
549 Slog.e(TAG, "Unregister of nonexistent drag input channel");
550 } else {
551 mInputManager.unregisterInputChannel(mServerChannel);
552 InputQueue.unregisterInputChannel(mClientChannel);
553 mClientChannel.dispose();
554 mClientChannel = null;
555 mServerChannel = null;
556 }
557 }
558
Chris Tatea32dcf72010-10-14 12:13:50 -0700559 int getDragLayerLw() {
560 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
561 * TYPE_LAYER_MULTIPLIER
562 + TYPE_LAYER_OFFSET;
563 }
564
Christopher Tatea53146c2010-09-07 11:57:52 -0700565 /* call out to each visible window/session informing it about the drag
566 */
Chris Tateb8203e92010-10-12 14:23:21 -0700567 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700568 // Cache a base-class instance of the clip metadata so that parceling
569 // works correctly in calling out to the apps.
570 mDataDescription = new ClipDescription(mData);
571 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700572 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700573
574 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700575 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700576 }
577
Christopher Tate2c095f32010-10-04 14:13:40 -0700578 final int N = mWindows.size();
579 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700580 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700582 }
583
584 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
585 * designated window is potentially a drop recipient. There are race situations
586 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
587 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700588 *
589 * This method clones the 'event' parameter if it's being delivered to the same
590 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700591 */
Chris Tateb478f462010-10-15 16:02:26 -0700592 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
593 ClipDescription desc) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700594 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700595 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
596 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
597 desc, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 try {
599 newWin.mClient.dispatchDragEvent(event);
600 // track each window that we've notified that the drag is starting
601 mNotifiedWindows.add(newWin);
602 } catch (RemoteException e) {
603 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700604 } finally {
605 // if the callee was local, the dispatch has already recycled the event
606 if (Process.myPid() != newWin.mSession.mPid) {
607 event.recycle();
608 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700609 }
610 }
611 }
612
613 /* helper - construct and send a DRAG_STARTED event only if the window has not
614 * previously been notified, i.e. it became visible after the drag operation
615 * was begun. This is a rare case.
616 */
617 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700618 if (mDragInProgress) {
619 // If we have sent the drag-started, we needn't do so again
620 for (WindowState ws : mNotifiedWindows) {
621 if (ws == newWin) {
622 return;
623 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700624 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700625 if (DEBUG_DRAG) {
626 Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin);
627 }
Chris Tateb478f462010-10-15 16:02:26 -0700628 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700629 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700630 }
631
632 void broadcastDragEnded() {
633 if (DEBUG_DRAG) {
634 Slog.d(TAG, "broadcasting DRAG_ENDED");
635 }
636 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null);
637 synchronized (mWindowMap) {
638 for (WindowState ws: mNotifiedWindows) {
639 try {
640 ws.mClient.dispatchDragEvent(evt);
641 } catch (RemoteException e) {
642 Slog.w(TAG, "Unable to drag-end window " + ws);
643 }
644 }
645 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700646 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700647 }
648 evt.recycle();
649 }
650
651 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700652 final int myPid = Process.myPid();
653
654 // Move the surface to the given touch
655 mSurface.openTransaction();
656 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
657 mSurface.closeTransaction();
658
659 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700660 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
661 try {
662 // have we dragged over a new window?
663 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
664 if (DEBUG_DRAG) {
665 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
666 }
667 // force DRAG_EXITED_EVENT if appropriate
668 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700669 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
670 null, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700671 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700672 if (myPid != mTargetWindow.mSession.mPid) {
673 evt.recycle();
674 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700675 }
676 if (touchedWin != null) {
677 if (DEBUG_DRAG) {
678 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
679 }
680 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700681 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
682 null, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700683 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700684 if (myPid != touchedWin.mSession.mPid) {
685 evt.recycle();
686 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700687 }
688 } catch (RemoteException e) {
689 Slog.w(TAG, "can't send drag notification to windows");
690 }
691 mTargetWindow = touchedWin;
692 }
693
694 // Tell the drop target about the data, and then broadcast the drag-ended notification
695 void notifyDropLw(float x, float y) {
696 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
697 if (touchedWin != null) {
698 if (DEBUG_DRAG) {
699 Slog.d(TAG, "sending DROP to " + touchedWin);
700 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700701 final int myPid = Process.myPid();
Chris Tateb478f462010-10-15 16:02:26 -0700702 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
703 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
704 null, mData);
Christopher Tatea53146c2010-09-07 11:57:52 -0700705 try {
706 touchedWin.mClient.dispatchDragEvent(evt);
707 } catch (RemoteException e) {
708 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
709 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700710 if (myPid != touchedWin.mSession.mPid) {
711 evt.recycle();
712 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700713 }
714 }
715
716 // Find the visible, touch-deliverable window under the given point
717 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
718 WindowState touchedWin = null;
719 final int x = (int) xf;
720 final int y = (int) yf;
721 final ArrayList<WindowState> windows = mWindows;
722 final int N = windows.size();
723 for (int i = N - 1; i >= 0; i--) {
724 WindowState child = windows.get(i);
725 final int flags = child.mAttrs.flags;
726 if (!child.isVisibleLw()) {
727 // not visible == don't tell about drags
728 continue;
729 }
730 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
731 // not touchable == don't tell about drags
732 continue;
733 }
734 // account for the window's decor etc
735 tmpRect.set(child.mFrame);
736 if (child.mTouchableInsets == ViewTreeObserver
737 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
738 // The point is inside of the window if it is
739 // inside the frame, AND the content part of that
740 // frame that was given by the application.
741 tmpRect.left += child.mGivenContentInsets.left;
742 tmpRect.top += child.mGivenContentInsets.top;
743 tmpRect.right -= child.mGivenContentInsets.right;
744 tmpRect.bottom -= child.mGivenContentInsets.bottom;
745 } else if (child.mTouchableInsets == ViewTreeObserver
746 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
747 // The point is inside of the window if it is
748 // inside the frame, AND the visible part of that
749 // frame that was given by the application.
750 tmpRect.left += child.mGivenVisibleInsets.left;
751 tmpRect.top += child.mGivenVisibleInsets.top;
752 tmpRect.right -= child.mGivenVisibleInsets.right;
753 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
754 }
755 final int touchFlags = flags &
756 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
757 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
758 if (tmpRect.contains(x, y) || touchFlags == 0) {
759 // Found it
760 touchedWin = child;
761 break;
762 }
763 }
764
765 return touchedWin;
766 }
767 }
768
769 DragState mDragState = null;
770 private final InputHandler mDragInputHandler = new BaseInputHandler() {
771 @Override
772 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
773 boolean endDrag = false;
774 final float newX = event.getRawX();
775 final float newY = event.getRawY();
776
777 try {
778 if (mDragState != null) {
779 switch (event.getAction()) {
780 case MotionEvent.ACTION_DOWN: {
781 if (DEBUG_DRAG) {
782 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
783 }
784 } break;
785
786 case MotionEvent.ACTION_MOVE: {
787 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700788 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700789 mDragState.notifyMoveLw(newX, newY);
790 }
791 } break;
792
793 case MotionEvent.ACTION_UP: {
794 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
795 + newX + "," + newY);
796 synchronized (mWindowMap) {
797 mDragState.notifyDropLw(newX, newY);
798 }
799 endDrag = true;
800 } break;
801
802 case MotionEvent.ACTION_CANCEL: {
803 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
804 endDrag = true;
805 } break;
806 }
807
808 if (endDrag) {
809 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
810 // tell all the windows that the drag has ended
811 mDragState.broadcastDragEnded();
812
813 // stop intercepting input
814 mDragState.unregister();
Chris Tate59943592010-10-11 20:33:44 -0700815 synchronized (mWindowMap) {
816 mInputMonitor.updateInputWindowsLw();
817 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700818
819 // free our resources and drop all the object references
820 mDragState.reset();
821 mDragState = null;
822 }
823 }
824 } catch (Exception e) {
825 Slog.e(TAG, "Exception caught by drag handleMotion", e);
826 } finally {
827 finishedCallback.run();
828 }
829 }
830 };
831
832 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 * Whether the UI is currently running in touch mode (not showing
834 * navigational focus because the user is directly pressing the screen).
835 */
836 boolean mInTouchMode = false;
837
838 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700839 private ArrayList<WindowChangeListener> mWindowChangeListeners =
840 new ArrayList<WindowChangeListener>();
841 private boolean mWindowsChanged = false;
842
843 public interface WindowChangeListener {
844 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700845 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847
Dianne Hackbornc485a602009-03-24 22:39:49 -0700848 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700849 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700850
851 // The frame use to limit the size of the app running in compatibility mode.
852 Rect mCompatibleScreenFrame = new Rect();
853 // The surface used to fill the outer rim of the app running in compatibility mode.
854 Surface mBackgroundFillerSurface = null;
855 boolean mBackgroundFillerShown = false;
856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 public static WindowManagerService main(Context context,
858 PowerManagerService pm, boolean haveInputMethods) {
859 WMThread thr = new WMThread(context, pm, haveInputMethods);
860 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 synchronized (thr) {
863 while (thr.mService == null) {
864 try {
865 thr.wait();
866 } catch (InterruptedException e) {
867 }
868 }
869 }
Romain Guy06882f82009-06-10 13:36:04 -0700870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 return thr.mService;
872 }
Romain Guy06882f82009-06-10 13:36:04 -0700873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 static class WMThread extends Thread {
875 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 private final Context mContext;
878 private final PowerManagerService mPM;
879 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 public WMThread(Context context, PowerManagerService pm,
882 boolean haveInputMethods) {
883 super("WindowManager");
884 mContext = context;
885 mPM = pm;
886 mHaveInputMethods = haveInputMethods;
887 }
Romain Guy06882f82009-06-10 13:36:04 -0700888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 public void run() {
890 Looper.prepare();
891 WindowManagerService s = new WindowManagerService(mContext, mPM,
892 mHaveInputMethods);
893 android.os.Process.setThreadPriority(
894 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700895 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 synchronized (this) {
898 mService = s;
899 notifyAll();
900 }
Romain Guy06882f82009-06-10 13:36:04 -0700901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 Looper.loop();
903 }
904 }
905
906 static class PolicyThread extends Thread {
907 private final WindowManagerPolicy mPolicy;
908 private final WindowManagerService mService;
909 private final Context mContext;
910 private final PowerManagerService mPM;
911 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 public PolicyThread(WindowManagerPolicy policy,
914 WindowManagerService service, Context context,
915 PowerManagerService pm) {
916 super("WindowManagerPolicy");
917 mPolicy = policy;
918 mService = service;
919 mContext = context;
920 mPM = pm;
921 }
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 public void run() {
924 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800925 WindowManagerPolicyThread.set(this, Looper.myLooper());
926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800928 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 android.os.Process.setThreadPriority(
930 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700931 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 synchronized (this) {
935 mRunning = true;
936 notifyAll();
937 }
Romain Guy06882f82009-06-10 13:36:04 -0700938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 Looper.loop();
940 }
941 }
942
943 private WindowManagerService(Context context, PowerManagerService pm,
944 boolean haveInputMethods) {
945 mContext = context;
946 mHaveInputMethods = haveInputMethods;
947 mLimitedAlphaCompositing = context.getResources().getBoolean(
948 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 mPowerManager = pm;
951 mPowerManager.setPolicy(mPolicy);
952 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
953 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
954 "SCREEN_FROZEN");
955 mScreenFrozenLock.setReferenceCounted(false);
956
957 mActivityManager = ActivityManagerNative.getDefault();
958 mBatteryStats = BatteryStatsService.getService();
959
960 // Get persisted window scale setting
961 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
962 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
963 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
964 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700965
Jim Miller284b62e2010-06-08 14:27:42 -0700966 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
967 IntentFilter filter = new IntentFilter();
968 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
969 mContext.registerReceiver(mBroadcastReceiver, filter);
970
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700971 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
972 "KEEP_SCREEN_ON_FLAG");
973 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974
Jeff Browne33348b2010-07-15 23:54:05 -0700975 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
978 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 synchronized (thr) {
981 while (!thr.mRunning) {
982 try {
983 thr.wait();
984 } catch (InterruptedException e) {
985 }
986 }
987 }
Romain Guy06882f82009-06-10 13:36:04 -0700988
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700989 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 // Add ourself to the Watchdog monitors.
992 Watchdog.getInstance().addMonitor(this);
993 }
994
995 @Override
996 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
997 throws RemoteException {
998 try {
999 return super.onTransact(code, data, reply, flags);
1000 } catch (RuntimeException e) {
1001 // The window manager only throws security exceptions, so let's
1002 // log all others.
1003 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001004 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 }
1006 throw e;
1007 }
1008 }
1009
Jeff Browne33348b2010-07-15 23:54:05 -07001010 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001012 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 TAG, "Adding window " + window + " at "
1014 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1015 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001016 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 }
1018
Jeff Browne33348b2010-07-15 23:54:05 -07001019 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001021 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 TAG, "Adding window " + window + " at "
1023 + i + " of " + mWindows.size() + " (before " + pos + ")");
1024 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001025 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 }
1027
1028 //This method finds out the index of a window that has the same app token as
1029 //win. used for z ordering the windows in mWindows
1030 private int findIdxBasedOnAppTokens(WindowState win) {
1031 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001032 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 int jmax = localmWindows.size();
1034 if(jmax == 0) {
1035 return -1;
1036 }
1037 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001038 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 if(wentry.mAppToken == win.mAppToken) {
1040 return j;
1041 }
1042 }
1043 return -1;
1044 }
Romain Guy06882f82009-06-10 13:36:04 -07001045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1047 final IWindow client = win.mClient;
1048 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001049 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 final int N = localmWindows.size();
1052 final WindowState attached = win.mAttachedWindow;
1053 int i;
1054 if (attached == null) {
1055 int tokenWindowsPos = token.windows.size();
1056 if (token.appWindowToken != null) {
1057 int index = tokenWindowsPos-1;
1058 if (index >= 0) {
1059 // If this application has existing windows, we
1060 // simply place the new window on top of them... but
1061 // keep the starting window on top.
1062 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1063 // Base windows go behind everything else.
1064 placeWindowBefore(token.windows.get(0), win);
1065 tokenWindowsPos = 0;
1066 } else {
1067 AppWindowToken atoken = win.mAppToken;
1068 if (atoken != null &&
1069 token.windows.get(index) == atoken.startingWindow) {
1070 placeWindowBefore(token.windows.get(index), win);
1071 tokenWindowsPos--;
1072 } else {
1073 int newIdx = findIdxBasedOnAppTokens(win);
1074 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001075 //there is a window above this one associated with the same
1076 //apptoken note that the window could be a floating window
1077 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001079 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001080 TAG, "Adding window " + win + " at "
1081 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001083 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 }
1086 }
1087 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001088 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 TAG, "Figuring out where to add app window "
1090 + client.asBinder() + " (token=" + token + ")");
1091 // Figure out where the window should go, based on the
1092 // order of applications.
1093 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001094 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 for (i=NA-1; i>=0; i--) {
1096 AppWindowToken t = mAppTokens.get(i);
1097 if (t == token) {
1098 i--;
1099 break;
1100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001101
Dianne Hackborna8f60182009-09-01 19:01:50 -07001102 // We haven't reached the token yet; if this token
1103 // is not going to the bottom and has windows, we can
1104 // use it as an anchor for when we do reach the token.
1105 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 pos = t.windows.get(0);
1107 }
1108 }
1109 // We now know the index into the apps. If we found
1110 // an app window above, that gives us the position; else
1111 // we need to look some more.
1112 if (pos != null) {
1113 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001114 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 if (atoken != null) {
1116 final int NC = atoken.windows.size();
1117 if (NC > 0) {
1118 WindowState bottom = atoken.windows.get(0);
1119 if (bottom.mSubLayer < 0) {
1120 pos = bottom;
1121 }
1122 }
1123 }
1124 placeWindowBefore(pos, win);
1125 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001126 // Continue looking down until we find the first
1127 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 while (i >= 0) {
1129 AppWindowToken t = mAppTokens.get(i);
1130 final int NW = t.windows.size();
1131 if (NW > 0) {
1132 pos = t.windows.get(NW-1);
1133 break;
1134 }
1135 i--;
1136 }
1137 if (pos != null) {
1138 // Move in front of any windows attached to this
1139 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001140 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 if (atoken != null) {
1142 final int NC = atoken.windows.size();
1143 if (NC > 0) {
1144 WindowState top = atoken.windows.get(NC-1);
1145 if (top.mSubLayer >= 0) {
1146 pos = top;
1147 }
1148 }
1149 }
1150 placeWindowAfter(pos, win);
1151 } else {
1152 // Just search for the start of this layer.
1153 final int myLayer = win.mBaseLayer;
1154 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001155 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 if (w.mBaseLayer > myLayer) {
1157 break;
1158 }
1159 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001160 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001161 TAG, "Adding window " + win + " at "
1162 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001164 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 }
1166 }
1167 }
1168 } else {
1169 // Figure out where window should go, based on layer.
1170 final int myLayer = win.mBaseLayer;
1171 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001172 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 i++;
1174 break;
1175 }
1176 }
1177 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001178 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001179 TAG, "Adding window " + win + " at "
1180 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001182 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 }
1184 if (addToToken) {
1185 token.windows.add(tokenWindowsPos, win);
1186 }
1187
1188 } else {
1189 // Figure out this window's ordering relative to the window
1190 // it is attached to.
1191 final int NA = token.windows.size();
1192 final int sublayer = win.mSubLayer;
1193 int largestSublayer = Integer.MIN_VALUE;
1194 WindowState windowWithLargestSublayer = null;
1195 for (i=0; i<NA; i++) {
1196 WindowState w = token.windows.get(i);
1197 final int wSublayer = w.mSubLayer;
1198 if (wSublayer >= largestSublayer) {
1199 largestSublayer = wSublayer;
1200 windowWithLargestSublayer = w;
1201 }
1202 if (sublayer < 0) {
1203 // For negative sublayers, we go below all windows
1204 // in the same sublayer.
1205 if (wSublayer >= sublayer) {
1206 if (addToToken) {
1207 token.windows.add(i, win);
1208 }
1209 placeWindowBefore(
1210 wSublayer >= 0 ? attached : w, win);
1211 break;
1212 }
1213 } else {
1214 // For positive sublayers, we go above all windows
1215 // in the same sublayer.
1216 if (wSublayer > sublayer) {
1217 if (addToToken) {
1218 token.windows.add(i, win);
1219 }
1220 placeWindowBefore(w, win);
1221 break;
1222 }
1223 }
1224 }
1225 if (i >= NA) {
1226 if (addToToken) {
1227 token.windows.add(win);
1228 }
1229 if (sublayer < 0) {
1230 placeWindowBefore(attached, win);
1231 } else {
1232 placeWindowAfter(largestSublayer >= 0
1233 ? windowWithLargestSublayer
1234 : attached,
1235 win);
1236 }
1237 }
1238 }
Romain Guy06882f82009-06-10 13:36:04 -07001239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 if (win.mAppToken != null && addToToken) {
1241 win.mAppToken.allAppWindows.add(win);
1242 }
1243 }
Romain Guy06882f82009-06-10 13:36:04 -07001244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 static boolean canBeImeTarget(WindowState w) {
1246 final int fl = w.mAttrs.flags
1247 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1248 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1249 return w.isVisibleOrAdding();
1250 }
1251 return false;
1252 }
Romain Guy06882f82009-06-10 13:36:04 -07001253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001255 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 final int N = localmWindows.size();
1257 WindowState w = null;
1258 int i = N;
1259 while (i > 0) {
1260 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001261 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001262
Joe Onorato8a9b2202010-02-26 18:56:32 -08001263 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 // + Integer.toHexString(w.mAttrs.flags));
1265 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001266 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 // Yet more tricksyness! If this window is a "starting"
1269 // window, we do actually want to be on top of it, but
1270 // it is not -really- where input will go. So if the caller
1271 // is not actually looking to move the IME, look down below
1272 // for a real window to target...
1273 if (!willMove
1274 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1275 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001276 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1278 i--;
1279 w = wb;
1280 }
1281 }
1282 break;
1283 }
1284 }
Romain Guy06882f82009-06-10 13:36:04 -07001285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001287
Joe Onorato8a9b2202010-02-26 18:56:32 -08001288 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 if (willMove && w != null) {
1292 final WindowState curTarget = mInputMethodTarget;
1293 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 // Now some fun for dealing with window animations that
1296 // modify the Z order. We need to look at all windows below
1297 // the current target that are in this app, finding the highest
1298 // visible one in layering.
1299 AppWindowToken token = curTarget.mAppToken;
1300 WindowState highestTarget = null;
1301 int highestPos = 0;
1302 if (token.animating || token.animation != null) {
1303 int pos = 0;
1304 pos = localmWindows.indexOf(curTarget);
1305 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001306 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 if (win.mAppToken != token) {
1308 break;
1309 }
1310 if (!win.mRemoved) {
1311 if (highestTarget == null || win.mAnimLayer >
1312 highestTarget.mAnimLayer) {
1313 highestTarget = win;
1314 highestPos = pos;
1315 }
1316 }
1317 pos--;
1318 }
1319 }
Romain Guy06882f82009-06-10 13:36:04 -07001320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001322 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 + mNextAppTransition + " " + highestTarget
1324 + " animating=" + highestTarget.isAnimating()
1325 + " layer=" + highestTarget.mAnimLayer
1326 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001327
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001328 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 // If we are currently setting up for an animation,
1330 // hold everything until we can find out what will happen.
1331 mInputMethodTargetWaitingAnim = true;
1332 mInputMethodTarget = highestTarget;
1333 return highestPos + 1;
1334 } else if (highestTarget.isAnimating() &&
1335 highestTarget.mAnimLayer > w.mAnimLayer) {
1336 // If the window we are currently targeting is involved
1337 // with an animation, and it is on top of the next target
1338 // we will be over, then hold off on moving until
1339 // that is done.
1340 mInputMethodTarget = highestTarget;
1341 return highestPos + 1;
1342 }
1343 }
1344 }
1345 }
Romain Guy06882f82009-06-10 13:36:04 -07001346
Joe Onorato8a9b2202010-02-26 18:56:32 -08001347 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 if (w != null) {
1349 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001350 if (DEBUG_INPUT_METHOD) {
1351 RuntimeException e = null;
1352 if (!HIDE_STACK_CRAWLS) {
1353 e = new RuntimeException();
1354 e.fillInStackTrace();
1355 }
1356 Slog.w(TAG, "Moving IM target from "
1357 + mInputMethodTarget + " to " + w, e);
1358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 mInputMethodTarget = w;
1360 if (w.mAppToken != null) {
1361 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1362 } else {
1363 setInputMethodAnimLayerAdjustment(0);
1364 }
1365 }
1366 return i+1;
1367 }
1368 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001369 if (DEBUG_INPUT_METHOD) {
1370 RuntimeException e = null;
1371 if (!HIDE_STACK_CRAWLS) {
1372 e = new RuntimeException();
1373 e.fillInStackTrace();
1374 }
1375 Slog.w(TAG, "Moving IM target from "
1376 + mInputMethodTarget + " to null", e);
1377 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 mInputMethodTarget = null;
1379 setInputMethodAnimLayerAdjustment(0);
1380 }
1381 return -1;
1382 }
Romain Guy06882f82009-06-10 13:36:04 -07001383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 void addInputMethodWindowToListLocked(WindowState win) {
1385 int pos = findDesiredInputMethodWindowIndexLocked(true);
1386 if (pos >= 0) {
1387 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001389 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001391 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 moveInputMethodDialogsLocked(pos+1);
1393 return;
1394 }
1395 win.mTargetAppToken = null;
1396 addWindowToListInOrderLocked(win, true);
1397 moveInputMethodDialogsLocked(pos);
1398 }
Romain Guy06882f82009-06-10 13:36:04 -07001399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001401 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 mInputMethodAnimLayerAdjustment = adj;
1403 WindowState imw = mInputMethodWindow;
1404 if (imw != null) {
1405 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001406 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 + " anim layer: " + imw.mAnimLayer);
1408 int wi = imw.mChildWindows.size();
1409 while (wi > 0) {
1410 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001411 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001413 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 + " anim layer: " + cw.mAnimLayer);
1415 }
1416 }
1417 int di = mInputMethodDialogs.size();
1418 while (di > 0) {
1419 di --;
1420 imw = mInputMethodDialogs.get(di);
1421 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001422 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 + " anim layer: " + imw.mAnimLayer);
1424 }
1425 }
Romain Guy06882f82009-06-10 13:36:04 -07001426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1428 int wpos = mWindows.indexOf(win);
1429 if (wpos >= 0) {
1430 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001431 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001433 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 int NC = win.mChildWindows.size();
1435 while (NC > 0) {
1436 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001437 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 int cpos = mWindows.indexOf(cw);
1439 if (cpos >= 0) {
1440 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001441 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001442 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 mWindows.remove(cpos);
1444 }
1445 }
1446 }
1447 return interestingPos;
1448 }
Romain Guy06882f82009-06-10 13:36:04 -07001449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 private void reAddWindowToListInOrderLocked(WindowState win) {
1451 addWindowToListInOrderLocked(win, false);
1452 // This is a hack to get all of the child windows added as well
1453 // at the right position. Child windows should be rare and
1454 // this case should be rare, so it shouldn't be that big a deal.
1455 int wpos = mWindows.indexOf(win);
1456 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001457 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001458 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001460 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 reAddWindowLocked(wpos, win);
1462 }
1463 }
Romain Guy06882f82009-06-10 13:36:04 -07001464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 void logWindowList(String prefix) {
1466 int N = mWindows.size();
1467 while (N > 0) {
1468 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001469 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 }
1471 }
Romain Guy06882f82009-06-10 13:36:04 -07001472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 void moveInputMethodDialogsLocked(int pos) {
1474 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001477 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 for (int i=0; i<N; i++) {
1479 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1480 }
1481 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001482 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 logWindowList(" ");
1484 }
Romain Guy06882f82009-06-10 13:36:04 -07001485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 if (pos >= 0) {
1487 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1488 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001489 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 if (wp == mInputMethodWindow) {
1491 pos++;
1492 }
1493 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001494 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 for (int i=0; i<N; i++) {
1496 WindowState win = dialogs.get(i);
1497 win.mTargetAppToken = targetAppToken;
1498 pos = reAddWindowLocked(pos, win);
1499 }
1500 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001501 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 logWindowList(" ");
1503 }
1504 return;
1505 }
1506 for (int i=0; i<N; i++) {
1507 WindowState win = dialogs.get(i);
1508 win.mTargetAppToken = null;
1509 reAddWindowToListInOrderLocked(win);
1510 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001511 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 logWindowList(" ");
1513 }
1514 }
1515 }
Romain Guy06882f82009-06-10 13:36:04 -07001516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1518 final WindowState imWin = mInputMethodWindow;
1519 final int DN = mInputMethodDialogs.size();
1520 if (imWin == null && DN == 0) {
1521 return false;
1522 }
Romain Guy06882f82009-06-10 13:36:04 -07001523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1525 if (imPos >= 0) {
1526 // In this case, the input method windows are to be placed
1527 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 // First check to see if the input method windows are already
1530 // located here, and contiguous.
1531 final int N = mWindows.size();
1532 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001533 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 // Figure out the actual input method window that should be
1536 // at the bottom of their stack.
1537 WindowState baseImWin = imWin != null
1538 ? imWin : mInputMethodDialogs.get(0);
1539 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001540 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 if (cw.mSubLayer < 0) baseImWin = cw;
1542 }
Romain Guy06882f82009-06-10 13:36:04 -07001543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 if (firstImWin == baseImWin) {
1545 // The windows haven't moved... but are they still contiguous?
1546 // First find the top IM window.
1547 int pos = imPos+1;
1548 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001549 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 break;
1551 }
1552 pos++;
1553 }
1554 pos++;
1555 // Now there should be no more input method windows above.
1556 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001557 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 break;
1559 }
1560 pos++;
1561 }
1562 if (pos >= N) {
1563 // All is good!
1564 return false;
1565 }
1566 }
Romain Guy06882f82009-06-10 13:36:04 -07001567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 if (imWin != null) {
1569 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001570 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 logWindowList(" ");
1572 }
1573 imPos = tmpRemoveWindowLocked(imPos, imWin);
1574 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001575 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 logWindowList(" ");
1577 }
1578 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1579 reAddWindowLocked(imPos, imWin);
1580 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001581 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 logWindowList(" ");
1583 }
1584 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1585 } else {
1586 moveInputMethodDialogsLocked(imPos);
1587 }
Romain Guy06882f82009-06-10 13:36:04 -07001588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 } else {
1590 // In this case, the input method windows go in a fixed layer,
1591 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001594 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 tmpRemoveWindowLocked(0, imWin);
1596 imWin.mTargetAppToken = null;
1597 reAddWindowToListInOrderLocked(imWin);
1598 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001599 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 logWindowList(" ");
1601 }
1602 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1603 } else {
1604 moveInputMethodDialogsLocked(-1);;
1605 }
Romain Guy06882f82009-06-10 13:36:04 -07001606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 }
Romain Guy06882f82009-06-10 13:36:04 -07001608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 if (needAssignLayers) {
1610 assignLayersLocked();
1611 }
Romain Guy06882f82009-06-10 13:36:04 -07001612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 return true;
1614 }
Romain Guy06882f82009-06-10 13:36:04 -07001615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 void adjustInputMethodDialogsLocked() {
1617 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1618 }
Romain Guy06882f82009-06-10 13:36:04 -07001619
Dianne Hackborn25994b42009-09-04 14:21:19 -07001620 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001621 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001622 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1623 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1624 ? wallpaperTarget.mAppToken.animation : null)
1625 + " upper=" + mUpperWallpaperTarget
1626 + " lower=" + mLowerWallpaperTarget);
1627 return (wallpaperTarget != null
1628 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1629 && wallpaperTarget.mAppToken.animation != null)))
1630 || mUpperWallpaperTarget != null
1631 || mLowerWallpaperTarget != null;
1632 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001633
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001634 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1635 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001636
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001637 int adjustWallpaperWindowsLocked() {
1638 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001639
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001640 final int dw = mDisplay.getWidth();
1641 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001642
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001643 // First find top-most window that has asked to be on top of the
1644 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001645 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001646 int N = localmWindows.size();
1647 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001648 WindowState foundW = null;
1649 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001650 WindowState topCurW = null;
1651 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001652 int i = N;
1653 while (i > 0) {
1654 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001655 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001656 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1657 if (topCurW == null) {
1658 topCurW = w;
1659 topCurI = i;
1660 }
1661 continue;
1662 }
1663 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001664 if (w.mAppToken != null) {
1665 // If this window's app token is hidden and not animating,
1666 // it is of no interest to us.
1667 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001668 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001669 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001670 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001671 continue;
1672 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001673 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001674 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001675 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1676 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001677 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001678 && (mWallpaperTarget == w
1679 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001680 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001681 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001682 foundW = w;
1683 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001684 if (w == mWallpaperTarget && ((w.mAppToken != null
1685 && w.mAppToken.animation != null)
1686 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001687 // The current wallpaper target is animating, so we'll
1688 // look behind it for another possible target and figure
1689 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001690 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001691 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001692 continue;
1693 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001694 break;
1695 }
1696 }
1697
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001698 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001699 // If we are currently waiting for an app transition, and either
1700 // the current target or the next target are involved with it,
1701 // then hold off on doing anything with the wallpaper.
1702 // Note that we are checking here for just whether the target
1703 // is part of an app token... which is potentially overly aggressive
1704 // (the app token may not be involved in the transition), but good
1705 // enough (we'll just wait until whatever transition is pending
1706 // executes).
1707 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001708 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001709 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001710 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001711 }
1712 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001713 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001714 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001715 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001716 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001717 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001718
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001719 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001720 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001721 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001722 + " oldTarget: " + mWallpaperTarget);
1723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001724
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001725 mLowerWallpaperTarget = null;
1726 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001727
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001728 WindowState oldW = mWallpaperTarget;
1729 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001730
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001731 // Now what is happening... if the current and new targets are
1732 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001733 if (foundW != null && oldW != null) {
1734 boolean oldAnim = oldW.mAnimation != null
1735 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1736 boolean foundAnim = foundW.mAnimation != null
1737 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001738 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001739 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001740 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001742 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001743 int oldI = localmWindows.indexOf(oldW);
1744 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001745 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 }
1747 if (oldI >= 0) {
1748 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001749 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001750 + "=" + oldW + "; new#" + foundI
1751 + "=" + foundW);
1752 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001753
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001754 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001755 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001756 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001757 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001758 }
1759 mWallpaperTarget = oldW;
1760 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001761
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001762 // Now set the upper and lower wallpaper targets
1763 // correctly, and make sure that we are positioning
1764 // the wallpaper below the lower.
1765 if (foundI > oldI) {
1766 // The new target is on top of the old one.
1767 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001768 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001769 }
1770 mUpperWallpaperTarget = foundW;
1771 mLowerWallpaperTarget = oldW;
1772 foundW = oldW;
1773 foundI = oldI;
1774 } else {
1775 // The new target is below the old one.
1776 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001777 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001778 }
1779 mUpperWallpaperTarget = oldW;
1780 mLowerWallpaperTarget = foundW;
1781 }
1782 }
1783 }
1784 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001785
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001786 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001787 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001788 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1789 || (mLowerWallpaperTarget.mAppToken != null
1790 && mLowerWallpaperTarget.mAppToken.animation != null);
1791 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1792 || (mUpperWallpaperTarget.mAppToken != null
1793 && mUpperWallpaperTarget.mAppToken.animation != null);
1794 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001795 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 }
1798 mLowerWallpaperTarget = null;
1799 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001800 }
1801 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001802
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001803 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001804 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001805 // The window is visible to the compositor... but is it visible
1806 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001807 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001808 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001809
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001810 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001811 // its layer adjustment. Only do this if we are not transfering
1812 // between two wallpaper targets.
1813 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001815 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001816
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001817 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1818 * TYPE_LAYER_MULTIPLIER
1819 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001820
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001821 // Now w is the window we are supposed to be behind... but we
1822 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001823 // AND any starting window associated with it, AND below the
1824 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001825 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001826 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001827 if (wb.mBaseLayer < maxLayer &&
1828 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001829 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001830 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001831 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001832 // This window is not related to the previous one in any
1833 // interesting way, so stop here.
1834 break;
1835 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001836 foundW = wb;
1837 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001838 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001839 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001840 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001842
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001843 if (foundW == null && topCurW != null) {
1844 // There is no wallpaper target, so it goes at the bottom.
1845 // We will assume it is the same place as last time, if known.
1846 foundW = topCurW;
1847 foundI = topCurI+1;
1848 } else {
1849 // Okay i is the position immediately above the wallpaper. Look at
1850 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001851 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001853
Dianne Hackborn284ac932009-08-28 10:34:25 -07001854 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001855 if (mWallpaperTarget.mWallpaperX >= 0) {
1856 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001857 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001858 }
1859 if (mWallpaperTarget.mWallpaperY >= 0) {
1860 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001861 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001862 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001863 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001864
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001865 // Start stepping backwards from here, ensuring that our wallpaper windows
1866 // are correctly placed.
1867 int curTokenIndex = mWallpaperTokens.size();
1868 while (curTokenIndex > 0) {
1869 curTokenIndex--;
1870 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001871 if (token.hidden == visible) {
1872 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1873 token.hidden = !visible;
1874 // Need to do a layout to ensure the wallpaper now has the
1875 // correct size.
1876 mLayoutNeeded = true;
1877 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001878
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001879 int curWallpaperIndex = token.windows.size();
1880 while (curWallpaperIndex > 0) {
1881 curWallpaperIndex--;
1882 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001883
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001884 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001885 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001886 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001887
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001888 // First, make sure the client has the current visibility
1889 // state.
1890 if (wallpaper.mWallpaperVisible != visible) {
1891 wallpaper.mWallpaperVisible = visible;
1892 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001893 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001894 "Setting visibility of wallpaper " + wallpaper
1895 + ": " + visible);
1896 wallpaper.mClient.dispatchAppVisibility(visible);
1897 } catch (RemoteException e) {
1898 }
1899 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001900
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001901 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001902 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001903 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001904
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001905 // First, if this window is at the current index, then all
1906 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001907 if (wallpaper == foundW) {
1908 foundI--;
1909 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001910 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001911 continue;
1912 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001913
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001914 // The window didn't match... the current wallpaper window,
1915 // wherever it is, is in the wrong place, so make sure it is
1916 // not in the list.
1917 int oldIndex = localmWindows.indexOf(wallpaper);
1918 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001919 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001920 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001921 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001922 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001923 if (oldIndex < foundI) {
1924 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001925 }
1926 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001927
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001928 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001929 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001930 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001931 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001932
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001933 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001934 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001935 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001936 }
1937 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001938
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001939 return changed;
1940 }
1941
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001942 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001943 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001944 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001945 mWallpaperAnimLayerAdjustment = adj;
1946 int curTokenIndex = mWallpaperTokens.size();
1947 while (curTokenIndex > 0) {
1948 curTokenIndex--;
1949 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1950 int curWallpaperIndex = token.windows.size();
1951 while (curWallpaperIndex > 0) {
1952 curWallpaperIndex--;
1953 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1954 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001955 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001956 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001957 }
1958 }
1959 }
1960
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001961 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1962 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001963 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001964 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001965 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001966 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001967 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1968 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1969 changed = wallpaperWin.mXOffset != offset;
1970 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001971 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001972 + wallpaperWin + " x: " + offset);
1973 wallpaperWin.mXOffset = offset;
1974 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001975 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001976 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001977 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001978 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001979 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001980
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001981 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001982 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001983 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1984 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1985 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001986 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001987 + wallpaperWin + " y: " + offset);
1988 changed = true;
1989 wallpaperWin.mYOffset = offset;
1990 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001991 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001992 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001993 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001994 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001995 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001996
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001997 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001998 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001999 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002000 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2001 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002002 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002003 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002004 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002005 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002006 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2007 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002008 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002009 if (mWaitingOnWallpaper != null) {
2010 long start = SystemClock.uptimeMillis();
2011 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2012 < start) {
2013 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002014 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002015 "Waiting for offset complete...");
2016 mWindowMap.wait(WALLPAPER_TIMEOUT);
2017 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002018 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002019 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002020 if ((start+WALLPAPER_TIMEOUT)
2021 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002022 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002023 + wallpaperWin);
2024 mLastWallpaperTimeoutTime = start;
2025 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002026 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002027 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002028 }
2029 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002030 } catch (RemoteException e) {
2031 }
2032 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002033
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002034 return changed;
2035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002036
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002037 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002038 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002039 if (mWaitingOnWallpaper != null &&
2040 mWaitingOnWallpaper.mClient.asBinder() == window) {
2041 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002042 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002043 }
2044 }
2045 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002046
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002047 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002048 final int dw = mDisplay.getWidth();
2049 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002050
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002051 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002052
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002053 WindowState target = mWallpaperTarget;
2054 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002055 if (target.mWallpaperX >= 0) {
2056 mLastWallpaperX = target.mWallpaperX;
2057 } else if (changingTarget.mWallpaperX >= 0) {
2058 mLastWallpaperX = changingTarget.mWallpaperX;
2059 }
2060 if (target.mWallpaperY >= 0) {
2061 mLastWallpaperY = target.mWallpaperY;
2062 } else if (changingTarget.mWallpaperY >= 0) {
2063 mLastWallpaperY = changingTarget.mWallpaperY;
2064 }
2065 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002066
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002067 int curTokenIndex = mWallpaperTokens.size();
2068 while (curTokenIndex > 0) {
2069 curTokenIndex--;
2070 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2071 int curWallpaperIndex = token.windows.size();
2072 while (curWallpaperIndex > 0) {
2073 curWallpaperIndex--;
2074 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2075 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2076 wallpaper.computeShownFrameLocked();
2077 changed = true;
2078 // We only want to be synchronous with one wallpaper.
2079 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002080 }
2081 }
2082 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002083
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002084 return changed;
2085 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002086
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002087 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002088 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002089 final int dw = mDisplay.getWidth();
2090 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002091
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002092 int curTokenIndex = mWallpaperTokens.size();
2093 while (curTokenIndex > 0) {
2094 curTokenIndex--;
2095 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002096 if (token.hidden == visible) {
2097 token.hidden = !visible;
2098 // Need to do a layout to ensure the wallpaper now has the
2099 // correct size.
2100 mLayoutNeeded = true;
2101 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002102
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002103 int curWallpaperIndex = token.windows.size();
2104 while (curWallpaperIndex > 0) {
2105 curWallpaperIndex--;
2106 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2107 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002108 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002110
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002111 if (wallpaper.mWallpaperVisible != visible) {
2112 wallpaper.mWallpaperVisible = visible;
2113 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002114 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002115 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002116 + ": " + visible);
2117 wallpaper.mClient.dispatchAppVisibility(visible);
2118 } catch (RemoteException e) {
2119 }
2120 }
2121 }
2122 }
2123 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 public int addWindow(Session session, IWindow client,
2126 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002127 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 int res = mPolicy.checkAddPermission(attrs);
2129 if (res != WindowManagerImpl.ADD_OKAY) {
2130 return res;
2131 }
Romain Guy06882f82009-06-10 13:36:04 -07002132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 boolean reportNewConfig = false;
2134 WindowState attachedWindow = null;
2135 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002136 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002140 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 }
Romain Guy06882f82009-06-10 13:36:04 -07002142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002144 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2146 }
2147
2148 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002149 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002151 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 + attrs.token + ". Aborting.");
2153 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2154 }
2155 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2156 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002157 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 + attrs.token + ". Aborting.");
2159 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2160 }
2161 }
2162
2163 boolean addToken = false;
2164 WindowToken token = mTokenMap.get(attrs.token);
2165 if (token == null) {
2166 if (attrs.type >= FIRST_APPLICATION_WINDOW
2167 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002168 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 + attrs.token + ". Aborting.");
2170 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2171 }
2172 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002173 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 + attrs.token + ". Aborting.");
2175 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2176 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002177 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002178 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002179 + attrs.token + ". Aborting.");
2180 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 token = new WindowToken(attrs.token, -1, false);
2183 addToken = true;
2184 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2185 && attrs.type <= LAST_APPLICATION_WINDOW) {
2186 AppWindowToken atoken = token.appWindowToken;
2187 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002188 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 + token + ". Aborting.");
2190 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2191 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002192 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193 + token + ". Aborting.");
2194 return WindowManagerImpl.ADD_APP_EXITING;
2195 }
2196 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2197 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002198 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2200 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2201 }
2202 } else if (attrs.type == TYPE_INPUT_METHOD) {
2203 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002204 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 + attrs.token + ". Aborting.");
2206 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2207 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002208 } else if (attrs.type == TYPE_WALLPAPER) {
2209 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002210 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002211 + attrs.token + ". Aborting.");
2212 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 }
2215
2216 win = new WindowState(session, client, token,
2217 attachedWindow, attrs, viewVisibility);
2218 if (win.mDeathRecipient == null) {
2219 // Client has apparently died, so there is no reason to
2220 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002221 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 + " that is dead, aborting.");
2223 return WindowManagerImpl.ADD_APP_EXITING;
2224 }
2225
2226 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 res = mPolicy.prepareAddWindowLw(win, attrs);
2229 if (res != WindowManagerImpl.ADD_OKAY) {
2230 return res;
2231 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002232
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002233 if (outInputChannel != null) {
2234 String name = win.makeInputChannelName();
2235 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2236 win.mInputChannel = inputChannels[0];
2237 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2238
2239 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002240 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241
2242 // From now on, no exceptions or errors allowed!
2243
2244 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002245
Dianne Hackborn5132b372010-07-29 12:51:35 -07002246 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002248 if (addToken) {
2249 mTokenMap.put(attrs.token, token);
2250 mTokenList.add(token);
2251 }
2252 win.attach();
2253 mWindowMap.put(client.asBinder(), win);
2254
2255 if (attrs.type == TYPE_APPLICATION_STARTING &&
2256 token.appWindowToken != null) {
2257 token.appWindowToken.startingWindow = win;
2258 }
2259
2260 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 if (attrs.type == TYPE_INPUT_METHOD) {
2263 mInputMethodWindow = win;
2264 addInputMethodWindowToListLocked(win);
2265 imMayMove = false;
2266 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2267 mInputMethodDialogs.add(win);
2268 addWindowToListInOrderLocked(win, true);
2269 adjustInputMethodDialogsLocked();
2270 imMayMove = false;
2271 } else {
2272 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002273 if (attrs.type == TYPE_WALLPAPER) {
2274 mLastWallpaperTimeoutTime = 0;
2275 adjustWallpaperWindowsLocked();
2276 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002277 adjustWallpaperWindowsLocked();
2278 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 }
Romain Guy06882f82009-06-10 13:36:04 -07002280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 if (mInTouchMode) {
2286 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2287 }
2288 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2289 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2290 }
Romain Guy06882f82009-06-10 13:36:04 -07002291
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002292 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002294 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2295 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 imMayMove = false;
2297 }
2298 }
Romain Guy06882f82009-06-10 13:36:04 -07002299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002301 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 }
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 assignLayersLocked();
2305 // Don't do layout here, the window must call
2306 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 //dump();
2309
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002310 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002311 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002312 }
Jeff Brown349703e2010-06-22 01:27:15 -07002313
Joe Onorato8a9b2202010-02-26 18:56:32 -08002314 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 TAG, "New client " + client.asBinder()
2316 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002317
2318 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2319 reportNewConfig = true;
2320 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 }
2322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 if (reportNewConfig) {
2324 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 return res;
2330 }
Romain Guy06882f82009-06-10 13:36:04 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 public void removeWindow(Session session, IWindow client) {
2333 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002334 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 if (win == null) {
2336 return;
2337 }
2338 removeWindowLocked(session, win);
2339 }
2340 }
Romain Guy06882f82009-06-10 13:36:04 -07002341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 public void removeWindowLocked(Session session, WindowState win) {
2343
Joe Onorato8a9b2202010-02-26 18:56:32 -08002344 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 TAG, "Remove " + win + " client="
2346 + Integer.toHexString(System.identityHashCode(
2347 win.mClient.asBinder()))
2348 + ", surface=" + win.mSurface);
2349
2350 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002351
2352 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002353
Joe Onorato8a9b2202010-02-26 18:56:32 -08002354 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2356 + " mExiting=" + win.mExiting
2357 + " isAnimating=" + win.isAnimating()
2358 + " app-animation="
2359 + (win.mAppToken != null ? win.mAppToken.animation : null)
2360 + " inPendingTransaction="
2361 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2362 + " mDisplayFrozen=" + mDisplayFrozen);
2363 // Visibility of the removed window. Will be used later to update orientation later on.
2364 boolean wasVisible = false;
2365 // First, see if we need to run an animation. If we do, we have
2366 // to hold off on removing the window until the animation is done.
2367 // If the display is frozen, just remove immediately, since the
2368 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002369 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 // If we are not currently running the exit animation, we
2371 // need to see about starting one.
2372 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2375 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2376 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2377 }
2378 // Try starting an animation.
2379 if (applyAnimationLocked(win, transit, false)) {
2380 win.mExiting = true;
2381 }
2382 }
2383 if (win.mExiting || win.isAnimating()) {
2384 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002385 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 win.mExiting = true;
2387 win.mRemoveOnExit = true;
2388 mLayoutNeeded = true;
2389 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2390 performLayoutAndPlaceSurfacesLocked();
2391 if (win.mAppToken != null) {
2392 win.mAppToken.updateReportedVisibilityLocked();
2393 }
2394 //dump();
2395 Binder.restoreCallingIdentity(origId);
2396 return;
2397 }
2398 }
2399
2400 removeWindowInnerLocked(session, win);
2401 // Removing a visible window will effect the computed orientation
2402 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002403 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002404 != mForcedAppOrientation
2405 && updateOrientationFromAppTokensLocked()) {
2406 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 }
2408 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2409 Binder.restoreCallingIdentity(origId);
2410 }
Romain Guy06882f82009-06-10 13:36:04 -07002411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 if (mInputMethodTarget == win) {
2416 moveInputMethodWindowsIfNeededLocked(false);
2417 }
Romain Guy06882f82009-06-10 13:36:04 -07002418
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002419 if (false) {
2420 RuntimeException e = new RuntimeException("here");
2421 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002422 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002423 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 mPolicy.removeWindowLw(win);
2426 win.removeLocked();
2427
2428 mWindowMap.remove(win.mClient.asBinder());
2429 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002430 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002431 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432
2433 if (mInputMethodWindow == win) {
2434 mInputMethodWindow = null;
2435 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2436 mInputMethodDialogs.remove(win);
2437 }
Romain Guy06882f82009-06-10 13:36:04 -07002438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 final WindowToken token = win.mToken;
2440 final AppWindowToken atoken = win.mAppToken;
2441 token.windows.remove(win);
2442 if (atoken != null) {
2443 atoken.allAppWindows.remove(win);
2444 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002445 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 TAG, "**** Removing window " + win + ": count="
2447 + token.windows.size());
2448 if (token.windows.size() == 0) {
2449 if (!token.explicit) {
2450 mTokenMap.remove(token.token);
2451 mTokenList.remove(token);
2452 } else if (atoken != null) {
2453 atoken.firstWindowDrawn = false;
2454 }
2455 }
2456
2457 if (atoken != null) {
2458 if (atoken.startingWindow == win) {
2459 atoken.startingWindow = null;
2460 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2461 // If this is the last window and we had requested a starting
2462 // transition window, well there is no point now.
2463 atoken.startingData = null;
2464 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2465 // If this is the last window except for a starting transition
2466 // window, we need to get rid of the starting transition.
2467 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002468 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 + ": no more real windows");
2470 }
2471 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2472 mH.sendMessage(m);
2473 }
2474 }
Romain Guy06882f82009-06-10 13:36:04 -07002475
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002476 if (win.mAttrs.type == TYPE_WALLPAPER) {
2477 mLastWallpaperTimeoutTime = 0;
2478 adjustWallpaperWindowsLocked();
2479 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002480 adjustWallpaperWindowsLocked();
2481 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 if (!mInLayout) {
2484 assignLayersLocked();
2485 mLayoutNeeded = true;
2486 performLayoutAndPlaceSurfacesLocked();
2487 if (win.mAppToken != null) {
2488 win.mAppToken.updateReportedVisibilityLocked();
2489 }
2490 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002491
2492 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 }
2494
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002495 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2496 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2497 + ": " + msg + " / " + w.mAttrs.getTitle();
2498 if (where != null) {
2499 Slog.i(TAG, str, where);
2500 } else {
2501 Slog.i(TAG, str);
2502 }
2503 }
2504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2506 long origId = Binder.clearCallingIdentity();
2507 try {
2508 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002509 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002511 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 Surface.openTransaction();
2513 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002514 if (SHOW_TRANSACTIONS) logSurface(w,
2515 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 w.mSurface.setTransparentRegionHint(region);
2517 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002518 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002519 Surface.closeTransaction();
2520 }
2521 }
2522 }
2523 } finally {
2524 Binder.restoreCallingIdentity(origId);
2525 }
2526 }
2527
2528 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002529 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 Rect visibleInsets) {
2531 long origId = Binder.clearCallingIdentity();
2532 try {
2533 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002534 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 if (w != null) {
2536 w.mGivenInsetsPending = false;
2537 w.mGivenContentInsets.set(contentInsets);
2538 w.mGivenVisibleInsets.set(visibleInsets);
2539 w.mTouchableInsets = touchableInsets;
2540 mLayoutNeeded = true;
2541 performLayoutAndPlaceSurfacesLocked();
2542 }
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(origId);
2546 }
2547 }
Romain Guy06882f82009-06-10 13:36:04 -07002548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 public void getWindowDisplayFrame(Session session, IWindow client,
2550 Rect outDisplayFrame) {
2551 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002552 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 if (win == null) {
2554 outDisplayFrame.setEmpty();
2555 return;
2556 }
2557 outDisplayFrame.set(win.mDisplayFrame);
2558 }
2559 }
2560
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002561 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2562 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002563 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2564 window.mWallpaperX = x;
2565 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002566 window.mWallpaperXStep = xStep;
2567 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002568 if (updateWallpaperOffsetLocked(window, true)) {
2569 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002570 }
2571 }
2572 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002573
Dianne Hackborn75804932009-10-20 20:15:20 -07002574 void wallpaperCommandComplete(IBinder window, Bundle result) {
2575 synchronized (mWindowMap) {
2576 if (mWaitingOnWallpaper != null &&
2577 mWaitingOnWallpaper.mClient.asBinder() == window) {
2578 mWaitingOnWallpaper = null;
2579 mWindowMap.notifyAll();
2580 }
2581 }
2582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002583
Dianne Hackborn75804932009-10-20 20:15:20 -07002584 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2585 String action, int x, int y, int z, Bundle extras, boolean sync) {
2586 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2587 || window == mUpperWallpaperTarget) {
2588 boolean doWait = sync;
2589 int curTokenIndex = mWallpaperTokens.size();
2590 while (curTokenIndex > 0) {
2591 curTokenIndex--;
2592 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2593 int curWallpaperIndex = token.windows.size();
2594 while (curWallpaperIndex > 0) {
2595 curWallpaperIndex--;
2596 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2597 try {
2598 wallpaper.mClient.dispatchWallpaperCommand(action,
2599 x, y, z, extras, sync);
2600 // We only want to be synchronous with one wallpaper.
2601 sync = false;
2602 } catch (RemoteException e) {
2603 }
2604 }
2605 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002606
Dianne Hackborn75804932009-10-20 20:15:20 -07002607 if (doWait) {
2608 // XXX Need to wait for result.
2609 }
2610 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002611
Dianne Hackborn75804932009-10-20 20:15:20 -07002612 return null;
2613 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 public int relayoutWindow(Session session, IWindow client,
2616 WindowManager.LayoutParams attrs, int requestedWidth,
2617 int requestedHeight, int viewVisibility, boolean insetsPending,
2618 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002619 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002620 boolean displayed = false;
2621 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002622 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002626 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 if (win == null) {
2628 return 0;
2629 }
2630 win.mRequestedWidth = requestedWidth;
2631 win.mRequestedHeight = requestedHeight;
2632
2633 if (attrs != null) {
2634 mPolicy.adjustWindowParamsLw(attrs);
2635 }
Romain Guy06882f82009-06-10 13:36:04 -07002636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637 int attrChanges = 0;
2638 int flagChanges = 0;
2639 if (attrs != null) {
2640 flagChanges = win.mAttrs.flags ^= attrs.flags;
2641 attrChanges = win.mAttrs.copyFrom(attrs);
2642 }
2643
Joe Onorato8a9b2202010-02-26 18:56:32 -08002644 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645
2646 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2647 win.mAlpha = attrs.alpha;
2648 }
2649
2650 final boolean scaledWindow =
2651 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2652
2653 if (scaledWindow) {
2654 // requested{Width|Height} Surface's physical size
2655 // attrs.{width|height} Size on screen
2656 win.mHScale = (attrs.width != requestedWidth) ?
2657 (attrs.width / (float)requestedWidth) : 1.0f;
2658 win.mVScale = (attrs.height != requestedHeight) ?
2659 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002660 } else {
2661 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002662 }
2663
2664 boolean imMayMove = (flagChanges&(
2665 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2666 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 boolean focusMayChange = win.mViewVisibility != viewVisibility
2669 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2670 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002671
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002672 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2673 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 win.mRelayoutCalled = true;
2676 final int oldVisibility = win.mViewVisibility;
2677 win.mViewVisibility = viewVisibility;
2678 if (viewVisibility == View.VISIBLE &&
2679 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2680 displayed = !win.isVisibleLw();
2681 if (win.mExiting) {
2682 win.mExiting = false;
2683 win.mAnimation = null;
2684 }
2685 if (win.mDestroying) {
2686 win.mDestroying = false;
2687 mDestroySurface.remove(win);
2688 }
2689 if (oldVisibility == View.GONE) {
2690 win.mEnterAnimationPending = true;
2691 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002692 if (displayed) {
2693 if (win.mSurface != null && !win.mDrawPending
2694 && !win.mCommitDrawPending && !mDisplayFrozen
2695 && mPolicy.isScreenOn()) {
2696 applyEnterAnimationLocked(win);
2697 }
2698 if ((win.mAttrs.flags
2699 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2700 if (DEBUG_VISIBILITY) Slog.v(TAG,
2701 "Relayout window turning screen on: " + win);
2702 win.mTurnOnScreen = true;
2703 }
2704 int diff = 0;
2705 if (win.mConfiguration != mCurConfiguration
2706 && (win.mConfiguration == null
2707 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2708 win.mConfiguration = mCurConfiguration;
2709 if (DEBUG_CONFIGURATION) {
2710 Slog.i(TAG, "Window " + win + " visible with new config: "
2711 + win.mConfiguration + " / 0x"
2712 + Integer.toHexString(diff));
2713 }
2714 outConfig.setTo(mCurConfiguration);
2715 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2718 // To change the format, we need to re-build the surface.
2719 win.destroySurfaceLocked();
2720 displayed = true;
2721 }
2722 try {
2723 Surface surface = win.createSurfaceLocked();
2724 if (surface != null) {
2725 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002726 win.mReportDestroySurface = false;
2727 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002728 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002729 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002731 // For some reason there isn't a surface. Clear the
2732 // caller's object so they see the same state.
2733 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002734 }
2735 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002736 mInputMonitor.updateInputWindowsLw();
2737
Joe Onorato8a9b2202010-02-26 18:56:32 -08002738 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002739 + client + " (" + win.mAttrs.getTitle() + ")",
2740 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 Binder.restoreCallingIdentity(origId);
2742 return 0;
2743 }
2744 if (displayed) {
2745 focusMayChange = true;
2746 }
2747 if (win.mAttrs.type == TYPE_INPUT_METHOD
2748 && mInputMethodWindow == null) {
2749 mInputMethodWindow = win;
2750 imMayMove = true;
2751 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002752 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2753 && win.mAppToken != null
2754 && win.mAppToken.startingWindow != null) {
2755 // Special handling of starting window over the base
2756 // window of the app: propagate lock screen flags to it,
2757 // to provide the correct semantics while starting.
2758 final int mask =
2759 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002760 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2761 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002762 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2763 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2764 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 } else {
2766 win.mEnterAnimationPending = false;
2767 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002768 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002769 + ": mExiting=" + win.mExiting
2770 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 // If we are not currently running the exit animation, we
2772 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002773 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 // Try starting an animation; if there isn't one, we
2775 // can destroy the surface right away.
2776 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2777 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2778 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2779 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002780 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002781 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002782 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 } else if (win.isAnimating()) {
2785 // Currently in a hide animation... turn this into
2786 // an exit.
2787 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002788 } else if (win == mWallpaperTarget) {
2789 // If the wallpaper is currently behind this
2790 // window, we need to change both of them inside
2791 // of a transaction to avoid artifacts.
2792 win.mExiting = true;
2793 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 } else {
2795 if (mInputMethodWindow == win) {
2796 mInputMethodWindow = null;
2797 }
2798 win.destroySurfaceLocked();
2799 }
2800 }
2801 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002802
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002803 if (win.mSurface == null || (win.getAttrs().flags
2804 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2805 || win.mSurfacePendingDestroy) {
2806 // We are being called from a local process, which
2807 // means outSurface holds its current surface. Ensure the
2808 // surface object is cleared, but we don't want it actually
2809 // destroyed at this point.
2810 win.mSurfacePendingDestroy = false;
2811 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002812 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002813 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002814 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002815 "Keeping surface, will report destroy: " + win);
2816 win.mReportDestroySurface = true;
2817 outSurface.copyFrom(win.mSurface);
2818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 }
2820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 if (focusMayChange) {
2822 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2823 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 imMayMove = false;
2825 }
2826 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2827 }
Romain Guy06882f82009-06-10 13:36:04 -07002828
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002829 // updateFocusedWindowLocked() already assigned layers so we only need to
2830 // reassign them at this point if the IM window state gets shuffled
2831 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002834 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2835 // Little hack here -- we -should- be able to rely on the
2836 // function to return true if the IME has moved and needs
2837 // its layer recomputed. However, if the IME was hidden
2838 // and isn't actually moved in the list, its layer may be
2839 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 assignLayers = true;
2841 }
2842 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002843 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002844 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002845 assignLayers = true;
2846 }
2847 }
Romain Guy06882f82009-06-10 13:36:04 -07002848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 mLayoutNeeded = true;
2850 win.mGivenInsetsPending = insetsPending;
2851 if (assignLayers) {
2852 assignLayersLocked();
2853 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002854 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002856 if (displayed && win.mIsWallpaper) {
2857 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002858 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 if (win.mAppToken != null) {
2861 win.mAppToken.updateReportedVisibilityLocked();
2862 }
2863 outFrame.set(win.mFrame);
2864 outContentInsets.set(win.mContentInsets);
2865 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002866 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002868 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 + ", requestedHeight=" + requestedHeight
2870 + ", viewVisibility=" + viewVisibility
2871 + "\nRelayout returning frame=" + outFrame
2872 + ", surface=" + outSurface);
2873
Joe Onorato8a9b2202010-02-26 18:56:32 -08002874 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2876
2877 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002878
2879 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 }
2881
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002882 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 sendNewConfiguration();
2884 }
Romain Guy06882f82009-06-10 13:36:04 -07002885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2889 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2890 }
2891
2892 public void finishDrawingWindow(Session session, IWindow client) {
2893 final long origId = Binder.clearCallingIdentity();
2894 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002895 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002897 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2898 adjustWallpaperWindowsLocked();
2899 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 mLayoutNeeded = true;
2901 performLayoutAndPlaceSurfacesLocked();
2902 }
2903 }
2904 Binder.restoreCallingIdentity(origId);
2905 }
2906
2907 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002908 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 + (lp != null ? lp.packageName : null)
2910 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2911 if (lp != null && lp.windowAnimations != 0) {
2912 // If this is a system resource, don't try to load it from the
2913 // application resources. It is nice to avoid loading application
2914 // resources if we can.
2915 String packageName = lp.packageName != null ? lp.packageName : "android";
2916 int resId = lp.windowAnimations;
2917 if ((resId&0xFF000000) == 0x01000000) {
2918 packageName = "android";
2919 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002920 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 + packageName);
2922 return AttributeCache.instance().get(packageName, resId,
2923 com.android.internal.R.styleable.WindowAnimation);
2924 }
2925 return null;
2926 }
Romain Guy06882f82009-06-10 13:36:04 -07002927
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002928 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002929 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002930 + packageName + " resId=0x" + Integer.toHexString(resId));
2931 if (packageName != null) {
2932 if ((resId&0xFF000000) == 0x01000000) {
2933 packageName = "android";
2934 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002935 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002936 + packageName);
2937 return AttributeCache.instance().get(packageName, resId,
2938 com.android.internal.R.styleable.WindowAnimation);
2939 }
2940 return null;
2941 }
2942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 private void applyEnterAnimationLocked(WindowState win) {
2944 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2945 if (win.mEnterAnimationPending) {
2946 win.mEnterAnimationPending = false;
2947 transit = WindowManagerPolicy.TRANSIT_ENTER;
2948 }
2949
2950 applyAnimationLocked(win, transit, true);
2951 }
2952
2953 private boolean applyAnimationLocked(WindowState win,
2954 int transit, boolean isEntrance) {
2955 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2956 // If we are trying to apply an animation, but already running
2957 // an animation of the same type, then just leave that one alone.
2958 return true;
2959 }
Romain Guy06882f82009-06-10 13:36:04 -07002960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 // Only apply an animation if the display isn't frozen. If it is
2962 // frozen, there is no reason to animate and it can cause strange
2963 // artifacts when we unfreeze the display if some different animation
2964 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002965 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 int anim = mPolicy.selectAnimationLw(win, transit);
2967 int attr = -1;
2968 Animation a = null;
2969 if (anim != 0) {
2970 a = AnimationUtils.loadAnimation(mContext, anim);
2971 } else {
2972 switch (transit) {
2973 case WindowManagerPolicy.TRANSIT_ENTER:
2974 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2975 break;
2976 case WindowManagerPolicy.TRANSIT_EXIT:
2977 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2978 break;
2979 case WindowManagerPolicy.TRANSIT_SHOW:
2980 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2981 break;
2982 case WindowManagerPolicy.TRANSIT_HIDE:
2983 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2984 break;
2985 }
2986 if (attr >= 0) {
2987 a = loadAnimation(win.mAttrs, attr);
2988 }
2989 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002990 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2992 + " mAnimation=" + win.mAnimation
2993 + " isEntrance=" + isEntrance);
2994 if (a != null) {
2995 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002996 RuntimeException e = null;
2997 if (!HIDE_STACK_CRAWLS) {
2998 e = new RuntimeException();
2999 e.fillInStackTrace();
3000 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003001 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 }
3003 win.setAnimation(a);
3004 win.mAnimationIsEntrance = isEntrance;
3005 }
3006 } else {
3007 win.clearAnimation();
3008 }
3009
3010 return win.mAnimation != null;
3011 }
3012
3013 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3014 int anim = 0;
3015 Context context = mContext;
3016 if (animAttr >= 0) {
3017 AttributeCache.Entry ent = getCachedAnimations(lp);
3018 if (ent != null) {
3019 context = ent.context;
3020 anim = ent.array.getResourceId(animAttr, 0);
3021 }
3022 }
3023 if (anim != 0) {
3024 return AnimationUtils.loadAnimation(context, anim);
3025 }
3026 return null;
3027 }
Romain Guy06882f82009-06-10 13:36:04 -07003028
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003029 private Animation loadAnimation(String packageName, int resId) {
3030 int anim = 0;
3031 Context context = mContext;
3032 if (resId >= 0) {
3033 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3034 if (ent != null) {
3035 context = ent.context;
3036 anim = resId;
3037 }
3038 }
3039 if (anim != 0) {
3040 return AnimationUtils.loadAnimation(context, anim);
3041 }
3042 return null;
3043 }
3044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 private boolean applyAnimationLocked(AppWindowToken wtoken,
3046 WindowManager.LayoutParams lp, int transit, boolean enter) {
3047 // Only apply an animation if the display isn't frozen. If it is
3048 // frozen, there is no reason to animate and it can cause strange
3049 // artifacts when we unfreeze the display if some different animation
3050 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003051 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003052 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003053 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003054 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003055 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003056 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003057 } else if (mNextAppTransitionPackage != null) {
3058 a = loadAnimation(mNextAppTransitionPackage, enter ?
3059 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003060 } else {
3061 int animAttr = 0;
3062 switch (transit) {
3063 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3064 animAttr = enter
3065 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3066 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3067 break;
3068 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3069 animAttr = enter
3070 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3071 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3072 break;
3073 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3074 animAttr = enter
3075 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3076 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3077 break;
3078 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3079 animAttr = enter
3080 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3081 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3082 break;
3083 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3084 animAttr = enter
3085 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3086 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3087 break;
3088 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3089 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003090 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003091 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3092 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003093 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003094 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003095 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3096 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003097 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003098 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003099 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003100 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3101 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3102 break;
3103 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3104 animAttr = enter
3105 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3106 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3107 break;
3108 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3109 animAttr = enter
3110 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3111 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003112 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003113 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003114 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003115 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003116 + " anim=" + a
3117 + " animAttr=0x" + Integer.toHexString(animAttr)
3118 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 if (a != null) {
3121 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003122 RuntimeException e = null;
3123 if (!HIDE_STACK_CRAWLS) {
3124 e = new RuntimeException();
3125 e.fillInStackTrace();
3126 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003127 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 }
3129 wtoken.setAnimation(a);
3130 }
3131 } else {
3132 wtoken.clearAnimation();
3133 }
3134
3135 return wtoken.animation != null;
3136 }
3137
3138 // -------------------------------------------------------------
3139 // Application Window Tokens
3140 // -------------------------------------------------------------
3141
3142 public void validateAppTokens(List tokens) {
3143 int v = tokens.size()-1;
3144 int m = mAppTokens.size()-1;
3145 while (v >= 0 && m >= 0) {
3146 AppWindowToken wtoken = mAppTokens.get(m);
3147 if (wtoken.removed) {
3148 m--;
3149 continue;
3150 }
3151 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003152 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3154 }
3155 v--;
3156 m--;
3157 }
3158 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003159 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 v--;
3161 }
3162 while (m >= 0) {
3163 AppWindowToken wtoken = mAppTokens.get(m);
3164 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003165 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 }
3167 m--;
3168 }
3169 }
3170
3171 boolean checkCallingPermission(String permission, String func) {
3172 // Quick check: if the calling permission is me, it's all okay.
3173 if (Binder.getCallingPid() == Process.myPid()) {
3174 return true;
3175 }
Romain Guy06882f82009-06-10 13:36:04 -07003176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 if (mContext.checkCallingPermission(permission)
3178 == PackageManager.PERMISSION_GRANTED) {
3179 return true;
3180 }
3181 String msg = "Permission Denial: " + func + " from pid="
3182 + Binder.getCallingPid()
3183 + ", uid=" + Binder.getCallingUid()
3184 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003185 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 return false;
3187 }
Romain Guy06882f82009-06-10 13:36:04 -07003188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 AppWindowToken findAppWindowToken(IBinder token) {
3190 WindowToken wtoken = mTokenMap.get(token);
3191 if (wtoken == null) {
3192 return null;
3193 }
3194 return wtoken.appWindowToken;
3195 }
Romain Guy06882f82009-06-10 13:36:04 -07003196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 public void addWindowToken(IBinder token, int type) {
3198 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3199 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003200 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 }
Romain Guy06882f82009-06-10 13:36:04 -07003202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003203 synchronized(mWindowMap) {
3204 WindowToken wtoken = mTokenMap.get(token);
3205 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003206 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 return;
3208 }
3209 wtoken = new WindowToken(token, type, true);
3210 mTokenMap.put(token, wtoken);
3211 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003212 if (type == TYPE_WALLPAPER) {
3213 mWallpaperTokens.add(wtoken);
3214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 }
3216 }
Romain Guy06882f82009-06-10 13:36:04 -07003217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 public void removeWindowToken(IBinder token) {
3219 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3220 "removeWindowToken()")) {
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 }
3223
3224 final long origId = Binder.clearCallingIdentity();
3225 synchronized(mWindowMap) {
3226 WindowToken wtoken = mTokenMap.remove(token);
3227 mTokenList.remove(wtoken);
3228 if (wtoken != null) {
3229 boolean delayed = false;
3230 if (!wtoken.hidden) {
3231 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 final int N = wtoken.windows.size();
3234 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 for (int i=0; i<N; i++) {
3237 WindowState win = wtoken.windows.get(i);
3238
3239 if (win.isAnimating()) {
3240 delayed = true;
3241 }
Romain Guy06882f82009-06-10 13:36:04 -07003242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 if (win.isVisibleNow()) {
3244 applyAnimationLocked(win,
3245 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 changed = true;
3247 }
3248 }
3249
3250 if (changed) {
3251 mLayoutNeeded = true;
3252 performLayoutAndPlaceSurfacesLocked();
3253 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3254 }
Romain Guy06882f82009-06-10 13:36:04 -07003255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 if (delayed) {
3257 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003258 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3259 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 }
3261 }
Romain Guy06882f82009-06-10 13:36:04 -07003262
Jeff Brownc5ed5912010-07-14 18:48:53 -07003263 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003265 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 }
3267 }
3268 Binder.restoreCallingIdentity(origId);
3269 }
3270
3271 public void addAppToken(int addPos, IApplicationToken token,
3272 int groupId, int requestedOrientation, boolean fullscreen) {
3273 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3274 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003275 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 }
Jeff Brown349703e2010-06-22 01:27:15 -07003277
3278 // Get the dispatching timeout here while we are not holding any locks so that it
3279 // can be cached by the AppWindowToken. The timeout value is used later by the
3280 // input dispatcher in code that does hold locks. If we did not cache the value
3281 // here we would run the chance of introducing a deadlock between the window manager
3282 // (which holds locks while updating the input dispatcher state) and the activity manager
3283 // (which holds locks while querying the application token).
3284 long inputDispatchingTimeoutNanos;
3285 try {
3286 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3287 } catch (RemoteException ex) {
3288 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3289 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3290 }
Romain Guy06882f82009-06-10 13:36:04 -07003291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 synchronized(mWindowMap) {
3293 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3294 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003295 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 return;
3297 }
3298 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003299 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 wtoken.groupId = groupId;
3301 wtoken.appFullscreen = fullscreen;
3302 wtoken.requestedOrientation = requestedOrientation;
3303 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 mTokenMap.put(token.asBinder(), wtoken);
3306 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 // Application tokens start out hidden.
3309 wtoken.hidden = true;
3310 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 //dump();
3313 }
3314 }
Romain Guy06882f82009-06-10 13:36:04 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 public void setAppGroupId(IBinder token, int groupId) {
3317 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3318 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003319 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 }
3321
3322 synchronized(mWindowMap) {
3323 AppWindowToken wtoken = findAppWindowToken(token);
3324 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003325 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 return;
3327 }
3328 wtoken.groupId = groupId;
3329 }
3330 }
Romain Guy06882f82009-06-10 13:36:04 -07003331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 public int getOrientationFromWindowsLocked() {
3333 int pos = mWindows.size() - 1;
3334 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003335 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 pos--;
3337 if (wtoken.mAppToken != null) {
3338 // We hit an application window. so the orientation will be determined by the
3339 // app window. No point in continuing further.
3340 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3341 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003342 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 continue;
3344 }
3345 int req = wtoken.mAttrs.screenOrientation;
3346 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3347 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3348 continue;
3349 } else {
3350 return req;
3351 }
3352 }
3353 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3354 }
Romain Guy06882f82009-06-10 13:36:04 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003357 int pos = mAppTokens.size() - 1;
3358 int curGroup = 0;
3359 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3360 boolean findingBehind = false;
3361 boolean haveGroup = false;
3362 boolean lastFullscreen = false;
3363 while (pos >= 0) {
3364 AppWindowToken wtoken = mAppTokens.get(pos);
3365 pos--;
3366 // if we're about to tear down this window and not seek for
3367 // the behind activity, don't use it for orientation
3368 if (!findingBehind
3369 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3370 continue;
3371 }
3372
3373 if (!haveGroup) {
3374 // We ignore any hidden applications on the top.
3375 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003376 continue;
3377 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003378 haveGroup = true;
3379 curGroup = wtoken.groupId;
3380 lastOrientation = wtoken.requestedOrientation;
3381 } else if (curGroup != wtoken.groupId) {
3382 // If we have hit a new application group, and the bottom
3383 // of the previous group didn't explicitly say to use
3384 // the orientation behind it, and the last app was
3385 // full screen, then we'll stick with the
3386 // user's orientation.
3387 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3388 && lastFullscreen) {
3389 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003392 int or = wtoken.requestedOrientation;
3393 // If this application is fullscreen, and didn't explicitly say
3394 // to use the orientation behind it, then just take whatever
3395 // orientation it has and ignores whatever is under it.
3396 lastFullscreen = wtoken.appFullscreen;
3397 if (lastFullscreen
3398 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3399 return or;
3400 }
3401 // If this application has requested an explicit orientation,
3402 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003403 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3404 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003405 return or;
3406 }
3407 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3408 }
3409 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 }
Romain Guy06882f82009-06-10 13:36:04 -07003411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003413 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003414 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3415 "updateOrientationFromAppTokens()")) {
3416 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003418
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003419 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003421
3422 synchronized(mWindowMap) {
3423 if (updateOrientationFromAppTokensLocked()) {
3424 if (freezeThisOneIfNeeded != null) {
3425 AppWindowToken wtoken = findAppWindowToken(
3426 freezeThisOneIfNeeded);
3427 if (wtoken != null) {
3428 startAppFreezingScreenLocked(wtoken,
3429 ActivityInfo.CONFIG_ORIENTATION);
3430 }
3431 }
3432 config = computeNewConfigurationLocked();
3433
3434 } else if (currentConfig != null) {
3435 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003436 // state mismatches the activity manager's, update it,
3437 // disregarding font scale, which should remain set to
3438 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003439 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003440 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003441 if (computeNewConfigurationLocked(mTempConfiguration)) {
3442 if (currentConfig.diff(mTempConfiguration) != 0) {
3443 mWaitingForConfig = true;
3444 mLayoutNeeded = true;
3445 startFreezingDisplayLocked();
3446 config = new Configuration(mTempConfiguration);
3447 }
3448 }
3449 }
3450 }
3451
Dianne Hackborncfaef692009-06-15 14:24:44 -07003452 Binder.restoreCallingIdentity(ident);
3453 return config;
3454 }
3455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003457 * Determine the new desired orientation of the display, returning
3458 * a non-null new Configuration if it has changed from the current
3459 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3460 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3461 * SCREEN. This will typically be done for you if you call
3462 * sendNewConfiguration().
3463 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 * The orientation is computed from non-application windows first. If none of
3465 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003466 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003467 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3468 * android.os.IBinder)
3469 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003470 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003471 if (mDisplayFrozen) {
3472 // If the display is frozen, some activities may be in the middle
3473 // of restarting, and thus have removed their old window. If the
3474 // window has the flag to hide the lock screen, then the lock screen
3475 // can re-appear and inflict its own orientation on us. Keep the
3476 // orientation stable until this all settles down.
3477 return false;
3478 }
3479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 long ident = Binder.clearCallingIdentity();
3482 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003483 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 mForcedAppOrientation = req;
3487 //send a message to Policy indicating orientation change to take
3488 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003489 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003490 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3491 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3492 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 }
3494 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003495
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003496 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003497 } finally {
3498 Binder.restoreCallingIdentity(ident);
3499 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 }
Romain Guy06882f82009-06-10 13:36:04 -07003501
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003502 int computeForcedAppOrientationLocked() {
3503 int req = getOrientationFromWindowsLocked();
3504 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3505 req = getOrientationFromAppTokensLocked();
3506 }
3507 return req;
3508 }
Romain Guy06882f82009-06-10 13:36:04 -07003509
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003510 public void setNewConfiguration(Configuration config) {
3511 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3512 "setNewConfiguration()")) {
3513 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3514 }
3515
3516 synchronized(mWindowMap) {
3517 mCurConfiguration = new Configuration(config);
3518 mWaitingForConfig = false;
3519 performLayoutAndPlaceSurfacesLocked();
3520 }
3521 }
3522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3524 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3525 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003526 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 }
Romain Guy06882f82009-06-10 13:36:04 -07003528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 synchronized(mWindowMap) {
3530 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3531 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003532 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 return;
3534 }
Romain Guy06882f82009-06-10 13:36:04 -07003535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003536 wtoken.requestedOrientation = requestedOrientation;
3537 }
3538 }
Romain Guy06882f82009-06-10 13:36:04 -07003539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 public int getAppOrientation(IApplicationToken token) {
3541 synchronized(mWindowMap) {
3542 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3543 if (wtoken == null) {
3544 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3545 }
Romain Guy06882f82009-06-10 13:36:04 -07003546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 return wtoken.requestedOrientation;
3548 }
3549 }
Romain Guy06882f82009-06-10 13:36:04 -07003550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003551 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3552 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3553 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003554 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003555 }
3556
3557 synchronized(mWindowMap) {
3558 boolean changed = false;
3559 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003560 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 changed = mFocusedApp != null;
3562 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003563 if (changed) {
3564 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 } else {
3567 AppWindowToken newFocus = findAppWindowToken(token);
3568 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003569 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 return;
3571 }
3572 changed = mFocusedApp != newFocus;
3573 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003574 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003575 if (changed) {
3576 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 }
3579
3580 if (moveFocusNow && changed) {
3581 final long origId = Binder.clearCallingIdentity();
3582 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3583 Binder.restoreCallingIdentity(origId);
3584 }
3585 }
3586 }
3587
3588 public void prepareAppTransition(int transit) {
3589 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3590 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003591 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 }
Romain Guy06882f82009-06-10 13:36:04 -07003593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003595 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 TAG, "Prepare app transition: transit=" + transit
3597 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003598 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003599 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3600 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003602 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3603 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3604 // Opening a new task always supersedes a close for the anim.
3605 mNextAppTransition = transit;
3606 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3607 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3608 // Opening a new activity always supersedes a close for the anim.
3609 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 }
3611 mAppTransitionReady = false;
3612 mAppTransitionTimeout = false;
3613 mStartingIconInTransition = false;
3614 mSkipAppTransitionAnimation = false;
3615 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3616 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3617 5000);
3618 }
3619 }
3620 }
3621
3622 public int getPendingAppTransition() {
3623 return mNextAppTransition;
3624 }
Romain Guy06882f82009-06-10 13:36:04 -07003625
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003626 public void overridePendingAppTransition(String packageName,
3627 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003628 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003629 mNextAppTransitionPackage = packageName;
3630 mNextAppTransitionEnter = enterAnim;
3631 mNextAppTransitionExit = exitAnim;
3632 }
3633 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 public void executeAppTransition() {
3636 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3637 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003638 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 }
Romain Guy06882f82009-06-10 13:36:04 -07003640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003642 if (DEBUG_APP_TRANSITIONS) {
3643 RuntimeException e = new RuntimeException("here");
3644 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003645 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003646 + mNextAppTransition, e);
3647 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003648 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 mAppTransitionReady = true;
3650 final long origId = Binder.clearCallingIdentity();
3651 performLayoutAndPlaceSurfacesLocked();
3652 Binder.restoreCallingIdentity(origId);
3653 }
3654 }
3655 }
3656
3657 public void setAppStartingWindow(IBinder token, String pkg,
3658 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3659 IBinder transferFrom, boolean createIfNeeded) {
3660 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3661 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003662 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 }
3664
3665 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003666 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3668 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 AppWindowToken wtoken = findAppWindowToken(token);
3671 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003672 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 return;
3674 }
3675
3676 // If the display is frozen, we won't do anything until the
3677 // actual window is displayed so there is no reason to put in
3678 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003679 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 return;
3681 }
Romain Guy06882f82009-06-10 13:36:04 -07003682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 if (wtoken.startingData != null) {
3684 return;
3685 }
Romain Guy06882f82009-06-10 13:36:04 -07003686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 if (transferFrom != null) {
3688 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3689 if (ttoken != null) {
3690 WindowState startingWindow = ttoken.startingWindow;
3691 if (startingWindow != null) {
3692 if (mStartingIconInTransition) {
3693 // In this case, the starting icon has already
3694 // been displayed, so start letting windows get
3695 // shown immediately without any more transitions.
3696 mSkipAppTransitionAnimation = true;
3697 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003698 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 "Moving existing starting from " + ttoken
3700 + " to " + wtoken);
3701 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 // Transfer the starting window over to the new
3704 // token.
3705 wtoken.startingData = ttoken.startingData;
3706 wtoken.startingView = ttoken.startingView;
3707 wtoken.startingWindow = startingWindow;
3708 ttoken.startingData = null;
3709 ttoken.startingView = null;
3710 ttoken.startingWindow = null;
3711 ttoken.startingMoved = true;
3712 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003713 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003715 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003716 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003718 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 ttoken.windows.remove(startingWindow);
3720 ttoken.allAppWindows.remove(startingWindow);
3721 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 // Propagate other interesting state between the
3724 // tokens. If the old token is displayed, we should
3725 // immediately force the new one to be displayed. If
3726 // it is animating, we need to move that animation to
3727 // the new one.
3728 if (ttoken.allDrawn) {
3729 wtoken.allDrawn = true;
3730 }
3731 if (ttoken.firstWindowDrawn) {
3732 wtoken.firstWindowDrawn = true;
3733 }
3734 if (!ttoken.hidden) {
3735 wtoken.hidden = false;
3736 wtoken.hiddenRequested = false;
3737 wtoken.willBeHidden = false;
3738 }
3739 if (wtoken.clientHidden != ttoken.clientHidden) {
3740 wtoken.clientHidden = ttoken.clientHidden;
3741 wtoken.sendAppVisibilityToClients();
3742 }
3743 if (ttoken.animation != null) {
3744 wtoken.animation = ttoken.animation;
3745 wtoken.animating = ttoken.animating;
3746 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3747 ttoken.animation = null;
3748 ttoken.animLayerAdjustment = 0;
3749 wtoken.updateLayers();
3750 ttoken.updateLayers();
3751 }
Romain Guy06882f82009-06-10 13:36:04 -07003752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 mLayoutNeeded = true;
3755 performLayoutAndPlaceSurfacesLocked();
3756 Binder.restoreCallingIdentity(origId);
3757 return;
3758 } else if (ttoken.startingData != null) {
3759 // The previous app was getting ready to show a
3760 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003761 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 "Moving pending starting from " + ttoken
3763 + " to " + wtoken);
3764 wtoken.startingData = ttoken.startingData;
3765 ttoken.startingData = null;
3766 ttoken.startingMoved = true;
3767 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3768 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3769 // want to process the message ASAP, before any other queued
3770 // messages.
3771 mH.sendMessageAtFrontOfQueue(m);
3772 return;
3773 }
3774 }
3775 }
3776
3777 // There is no existing starting window, and the caller doesn't
3778 // want us to create one, so that's it!
3779 if (!createIfNeeded) {
3780 return;
3781 }
Romain Guy06882f82009-06-10 13:36:04 -07003782
Dianne Hackborn284ac932009-08-28 10:34:25 -07003783 // If this is a translucent or wallpaper window, then don't
3784 // show a starting window -- the current effect (a full-screen
3785 // opaque starting window that fades away to the real contents
3786 // when it is ready) does not work for this.
3787 if (theme != 0) {
3788 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3789 com.android.internal.R.styleable.Window);
3790 if (ent.array.getBoolean(
3791 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3792 return;
3793 }
3794 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003795 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3796 return;
3797 }
3798 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003799 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3800 return;
3801 }
3802 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 mStartingIconInTransition = true;
3805 wtoken.startingData = new StartingData(
3806 pkg, theme, nonLocalizedLabel,
3807 labelRes, icon);
3808 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3809 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3810 // want to process the message ASAP, before any other queued
3811 // messages.
3812 mH.sendMessageAtFrontOfQueue(m);
3813 }
3814 }
3815
3816 public void setAppWillBeHidden(IBinder token) {
3817 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3818 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003819 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 }
3821
3822 AppWindowToken wtoken;
3823
3824 synchronized(mWindowMap) {
3825 wtoken = findAppWindowToken(token);
3826 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003827 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 -08003828 return;
3829 }
3830 wtoken.willBeHidden = true;
3831 }
3832 }
Romain Guy06882f82009-06-10 13:36:04 -07003833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3835 boolean visible, int transit, boolean performLayout) {
3836 boolean delayed = false;
3837
3838 if (wtoken.clientHidden == visible) {
3839 wtoken.clientHidden = !visible;
3840 wtoken.sendAppVisibilityToClients();
3841 }
Romain Guy06882f82009-06-10 13:36:04 -07003842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 wtoken.willBeHidden = false;
3844 if (wtoken.hidden == visible) {
3845 final int N = wtoken.allAppWindows.size();
3846 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003847 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3849 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003852
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003853 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003854 if (wtoken.animation == sDummyAnimation) {
3855 wtoken.animation = null;
3856 }
3857 applyAnimationLocked(wtoken, lp, transit, visible);
3858 changed = true;
3859 if (wtoken.animation != null) {
3860 delayed = runningAppAnimation = true;
3861 }
3862 }
Romain Guy06882f82009-06-10 13:36:04 -07003863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 for (int i=0; i<N; i++) {
3865 WindowState win = wtoken.allAppWindows.get(i);
3866 if (win == wtoken.startingWindow) {
3867 continue;
3868 }
3869
3870 if (win.isAnimating()) {
3871 delayed = true;
3872 }
Romain Guy06882f82009-06-10 13:36:04 -07003873
Joe Onorato8a9b2202010-02-26 18:56:32 -08003874 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 //win.dump(" ");
3876 if (visible) {
3877 if (!win.isVisibleNow()) {
3878 if (!runningAppAnimation) {
3879 applyAnimationLocked(win,
3880 WindowManagerPolicy.TRANSIT_ENTER, true);
3881 }
3882 changed = true;
3883 }
3884 } else if (win.isVisibleNow()) {
3885 if (!runningAppAnimation) {
3886 applyAnimationLocked(win,
3887 WindowManagerPolicy.TRANSIT_EXIT, false);
3888 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 changed = true;
3890 }
3891 }
3892
3893 wtoken.hidden = wtoken.hiddenRequested = !visible;
3894 if (!visible) {
3895 unsetAppFreezingScreenLocked(wtoken, true, true);
3896 } else {
3897 // If we are being set visible, and the starting window is
3898 // not yet displayed, then make sure it doesn't get displayed.
3899 WindowState swin = wtoken.startingWindow;
3900 if (swin != null && (swin.mDrawPending
3901 || swin.mCommitDrawPending)) {
3902 swin.mPolicyVisibility = false;
3903 swin.mPolicyVisibilityAfterAnim = false;
3904 }
3905 }
Romain Guy06882f82009-06-10 13:36:04 -07003906
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003908 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3909 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003910
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003911 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003912 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003913 if (performLayout) {
3914 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3915 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003916 } else {
3917 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 }
3920 }
3921
3922 if (wtoken.animation != null) {
3923 delayed = true;
3924 }
Romain Guy06882f82009-06-10 13:36:04 -07003925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003926 return delayed;
3927 }
3928
3929 public void setAppVisibility(IBinder token, boolean visible) {
3930 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3931 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003932 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 }
3934
3935 AppWindowToken wtoken;
3936
3937 synchronized(mWindowMap) {
3938 wtoken = findAppWindowToken(token);
3939 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003940 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 return;
3942 }
3943
3944 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003945 RuntimeException e = null;
3946 if (!HIDE_STACK_CRAWLS) {
3947 e = new RuntimeException();
3948 e.fillInStackTrace();
3949 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003950 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003951 + "): mNextAppTransition=" + mNextAppTransition
3952 + " hidden=" + wtoken.hidden
3953 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3954 }
Romain Guy06882f82009-06-10 13:36:04 -07003955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 // If we are preparing an app transition, then delay changing
3957 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003958 if (!mDisplayFrozen && mPolicy.isScreenOn()
3959 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 // Already in requested state, don't do anything more.
3961 if (wtoken.hiddenRequested != visible) {
3962 return;
3963 }
3964 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003965
Joe Onorato8a9b2202010-02-26 18:56:32 -08003966 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 TAG, "Setting dummy animation on: " + wtoken);
3968 wtoken.setDummyAnimation();
3969 mOpeningApps.remove(wtoken);
3970 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003971 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 wtoken.inPendingTransaction = true;
3973 if (visible) {
3974 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 wtoken.startingDisplayed = false;
3976 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003977
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003978 // If the token is currently hidden (should be the
3979 // common case), then we need to set up to wait for
3980 // its windows to be ready.
3981 if (wtoken.hidden) {
3982 wtoken.allDrawn = false;
3983 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003984
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003985 if (wtoken.clientHidden) {
3986 // In the case where we are making an app visible
3987 // but holding off for a transition, we still need
3988 // to tell the client to make its windows visible so
3989 // they get drawn. Otherwise, we will wait on
3990 // performing the transition until all windows have
3991 // been drawn, they never will be, and we are sad.
3992 wtoken.clientHidden = false;
3993 wtoken.sendAppVisibilityToClients();
3994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 }
3996 } else {
3997 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003998
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003999 // If the token is currently visible (should be the
4000 // common case), then set up to wait for it to be hidden.
4001 if (!wtoken.hidden) {
4002 wtoken.waitingToHide = true;
4003 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 }
4005 return;
4006 }
Romain Guy06882f82009-06-10 13:36:04 -07004007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004009 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 wtoken.updateReportedVisibilityLocked();
4011 Binder.restoreCallingIdentity(origId);
4012 }
4013 }
4014
4015 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4016 boolean unfreezeSurfaceNow, boolean force) {
4017 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004018 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 + " force=" + force);
4020 final int N = wtoken.allAppWindows.size();
4021 boolean unfrozeWindows = false;
4022 for (int i=0; i<N; i++) {
4023 WindowState w = wtoken.allAppWindows.get(i);
4024 if (w.mAppFreezing) {
4025 w.mAppFreezing = false;
4026 if (w.mSurface != null && !w.mOrientationChanging) {
4027 w.mOrientationChanging = true;
4028 }
4029 unfrozeWindows = true;
4030 }
4031 }
4032 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004033 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 wtoken.freezingScreen = false;
4035 mAppsFreezingScreen--;
4036 }
4037 if (unfreezeSurfaceNow) {
4038 if (unfrozeWindows) {
4039 mLayoutNeeded = true;
4040 performLayoutAndPlaceSurfacesLocked();
4041 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004042 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004043 }
4044 }
4045 }
Romain Guy06882f82009-06-10 13:36:04 -07004046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004047 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4048 int configChanges) {
4049 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004050 RuntimeException e = null;
4051 if (!HIDE_STACK_CRAWLS) {
4052 e = new RuntimeException();
4053 e.fillInStackTrace();
4054 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004055 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004056 + ": hidden=" + wtoken.hidden + " freezing="
4057 + wtoken.freezingScreen, e);
4058 }
4059 if (!wtoken.hiddenRequested) {
4060 if (!wtoken.freezingScreen) {
4061 wtoken.freezingScreen = true;
4062 mAppsFreezingScreen++;
4063 if (mAppsFreezingScreen == 1) {
4064 startFreezingDisplayLocked();
4065 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4066 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4067 5000);
4068 }
4069 }
4070 final int N = wtoken.allAppWindows.size();
4071 for (int i=0; i<N; i++) {
4072 WindowState w = wtoken.allAppWindows.get(i);
4073 w.mAppFreezing = true;
4074 }
4075 }
4076 }
Romain Guy06882f82009-06-10 13:36:04 -07004077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 public void startAppFreezingScreen(IBinder token, int configChanges) {
4079 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4080 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004081 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 }
4083
4084 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004085 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004086 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004087 return;
4088 }
Romain Guy06882f82009-06-10 13:36:04 -07004089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 AppWindowToken wtoken = findAppWindowToken(token);
4091 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004092 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 return;
4094 }
4095 final long origId = Binder.clearCallingIdentity();
4096 startAppFreezingScreenLocked(wtoken, configChanges);
4097 Binder.restoreCallingIdentity(origId);
4098 }
4099 }
Romain Guy06882f82009-06-10 13:36:04 -07004100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 public void stopAppFreezingScreen(IBinder token, boolean force) {
4102 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4103 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004104 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004105 }
4106
4107 synchronized(mWindowMap) {
4108 AppWindowToken wtoken = findAppWindowToken(token);
4109 if (wtoken == null || wtoken.appToken == null) {
4110 return;
4111 }
4112 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004113 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4115 unsetAppFreezingScreenLocked(wtoken, true, force);
4116 Binder.restoreCallingIdentity(origId);
4117 }
4118 }
Romain Guy06882f82009-06-10 13:36:04 -07004119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004120 public void removeAppToken(IBinder token) {
4121 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4122 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004123 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 }
4125
4126 AppWindowToken wtoken = null;
4127 AppWindowToken startingToken = null;
4128 boolean delayed = false;
4129
4130 final long origId = Binder.clearCallingIdentity();
4131 synchronized(mWindowMap) {
4132 WindowToken basewtoken = mTokenMap.remove(token);
4133 mTokenList.remove(basewtoken);
4134 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004135 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004136 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004137 wtoken.inPendingTransaction = false;
4138 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004139 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 if (mClosingApps.contains(wtoken)) {
4141 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004142 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004143 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004144 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 delayed = true;
4146 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004147 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004148 TAG, "Removing app " + wtoken + " delayed=" + delayed
4149 + " animation=" + wtoken.animation
4150 + " animating=" + wtoken.animating);
4151 if (delayed) {
4152 // set the token aside because it has an active animation to be finished
4153 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004154 } else {
4155 // Make sure there is no animation running on this token,
4156 // so any windows associated with it will be removed as
4157 // soon as their animations are complete
4158 wtoken.animation = null;
4159 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 }
4161 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004162 if (mLastEnterAnimToken == wtoken) {
4163 mLastEnterAnimToken = null;
4164 mLastEnterAnimParams = null;
4165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 wtoken.removed = true;
4167 if (wtoken.startingData != null) {
4168 startingToken = wtoken;
4169 }
4170 unsetAppFreezingScreenLocked(wtoken, true, true);
4171 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004172 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 mFocusedApp = null;
4174 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004175 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 }
4177 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004178 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 }
Romain Guy06882f82009-06-10 13:36:04 -07004180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 if (!delayed && wtoken != null) {
4182 wtoken.updateReportedVisibilityLocked();
4183 }
4184 }
4185 Binder.restoreCallingIdentity(origId);
4186
4187 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004188 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189 + startingToken + ": app token removed");
4190 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4191 mH.sendMessage(m);
4192 }
4193 }
4194
4195 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4196 final int NW = token.windows.size();
4197 for (int i=0; i<NW; i++) {
4198 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004199 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004201 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 int j = win.mChildWindows.size();
4203 while (j > 0) {
4204 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004205 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004206 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004207 "Tmp removing child window " + cwin);
4208 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 }
4210 }
4211 return NW > 0;
4212 }
4213
4214 void dumpAppTokensLocked() {
4215 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004216 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 }
4218 }
Romain Guy06882f82009-06-10 13:36:04 -07004219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 void dumpWindowsLocked() {
4221 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004222 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 }
4224 }
Romain Guy06882f82009-06-10 13:36:04 -07004225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 private int findWindowOffsetLocked(int tokenPos) {
4227 final int NW = mWindows.size();
4228
4229 if (tokenPos >= mAppTokens.size()) {
4230 int i = NW;
4231 while (i > 0) {
4232 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004233 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004234 if (win.getAppToken() != null) {
4235 return i+1;
4236 }
4237 }
4238 }
4239
4240 while (tokenPos > 0) {
4241 // Find the first app token below the new position that has
4242 // a window displayed.
4243 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004244 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004246 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004247 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004248 "Skipping token -- currently sending to bottom");
4249 tokenPos--;
4250 continue;
4251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 int i = wtoken.windows.size();
4253 while (i > 0) {
4254 i--;
4255 WindowState win = wtoken.windows.get(i);
4256 int j = win.mChildWindows.size();
4257 while (j > 0) {
4258 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004259 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004260 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 for (int pos=NW-1; pos>=0; pos--) {
4262 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004263 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 "Found child win @" + (pos+1));
4265 return pos+1;
4266 }
4267 }
4268 }
4269 }
4270 for (int pos=NW-1; pos>=0; pos--) {
4271 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004272 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 return pos+1;
4274 }
4275 }
4276 }
4277 tokenPos--;
4278 }
4279
4280 return 0;
4281 }
4282
4283 private final int reAddWindowLocked(int index, WindowState win) {
4284 final int NCW = win.mChildWindows.size();
4285 boolean added = false;
4286 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004287 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004289 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004290 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 mWindows.add(index, win);
4292 index++;
4293 added = true;
4294 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004295 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004296 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 mWindows.add(index, cwin);
4298 index++;
4299 }
4300 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004301 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004302 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 mWindows.add(index, win);
4304 index++;
4305 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004306 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 return index;
4308 }
Romain Guy06882f82009-06-10 13:36:04 -07004309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4311 final int NW = token.windows.size();
4312 for (int i=0; i<NW; i++) {
4313 index = reAddWindowLocked(index, token.windows.get(i));
4314 }
4315 return index;
4316 }
4317
4318 public void moveAppToken(int index, IBinder token) {
4319 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4320 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004321 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
4323
4324 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004325 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 if (DEBUG_REORDER) dumpAppTokensLocked();
4327 final AppWindowToken wtoken = findAppWindowToken(token);
4328 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004329 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 + token + " (" + wtoken + ")");
4331 return;
4332 }
4333 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004334 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004338 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 if (DEBUG_REORDER) dumpWindowsLocked();
4340 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004341 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 if (DEBUG_REORDER) dumpWindowsLocked();
4343 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004344 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 if (DEBUG_REORDER) dumpWindowsLocked();
4346 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 mLayoutNeeded = true;
4348 performLayoutAndPlaceSurfacesLocked();
4349 }
4350 Binder.restoreCallingIdentity(origId);
4351 }
4352 }
4353
4354 private void removeAppTokensLocked(List<IBinder> tokens) {
4355 // XXX This should be done more efficiently!
4356 // (take advantage of the fact that both lists should be
4357 // ordered in the same way.)
4358 int N = tokens.size();
4359 for (int i=0; i<N; i++) {
4360 IBinder token = tokens.get(i);
4361 final AppWindowToken wtoken = findAppWindowToken(token);
4362 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004363 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 + token + " (" + wtoken + ")");
4365 i--;
4366 N--;
4367 }
4368 }
4369 }
4370
Dianne Hackborna8f60182009-09-01 19:01:50 -07004371 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4372 boolean updateFocusAndLayout) {
4373 // First remove all of the windows from the list.
4374 tmpRemoveAppWindowsLocked(wtoken);
4375
4376 // Where to start adding?
4377 int pos = findWindowOffsetLocked(tokenPos);
4378
4379 // And now add them back at the correct place.
4380 pos = reAddAppWindowsLocked(pos, wtoken);
4381
4382 if (updateFocusAndLayout) {
4383 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4384 assignLayersLocked();
4385 }
4386 mLayoutNeeded = true;
4387 performLayoutAndPlaceSurfacesLocked();
4388 }
4389 }
4390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004391 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4392 // First remove all of the windows from the list.
4393 final int N = tokens.size();
4394 int i;
4395 for (i=0; i<N; i++) {
4396 WindowToken token = mTokenMap.get(tokens.get(i));
4397 if (token != null) {
4398 tmpRemoveAppWindowsLocked(token);
4399 }
4400 }
4401
4402 // Where to start adding?
4403 int pos = findWindowOffsetLocked(tokenPos);
4404
4405 // And now add them back at the correct place.
4406 for (i=0; i<N; i++) {
4407 WindowToken token = mTokenMap.get(tokens.get(i));
4408 if (token != null) {
4409 pos = reAddAppWindowsLocked(pos, token);
4410 }
4411 }
4412
Dianne Hackborna8f60182009-09-01 19:01:50 -07004413 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4414 assignLayersLocked();
4415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 mLayoutNeeded = true;
4417 performLayoutAndPlaceSurfacesLocked();
4418
4419 //dump();
4420 }
4421
4422 public void moveAppTokensToTop(List<IBinder> tokens) {
4423 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4424 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004425 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 }
4427
4428 final long origId = Binder.clearCallingIdentity();
4429 synchronized(mWindowMap) {
4430 removeAppTokensLocked(tokens);
4431 final int N = tokens.size();
4432 for (int i=0; i<N; i++) {
4433 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4434 if (wt != null) {
4435 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004436 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004437 mToTopApps.remove(wt);
4438 mToBottomApps.remove(wt);
4439 mToTopApps.add(wt);
4440 wt.sendingToBottom = false;
4441 wt.sendingToTop = true;
4442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 }
4444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004445
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004446 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004447 moveAppWindowsLocked(tokens, mAppTokens.size());
4448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
4450 Binder.restoreCallingIdentity(origId);
4451 }
4452
4453 public void moveAppTokensToBottom(List<IBinder> tokens) {
4454 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4455 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004456 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457 }
4458
4459 final long origId = Binder.clearCallingIdentity();
4460 synchronized(mWindowMap) {
4461 removeAppTokensLocked(tokens);
4462 final int N = tokens.size();
4463 int pos = 0;
4464 for (int i=0; i<N; i++) {
4465 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4466 if (wt != null) {
4467 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004468 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004469 mToTopApps.remove(wt);
4470 mToBottomApps.remove(wt);
4471 mToBottomApps.add(i, wt);
4472 wt.sendingToTop = false;
4473 wt.sendingToBottom = true;
4474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 pos++;
4476 }
4477 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004478
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004479 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004480 moveAppWindowsLocked(tokens, 0);
4481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 }
4483 Binder.restoreCallingIdentity(origId);
4484 }
4485
4486 // -------------------------------------------------------------
4487 // Misc IWindowSession methods
4488 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004489
Jim Miller284b62e2010-06-08 14:27:42 -07004490 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004491 {
Jim Miller284b62e2010-06-08 14:27:42 -07004492 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4493 // called before DevicePolicyManagerService has started.
4494 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4495 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4496 Context.DEVICE_POLICY_SERVICE);
4497 if (dpm != null) {
4498 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4499 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4500 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4501 }
Jim Millerd6b57052010-06-07 17:52:42 -07004502 }
Jim Miller284b62e2010-06-08 14:27:42 -07004503 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004504 }
4505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004506 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004507 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 != PackageManager.PERMISSION_GRANTED) {
4509 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4510 }
Jim Millerd6b57052010-06-07 17:52:42 -07004511
Jim Miller284b62e2010-06-08 14:27:42 -07004512 synchronized (mKeyguardTokenWatcher) {
4513 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 }
4516
4517 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004518 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 != PackageManager.PERMISSION_GRANTED) {
4520 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522
Jim Miller284b62e2010-06-08 14:27:42 -07004523 synchronized (mKeyguardTokenWatcher) {
4524 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004525
Jim Miller284b62e2010-06-08 14:27:42 -07004526 if (!mKeyguardTokenWatcher.isAcquired()) {
4527 // If we are the last one to reenable the keyguard wait until
4528 // we have actually finished reenabling until returning.
4529 // It is possible that reenableKeyguard() can be called before
4530 // the previous disableKeyguard() is handled, in which case
4531 // neither mKeyguardTokenWatcher.acquired() or released() would
4532 // be called. In that case mKeyguardDisabled will be false here
4533 // and we have nothing to wait for.
4534 while (mKeyguardDisabled) {
4535 try {
4536 mKeyguardTokenWatcher.wait();
4537 } catch (InterruptedException e) {
4538 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004539 }
4540 }
4541 }
4542 }
4543 }
4544
4545 /**
4546 * @see android.app.KeyguardManager#exitKeyguardSecurely
4547 */
4548 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004549 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 != PackageManager.PERMISSION_GRANTED) {
4551 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4552 }
4553 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4554 public void onKeyguardExitResult(boolean success) {
4555 try {
4556 callback.onKeyguardExitResult(success);
4557 } catch (RemoteException e) {
4558 // Client has died, we don't care.
4559 }
4560 }
4561 });
4562 }
4563
4564 public boolean inKeyguardRestrictedInputMode() {
4565 return mPolicy.inKeyguardRestrictedKeyInputMode();
4566 }
Romain Guy06882f82009-06-10 13:36:04 -07004567
Dianne Hackbornffa42482009-09-23 22:20:11 -07004568 public void closeSystemDialogs(String reason) {
4569 synchronized(mWindowMap) {
4570 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004571 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004572 if (w.mSurface != null) {
4573 try {
4574 w.mClient.closeSystemDialogs(reason);
4575 } catch (RemoteException e) {
4576 }
4577 }
4578 }
4579 }
4580 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004582 static float fixScale(float scale) {
4583 if (scale < 0) scale = 0;
4584 else if (scale > 20) scale = 20;
4585 return Math.abs(scale);
4586 }
Romain Guy06882f82009-06-10 13:36:04 -07004587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 public void setAnimationScale(int which, float scale) {
4589 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4590 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004591 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 }
4593
4594 if (scale < 0) scale = 0;
4595 else if (scale > 20) scale = 20;
4596 scale = Math.abs(scale);
4597 switch (which) {
4598 case 0: mWindowAnimationScale = fixScale(scale); break;
4599 case 1: mTransitionAnimationScale = fixScale(scale); break;
4600 }
Romain Guy06882f82009-06-10 13:36:04 -07004601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004602 // Persist setting
4603 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4604 }
Romain Guy06882f82009-06-10 13:36:04 -07004605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004606 public void setAnimationScales(float[] scales) {
4607 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4608 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004609 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004610 }
4611
4612 if (scales != null) {
4613 if (scales.length >= 1) {
4614 mWindowAnimationScale = fixScale(scales[0]);
4615 }
4616 if (scales.length >= 2) {
4617 mTransitionAnimationScale = fixScale(scales[1]);
4618 }
4619 }
Romain Guy06882f82009-06-10 13:36:04 -07004620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 // Persist setting
4622 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4623 }
Romain Guy06882f82009-06-10 13:36:04 -07004624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004625 public float getAnimationScale(int which) {
4626 switch (which) {
4627 case 0: return mWindowAnimationScale;
4628 case 1: return mTransitionAnimationScale;
4629 }
4630 return 0;
4631 }
Romain Guy06882f82009-06-10 13:36:04 -07004632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 public float[] getAnimationScales() {
4634 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4635 }
Romain Guy06882f82009-06-10 13:36:04 -07004636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004637 public int getSwitchState(int sw) {
4638 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4639 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004640 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004642 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 }
Romain Guy06882f82009-06-10 13:36:04 -07004644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 public int getSwitchStateForDevice(int devid, int sw) {
4646 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4647 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004648 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004650 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 }
Romain Guy06882f82009-06-10 13:36:04 -07004652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 public int getScancodeState(int sw) {
4654 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4655 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004656 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004658 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 }
Romain Guy06882f82009-06-10 13:36:04 -07004660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 public int getScancodeStateForDevice(int devid, int sw) {
4662 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4663 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004664 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004666 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004667 }
Romain Guy06882f82009-06-10 13:36:04 -07004668
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004669 public int getTrackballScancodeState(int sw) {
4670 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4671 "getTrackballScancodeState()")) {
4672 throw new SecurityException("Requires READ_INPUT_STATE permission");
4673 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004674 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004675 }
4676
4677 public int getDPadScancodeState(int sw) {
4678 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4679 "getDPadScancodeState()")) {
4680 throw new SecurityException("Requires READ_INPUT_STATE permission");
4681 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004682 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004683 }
4684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 public int getKeycodeState(int sw) {
4686 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4687 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004688 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004690 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004691 }
Romain Guy06882f82009-06-10 13:36:04 -07004692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 public int getKeycodeStateForDevice(int devid, int sw) {
4694 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4695 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004696 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004698 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 }
Romain Guy06882f82009-06-10 13:36:04 -07004700
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004701 public int getTrackballKeycodeState(int sw) {
4702 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4703 "getTrackballKeycodeState()")) {
4704 throw new SecurityException("Requires READ_INPUT_STATE permission");
4705 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004706 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004707 }
4708
4709 public int getDPadKeycodeState(int sw) {
4710 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4711 "getDPadKeycodeState()")) {
4712 throw new SecurityException("Requires READ_INPUT_STATE permission");
4713 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004714 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004715 }
Jeff Browna41ca772010-08-11 14:46:32 -07004716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004718 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004719 }
Romain Guy06882f82009-06-10 13:36:04 -07004720
Jeff Browna41ca772010-08-11 14:46:32 -07004721 public InputChannel monitorInput(String inputChannelName) {
4722 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4723 "monitorInput()")) {
4724 throw new SecurityException("Requires READ_INPUT_STATE permission");
4725 }
4726 return mInputManager.monitorInput(inputChannelName);
4727 }
4728
Jeff Brown8d608662010-08-30 03:02:23 -07004729 public InputDevice getInputDevice(int deviceId) {
4730 return mInputManager.getInputDevice(deviceId);
4731 }
4732
4733 public int[] getInputDeviceIds() {
4734 return mInputManager.getInputDeviceIds();
4735 }
4736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 public void enableScreenAfterBoot() {
4738 synchronized(mWindowMap) {
4739 if (mSystemBooted) {
4740 return;
4741 }
4742 mSystemBooted = true;
4743 }
Romain Guy06882f82009-06-10 13:36:04 -07004744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 performEnableScreen();
4746 }
Romain Guy06882f82009-06-10 13:36:04 -07004747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004748 public void enableScreenIfNeededLocked() {
4749 if (mDisplayEnabled) {
4750 return;
4751 }
4752 if (!mSystemBooted) {
4753 return;
4754 }
4755 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4756 }
Romain Guy06882f82009-06-10 13:36:04 -07004757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004758 public void performEnableScreen() {
4759 synchronized(mWindowMap) {
4760 if (mDisplayEnabled) {
4761 return;
4762 }
4763 if (!mSystemBooted) {
4764 return;
4765 }
Romain Guy06882f82009-06-10 13:36:04 -07004766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 // Don't enable the screen until all existing windows
4768 // have been drawn.
4769 final int N = mWindows.size();
4770 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004771 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004772 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004773 return;
4774 }
4775 }
Romain Guy06882f82009-06-10 13:36:04 -07004776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004777 mDisplayEnabled = true;
4778 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004779 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004780 StringWriter sw = new StringWriter();
4781 PrintWriter pw = new PrintWriter(sw);
4782 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004783 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004784 }
4785 try {
4786 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4787 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004788 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 Parcel data = Parcel.obtain();
4790 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4791 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4792 data, null, 0);
4793 data.recycle();
4794 }
4795 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004796 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 }
4798 }
Romain Guy06882f82009-06-10 13:36:04 -07004799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004800 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004802 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004803 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4804 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 }
Romain Guy06882f82009-06-10 13:36:04 -07004806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 public void setInTouchMode(boolean mode) {
4808 synchronized(mWindowMap) {
4809 mInTouchMode = mode;
4810 }
4811 }
4812
Romain Guy06882f82009-06-10 13:36:04 -07004813 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004814 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004816 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004817 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 }
4819
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004820 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 }
Romain Guy06882f82009-06-10 13:36:04 -07004822
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004823 public void setRotationUnchecked(int rotation,
4824 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004825 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004826 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004828 long origId = Binder.clearCallingIdentity();
4829 boolean changed;
4830 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004831 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004832 }
Romain Guy06882f82009-06-10 13:36:04 -07004833
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004834 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 sendNewConfiguration();
4836 }
Romain Guy06882f82009-06-10 13:36:04 -07004837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004838 Binder.restoreCallingIdentity(origId);
4839 }
Romain Guy06882f82009-06-10 13:36:04 -07004840
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004841 /**
4842 * Apply a new rotation to the screen, respecting the requests of
4843 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4844 * re-evaluate the desired rotation.
4845 *
4846 * Returns null if the rotation has been changed. In this case YOU
4847 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4848 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004849 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 boolean changed;
4851 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4852 rotation = mRequestedRotation;
4853 } else {
4854 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004855 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004857 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004858 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004860 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004864 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 "Rotation changed to " + rotation
4866 + " from " + mRotation
4867 + " (forceApp=" + mForcedAppOrientation
4868 + ", req=" + mRequestedRotation + ")");
4869 mRotation = rotation;
4870 mWindowsFreezingScreen = true;
4871 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4872 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4873 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004874 mWaitingForConfig = true;
4875 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004877 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004878 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004879 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004880 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 }
4882 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004883 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 if (w.mSurface != null) {
4885 w.mOrientationChanging = true;
4886 }
4887 }
4888 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4889 try {
4890 mRotationWatchers.get(i).onRotationChanged(rotation);
4891 } catch (RemoteException e) {
4892 }
4893 }
4894 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004896 return changed;
4897 }
Romain Guy06882f82009-06-10 13:36:04 -07004898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004899 public int getRotation() {
4900 return mRotation;
4901 }
4902
4903 public int watchRotation(IRotationWatcher watcher) {
4904 final IBinder watcherBinder = watcher.asBinder();
4905 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4906 public void binderDied() {
4907 synchronized (mWindowMap) {
4908 for (int i=0; i<mRotationWatchers.size(); i++) {
4909 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004910 IRotationWatcher removed = mRotationWatchers.remove(i);
4911 if (removed != null) {
4912 removed.asBinder().unlinkToDeath(this, 0);
4913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914 i--;
4915 }
4916 }
4917 }
4918 }
4919 };
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 synchronized (mWindowMap) {
4922 try {
4923 watcher.asBinder().linkToDeath(dr, 0);
4924 mRotationWatchers.add(watcher);
4925 } catch (RemoteException e) {
4926 // Client died, no cleanup needed.
4927 }
Romain Guy06882f82009-06-10 13:36:04 -07004928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 return mRotation;
4930 }
4931 }
4932
4933 /**
4934 * Starts the view server on the specified port.
4935 *
4936 * @param port The port to listener to.
4937 *
4938 * @return True if the server was successfully started, false otherwise.
4939 *
4940 * @see com.android.server.ViewServer
4941 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4942 */
4943 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004944 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 return false;
4946 }
4947
4948 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4949 return false;
4950 }
4951
4952 if (port < 1024) {
4953 return false;
4954 }
4955
4956 if (mViewServer != null) {
4957 if (!mViewServer.isRunning()) {
4958 try {
4959 return mViewServer.start();
4960 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004961 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 }
4963 }
4964 return false;
4965 }
4966
4967 try {
4968 mViewServer = new ViewServer(this, port);
4969 return mViewServer.start();
4970 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004971 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004972 }
4973 return false;
4974 }
4975
Romain Guy06882f82009-06-10 13:36:04 -07004976 private boolean isSystemSecure() {
4977 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4978 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4979 }
4980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 /**
4982 * Stops the view server if it exists.
4983 *
4984 * @return True if the server stopped, false if it wasn't started or
4985 * couldn't be stopped.
4986 *
4987 * @see com.android.server.ViewServer
4988 */
4989 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004990 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004991 return false;
4992 }
4993
4994 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4995 return false;
4996 }
4997
4998 if (mViewServer != null) {
4999 return mViewServer.stop();
5000 }
5001 return false;
5002 }
5003
5004 /**
5005 * Indicates whether the view server is running.
5006 *
5007 * @return True if the server is running, false otherwise.
5008 *
5009 * @see com.android.server.ViewServer
5010 */
5011 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005012 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005013 return false;
5014 }
5015
5016 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5017 return false;
5018 }
5019
5020 return mViewServer != null && mViewServer.isRunning();
5021 }
5022
5023 /**
5024 * Lists all availble windows in the system. The listing is written in the
5025 * specified Socket's output stream with the following syntax:
5026 * windowHashCodeInHexadecimal windowName
5027 * Each line of the ouput represents a different window.
5028 *
5029 * @param client The remote client to send the listing to.
5030 * @return False if an error occured, true otherwise.
5031 */
5032 boolean viewServerListWindows(Socket client) {
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 boolean result = true;
5038
Jeff Browne33348b2010-07-15 23:54:05 -07005039 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005040 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005042 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 }
5044
5045 BufferedWriter out = null;
5046
5047 // Any uncaught exception will crash the system process
5048 try {
5049 OutputStream clientStream = client.getOutputStream();
5050 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5051
5052 final int count = windows.length;
5053 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005054 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 out.write(Integer.toHexString(System.identityHashCode(w)));
5056 out.write(' ');
5057 out.append(w.mAttrs.getTitle());
5058 out.write('\n');
5059 }
5060
5061 out.write("DONE.\n");
5062 out.flush();
5063 } catch (Exception e) {
5064 result = false;
5065 } finally {
5066 if (out != null) {
5067 try {
5068 out.close();
5069 } catch (IOException e) {
5070 result = false;
5071 }
5072 }
5073 }
5074
5075 return result;
5076 }
5077
5078 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005079 * Returns the focused window in the following format:
5080 * windowHashCodeInHexadecimal windowName
5081 *
5082 * @param client The remote client to send the listing to.
5083 * @return False if an error occurred, true otherwise.
5084 */
5085 boolean viewServerGetFocusedWindow(Socket client) {
5086 if (isSystemSecure()) {
5087 return false;
5088 }
5089
5090 boolean result = true;
5091
5092 WindowState focusedWindow = getFocusedWindow();
5093
5094 BufferedWriter out = null;
5095
5096 // Any uncaught exception will crash the system process
5097 try {
5098 OutputStream clientStream = client.getOutputStream();
5099 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5100
5101 if(focusedWindow != null) {
5102 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5103 out.write(' ');
5104 out.append(focusedWindow.mAttrs.getTitle());
5105 }
5106 out.write('\n');
5107 out.flush();
5108 } catch (Exception e) {
5109 result = false;
5110 } finally {
5111 if (out != null) {
5112 try {
5113 out.close();
5114 } catch (IOException e) {
5115 result = false;
5116 }
5117 }
5118 }
5119
5120 return result;
5121 }
5122
5123 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 * Sends a command to a target window. The result of the command, if any, will be
5125 * written in the output stream of the specified socket.
5126 *
5127 * The parameters must follow this syntax:
5128 * windowHashcode extra
5129 *
5130 * Where XX is the length in characeters of the windowTitle.
5131 *
5132 * The first parameter is the target window. The window with the specified hashcode
5133 * will be the target. If no target can be found, nothing happens. The extra parameters
5134 * will be delivered to the target window and as parameters to the command itself.
5135 *
5136 * @param client The remote client to sent the result, if any, to.
5137 * @param command The command to execute.
5138 * @param parameters The command parameters.
5139 *
5140 * @return True if the command was successfully delivered, false otherwise. This does
5141 * not indicate whether the command itself was successful.
5142 */
5143 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005144 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005145 return false;
5146 }
5147
5148 boolean success = true;
5149 Parcel data = null;
5150 Parcel reply = null;
5151
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005152 BufferedWriter out = null;
5153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005154 // Any uncaught exception will crash the system process
5155 try {
5156 // Find the hashcode of the window
5157 int index = parameters.indexOf(' ');
5158 if (index == -1) {
5159 index = parameters.length();
5160 }
5161 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005162 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005163
5164 // Extract the command's parameter after the window description
5165 if (index < parameters.length()) {
5166 parameters = parameters.substring(index + 1);
5167 } else {
5168 parameters = "";
5169 }
5170
5171 final WindowManagerService.WindowState window = findWindow(hashCode);
5172 if (window == null) {
5173 return false;
5174 }
5175
5176 data = Parcel.obtain();
5177 data.writeInterfaceToken("android.view.IWindow");
5178 data.writeString(command);
5179 data.writeString(parameters);
5180 data.writeInt(1);
5181 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5182
5183 reply = Parcel.obtain();
5184
5185 final IBinder binder = window.mClient.asBinder();
5186 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5187 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5188
5189 reply.readException();
5190
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005191 if (!client.isOutputShutdown()) {
5192 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5193 out.write("DONE\n");
5194 out.flush();
5195 }
5196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005197 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005198 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005199 success = false;
5200 } finally {
5201 if (data != null) {
5202 data.recycle();
5203 }
5204 if (reply != null) {
5205 reply.recycle();
5206 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005207 if (out != null) {
5208 try {
5209 out.close();
5210 } catch (IOException e) {
5211
5212 }
5213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005214 }
5215
5216 return success;
5217 }
5218
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005219 public void addWindowChangeListener(WindowChangeListener listener) {
5220 synchronized(mWindowMap) {
5221 mWindowChangeListeners.add(listener);
5222 }
5223 }
5224
5225 public void removeWindowChangeListener(WindowChangeListener listener) {
5226 synchronized(mWindowMap) {
5227 mWindowChangeListeners.remove(listener);
5228 }
5229 }
5230
5231 private void notifyWindowsChanged() {
5232 WindowChangeListener[] windowChangeListeners;
5233 synchronized(mWindowMap) {
5234 if(mWindowChangeListeners.isEmpty()) {
5235 return;
5236 }
5237 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5238 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5239 }
5240 int N = windowChangeListeners.length;
5241 for(int i = 0; i < N; i++) {
5242 windowChangeListeners[i].windowsChanged();
5243 }
5244 }
5245
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005246 private void notifyFocusChanged() {
5247 WindowChangeListener[] windowChangeListeners;
5248 synchronized(mWindowMap) {
5249 if(mWindowChangeListeners.isEmpty()) {
5250 return;
5251 }
5252 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5253 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5254 }
5255 int N = windowChangeListeners.length;
5256 for(int i = 0; i < N; i++) {
5257 windowChangeListeners[i].focusChanged();
5258 }
5259 }
5260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005261 private WindowState findWindow(int hashCode) {
5262 if (hashCode == -1) {
5263 return getFocusedWindow();
5264 }
5265
5266 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005267 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005268 final int count = windows.size();
5269
5270 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005271 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005272 if (System.identityHashCode(w) == hashCode) {
5273 return w;
5274 }
5275 }
5276 }
5277
5278 return null;
5279 }
5280
5281 /*
5282 * Instruct the Activity Manager to fetch the current configuration and broadcast
5283 * that to config-changed listeners if appropriate.
5284 */
5285 void sendNewConfiguration() {
5286 try {
5287 mActivityManager.updateConfiguration(null);
5288 } catch (RemoteException e) {
5289 }
5290 }
Romain Guy06882f82009-06-10 13:36:04 -07005291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005292 public Configuration computeNewConfiguration() {
5293 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005294 return computeNewConfigurationLocked();
5295 }
5296 }
Romain Guy06882f82009-06-10 13:36:04 -07005297
Dianne Hackbornc485a602009-03-24 22:39:49 -07005298 Configuration computeNewConfigurationLocked() {
5299 Configuration config = new Configuration();
5300 if (!computeNewConfigurationLocked(config)) {
5301 return null;
5302 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005303 return config;
5304 }
Romain Guy06882f82009-06-10 13:36:04 -07005305
Dianne Hackbornc485a602009-03-24 22:39:49 -07005306 boolean computeNewConfigurationLocked(Configuration config) {
5307 if (mDisplay == null) {
5308 return false;
5309 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005310
5311 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005312
5313 // Use the effective "visual" dimensions based on current rotation
5314 final boolean rotated = (mRotation == Surface.ROTATION_90
5315 || mRotation == Surface.ROTATION_270);
5316 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5317 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5318
Dianne Hackbornc485a602009-03-24 22:39:49 -07005319 int orientation = Configuration.ORIENTATION_SQUARE;
5320 if (dw < dh) {
5321 orientation = Configuration.ORIENTATION_PORTRAIT;
5322 } else if (dw > dh) {
5323 orientation = Configuration.ORIENTATION_LANDSCAPE;
5324 }
5325 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005326
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005327 DisplayMetrics dm = new DisplayMetrics();
5328 mDisplay.getMetrics(dm);
5329 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5330
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005331 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005332 // Note we only do this once because at this point we don't
5333 // expect the screen to change in this way at runtime, and want
5334 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005335 int longSize = dw;
5336 int shortSize = dh;
5337 if (longSize < shortSize) {
5338 int tmp = longSize;
5339 longSize = shortSize;
5340 shortSize = tmp;
5341 }
5342 longSize = (int)(longSize/dm.density);
5343 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005344
Dianne Hackborn723738c2009-06-25 19:48:04 -07005345 // These semi-magic numbers define our compatibility modes for
5346 // applications with different screens. Don't change unless you
5347 // make sure to test lots and lots of apps!
5348 if (longSize < 470) {
5349 // This is shorter than an HVGA normal density screen (which
5350 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005351 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5352 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005353 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005354 // What size is this screen screen?
5355 if (longSize >= 800 && shortSize >= 600) {
5356 // SVGA or larger screens at medium density are the point
5357 // at which we consider it to be an extra large screen.
5358 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5359 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005360 // VGA or larger screens at medium density are the point
5361 // at which we consider it to be a large screen.
5362 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5363 } else {
5364 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005365
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005366 // If this screen is wider than normal HVGA, or taller
5367 // than FWVGA, then for old apps we want to run in size
5368 // compatibility mode.
5369 if (shortSize > 321 || longSize > 570) {
5370 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5371 }
5372 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005373
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005374 // Is this a long screen?
5375 if (((longSize*3)/5) >= (shortSize-1)) {
5376 // Anything wider than WVGA (5:3) is considering to be long.
5377 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5378 } else {
5379 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5380 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005381 }
5382 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005383 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005384
Dianne Hackbornc485a602009-03-24 22:39:49 -07005385 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5386 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5387 mPolicy.adjustConfigurationLw(config);
5388 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005389 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005390
5391 // -------------------------------------------------------------
5392 // Drag and drop
5393 // -------------------------------------------------------------
5394
5395 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5396 boolean localOnly, int width, int height, Surface outSurface) {
5397 if (DEBUG_DRAG) {
5398 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5399 + " local=" + localOnly + " win=" + window
5400 + " asbinder=" + window.asBinder());
5401 }
5402
5403 final int callerPid = Binder.getCallingPid();
5404 final long origId = Binder.clearCallingIdentity();
5405 IBinder token = null;
5406
5407 try {
5408 synchronized (mWindowMap) {
5409 try {
5410 // !!! TODO: fail if the given window does not currently have touch focus?
5411
5412 if (mDragState == null) {
5413 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5414 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5415 outSurface.copyFrom(surface);
5416 token = new Binder();
5417 mDragState = new DragState(token, surface, localOnly);
5418 mDragState.mSurface = surface;
5419 mDragState.mLocalOnly = localOnly;
5420 token = mDragState.mToken = new Binder();
5421
5422 // 5 second timeout for this window to actually begin the drag
5423 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5424 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5425 mH.sendMessageDelayed(msg, 5000);
5426 } else {
5427 Slog.w(TAG, "Drag already in progress");
5428 }
5429 } catch (Surface.OutOfResourcesException e) {
5430 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5431 if (mDragState != null) {
5432 mDragState.reset();
5433 mDragState = null;
5434 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005435 }
5436 }
5437 } finally {
5438 Binder.restoreCallingIdentity(origId);
5439 }
5440
5441 return token;
5442 }
5443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005444 // -------------------------------------------------------------
5445 // Input Events and Focus Management
5446 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005447
Jeff Brown349703e2010-06-22 01:27:15 -07005448 InputMonitor mInputMonitor = new InputMonitor();
5449
5450 /* Tracks the progress of input dispatch and ensures that input dispatch state
5451 * is kept in sync with changes in window focus, visibility, registration, and
5452 * other relevant Window Manager state transitions. */
5453 final class InputMonitor {
5454 // Current window with input focus for keys and other non-touch events. May be null.
5455 private WindowState mInputFocus;
5456
5457 // When true, prevents input dispatch from proceeding until set to false again.
5458 private boolean mInputDispatchFrozen;
5459
5460 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5461 private boolean mInputDispatchEnabled = true;
5462
5463 // Temporary list of windows information to provide to the input dispatcher.
5464 private InputWindowList mTempInputWindows = new InputWindowList();
5465
5466 // Temporary input application object to provide to the input dispatcher.
5467 private InputApplication mTempInputApplication = new InputApplication();
5468
5469 /* Notifies the window manager about a broken input channel.
5470 *
5471 * Called by the InputManager.
5472 */
5473 public void notifyInputChannelBroken(InputChannel inputChannel) {
5474 synchronized (mWindowMap) {
5475 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5476 if (windowState == null) {
5477 return; // irrelevant
5478 }
5479
5480 Slog.i(TAG, "WINDOW DIED " + windowState);
5481 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005482 }
5483 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005484
Jeff Brown519e0242010-09-15 15:18:56 -07005485 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005486 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005487 *
5488 * Called by the InputManager.
5489 */
Jeff Brown519e0242010-09-15 15:18:56 -07005490 public long notifyANR(Object token, InputChannel inputChannel) {
5491 AppWindowToken appWindowToken = null;
5492 if (inputChannel != null) {
5493 synchronized (mWindowMap) {
5494 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5495 if (windowState != null) {
5496 Slog.i(TAG, "Input event dispatching timed out sending to "
5497 + windowState.mAttrs.getTitle());
5498 appWindowToken = windowState.mAppToken;
5499 }
Jeff Brown349703e2010-06-22 01:27:15 -07005500 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005501 }
5502
Jeff Brown519e0242010-09-15 15:18:56 -07005503 if (appWindowToken == null && token != null) {
5504 appWindowToken = (AppWindowToken) token;
5505 Slog.i(TAG, "Input event dispatching timed out sending to application "
5506 + appWindowToken.stringName);
5507 }
Jeff Brown349703e2010-06-22 01:27:15 -07005508
Jeff Brown519e0242010-09-15 15:18:56 -07005509 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005510 try {
5511 // Notify the activity manager about the timeout and let it decide whether
5512 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005513 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005514 if (! abort) {
5515 // The activity manager declined to abort dispatching.
5516 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005517 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005518 }
Jeff Brown349703e2010-06-22 01:27:15 -07005519 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005520 }
5521 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005522 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005523 }
5524
Jeff Brown349703e2010-06-22 01:27:15 -07005525 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5526 synchronized (mWindowMap) {
5527 return getWindowStateForInputChannelLocked(inputChannel);
5528 }
5529 }
5530
5531 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5532 int windowCount = mWindows.size();
5533 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005534 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005535 if (windowState.mInputChannel == inputChannel) {
5536 return windowState;
5537 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005538 }
5539
Jeff Brown349703e2010-06-22 01:27:15 -07005540 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005541 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005542
Chris Tatea32dcf72010-10-14 12:13:50 -07005543 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005544 final InputWindow inputWindow = windowList.add();
5545 inputWindow.inputChannel = mDragState.mServerChannel;
5546 inputWindow.name = "drag";
5547 inputWindow.layoutParamsFlags = 0;
5548 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5549 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5550 inputWindow.visible = true;
5551 inputWindow.canReceiveKeys = false;
5552 inputWindow.hasFocus = true;
5553 inputWindow.hasWallpaper = false;
5554 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005555 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005556 inputWindow.ownerPid = Process.myPid();
5557 inputWindow.ownerUid = Process.myUid();
5558
5559 // The drag window covers the entire display
5560 inputWindow.frameLeft = 0;
5561 inputWindow.frameTop = 0;
5562 inputWindow.frameRight = mDisplay.getWidth();
5563 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005564
Christopher Tatea53146c2010-09-07 11:57:52 -07005565 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5566 inputWindow.visibleFrameTop = inputWindow.frameTop;
5567 inputWindow.visibleFrameRight = inputWindow.frameRight;
5568 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5569
5570 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5571 inputWindow.touchableAreaTop = inputWindow.frameTop;
5572 inputWindow.touchableAreaRight = inputWindow.frameRight;
5573 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5574 }
5575
Jeff Brown349703e2010-06-22 01:27:15 -07005576 /* Updates the cached window information provided to the input dispatcher. */
5577 public void updateInputWindowsLw() {
5578 // Populate the input window list with information about all of the windows that
5579 // could potentially receive input.
5580 // As an optimization, we could try to prune the list of windows but this turns
5581 // out to be difficult because only the native code knows for sure which window
5582 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005583 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005584
5585 // If there's a drag in flight, provide a pseudowindow to catch drag input
5586 final boolean inDrag = (mDragState != null);
5587 if (inDrag) {
5588 if (DEBUG_DRAG) {
5589 Log.d(TAG, "Inserting drag window");
5590 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005591 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005592 }
5593
Jeff Brown7fbdc842010-06-17 20:52:56 -07005594 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005595 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005596 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005597 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005598 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005599 continue;
5600 }
5601
Jeff Brown349703e2010-06-22 01:27:15 -07005602 final int flags = child.mAttrs.flags;
5603 final int type = child.mAttrs.type;
5604
5605 final boolean hasFocus = (child == mInputFocus);
5606 final boolean isVisible = child.isVisibleLw();
5607 final boolean hasWallpaper = (child == mWallpaperTarget)
5608 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005609
5610 // If there's a drag in progress and 'child' is a potential drop target,
5611 // make sure it's been told about the drag
5612 if (inDrag && isVisible) {
5613 mDragState.sendDragStartedIfNeededLw(child);
5614 }
5615
Jeff Brown349703e2010-06-22 01:27:15 -07005616 // Add a window to our list of input windows.
5617 final InputWindow inputWindow = mTempInputWindows.add();
5618 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005619 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005620 inputWindow.layoutParamsFlags = flags;
5621 inputWindow.layoutParamsType = type;
5622 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5623 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005624 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005625 inputWindow.hasFocus = hasFocus;
5626 inputWindow.hasWallpaper = hasWallpaper;
5627 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005628 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005629 inputWindow.ownerPid = child.mSession.mPid;
5630 inputWindow.ownerUid = child.mSession.mUid;
5631
5632 final Rect frame = child.mFrame;
5633 inputWindow.frameLeft = frame.left;
5634 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005635 inputWindow.frameRight = frame.right;
5636 inputWindow.frameBottom = frame.bottom;
5637
5638 final Rect visibleFrame = child.mVisibleFrame;
5639 inputWindow.visibleFrameLeft = visibleFrame.left;
5640 inputWindow.visibleFrameTop = visibleFrame.top;
5641 inputWindow.visibleFrameRight = visibleFrame.right;
5642 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005643
5644 switch (child.mTouchableInsets) {
5645 default:
5646 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5647 inputWindow.touchableAreaLeft = frame.left;
5648 inputWindow.touchableAreaTop = frame.top;
5649 inputWindow.touchableAreaRight = frame.right;
5650 inputWindow.touchableAreaBottom = frame.bottom;
5651 break;
5652
5653 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5654 Rect inset = child.mGivenContentInsets;
5655 inputWindow.touchableAreaLeft = frame.left + inset.left;
5656 inputWindow.touchableAreaTop = frame.top + inset.top;
5657 inputWindow.touchableAreaRight = frame.right - inset.right;
5658 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5659 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005660 }
Jeff Brown349703e2010-06-22 01:27:15 -07005661
5662 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5663 Rect inset = child.mGivenVisibleInsets;
5664 inputWindow.touchableAreaLeft = frame.left + inset.left;
5665 inputWindow.touchableAreaTop = frame.top + inset.top;
5666 inputWindow.touchableAreaRight = frame.right - inset.right;
5667 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005668 break;
5669 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005670 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005671 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005672
Jeff Brown349703e2010-06-22 01:27:15 -07005673 // Send windows to native code.
5674 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005675
Jeff Brown349703e2010-06-22 01:27:15 -07005676 // Clear the list in preparation for the next round.
5677 // Also avoids keeping InputChannel objects referenced unnecessarily.
5678 mTempInputWindows.clear();
5679 }
5680
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005681 /* Notifies that the lid switch changed state. */
5682 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5683 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5684 }
5685
Jeff Brown349703e2010-06-22 01:27:15 -07005686 /* Provides an opportunity for the window manager policy to intercept early key
5687 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005688 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5689 int policyFlags, boolean isScreenOn) {
5690 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5691 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005692 }
5693
5694 /* Provides an opportunity for the window manager policy to process a key before
5695 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005696 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5697 int action, int flags, int keyCode, int metaState, int repeatCount,
5698 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005699 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005700 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5701 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005702 }
5703
5704 /* Called when the current input focus changes.
5705 * Layer assignment is assumed to be complete by the time this is called.
5706 */
5707 public void setInputFocusLw(WindowState newWindow) {
5708 if (DEBUG_INPUT) {
5709 Slog.d(TAG, "Input focus has changed to " + newWindow);
5710 }
5711
5712 if (newWindow != mInputFocus) {
5713 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005714 // Displaying a window implicitly causes dispatching to be unpaused.
5715 // This is to protect against bugs if someone pauses dispatching but
5716 // forgets to resume.
5717 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005718 }
Jeff Brown349703e2010-06-22 01:27:15 -07005719
5720 mInputFocus = newWindow;
5721 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005722 }
5723 }
5724
Jeff Brown349703e2010-06-22 01:27:15 -07005725 public void setFocusedAppLw(AppWindowToken newApp) {
5726 // Focused app has changed.
5727 if (newApp == null) {
5728 mInputManager.setFocusedApplication(null);
5729 } else {
5730 mTempInputApplication.name = newApp.toString();
5731 mTempInputApplication.dispatchingTimeoutNanos =
5732 newApp.inputDispatchingTimeoutNanos;
5733 mTempInputApplication.token = newApp;
5734
5735 mInputManager.setFocusedApplication(mTempInputApplication);
5736 }
5737 }
5738
Jeff Brown349703e2010-06-22 01:27:15 -07005739 public void pauseDispatchingLw(WindowToken window) {
5740 if (! window.paused) {
5741 if (DEBUG_INPUT) {
5742 Slog.v(TAG, "Pausing WindowToken " + window);
5743 }
5744
5745 window.paused = true;
5746 updateInputWindowsLw();
5747 }
5748 }
5749
5750 public void resumeDispatchingLw(WindowToken window) {
5751 if (window.paused) {
5752 if (DEBUG_INPUT) {
5753 Slog.v(TAG, "Resuming WindowToken " + window);
5754 }
5755
5756 window.paused = false;
5757 updateInputWindowsLw();
5758 }
5759 }
5760
5761 public void freezeInputDispatchingLw() {
5762 if (! mInputDispatchFrozen) {
5763 if (DEBUG_INPUT) {
5764 Slog.v(TAG, "Freezing input dispatching");
5765 }
5766
5767 mInputDispatchFrozen = true;
5768 updateInputDispatchModeLw();
5769 }
5770 }
5771
5772 public void thawInputDispatchingLw() {
5773 if (mInputDispatchFrozen) {
5774 if (DEBUG_INPUT) {
5775 Slog.v(TAG, "Thawing input dispatching");
5776 }
5777
5778 mInputDispatchFrozen = false;
5779 updateInputDispatchModeLw();
5780 }
5781 }
5782
5783 public void setEventDispatchingLw(boolean enabled) {
5784 if (mInputDispatchEnabled != enabled) {
5785 if (DEBUG_INPUT) {
5786 Slog.v(TAG, "Setting event dispatching to " + enabled);
5787 }
5788
5789 mInputDispatchEnabled = enabled;
5790 updateInputDispatchModeLw();
5791 }
5792 }
5793
5794 private void updateInputDispatchModeLw() {
5795 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5796 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 public void pauseKeyDispatching(IBinder _token) {
5800 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5801 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005802 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005803 }
5804
5805 synchronized (mWindowMap) {
5806 WindowToken token = mTokenMap.get(_token);
5807 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005808 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005809 }
5810 }
5811 }
5812
5813 public void resumeKeyDispatching(IBinder _token) {
5814 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5815 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005816 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005817 }
5818
5819 synchronized (mWindowMap) {
5820 WindowToken token = mTokenMap.get(_token);
5821 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005822 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 }
5824 }
5825 }
5826
5827 public void setEventDispatching(boolean enabled) {
5828 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5829 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005830 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 }
5832
5833 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005834 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005835 }
5836 }
Romain Guy06882f82009-06-10 13:36:04 -07005837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 /**
5839 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005840 * Even when sync is false, this method may block while waiting for current
5841 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005842 *
5843 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 * {@link SystemClock#uptimeMillis()} as the timebase.)
5845 * @param sync If true, wait for the event to be completed before returning to the caller.
5846 * @return Returns true if event was dispatched, false if it was dropped for any reason
5847 */
5848 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5849 long downTime = ev.getDownTime();
5850 long eventTime = ev.getEventTime();
5851
5852 int action = ev.getAction();
5853 int code = ev.getKeyCode();
5854 int repeatCount = ev.getRepeatCount();
5855 int metaState = ev.getMetaState();
5856 int deviceId = ev.getDeviceId();
5857 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005858 int source = ev.getSource();
5859
5860 if (source == InputDevice.SOURCE_UNKNOWN) {
5861 source = InputDevice.SOURCE_KEYBOARD;
5862 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005863
5864 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5865 if (downTime == 0) downTime = eventTime;
5866
5867 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005868 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005869
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005870 final int pid = Binder.getCallingPid();
5871 final int uid = Binder.getCallingUid();
5872 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005873
Jeff Brownbbda99d2010-07-28 15:48:59 -07005874 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5875 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5876 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5877 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005878
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005879 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005880 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005881 }
5882
5883 /**
5884 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005885 * Even when sync is false, this method may block while waiting for current
5886 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005887 *
5888 * @param ev A motion event describing the pointer (touch) action. (As noted in
5889 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005890 * {@link SystemClock#uptimeMillis()} as the timebase.)
5891 * @param sync If true, wait for the event to be completed before returning to the caller.
5892 * @return Returns true if event was dispatched, false if it was dropped for any reason
5893 */
5894 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005895 final int pid = Binder.getCallingPid();
5896 final int uid = Binder.getCallingUid();
5897 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005898
Jeff Brownc5ed5912010-07-14 18:48:53 -07005899 MotionEvent newEvent = MotionEvent.obtain(ev);
5900 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5901 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5902 }
5903
Jeff Brownbbda99d2010-07-28 15:48:59 -07005904 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5905 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5906 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5907 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005908
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005909 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005910 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 }
Romain Guy06882f82009-06-10 13:36:04 -07005912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005913 /**
5914 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005915 * Even when sync is false, this method may block while waiting for current
5916 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005917 *
5918 * @param ev A motion event describing the trackball action. (As noted in
5919 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005920 * {@link SystemClock#uptimeMillis()} as the timebase.)
5921 * @param sync If true, wait for the event to be completed before returning to the caller.
5922 * @return Returns true if event was dispatched, false if it was dropped for any reason
5923 */
5924 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005925 final int pid = Binder.getCallingPid();
5926 final int uid = Binder.getCallingUid();
5927 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005928
Jeff Brownc5ed5912010-07-14 18:48:53 -07005929 MotionEvent newEvent = MotionEvent.obtain(ev);
5930 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5931 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5932 }
5933
Jeff Brownbbda99d2010-07-28 15:48:59 -07005934 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5935 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5936 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5937 INJECTION_TIMEOUT_MILLIS);
5938
5939 Binder.restoreCallingIdentity(ident);
5940 return reportInjectionResult(result);
5941 }
5942
5943 /**
5944 * Inject an input event into the UI without waiting for dispatch to commence.
5945 * This variant is useful for fire-and-forget input event injection. It does not
5946 * block any longer than it takes to enqueue the input event.
5947 *
5948 * @param ev An input event. (Be sure to set the input source correctly.)
5949 * @return Returns true if event was dispatched, false if it was dropped for any reason
5950 */
5951 public boolean injectInputEventNoWait(InputEvent ev) {
5952 final int pid = Binder.getCallingPid();
5953 final int uid = Binder.getCallingUid();
5954 final long ident = Binder.clearCallingIdentity();
5955
5956 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5957 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5958 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005959
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005960 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005961 return reportInjectionResult(result);
5962 }
5963
5964 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005965 switch (result) {
5966 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5967 Slog.w(TAG, "Input event injection permission denied.");
5968 throw new SecurityException(
5969 "Injecting to another application requires INJECT_EVENTS permission");
5970 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005971 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005972 return true;
5973 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5974 Slog.w(TAG, "Input event injection timed out.");
5975 return false;
5976 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5977 default:
5978 Slog.w(TAG, "Input event injection failed.");
5979 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005980 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005981 }
Romain Guy06882f82009-06-10 13:36:04 -07005982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005983 private WindowState getFocusedWindow() {
5984 synchronized (mWindowMap) {
5985 return getFocusedWindowLocked();
5986 }
5987 }
5988
5989 private WindowState getFocusedWindowLocked() {
5990 return mCurrentFocus;
5991 }
Romain Guy06882f82009-06-10 13:36:04 -07005992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005993 public boolean detectSafeMode() {
5994 mSafeMode = mPolicy.detectSafeMode();
5995 return mSafeMode;
5996 }
Romain Guy06882f82009-06-10 13:36:04 -07005997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005998 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005999 synchronized(mWindowMap) {
6000 if (mDisplay != null) {
6001 throw new IllegalStateException("Display already initialized");
6002 }
6003 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6004 mDisplay = wm.getDefaultDisplay();
6005 mInitialDisplayWidth = mDisplay.getWidth();
6006 mInitialDisplayHeight = mDisplay.getHeight();
6007 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6008 }
6009
6010 try {
6011 mActivityManager.updateConfiguration(null);
6012 } catch (RemoteException e) {
6013 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006014
6015 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006016 }
6017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006018 // -------------------------------------------------------------
6019 // Client Session State
6020 // -------------------------------------------------------------
6021
6022 private final class Session extends IWindowSession.Stub
6023 implements IBinder.DeathRecipient {
6024 final IInputMethodClient mClient;
6025 final IInputContext mInputContext;
6026 final int mUid;
6027 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006028 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006029 SurfaceSession mSurfaceSession;
6030 int mNumWindow = 0;
6031 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006033 public Session(IInputMethodClient client, IInputContext inputContext) {
6034 mClient = client;
6035 mInputContext = inputContext;
6036 mUid = Binder.getCallingUid();
6037 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006038 StringBuilder sb = new StringBuilder();
6039 sb.append("Session{");
6040 sb.append(Integer.toHexString(System.identityHashCode(this)));
6041 sb.append(" uid ");
6042 sb.append(mUid);
6043 sb.append("}");
6044 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006046 synchronized (mWindowMap) {
6047 if (mInputMethodManager == null && mHaveInputMethods) {
6048 IBinder b = ServiceManager.getService(
6049 Context.INPUT_METHOD_SERVICE);
6050 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6051 }
6052 }
6053 long ident = Binder.clearCallingIdentity();
6054 try {
6055 // Note: it is safe to call in to the input method manager
6056 // here because we are not holding our lock.
6057 if (mInputMethodManager != null) {
6058 mInputMethodManager.addClient(client, inputContext,
6059 mUid, mPid);
6060 } else {
6061 client.setUsingInputMethod(false);
6062 }
6063 client.asBinder().linkToDeath(this, 0);
6064 } catch (RemoteException e) {
6065 // The caller has died, so we can just forget about this.
6066 try {
6067 if (mInputMethodManager != null) {
6068 mInputMethodManager.removeClient(client);
6069 }
6070 } catch (RemoteException ee) {
6071 }
6072 } finally {
6073 Binder.restoreCallingIdentity(ident);
6074 }
6075 }
Romain Guy06882f82009-06-10 13:36:04 -07006076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006077 @Override
6078 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6079 throws RemoteException {
6080 try {
6081 return super.onTransact(code, data, reply, flags);
6082 } catch (RuntimeException e) {
6083 // Log all 'real' exceptions thrown to the caller
6084 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006085 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006086 }
6087 throw e;
6088 }
6089 }
6090
6091 public void binderDied() {
6092 // Note: it is safe to call in to the input method manager
6093 // here because we are not holding our lock.
6094 try {
6095 if (mInputMethodManager != null) {
6096 mInputMethodManager.removeClient(mClient);
6097 }
6098 } catch (RemoteException e) {
6099 }
6100 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006101 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006102 mClientDead = true;
6103 killSessionLocked();
6104 }
6105 }
6106
6107 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006108 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6109 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6110 outInputChannel);
6111 }
6112
6113 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006114 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006115 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 }
Romain Guy06882f82009-06-10 13:36:04 -07006117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 public void remove(IWindow window) {
6119 removeWindow(this, window);
6120 }
Romain Guy06882f82009-06-10 13:36:04 -07006121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6123 int requestedWidth, int requestedHeight, int viewFlags,
6124 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006125 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006126 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6127 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006129 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006130 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6131 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 }
Romain Guy06882f82009-06-10 13:36:04 -07006133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006134 public void setTransparentRegion(IWindow window, Region region) {
6135 setTransparentRegionWindow(this, window, region);
6136 }
Romain Guy06882f82009-06-10 13:36:04 -07006137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 public void setInsets(IWindow window, int touchableInsets,
6139 Rect contentInsets, Rect visibleInsets) {
6140 setInsetsWindow(this, window, touchableInsets, contentInsets,
6141 visibleInsets);
6142 }
Romain Guy06882f82009-06-10 13:36:04 -07006143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6145 getWindowDisplayFrame(this, window, outDisplayFrame);
6146 }
Romain Guy06882f82009-06-10 13:36:04 -07006147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006149 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 TAG, "IWindow finishDrawing called for " + window);
6151 finishDrawingWindow(this, window);
6152 }
6153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 public void setInTouchMode(boolean mode) {
6155 synchronized(mWindowMap) {
6156 mInTouchMode = mode;
6157 }
6158 }
6159
6160 public boolean getInTouchMode() {
6161 synchronized(mWindowMap) {
6162 return mInTouchMode;
6163 }
6164 }
6165
6166 public boolean performHapticFeedback(IWindow window, int effectId,
6167 boolean always) {
6168 synchronized(mWindowMap) {
6169 long ident = Binder.clearCallingIdentity();
6170 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006171 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006172 windowForClientLocked(this, window, true),
6173 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 } finally {
6175 Binder.restoreCallingIdentity(ident);
6176 }
6177 }
6178 }
Romain Guy06882f82009-06-10 13:36:04 -07006179
Christopher Tatea53146c2010-09-07 11:57:52 -07006180 /* Drag/drop */
6181 public IBinder prepareDrag(IWindow window, boolean localOnly,
6182 int width, int height, Surface outSurface) {
6183 return prepareDragSurface(window, mSurfaceSession, localOnly,
6184 width, height, outSurface);
6185 }
6186
6187 public boolean performDrag(IWindow window, IBinder dragToken,
6188 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6189 ClipData data) {
6190 if (DEBUG_DRAG) {
6191 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6192 }
6193
6194 synchronized (mWindowMap) {
6195 if (mDragState == null) {
6196 Slog.w(TAG, "No drag prepared");
6197 throw new IllegalStateException("performDrag() without prepareDrag()");
6198 }
6199
6200 if (dragToken != mDragState.mToken) {
6201 Slog.w(TAG, "Performing mismatched drag");
6202 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6203 }
6204
6205 WindowState callingWin = windowForClientLocked(null, window, false);
6206 if (callingWin == null) {
6207 Slog.w(TAG, "Bad requesting window " + window);
6208 return false; // !!! TODO: throw here?
6209 }
6210
6211 // !!! TODO: if input is not still focused on the initiating window, fail
6212 // the drag initiation (e.g. an alarm window popped up just as the application
6213 // called performDrag()
6214
6215 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6216
Christopher Tate2c095f32010-10-04 14:13:40 -07006217 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6218 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006219
Chris Tateb478f462010-10-15 16:02:26 -07006220 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6221 // the actual drag event dispatch stuff in the dragstate
6222
Christopher Tatea53146c2010-09-07 11:57:52 -07006223 mDragState.register();
6224 mInputMonitor.updateInputWindowsLw();
6225 mInputManager.transferTouchFocus(callingWin.mInputChannel,
6226 mDragState.mServerChannel);
6227
6228 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006229 mDragState.mCurrentX = touchX;
6230 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006231 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006232
6233 // remember the thumb offsets for later
6234 mDragState.mThumbOffsetX = thumbCenterX;
6235 mDragState.mThumbOffsetY = thumbCenterY;
6236
6237 // Make the surface visible at the proper location
6238 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006239 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006240 try {
6241 surface.setPosition((int)(touchX - thumbCenterX),
6242 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006243 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006244 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006245 surface.show();
6246 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006247 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006248 }
6249 }
6250
6251 return true; // success!
6252 }
6253
6254 public void dragRecipientEntered(IWindow window) {
6255 if (DEBUG_DRAG) {
6256 Slog.d(TAG, "Drag into new candidate view @ " + window);
6257 }
6258 }
6259
6260 public void dragRecipientExited(IWindow window) {
6261 if (DEBUG_DRAG) {
6262 Slog.d(TAG, "Drag from old candidate view @ " + window);
6263 }
6264 }
6265
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006266 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006267 synchronized(mWindowMap) {
6268 long ident = Binder.clearCallingIdentity();
6269 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006270 setWindowWallpaperPositionLocked(
6271 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006272 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006273 } finally {
6274 Binder.restoreCallingIdentity(ident);
6275 }
6276 }
6277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006278
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006279 public void wallpaperOffsetsComplete(IBinder window) {
6280 WindowManagerService.this.wallpaperOffsetsComplete(window);
6281 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006282
Dianne Hackborn75804932009-10-20 20:15:20 -07006283 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6284 int z, Bundle extras, boolean sync) {
6285 synchronized(mWindowMap) {
6286 long ident = Binder.clearCallingIdentity();
6287 try {
6288 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006289 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006290 action, x, y, z, extras, sync);
6291 } finally {
6292 Binder.restoreCallingIdentity(ident);
6293 }
6294 }
6295 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006296
Dianne Hackborn75804932009-10-20 20:15:20 -07006297 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6298 WindowManagerService.this.wallpaperCommandComplete(window, result);
6299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006301 void windowAddedLocked() {
6302 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006303 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 TAG, "First window added to " + this + ", creating SurfaceSession");
6305 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006306 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006307 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006308 mSessions.add(this);
6309 }
6310 mNumWindow++;
6311 }
6312
6313 void windowRemovedLocked() {
6314 mNumWindow--;
6315 killSessionLocked();
6316 }
Romain Guy06882f82009-06-10 13:36:04 -07006317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006318 void killSessionLocked() {
6319 if (mNumWindow <= 0 && mClientDead) {
6320 mSessions.remove(this);
6321 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006322 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006323 TAG, "Last window removed from " + this
6324 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006325 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006326 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327 try {
6328 mSurfaceSession.kill();
6329 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006330 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 + mSurfaceSession + " in session " + this
6332 + ": " + e.toString());
6333 }
6334 mSurfaceSession = null;
6335 }
6336 }
6337 }
Romain Guy06882f82009-06-10 13:36:04 -07006338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006339 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006340 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6341 pw.print(" mClientDead="); pw.print(mClientDead);
6342 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006343 }
6344
6345 @Override
6346 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006347 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 }
6349 }
6350
6351 // -------------------------------------------------------------
6352 // Client Window State
6353 // -------------------------------------------------------------
6354
6355 private final class WindowState implements WindowManagerPolicy.WindowState {
6356 final Session mSession;
6357 final IWindow mClient;
6358 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006359 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 AppWindowToken mAppToken;
6361 AppWindowToken mTargetAppToken;
6362 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6363 final DeathRecipient mDeathRecipient;
6364 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006365 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 final int mBaseLayer;
6367 final int mSubLayer;
6368 final boolean mLayoutAttached;
6369 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006370 final boolean mIsWallpaper;
6371 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 int mViewVisibility;
6373 boolean mPolicyVisibility = true;
6374 boolean mPolicyVisibilityAfterAnim = true;
6375 boolean mAppFreezing;
6376 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006377 boolean mReportDestroySurface;
6378 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 boolean mAttachedHidden; // is our parent window hidden?
6380 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006381 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 int mRequestedWidth;
6383 int mRequestedHeight;
6384 int mLastRequestedWidth;
6385 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 int mLayer;
6387 int mAnimLayer;
6388 int mLastLayer;
6389 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006390 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006391 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006392
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006393 int mLayoutSeq = -1;
6394
6395 Configuration mConfiguration = null;
6396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 // Actual frame shown on-screen (may be modified by animation)
6398 final Rect mShownFrame = new Rect();
6399 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006402 * Set when we have changed the size of the surface, to know that
6403 * we must tell them application to resize (and thus redraw itself).
6404 */
6405 boolean mSurfaceResized;
6406
6407 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 * Insets that determine the actually visible area
6409 */
6410 final Rect mVisibleInsets = new Rect();
6411 final Rect mLastVisibleInsets = new Rect();
6412 boolean mVisibleInsetsChanged;
6413
6414 /**
6415 * Insets that are covered by system windows
6416 */
6417 final Rect mContentInsets = new Rect();
6418 final Rect mLastContentInsets = new Rect();
6419 boolean mContentInsetsChanged;
6420
6421 /**
6422 * Set to true if we are waiting for this window to receive its
6423 * given internal insets before laying out other windows based on it.
6424 */
6425 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 /**
6428 * These are the content insets that were given during layout for
6429 * this window, to be applied to windows behind it.
6430 */
6431 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 /**
6434 * These are the visible insets that were given during layout for
6435 * this window, to be applied to windows behind it.
6436 */
6437 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 /**
6440 * Flag indicating whether the touchable region should be adjusted by
6441 * the visible insets; if false the area outside the visible insets is
6442 * NOT touchable, so we must use those to adjust the frame during hit
6443 * tests.
6444 */
6445 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447 // Current transformation being applied.
6448 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6449 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6450 float mHScale=1, mVScale=1;
6451 float mLastHScale=1, mLastVScale=1;
6452 final Matrix mTmpMatrix = new Matrix();
6453
6454 // "Real" frame that the application sees.
6455 final Rect mFrame = new Rect();
6456 final Rect mLastFrame = new Rect();
6457
6458 final Rect mContainingFrame = new Rect();
6459 final Rect mDisplayFrame = new Rect();
6460 final Rect mContentFrame = new Rect();
6461 final Rect mVisibleFrame = new Rect();
6462
6463 float mShownAlpha = 1;
6464 float mAlpha = 1;
6465 float mLastAlpha = 1;
6466
6467 // Set to true if, when the window gets displayed, it should perform
6468 // an enter animation.
6469 boolean mEnterAnimationPending;
6470
6471 // Currently running animation.
6472 boolean mAnimating;
6473 boolean mLocalAnimating;
6474 Animation mAnimation;
6475 boolean mAnimationIsEntrance;
6476 boolean mHasTransformation;
6477 boolean mHasLocalTransformation;
6478 final Transformation mTransformation = new Transformation();
6479
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006480 // If a window showing a wallpaper: the requested offset for the
6481 // wallpaper; if a wallpaper window: the currently applied offset.
6482 float mWallpaperX = -1;
6483 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006484
6485 // If a window showing a wallpaper: what fraction of the offset
6486 // range corresponds to a full virtual screen.
6487 float mWallpaperXStep = -1;
6488 float mWallpaperYStep = -1;
6489
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006490 // Wallpaper windows: pixels offset based on above variables.
6491 int mXOffset;
6492 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 // This is set after IWindowSession.relayout() has been called at
6495 // least once for the window. It allows us to detect the situation
6496 // where we don't yet have a surface, but should have one soon, so
6497 // we can give the window focus before waiting for the relayout.
6498 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006500 // This is set after the Surface has been created but before the
6501 // window has been drawn. During this time the surface is hidden.
6502 boolean mDrawPending;
6503
6504 // This is set after the window has finished drawing for the first
6505 // time but before its surface is shown. The surface will be
6506 // displayed when the next layout is run.
6507 boolean mCommitDrawPending;
6508
6509 // This is set during the time after the window's drawing has been
6510 // committed, and before its surface is actually shown. It is used
6511 // to delay showing the surface until all windows in a token are ready
6512 // to be shown.
6513 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 // Set when the window has been shown in the screen the first time.
6516 boolean mHasDrawn;
6517
6518 // Currently running an exit animation?
6519 boolean mExiting;
6520
6521 // Currently on the mDestroySurface list?
6522 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006524 // Completely remove from window manager after exit animation?
6525 boolean mRemoveOnExit;
6526
6527 // Set when the orientation is changing and this window has not yet
6528 // been updated for the new orientation.
6529 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 // Is this window now (or just being) removed?
6532 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006533
Dianne Hackborn16064f92010-03-25 00:47:24 -07006534 // For debugging, this is the last information given to the surface flinger.
6535 boolean mSurfaceShown;
6536 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6537 int mSurfaceLayer;
6538 float mSurfaceAlpha;
6539
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006540 // Input channel
6541 InputChannel mInputChannel;
6542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006543 WindowState(Session s, IWindow c, WindowToken token,
6544 WindowState attachedWindow, WindowManager.LayoutParams a,
6545 int viewVisibility) {
6546 mSession = s;
6547 mClient = c;
6548 mToken = token;
6549 mAttrs.copyFrom(a);
6550 mViewVisibility = viewVisibility;
6551 DeathRecipient deathRecipient = new DeathRecipient();
6552 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006553 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006554 TAG, "Window " + this + " client=" + c.asBinder()
6555 + " token=" + token + " (" + mAttrs.token + ")");
6556 try {
6557 c.asBinder().linkToDeath(deathRecipient, 0);
6558 } catch (RemoteException e) {
6559 mDeathRecipient = null;
6560 mAttachedWindow = null;
6561 mLayoutAttached = false;
6562 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006563 mIsWallpaper = false;
6564 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 mBaseLayer = 0;
6566 mSubLayer = 0;
6567 return;
6568 }
6569 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6572 mAttrs.type <= LAST_SUB_WINDOW)) {
6573 // The multiplier here is to reserve space for multiple
6574 // windows in the same type layer.
6575 mBaseLayer = mPolicy.windowTypeToLayerLw(
6576 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6577 + TYPE_LAYER_OFFSET;
6578 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6579 mAttachedWindow = attachedWindow;
6580 mAttachedWindow.mChildWindows.add(this);
6581 mLayoutAttached = mAttrs.type !=
6582 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6583 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6584 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006585 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6586 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 } else {
6588 // The multiplier here is to reserve space for multiple
6589 // windows in the same type layer.
6590 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6591 * TYPE_LAYER_MULTIPLIER
6592 + TYPE_LAYER_OFFSET;
6593 mSubLayer = 0;
6594 mAttachedWindow = null;
6595 mLayoutAttached = false;
6596 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6597 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006598 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6599 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 }
6601
6602 WindowState appWin = this;
6603 while (appWin.mAttachedWindow != null) {
6604 appWin = mAttachedWindow;
6605 }
6606 WindowToken appToken = appWin.mToken;
6607 while (appToken.appWindowToken == null) {
6608 WindowToken parent = mTokenMap.get(appToken.token);
6609 if (parent == null || appToken == parent) {
6610 break;
6611 }
6612 appToken = parent;
6613 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006614 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 mAppToken = appToken.appWindowToken;
6616
6617 mSurface = null;
6618 mRequestedWidth = 0;
6619 mRequestedHeight = 0;
6620 mLastRequestedWidth = 0;
6621 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006622 mXOffset = 0;
6623 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006624 mLayer = 0;
6625 mAnimLayer = 0;
6626 mLastLayer = 0;
6627 }
6628
6629 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006630 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006631 TAG, "Attaching " + this + " token=" + mToken
6632 + ", list=" + mToken.windows);
6633 mSession.windowAddedLocked();
6634 }
6635
6636 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6637 mHaveFrame = true;
6638
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006639 final Rect container = mContainingFrame;
6640 container.set(pf);
6641
6642 final Rect display = mDisplayFrame;
6643 display.set(df);
6644
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006645 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006646 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006647 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6648 display.intersect(mCompatibleScreenFrame);
6649 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006650 }
6651
6652 final int pw = container.right - container.left;
6653 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654
6655 int w,h;
6656 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6657 w = mAttrs.width < 0 ? pw : mAttrs.width;
6658 h = mAttrs.height< 0 ? ph : mAttrs.height;
6659 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006660 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6661 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662 }
Romain Guy06882f82009-06-10 13:36:04 -07006663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006664 final Rect content = mContentFrame;
6665 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 final Rect visible = mVisibleFrame;
6668 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006670 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006671 final int fw = frame.width();
6672 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006674 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6675 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6676
6677 Gravity.apply(mAttrs.gravity, w, h, container,
6678 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6679 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6680
6681 //System.out.println("Out: " + mFrame);
6682
6683 // Now make sure the window fits in the overall display.
6684 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 // Make sure the content and visible frames are inside of the
6687 // final window frame.
6688 if (content.left < frame.left) content.left = frame.left;
6689 if (content.top < frame.top) content.top = frame.top;
6690 if (content.right > frame.right) content.right = frame.right;
6691 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6692 if (visible.left < frame.left) visible.left = frame.left;
6693 if (visible.top < frame.top) visible.top = frame.top;
6694 if (visible.right > frame.right) visible.right = frame.right;
6695 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 final Rect contentInsets = mContentInsets;
6698 contentInsets.left = content.left-frame.left;
6699 contentInsets.top = content.top-frame.top;
6700 contentInsets.right = frame.right-content.right;
6701 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 final Rect visibleInsets = mVisibleInsets;
6704 visibleInsets.left = visible.left-frame.left;
6705 visibleInsets.top = visible.top-frame.top;
6706 visibleInsets.right = frame.right-visible.right;
6707 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006708
Dianne Hackborn284ac932009-08-28 10:34:25 -07006709 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6710 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006711 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006712 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006714 if (localLOGV) {
6715 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6716 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006717 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006718 + mRequestedWidth + ", mRequestedheight="
6719 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6720 + "): frame=" + mFrame.toShortString()
6721 + " ci=" + contentInsets.toShortString()
6722 + " vi=" + visibleInsets.toShortString());
6723 //}
6724 }
6725 }
Romain Guy06882f82009-06-10 13:36:04 -07006726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 public Rect getFrameLw() {
6728 return mFrame;
6729 }
6730
6731 public Rect getShownFrameLw() {
6732 return mShownFrame;
6733 }
6734
6735 public Rect getDisplayFrameLw() {
6736 return mDisplayFrame;
6737 }
6738
6739 public Rect getContentFrameLw() {
6740 return mContentFrame;
6741 }
6742
6743 public Rect getVisibleFrameLw() {
6744 return mVisibleFrame;
6745 }
6746
6747 public boolean getGivenInsetsPendingLw() {
6748 return mGivenInsetsPending;
6749 }
6750
6751 public Rect getGivenContentInsetsLw() {
6752 return mGivenContentInsets;
6753 }
Romain Guy06882f82009-06-10 13:36:04 -07006754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 public Rect getGivenVisibleInsetsLw() {
6756 return mGivenVisibleInsets;
6757 }
Romain Guy06882f82009-06-10 13:36:04 -07006758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006759 public WindowManager.LayoutParams getAttrs() {
6760 return mAttrs;
6761 }
6762
6763 public int getSurfaceLayer() {
6764 return mLayer;
6765 }
Romain Guy06882f82009-06-10 13:36:04 -07006766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 public IApplicationToken getAppToken() {
6768 return mAppToken != null ? mAppToken.appToken : null;
6769 }
Jeff Brown349703e2010-06-22 01:27:15 -07006770
6771 public long getInputDispatchingTimeoutNanos() {
6772 return mAppToken != null
6773 ? mAppToken.inputDispatchingTimeoutNanos
6774 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6775 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776
6777 public boolean hasAppShownWindows() {
6778 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6779 }
6780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006781 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006782 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006783 TAG, "Setting animation in " + this + ": " + anim);
6784 mAnimating = false;
6785 mLocalAnimating = false;
6786 mAnimation = anim;
6787 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6788 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6789 }
6790
6791 public void clearAnimation() {
6792 if (mAnimation != null) {
6793 mAnimating = true;
6794 mLocalAnimating = false;
6795 mAnimation = null;
6796 }
6797 }
Romain Guy06882f82009-06-10 13:36:04 -07006798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006799 Surface createSurfaceLocked() {
6800 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006801 mReportDestroySurface = false;
6802 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 mDrawPending = true;
6804 mCommitDrawPending = false;
6805 mReadyToShow = false;
6806 if (mAppToken != null) {
6807 mAppToken.allDrawn = false;
6808 }
6809
6810 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006811 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 flags |= Surface.PUSH_BUFFERS;
6813 }
6814
6815 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6816 flags |= Surface.SECURE;
6817 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006818 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006819 TAG, "Creating surface in session "
6820 + mSession.mSurfaceSession + " window " + this
6821 + " w=" + mFrame.width()
6822 + " h=" + mFrame.height() + " format="
6823 + mAttrs.format + " flags=" + flags);
6824
6825 int w = mFrame.width();
6826 int h = mFrame.height();
6827 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6828 // for a scaled surface, we always want the requested
6829 // size.
6830 w = mRequestedWidth;
6831 h = mRequestedHeight;
6832 }
6833
Romain Guy9825ec62009-10-01 00:58:09 -07006834 // Something is wrong and SurfaceFlinger will not like this,
6835 // try to revert to sane values
6836 if (w <= 0) w = 1;
6837 if (h <= 0) h = 1;
6838
Dianne Hackborn16064f92010-03-25 00:47:24 -07006839 mSurfaceShown = false;
6840 mSurfaceLayer = 0;
6841 mSurfaceAlpha = 1;
6842 mSurfaceX = 0;
6843 mSurfaceY = 0;
6844 mSurfaceW = w;
6845 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006847 final boolean isHwAccelerated = (mAttrs.flags &
6848 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6849 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6850 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6851 flags |= Surface.OPAQUE;
6852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006854 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006855 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006856 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006857 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006858 + mSurface + " IN SESSION "
6859 + mSession.mSurfaceSession
6860 + ": pid=" + mSession.mPid + " format="
6861 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006862 + Integer.toHexString(flags)
6863 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006865 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 reclaimSomeSurfaceMemoryLocked(this, "create");
6867 return null;
6868 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006869 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 return null;
6871 }
Romain Guy06882f82009-06-10 13:36:04 -07006872
Joe Onorato8a9b2202010-02-26 18:56:32 -08006873 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 TAG, "Got surface: " + mSurface
6875 + ", set left=" + mFrame.left + " top=" + mFrame.top
6876 + ", animLayer=" + mAnimLayer);
6877 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006878 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006879 if (SHOW_TRANSACTIONS) logSurface(this,
6880 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6881 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6882 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 }
6884 Surface.openTransaction();
6885 try {
6886 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006887 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006888 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006889 mSurface.setPosition(mSurfaceX, mSurfaceY);
6890 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006892 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 mSurface.hide();
6894 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006895 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 mSurface.setFlags(Surface.SURFACE_DITHER,
6897 Surface.SURFACE_DITHER);
6898 }
6899 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006900 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6902 }
6903 mLastHidden = true;
6904 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006905 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006906 Surface.closeTransaction();
6907 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006908 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 TAG, "Created surface " + this);
6910 }
6911 return mSurface;
6912 }
Romain Guy06882f82009-06-10 13:36:04 -07006913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006915 if (mAppToken != null && this == mAppToken.startingWindow) {
6916 mAppToken.startingDisplayed = false;
6917 }
Romain Guy06882f82009-06-10 13:36:04 -07006918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006920 mDrawPending = false;
6921 mCommitDrawPending = false;
6922 mReadyToShow = false;
6923
6924 int i = mChildWindows.size();
6925 while (i > 0) {
6926 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006927 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006928 c.mAttachedHidden = true;
6929 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006930
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006931 if (mReportDestroySurface) {
6932 mReportDestroySurface = false;
6933 mSurfacePendingDestroy = true;
6934 try {
6935 mClient.dispatchGetNewSurface();
6936 // We'll really destroy on the next time around.
6937 return;
6938 } catch (RemoteException e) {
6939 }
6940 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006942 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006943 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006944 RuntimeException e = null;
6945 if (!HIDE_STACK_CRAWLS) {
6946 e = new RuntimeException();
6947 e.fillInStackTrace();
6948 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006949 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006950 + mSurface + ", session " + mSession, e);
6951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006953 RuntimeException e = null;
6954 if (!HIDE_STACK_CRAWLS) {
6955 e = new RuntimeException();
6956 e.fillInStackTrace();
6957 }
6958 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006960 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006961 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006962 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 + " surface " + mSurface + " session " + mSession
6964 + ": " + e.toString());
6965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006966
Dianne Hackborn16064f92010-03-25 00:47:24 -07006967 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 }
6970 }
6971
6972 boolean finishDrawingLocked() {
6973 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006974 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 TAG, "finishDrawingLocked: " + mSurface);
6976 mCommitDrawPending = true;
6977 mDrawPending = false;
6978 return true;
6979 }
6980 return false;
6981 }
6982
6983 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006984 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006985 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006986 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006987 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006988 }
6989 mCommitDrawPending = false;
6990 mReadyToShow = true;
6991 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6992 final AppWindowToken atoken = mAppToken;
6993 if (atoken == null || atoken.allDrawn || starting) {
6994 performShowLocked();
6995 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006996 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006997 }
6998
6999 // This must be called while inside a transaction.
7000 boolean performShowLocked() {
7001 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007002 RuntimeException e = null;
7003 if (!HIDE_STACK_CRAWLS) {
7004 e = new RuntimeException();
7005 e.fillInStackTrace();
7006 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007007 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7009 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7010 }
7011 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007012 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7013 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007014 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007015 + " during animation: policyVis=" + mPolicyVisibility
7016 + " attHidden=" + mAttachedHidden
7017 + " tok.hiddenRequested="
7018 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007019 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 + (mAppToken != null ? mAppToken.hidden : false)
7021 + " animating=" + mAnimating
7022 + " tok animating="
7023 + (mAppToken != null ? mAppToken.animating : false));
7024 if (!showSurfaceRobustlyLocked(this)) {
7025 return false;
7026 }
7027 mLastAlpha = -1;
7028 mHasDrawn = true;
7029 mLastHidden = false;
7030 mReadyToShow = false;
7031 enableScreenIfNeededLocked();
7032
7033 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 int i = mChildWindows.size();
7036 while (i > 0) {
7037 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007038 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007039 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007040 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007041 if (c.mSurface != null) {
7042 c.performShowLocked();
7043 // It hadn't been shown, which means layout not
7044 // performed on it, so now we want to make sure to
7045 // do a layout. If called from within the transaction
7046 // loop, this will cause it to restart with a new
7047 // layout.
7048 mLayoutNeeded = true;
7049 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050 }
7051 }
Romain Guy06882f82009-06-10 13:36:04 -07007052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007053 if (mAttrs.type != TYPE_APPLICATION_STARTING
7054 && mAppToken != null) {
7055 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007056
Dianne Hackborn248b1882009-09-16 16:46:44 -07007057 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007058 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007059 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007060 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007061 // If this initial window is animating, stop it -- we
7062 // will do an animation to reveal it from behind the
7063 // starting window, so there is no need for it to also
7064 // be doing its own stuff.
7065 if (mAnimation != null) {
7066 mAnimation = null;
7067 // Make sure we clean up the animation.
7068 mAnimating = true;
7069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 mFinishedStarting.add(mAppToken);
7071 mH.sendEmptyMessage(H.FINISHED_STARTING);
7072 }
7073 mAppToken.updateReportedVisibilityLocked();
7074 }
7075 }
7076 return true;
7077 }
Romain Guy06882f82009-06-10 13:36:04 -07007078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 // This must be called while inside a transaction. Returns true if
7080 // there is more animation to run.
7081 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007082 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007085 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7086 mHasTransformation = true;
7087 mHasLocalTransformation = true;
7088 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007089 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 TAG, "Starting animation in " + this +
7091 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7092 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7093 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7094 mAnimation.setStartTime(currentTime);
7095 mLocalAnimating = true;
7096 mAnimating = true;
7097 }
7098 mTransformation.clear();
7099 final boolean more = mAnimation.getTransformation(
7100 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007101 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 TAG, "Stepped animation in " + this +
7103 ": more=" + more + ", xform=" + mTransformation);
7104 if (more) {
7105 // we're not done!
7106 return true;
7107 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007108 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007109 TAG, "Finished animation in " + this +
7110 " @ " + currentTime);
7111 mAnimation = null;
7112 //WindowManagerService.this.dump();
7113 }
7114 mHasLocalTransformation = false;
7115 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007116 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007117 // When our app token is animating, we kind-of pretend like
7118 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7119 // part of this check means that we will only do this if
7120 // our window is not currently exiting, or it is not
7121 // locally animating itself. The idea being that one that
7122 // is exiting and doing a local animation should be removed
7123 // once that animation is done.
7124 mAnimating = true;
7125 mHasTransformation = true;
7126 mTransformation.clear();
7127 return false;
7128 } else if (mHasTransformation) {
7129 // Little trick to get through the path below to act like
7130 // we have finished an animation.
7131 mAnimating = true;
7132 } else if (isAnimating()) {
7133 mAnimating = true;
7134 }
7135 } else if (mAnimation != null) {
7136 // If the display is frozen, and there is a pending animation,
7137 // clear it and make sure we run the cleanup code.
7138 mAnimating = true;
7139 mLocalAnimating = true;
7140 mAnimation = null;
7141 }
Romain Guy06882f82009-06-10 13:36:04 -07007142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007143 if (!mAnimating && !mLocalAnimating) {
7144 return false;
7145 }
7146
Joe Onorato8a9b2202010-02-26 18:56:32 -08007147 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007148 TAG, "Animation done in " + this + ": exiting=" + mExiting
7149 + ", reportedVisible="
7150 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 mAnimating = false;
7153 mLocalAnimating = false;
7154 mAnimation = null;
7155 mAnimLayer = mLayer;
7156 if (mIsImWindow) {
7157 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007158 } else if (mIsWallpaper) {
7159 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007160 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007161 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 + " anim layer: " + mAnimLayer);
7163 mHasTransformation = false;
7164 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007165 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7166 if (DEBUG_VISIBILITY) {
7167 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7168 + mPolicyVisibilityAfterAnim);
7169 }
7170 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7171 if (!mPolicyVisibility) {
7172 if (mCurrentFocus == this) {
7173 mFocusMayChange = true;
7174 }
7175 // Window is no longer visible -- make sure if we were waiting
7176 // for it to be displayed before enabling the display, that
7177 // we allow the display to be enabled now.
7178 enableScreenIfNeededLocked();
7179 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181 mTransformation.clear();
7182 if (mHasDrawn
7183 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7184 && mAppToken != null
7185 && mAppToken.firstWindowDrawn
7186 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007187 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007188 + mToken + ": first real window done animating");
7189 mFinishedStarting.add(mAppToken);
7190 mH.sendEmptyMessage(H.FINISHED_STARTING);
7191 }
Romain Guy06882f82009-06-10 13:36:04 -07007192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 finishExit();
7194
7195 if (mAppToken != null) {
7196 mAppToken.updateReportedVisibilityLocked();
7197 }
7198
7199 return false;
7200 }
7201
7202 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007203 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007204 TAG, "finishExit in " + this
7205 + ": exiting=" + mExiting
7206 + " remove=" + mRemoveOnExit
7207 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007209 final int N = mChildWindows.size();
7210 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007211 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007212 }
Romain Guy06882f82009-06-10 13:36:04 -07007213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007214 if (!mExiting) {
7215 return;
7216 }
Romain Guy06882f82009-06-10 13:36:04 -07007217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 if (isWindowAnimating()) {
7219 return;
7220 }
7221
Joe Onorato8a9b2202010-02-26 18:56:32 -08007222 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 TAG, "Exit animation finished in " + this
7224 + ": remove=" + mRemoveOnExit);
7225 if (mSurface != null) {
7226 mDestroySurface.add(this);
7227 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007228 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007229 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007230 try {
7231 mSurface.hide();
7232 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007233 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007234 }
7235 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 }
7237 mExiting = false;
7238 if (mRemoveOnExit) {
7239 mPendingRemove.add(this);
7240 mRemoveOnExit = false;
7241 }
7242 }
Romain Guy06882f82009-06-10 13:36:04 -07007243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7245 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7246 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7247 if (dtdx < -.000001f || dtdx > .000001f) return false;
7248 if (dsdy < -.000001f || dsdy > .000001f) return false;
7249 return true;
7250 }
Romain Guy06882f82009-06-10 13:36:04 -07007251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 void computeShownFrameLocked() {
7253 final boolean selfTransformation = mHasLocalTransformation;
7254 Transformation attachedTransformation =
7255 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7256 ? mAttachedWindow.mTransformation : null;
7257 Transformation appTransformation =
7258 (mAppToken != null && mAppToken.hasTransformation)
7259 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007260
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007261 // Wallpapers are animated based on the "real" window they
7262 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007263 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007264 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007265 if (mWallpaperTarget.mHasLocalTransformation &&
7266 mWallpaperTarget.mAnimation != null &&
7267 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007268 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007269 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007270 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007271 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007272 }
7273 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007274 mWallpaperTarget.mAppToken.hasTransformation &&
7275 mWallpaperTarget.mAppToken.animation != null &&
7276 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007277 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007278 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007279 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007280 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007281 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007282 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 if (selfTransformation || attachedTransformation != null
7285 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007286 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 final Rect frame = mFrame;
7288 final float tmpFloats[] = mTmpFloats;
7289 final Matrix tmpMatrix = mTmpMatrix;
7290
7291 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007292 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007294 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007296 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007297 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007298 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 }
7300 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007301 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007302 }
7303
7304 // "convert" it into SurfaceFlinger's format
7305 // (a 2x2 matrix + an offset)
7306 // Here we must not transform the position of the surface
7307 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007308 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 tmpMatrix.getValues(tmpFloats);
7311 mDsDx = tmpFloats[Matrix.MSCALE_X];
7312 mDtDx = tmpFloats[Matrix.MSKEW_X];
7313 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7314 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007315 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7316 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 int w = frame.width();
7318 int h = frame.height();
7319 mShownFrame.set(x, y, x+w, y+h);
7320
7321 // Now set the alpha... but because our current hardware
7322 // can't do alpha transformation on a non-opaque surface,
7323 // turn it off if we are running an animation that is also
7324 // transforming since it is more important to have that
7325 // animation be smooth.
7326 mShownAlpha = mAlpha;
7327 if (!mLimitedAlphaCompositing
7328 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7329 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7330 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007331 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 if (selfTransformation) {
7333 mShownAlpha *= mTransformation.getAlpha();
7334 }
7335 if (attachedTransformation != null) {
7336 mShownAlpha *= attachedTransformation.getAlpha();
7337 }
7338 if (appTransformation != null) {
7339 mShownAlpha *= appTransformation.getAlpha();
7340 }
7341 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007342 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 }
Romain Guy06882f82009-06-10 13:36:04 -07007344
Joe Onorato8a9b2202010-02-26 18:56:32 -08007345 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 TAG, "Continuing animation in " + this +
7347 ": " + mShownFrame +
7348 ", alpha=" + mTransformation.getAlpha());
7349 return;
7350 }
Romain Guy06882f82009-06-10 13:36:04 -07007351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007353 if (mXOffset != 0 || mYOffset != 0) {
7354 mShownFrame.offset(mXOffset, mYOffset);
7355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 mShownAlpha = mAlpha;
7357 mDsDx = 1;
7358 mDtDx = 0;
7359 mDsDy = 0;
7360 mDtDy = 1;
7361 }
Romain Guy06882f82009-06-10 13:36:04 -07007362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 /**
7364 * Is this window visible? It is not visible if there is no
7365 * surface, or we are in the process of running an exit animation
7366 * that will remove the surface, or its app token has been hidden.
7367 */
7368 public boolean isVisibleLw() {
7369 final AppWindowToken atoken = mAppToken;
7370 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7371 && (atoken == null || !atoken.hiddenRequested)
7372 && !mExiting && !mDestroying;
7373 }
7374
7375 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007376 * Like {@link #isVisibleLw}, but also counts a window that is currently
7377 * "hidden" behind the keyguard as visible. This allows us to apply
7378 * things like window flags that impact the keyguard.
7379 * XXX I am starting to think we need to have ANOTHER visibility flag
7380 * for this "hidden behind keyguard" state rather than overloading
7381 * mPolicyVisibility. Ungh.
7382 */
7383 public boolean isVisibleOrBehindKeyguardLw() {
7384 final AppWindowToken atoken = mAppToken;
7385 return mSurface != null && !mAttachedHidden
7386 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007387 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007388 && !mExiting && !mDestroying;
7389 }
7390
7391 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 * Is this window visible, ignoring its app token? It is not visible
7393 * if there is no surface, or we are in the process of running an exit animation
7394 * that will remove the surface.
7395 */
7396 public boolean isWinVisibleLw() {
7397 final AppWindowToken atoken = mAppToken;
7398 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7399 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7400 && !mExiting && !mDestroying;
7401 }
7402
7403 /**
7404 * The same as isVisible(), but follows the current hidden state of
7405 * the associated app token, not the pending requested hidden state.
7406 */
7407 boolean isVisibleNow() {
7408 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007409 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 }
7411
7412 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007413 * Can this window possibly be a drag/drop target? The test here is
7414 * a combination of the above "visible now" with the check that the
7415 * Input Manager uses when discarding windows from input consideration.
7416 */
7417 boolean isPotentialDragTarget() {
7418 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7419 }
7420
7421 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 * Same as isVisible(), but we also count it as visible between the
7423 * call to IWindowSession.add() and the first relayout().
7424 */
7425 boolean isVisibleOrAdding() {
7426 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007427 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7429 && mPolicyVisibility && !mAttachedHidden
7430 && (atoken == null || !atoken.hiddenRequested)
7431 && !mExiting && !mDestroying;
7432 }
7433
7434 /**
7435 * Is this window currently on-screen? It is on-screen either if it
7436 * is visible or it is currently running an animation before no longer
7437 * being visible.
7438 */
7439 boolean isOnScreen() {
7440 final AppWindowToken atoken = mAppToken;
7441 if (atoken != null) {
7442 return mSurface != null && mPolicyVisibility && !mDestroying
7443 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007444 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 } else {
7446 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007447 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 }
7449 }
Romain Guy06882f82009-06-10 13:36:04 -07007450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 /**
7452 * Like isOnScreen(), but we don't return true if the window is part
7453 * of a transition that has not yet been started.
7454 */
7455 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007456 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007457 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007458 return false;
7459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007461 final boolean animating = atoken != null
7462 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007464 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7465 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007466 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 }
7468
7469 /** Is the window or its container currently animating? */
7470 boolean isAnimating() {
7471 final WindowState attached = mAttachedWindow;
7472 final AppWindowToken atoken = mAppToken;
7473 return mAnimation != null
7474 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007475 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 (atoken.animation != null
7477 || atoken.inPendingTransaction));
7478 }
7479
7480 /** Is this window currently animating? */
7481 boolean isWindowAnimating() {
7482 return mAnimation != null;
7483 }
7484
7485 /**
7486 * Like isOnScreen, but returns false if the surface hasn't yet
7487 * been drawn.
7488 */
7489 public boolean isDisplayedLw() {
7490 final AppWindowToken atoken = mAppToken;
7491 return mSurface != null && mPolicyVisibility && !mDestroying
7492 && !mDrawPending && !mCommitDrawPending
7493 && ((!mAttachedHidden &&
7494 (atoken == null || !atoken.hiddenRequested))
7495 || mAnimating);
7496 }
7497
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007498 /**
7499 * Returns true if the window has a surface that it has drawn a
7500 * complete UI in to.
7501 */
7502 public boolean isDrawnLw() {
7503 final AppWindowToken atoken = mAppToken;
7504 return mSurface != null && !mDestroying
7505 && !mDrawPending && !mCommitDrawPending;
7506 }
7507
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007508 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007509 * Return true if the window is opaque and fully drawn. This indicates
7510 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007511 */
7512 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007513 return (mAttrs.format == PixelFormat.OPAQUE
7514 || mAttrs.type == TYPE_WALLPAPER)
7515 && mSurface != null && mAnimation == null
7516 && (mAppToken == null || mAppToken.animation == null)
7517 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007518 }
7519
7520 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7521 return
7522 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007523 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7524 // only if it's visible
7525 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007526 // and only if the application fills the compatible screen
7527 mFrame.left <= mCompatibleScreenFrame.left &&
7528 mFrame.top <= mCompatibleScreenFrame.top &&
7529 mFrame.right >= mCompatibleScreenFrame.right &&
7530 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007531 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007532 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007533 }
7534
7535 boolean isFullscreen(int screenWidth, int screenHeight) {
7536 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007537 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007538 }
7539
7540 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007541 disposeInputChannel();
7542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 if (mAttachedWindow != null) {
7544 mAttachedWindow.mChildWindows.remove(this);
7545 }
7546 destroySurfaceLocked();
7547 mSession.windowRemovedLocked();
7548 try {
7549 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7550 } catch (RuntimeException e) {
7551 // Ignore if it has already been removed (usually because
7552 // we are doing this as part of processing a death note.)
7553 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007554 }
7555
7556 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007557 if (mInputChannel != null) {
7558 mInputManager.unregisterInputChannel(mInputChannel);
7559
7560 mInputChannel.dispose();
7561 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 }
7564
7565 private class DeathRecipient implements IBinder.DeathRecipient {
7566 public void binderDied() {
7567 try {
7568 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007569 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007570 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007571 if (win != null) {
7572 removeWindowLocked(mSession, win);
7573 }
7574 }
7575 } catch (IllegalArgumentException ex) {
7576 // This will happen if the window has already been
7577 // removed.
7578 }
7579 }
7580 }
7581
7582 /** Returns true if this window desires key events. */
7583 public final boolean canReceiveKeys() {
7584 return isVisibleOrAdding()
7585 && (mViewVisibility == View.VISIBLE)
7586 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7587 }
7588
7589 public boolean hasDrawnLw() {
7590 return mHasDrawn;
7591 }
7592
7593 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007594 return showLw(doAnimation, true);
7595 }
7596
7597 boolean showLw(boolean doAnimation, boolean requestAnim) {
7598 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7599 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007600 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007601 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007602 if (doAnimation) {
7603 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7604 + mPolicyVisibility + " mAnimation=" + mAnimation);
7605 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7606 doAnimation = false;
7607 } else if (mPolicyVisibility && mAnimation == null) {
7608 // Check for the case where we are currently visible and
7609 // not animating; we do not want to do animation at such a
7610 // point to become visible when we already are.
7611 doAnimation = false;
7612 }
7613 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007614 mPolicyVisibility = true;
7615 mPolicyVisibilityAfterAnim = true;
7616 if (doAnimation) {
7617 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7618 }
7619 if (requestAnim) {
7620 requestAnimationLocked(0);
7621 }
7622 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 }
7624
7625 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007626 return hideLw(doAnimation, true);
7627 }
7628
7629 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007630 if (doAnimation) {
7631 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7632 doAnimation = false;
7633 }
7634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007635 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7636 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007637 if (!current) {
7638 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007640 if (doAnimation) {
7641 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7642 if (mAnimation == null) {
7643 doAnimation = false;
7644 }
7645 }
7646 if (doAnimation) {
7647 mPolicyVisibilityAfterAnim = false;
7648 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007649 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007650 mPolicyVisibilityAfterAnim = false;
7651 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007652 // Window is no longer visible -- make sure if we were waiting
7653 // for it to be displayed before enabling the display, that
7654 // we allow the display to be enabled now.
7655 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007656 if (mCurrentFocus == this) {
7657 mFocusMayChange = true;
7658 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007659 }
7660 if (requestAnim) {
7661 requestAnimationLocked(0);
7662 }
7663 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007664 }
7665
7666 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007667 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7668 pw.print(" mClient="); pw.println(mClient.asBinder());
7669 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7670 if (mAttachedWindow != null || mLayoutAttached) {
7671 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7672 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7673 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007674 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7675 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7676 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007677 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7678 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007679 }
7680 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7681 pw.print(" mSubLayer="); pw.print(mSubLayer);
7682 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7683 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7684 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7685 pw.print("="); pw.print(mAnimLayer);
7686 pw.print(" mLastLayer="); pw.println(mLastLayer);
7687 if (mSurface != null) {
7688 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007689 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7690 pw.print(" layer="); pw.print(mSurfaceLayer);
7691 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7692 pw.print(" rect=("); pw.print(mSurfaceX);
7693 pw.print(","); pw.print(mSurfaceY);
7694 pw.print(") "); pw.print(mSurfaceW);
7695 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007696 }
7697 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7698 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7699 if (mAppToken != null) {
7700 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7701 }
7702 if (mTargetAppToken != null) {
7703 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7704 }
7705 pw.print(prefix); pw.print("mViewVisibility=0x");
7706 pw.print(Integer.toHexString(mViewVisibility));
7707 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007708 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7709 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007710 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7711 pw.print(prefix); pw.print("mPolicyVisibility=");
7712 pw.print(mPolicyVisibility);
7713 pw.print(" mPolicyVisibilityAfterAnim=");
7714 pw.print(mPolicyVisibilityAfterAnim);
7715 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7716 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007717 if (!mRelayoutCalled) {
7718 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7719 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007720 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007721 pw.print(" h="); pw.print(mRequestedHeight);
7722 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007723 if (mXOffset != 0 || mYOffset != 0) {
7724 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7725 pw.print(" y="); pw.println(mYOffset);
7726 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007727 pw.print(prefix); pw.print("mGivenContentInsets=");
7728 mGivenContentInsets.printShortString(pw);
7729 pw.print(" mGivenVisibleInsets=");
7730 mGivenVisibleInsets.printShortString(pw);
7731 pw.println();
7732 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7733 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7734 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7735 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007736 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007737 pw.print(prefix); pw.print("mShownFrame=");
7738 mShownFrame.printShortString(pw);
7739 pw.print(" last="); mLastShownFrame.printShortString(pw);
7740 pw.println();
7741 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7742 pw.print(" last="); mLastFrame.printShortString(pw);
7743 pw.println();
7744 pw.print(prefix); pw.print("mContainingFrame=");
7745 mContainingFrame.printShortString(pw);
7746 pw.print(" mDisplayFrame=");
7747 mDisplayFrame.printShortString(pw);
7748 pw.println();
7749 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7750 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7751 pw.println();
7752 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7753 pw.print(" last="); mLastContentInsets.printShortString(pw);
7754 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7755 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7756 pw.println();
7757 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7758 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7759 pw.print(" mAlpha="); pw.print(mAlpha);
7760 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7761 }
7762 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7763 || mAnimation != null) {
7764 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7765 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7766 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7767 pw.print(" mAnimation="); pw.println(mAnimation);
7768 }
7769 if (mHasTransformation || mHasLocalTransformation) {
7770 pw.print(prefix); pw.print("XForm: has=");
7771 pw.print(mHasTransformation);
7772 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7773 pw.print(" "); mTransformation.printShortString(pw);
7774 pw.println();
7775 }
7776 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7777 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7778 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7779 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7780 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7781 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7782 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7783 pw.print(" mDestroying="); pw.print(mDestroying);
7784 pw.print(" mRemoved="); pw.println(mRemoved);
7785 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007786 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007787 pw.print(prefix); pw.print("mOrientationChanging=");
7788 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007789 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7790 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007791 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007792 if (mHScale != 1 || mVScale != 1) {
7793 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7794 pw.print(" mVScale="); pw.println(mVScale);
7795 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007796 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007797 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7798 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7799 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007800 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7801 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7802 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7803 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007804 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007805
7806 String makeInputChannelName() {
7807 return Integer.toHexString(System.identityHashCode(this))
7808 + " " + mAttrs.getTitle();
7809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007810
7811 @Override
7812 public String toString() {
7813 return "Window{"
7814 + Integer.toHexString(System.identityHashCode(this))
7815 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7816 }
7817 }
Romain Guy06882f82009-06-10 13:36:04 -07007818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007819 // -------------------------------------------------------------
7820 // Window Token State
7821 // -------------------------------------------------------------
7822
7823 class WindowToken {
7824 // The actual token.
7825 final IBinder token;
7826
7827 // The type of window this token is for, as per WindowManager.LayoutParams.
7828 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 // Set if this token was explicitly added by a client, so should
7831 // not be removed when all windows are removed.
7832 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007833
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007834 // For printing.
7835 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007837 // If this is an AppWindowToken, this is non-null.
7838 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840 // All of the windows associated with this token.
7841 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7842
7843 // Is key dispatching paused for this token?
7844 boolean paused = false;
7845
7846 // Should this token's windows be hidden?
7847 boolean hidden;
7848
7849 // Temporary for finding which tokens no longer have visible windows.
7850 boolean hasVisible;
7851
Dianne Hackborna8f60182009-09-01 19:01:50 -07007852 // Set to true when this token is in a pending transaction where it
7853 // will be shown.
7854 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007855
Dianne Hackborna8f60182009-09-01 19:01:50 -07007856 // Set to true when this token is in a pending transaction where it
7857 // will be hidden.
7858 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007859
Dianne Hackborna8f60182009-09-01 19:01:50 -07007860 // Set to true when this token is in a pending transaction where its
7861 // windows will be put to the bottom of the list.
7862 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007863
Dianne Hackborna8f60182009-09-01 19:01:50 -07007864 // Set to true when this token is in a pending transaction where its
7865 // windows will be put to the top of the list.
7866 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 WindowToken(IBinder _token, int type, boolean _explicit) {
7869 token = _token;
7870 windowType = type;
7871 explicit = _explicit;
7872 }
7873
7874 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007875 pw.print(prefix); pw.print("token="); pw.println(token);
7876 pw.print(prefix); pw.print("windows="); pw.println(windows);
7877 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7878 pw.print(" hidden="); pw.print(hidden);
7879 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007880 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7881 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7882 pw.print(" waitingToHide="); pw.print(waitingToHide);
7883 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7884 pw.print(" sendingToTop="); pw.println(sendingToTop);
7885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 }
7887
7888 @Override
7889 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007890 if (stringName == null) {
7891 StringBuilder sb = new StringBuilder();
7892 sb.append("WindowToken{");
7893 sb.append(Integer.toHexString(System.identityHashCode(this)));
7894 sb.append(" token="); sb.append(token); sb.append('}');
7895 stringName = sb.toString();
7896 }
7897 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 }
7899 };
7900
7901 class AppWindowToken extends WindowToken {
7902 // Non-null only for application tokens.
7903 final IApplicationToken appToken;
7904
7905 // All of the windows and child windows that are included in this
7906 // application token. Note this list is NOT sorted!
7907 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7908
7909 int groupId = -1;
7910 boolean appFullscreen;
7911 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007912
7913 // The input dispatching timeout for this application token in nanoseconds.
7914 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 // These are used for determining when all windows associated with
7917 // an activity have been drawn, so they can be made visible together
7918 // at the same time.
7919 int lastTransactionSequence = mTransactionSequence-1;
7920 int numInterestingWindows;
7921 int numDrawnWindows;
7922 boolean inPendingTransaction;
7923 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 // Is this token going to be hidden in a little while? If so, it
7926 // won't be taken into account for setting the screen orientation.
7927 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 // Is this window's surface needed? This is almost like hidden, except
7930 // it will sometimes be true a little earlier: when the token has
7931 // been shown, but is still waiting for its app transition to execute
7932 // before making its windows shown.
7933 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007935 // Have we told the window clients to hide themselves?
7936 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007938 // Last visibility state we reported to the app token.
7939 boolean reportedVisible;
7940
7941 // Set to true when the token has been removed from the window mgr.
7942 boolean removed;
7943
7944 // Have we been asked to have this token keep the screen frozen?
7945 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007947 boolean animating;
7948 Animation animation;
7949 boolean hasTransformation;
7950 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007952 // Offset to the window of all layers in the token, for use by
7953 // AppWindowToken animations.
7954 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007956 // Information about an application starting window if displayed.
7957 StartingData startingData;
7958 WindowState startingWindow;
7959 View startingView;
7960 boolean startingDisplayed;
7961 boolean startingMoved;
7962 boolean firstWindowDrawn;
7963
7964 AppWindowToken(IApplicationToken _token) {
7965 super(_token.asBinder(),
7966 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7967 appWindowToken = this;
7968 appToken = _token;
7969 }
Romain Guy06882f82009-06-10 13:36:04 -07007970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007971 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007972 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 TAG, "Setting animation in " + this + ": " + anim);
7974 animation = anim;
7975 animating = false;
7976 anim.restrictDuration(MAX_ANIMATION_DURATION);
7977 anim.scaleCurrentDuration(mTransitionAnimationScale);
7978 int zorder = anim.getZAdjustment();
7979 int adj = 0;
7980 if (zorder == Animation.ZORDER_TOP) {
7981 adj = TYPE_LAYER_OFFSET;
7982 } else if (zorder == Animation.ZORDER_BOTTOM) {
7983 adj = -TYPE_LAYER_OFFSET;
7984 }
Romain Guy06882f82009-06-10 13:36:04 -07007985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007986 if (animLayerAdjustment != adj) {
7987 animLayerAdjustment = adj;
7988 updateLayers();
7989 }
7990 }
Romain Guy06882f82009-06-10 13:36:04 -07007991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007992 public void setDummyAnimation() {
7993 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007994 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007995 TAG, "Setting dummy animation in " + this);
7996 animation = sDummyAnimation;
7997 }
7998 }
7999
8000 public void clearAnimation() {
8001 if (animation != null) {
8002 animation = null;
8003 animating = true;
8004 }
8005 }
Romain Guy06882f82009-06-10 13:36:04 -07008006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008007 void updateLayers() {
8008 final int N = allAppWindows.size();
8009 final int adj = animLayerAdjustment;
8010 for (int i=0; i<N; i++) {
8011 WindowState w = allAppWindows.get(i);
8012 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008013 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008014 + w.mAnimLayer);
8015 if (w == mInputMethodTarget) {
8016 setInputMethodAnimLayerAdjustment(adj);
8017 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008018 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008019 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 }
8022 }
Romain Guy06882f82009-06-10 13:36:04 -07008023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008024 void sendAppVisibilityToClients() {
8025 final int N = allAppWindows.size();
8026 for (int i=0; i<N; i++) {
8027 WindowState win = allAppWindows.get(i);
8028 if (win == startingWindow && clientHidden) {
8029 // Don't hide the starting window.
8030 continue;
8031 }
8032 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008033 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 "Setting visibility of " + win + ": " + (!clientHidden));
8035 win.mClient.dispatchAppVisibility(!clientHidden);
8036 } catch (RemoteException e) {
8037 }
8038 }
8039 }
Romain Guy06882f82009-06-10 13:36:04 -07008040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008041 void showAllWindowsLocked() {
8042 final int NW = allAppWindows.size();
8043 for (int i=0; i<NW; i++) {
8044 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008045 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 "performing show on: " + w);
8047 w.performShowLocked();
8048 }
8049 }
Romain Guy06882f82009-06-10 13:36:04 -07008050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008051 // This must be called while inside a transaction.
8052 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008053 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008054 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008056 if (animation == sDummyAnimation) {
8057 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008058 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 // when it is really time to animate, this will be set to
8060 // a real animation and the next call will execute normally.
8061 return false;
8062 }
Romain Guy06882f82009-06-10 13:36:04 -07008063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008064 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8065 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008066 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 TAG, "Starting animation in " + this +
8068 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8069 + " scale=" + mTransitionAnimationScale
8070 + " allDrawn=" + allDrawn + " animating=" + animating);
8071 animation.initialize(dw, dh, dw, dh);
8072 animation.setStartTime(currentTime);
8073 animating = true;
8074 }
8075 transformation.clear();
8076 final boolean more = animation.getTransformation(
8077 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008078 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008079 TAG, "Stepped animation in " + this +
8080 ": more=" + more + ", xform=" + transformation);
8081 if (more) {
8082 // we're done!
8083 hasTransformation = true;
8084 return true;
8085 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008086 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008087 TAG, "Finished animation in " + this +
8088 " @ " + currentTime);
8089 animation = null;
8090 }
8091 } else if (animation != null) {
8092 // If the display is frozen, and there is a pending animation,
8093 // clear it and make sure we run the cleanup code.
8094 animating = true;
8095 animation = null;
8096 }
8097
8098 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008100 if (!animating) {
8101 return false;
8102 }
8103
8104 clearAnimation();
8105 animating = false;
8106 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8107 moveInputMethodWindowsIfNeededLocked(true);
8108 }
Romain Guy06882f82009-06-10 13:36:04 -07008109
Joe Onorato8a9b2202010-02-26 18:56:32 -08008110 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 TAG, "Animation done in " + this
8112 + ": reportedVisible=" + reportedVisible);
8113
8114 transformation.clear();
8115 if (animLayerAdjustment != 0) {
8116 animLayerAdjustment = 0;
8117 updateLayers();
8118 }
Romain Guy06882f82009-06-10 13:36:04 -07008119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 final int N = windows.size();
8121 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008122 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008123 }
8124 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008126 return false;
8127 }
8128
8129 void updateReportedVisibilityLocked() {
8130 if (appToken == null) {
8131 return;
8132 }
Romain Guy06882f82009-06-10 13:36:04 -07008133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 int numInteresting = 0;
8135 int numVisible = 0;
8136 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008137
Joe Onorato8a9b2202010-02-26 18:56:32 -08008138 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008139 final int N = allAppWindows.size();
8140 for (int i=0; i<N; i++) {
8141 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008142 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008143 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008144 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8145 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008146 continue;
8147 }
8148 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008149 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008150 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008152 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008153 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008154 + " pv=" + win.mPolicyVisibility
8155 + " dp=" + win.mDrawPending
8156 + " cdp=" + win.mCommitDrawPending
8157 + " ah=" + win.mAttachedHidden
8158 + " th="
8159 + (win.mAppToken != null
8160 ? win.mAppToken.hiddenRequested : false)
8161 + " a=" + win.mAnimating);
8162 }
8163 }
8164 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008165 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008166 if (!win.isAnimating()) {
8167 numVisible++;
8168 }
8169 nowGone = false;
8170 } else if (win.isAnimating()) {
8171 nowGone = false;
8172 }
8173 }
Romain Guy06882f82009-06-10 13:36:04 -07008174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008176 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008177 + numInteresting + " visible=" + numVisible);
8178 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008179 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008180 TAG, "Visibility changed in " + this
8181 + ": vis=" + nowVisible);
8182 reportedVisible = nowVisible;
8183 Message m = mH.obtainMessage(
8184 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8185 nowVisible ? 1 : 0,
8186 nowGone ? 1 : 0,
8187 this);
8188 mH.sendMessage(m);
8189 }
8190 }
Romain Guy06882f82009-06-10 13:36:04 -07008191
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008192 WindowState findMainWindow() {
8193 int j = windows.size();
8194 while (j > 0) {
8195 j--;
8196 WindowState win = windows.get(j);
8197 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8198 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8199 return win;
8200 }
8201 }
8202 return null;
8203 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 void dump(PrintWriter pw, String prefix) {
8206 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008207 if (appToken != null) {
8208 pw.print(prefix); pw.println("app=true");
8209 }
8210 if (allAppWindows.size() > 0) {
8211 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8212 }
8213 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008214 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008215 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8216 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8217 pw.print(" clientHidden="); pw.print(clientHidden);
8218 pw.print(" willBeHidden="); pw.print(willBeHidden);
8219 pw.print(" reportedVisible="); pw.println(reportedVisible);
8220 if (paused || freezingScreen) {
8221 pw.print(prefix); pw.print("paused="); pw.print(paused);
8222 pw.print(" freezingScreen="); pw.println(freezingScreen);
8223 }
8224 if (numInterestingWindows != 0 || numDrawnWindows != 0
8225 || inPendingTransaction || allDrawn) {
8226 pw.print(prefix); pw.print("numInterestingWindows=");
8227 pw.print(numInterestingWindows);
8228 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8229 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8230 pw.print(" allDrawn="); pw.println(allDrawn);
8231 }
8232 if (animating || animation != null) {
8233 pw.print(prefix); pw.print("animating="); pw.print(animating);
8234 pw.print(" animation="); pw.println(animation);
8235 }
8236 if (animLayerAdjustment != 0) {
8237 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8238 }
8239 if (hasTransformation) {
8240 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8241 pw.print(" transformation="); transformation.printShortString(pw);
8242 pw.println();
8243 }
8244 if (startingData != null || removed || firstWindowDrawn) {
8245 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8246 pw.print(" removed="); pw.print(removed);
8247 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8248 }
8249 if (startingWindow != null || startingView != null
8250 || startingDisplayed || startingMoved) {
8251 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8252 pw.print(" startingView="); pw.print(startingView);
8253 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8254 pw.print(" startingMoved"); pw.println(startingMoved);
8255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008256 }
8257
8258 @Override
8259 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008260 if (stringName == null) {
8261 StringBuilder sb = new StringBuilder();
8262 sb.append("AppWindowToken{");
8263 sb.append(Integer.toHexString(System.identityHashCode(this)));
8264 sb.append(" token="); sb.append(token); sb.append('}');
8265 stringName = sb.toString();
8266 }
8267 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 }
8269 }
Romain Guy06882f82009-06-10 13:36:04 -07008270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 // -------------------------------------------------------------
8272 // DummyAnimation
8273 // -------------------------------------------------------------
8274
8275 // This is an animation that does nothing: it just immediately finishes
8276 // itself every time it is called. It is used as a stub animation in cases
8277 // where we want to synchronize multiple things that may be animating.
8278 static final class DummyAnimation extends Animation {
8279 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8280 return false;
8281 }
8282 }
8283 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008285 // -------------------------------------------------------------
8286 // Async Handler
8287 // -------------------------------------------------------------
8288
8289 static final class StartingData {
8290 final String pkg;
8291 final int theme;
8292 final CharSequence nonLocalizedLabel;
8293 final int labelRes;
8294 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008296 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8297 int _labelRes, int _icon) {
8298 pkg = _pkg;
8299 theme = _theme;
8300 nonLocalizedLabel = _nonLocalizedLabel;
8301 labelRes = _labelRes;
8302 icon = _icon;
8303 }
8304 }
8305
8306 private final class H extends Handler {
8307 public static final int REPORT_FOCUS_CHANGE = 2;
8308 public static final int REPORT_LOSING_FOCUS = 3;
8309 public static final int ANIMATE = 4;
8310 public static final int ADD_STARTING = 5;
8311 public static final int REMOVE_STARTING = 6;
8312 public static final int FINISHED_STARTING = 7;
8313 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008314 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8315 public static final int HOLD_SCREEN_CHANGED = 12;
8316 public static final int APP_TRANSITION_TIMEOUT = 13;
8317 public static final int PERSIST_ANIMATION_SCALE = 14;
8318 public static final int FORCE_GC = 15;
8319 public static final int ENABLE_SCREEN = 16;
8320 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008321 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008322 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008323 public static final int DRAG_START_TIMEOUT = 20;
Romain Guy06882f82009-06-10 13:36:04 -07008324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008325 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008327 public H() {
8328 }
Romain Guy06882f82009-06-10 13:36:04 -07008329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008330 @Override
8331 public void handleMessage(Message msg) {
8332 switch (msg.what) {
8333 case REPORT_FOCUS_CHANGE: {
8334 WindowState lastFocus;
8335 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008337 synchronized(mWindowMap) {
8338 lastFocus = mLastFocus;
8339 newFocus = mCurrentFocus;
8340 if (lastFocus == newFocus) {
8341 // Focus is not changing, so nothing to do.
8342 return;
8343 }
8344 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008345 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346 // + " to " + newFocus);
8347 if (newFocus != null && lastFocus != null
8348 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008349 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008350 mLosingFocus.add(lastFocus);
8351 lastFocus = null;
8352 }
8353 }
8354
8355 if (lastFocus != newFocus) {
8356 //System.out.println("Changing focus from " + lastFocus
8357 // + " to " + newFocus);
8358 if (newFocus != null) {
8359 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008360 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008361 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8362 } catch (RemoteException e) {
8363 // Ignore if process has died.
8364 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008365 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008366 }
8367
8368 if (lastFocus != null) {
8369 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008370 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008371 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8372 } catch (RemoteException e) {
8373 // Ignore if process has died.
8374 }
8375 }
8376 }
8377 } break;
8378
8379 case REPORT_LOSING_FOCUS: {
8380 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008382 synchronized(mWindowMap) {
8383 losers = mLosingFocus;
8384 mLosingFocus = new ArrayList<WindowState>();
8385 }
8386
8387 final int N = losers.size();
8388 for (int i=0; i<N; i++) {
8389 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008390 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008391 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8392 } catch (RemoteException e) {
8393 // Ignore if process has died.
8394 }
8395 }
8396 } break;
8397
8398 case ANIMATE: {
8399 synchronized(mWindowMap) {
8400 mAnimationPending = false;
8401 performLayoutAndPlaceSurfacesLocked();
8402 }
8403 } break;
8404
8405 case ADD_STARTING: {
8406 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8407 final StartingData sd = wtoken.startingData;
8408
8409 if (sd == null) {
8410 // Animation has been canceled... do nothing.
8411 return;
8412 }
Romain Guy06882f82009-06-10 13:36:04 -07008413
Joe Onorato8a9b2202010-02-26 18:56:32 -08008414 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 View view = null;
8418 try {
8419 view = mPolicy.addStartingWindow(
8420 wtoken.token, sd.pkg,
8421 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8422 sd.icon);
8423 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008424 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425 }
8426
8427 if (view != null) {
8428 boolean abort = false;
8429
8430 synchronized(mWindowMap) {
8431 if (wtoken.removed || wtoken.startingData == null) {
8432 // If the window was successfully added, then
8433 // we need to remove it.
8434 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008435 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 "Aborted starting " + wtoken
8437 + ": removed=" + wtoken.removed
8438 + " startingData=" + wtoken.startingData);
8439 wtoken.startingWindow = null;
8440 wtoken.startingData = null;
8441 abort = true;
8442 }
8443 } else {
8444 wtoken.startingView = view;
8445 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008446 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 "Added starting " + wtoken
8448 + ": startingWindow="
8449 + wtoken.startingWindow + " startingView="
8450 + wtoken.startingView);
8451 }
8452
8453 if (abort) {
8454 try {
8455 mPolicy.removeStartingWindow(wtoken.token, view);
8456 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008457 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 }
8459 }
8460 }
8461 } break;
8462
8463 case REMOVE_STARTING: {
8464 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8465 IBinder token = null;
8466 View view = null;
8467 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008468 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 + wtoken + ": startingWindow="
8470 + wtoken.startingWindow + " startingView="
8471 + wtoken.startingView);
8472 if (wtoken.startingWindow != null) {
8473 view = wtoken.startingView;
8474 token = wtoken.token;
8475 wtoken.startingData = null;
8476 wtoken.startingView = null;
8477 wtoken.startingWindow = null;
8478 }
8479 }
8480 if (view != null) {
8481 try {
8482 mPolicy.removeStartingWindow(token, view);
8483 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008484 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008485 }
8486 }
8487 } break;
8488
8489 case FINISHED_STARTING: {
8490 IBinder token = null;
8491 View view = null;
8492 while (true) {
8493 synchronized (mWindowMap) {
8494 final int N = mFinishedStarting.size();
8495 if (N <= 0) {
8496 break;
8497 }
8498 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8499
Joe Onorato8a9b2202010-02-26 18:56:32 -08008500 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 "Finished starting " + wtoken
8502 + ": startingWindow=" + wtoken.startingWindow
8503 + " startingView=" + wtoken.startingView);
8504
8505 if (wtoken.startingWindow == null) {
8506 continue;
8507 }
8508
8509 view = wtoken.startingView;
8510 token = wtoken.token;
8511 wtoken.startingData = null;
8512 wtoken.startingView = null;
8513 wtoken.startingWindow = null;
8514 }
8515
8516 try {
8517 mPolicy.removeStartingWindow(token, view);
8518 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008519 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520 }
8521 }
8522 } break;
8523
8524 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8525 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8526
8527 boolean nowVisible = msg.arg1 != 0;
8528 boolean nowGone = msg.arg2 != 0;
8529
8530 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008531 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008532 TAG, "Reporting visible in " + wtoken
8533 + " visible=" + nowVisible
8534 + " gone=" + nowGone);
8535 if (nowVisible) {
8536 wtoken.appToken.windowsVisible();
8537 } else {
8538 wtoken.appToken.windowsGone();
8539 }
8540 } catch (RemoteException ex) {
8541 }
8542 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 case WINDOW_FREEZE_TIMEOUT: {
8545 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008546 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 int i = mWindows.size();
8548 while (i > 0) {
8549 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008550 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 if (w.mOrientationChanging) {
8552 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008553 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008554 }
8555 }
8556 performLayoutAndPlaceSurfacesLocked();
8557 }
8558 break;
8559 }
Romain Guy06882f82009-06-10 13:36:04 -07008560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 case HOLD_SCREEN_CHANGED: {
8562 Session oldHold;
8563 Session newHold;
8564 synchronized (mWindowMap) {
8565 oldHold = mLastReportedHold;
8566 newHold = (Session)msg.obj;
8567 mLastReportedHold = newHold;
8568 }
Romain Guy06882f82009-06-10 13:36:04 -07008569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 if (oldHold != newHold) {
8571 try {
8572 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008573 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 "window",
8575 BatteryStats.WAKE_TYPE_WINDOW);
8576 }
8577 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008578 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579 "window",
8580 BatteryStats.WAKE_TYPE_WINDOW);
8581 }
8582 } catch (RemoteException e) {
8583 }
8584 }
8585 break;
8586 }
Romain Guy06882f82009-06-10 13:36:04 -07008587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 case APP_TRANSITION_TIMEOUT: {
8589 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008590 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008591 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008592 "*** APP TRANSITION TIMEOUT");
8593 mAppTransitionReady = true;
8594 mAppTransitionTimeout = true;
8595 performLayoutAndPlaceSurfacesLocked();
8596 }
8597 }
8598 break;
8599 }
Romain Guy06882f82009-06-10 13:36:04 -07008600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008601 case PERSIST_ANIMATION_SCALE: {
8602 Settings.System.putFloat(mContext.getContentResolver(),
8603 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8604 Settings.System.putFloat(mContext.getContentResolver(),
8605 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8606 break;
8607 }
Romain Guy06882f82009-06-10 13:36:04 -07008608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008609 case FORCE_GC: {
8610 synchronized(mWindowMap) {
8611 if (mAnimationPending) {
8612 // If we are animating, don't do the gc now but
8613 // delay a bit so we don't interrupt the animation.
8614 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8615 2000);
8616 return;
8617 }
8618 // If we are currently rotating the display, it will
8619 // schedule a new message when done.
8620 if (mDisplayFrozen) {
8621 return;
8622 }
8623 mFreezeGcPending = 0;
8624 }
8625 Runtime.getRuntime().gc();
8626 break;
8627 }
Romain Guy06882f82009-06-10 13:36:04 -07008628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 case ENABLE_SCREEN: {
8630 performEnableScreen();
8631 break;
8632 }
Romain Guy06882f82009-06-10 13:36:04 -07008633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008634 case APP_FREEZE_TIMEOUT: {
8635 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008636 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 int i = mAppTokens.size();
8638 while (i > 0) {
8639 i--;
8640 AppWindowToken tok = mAppTokens.get(i);
8641 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008642 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008643 unsetAppFreezingScreenLocked(tok, true, true);
8644 }
8645 }
8646 }
8647 break;
8648 }
Romain Guy06882f82009-06-10 13:36:04 -07008649
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008650 case SEND_NEW_CONFIGURATION: {
8651 removeMessages(SEND_NEW_CONFIGURATION);
8652 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008653 break;
8654 }
Romain Guy06882f82009-06-10 13:36:04 -07008655
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008656 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008657 if (mWindowsChanged) {
8658 synchronized (mWindowMap) {
8659 mWindowsChanged = false;
8660 }
8661 notifyWindowsChanged();
8662 }
8663 break;
8664 }
8665
Christopher Tatea53146c2010-09-07 11:57:52 -07008666 case DRAG_START_TIMEOUT: {
8667 IBinder win = (IBinder)msg.obj;
8668 if (DEBUG_DRAG) {
8669 Slog.w(TAG, "Timeout starting drag by win " + win);
8670 }
8671 synchronized (mWindowMap) {
8672 // !!! TODO: ANR the app that has failed to start the drag in time
8673 if (mDragState != null) {
8674 mDragState.reset();
8675 mDragState = null;
8676 }
8677 }
8678 }
8679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 }
8681 }
8682 }
8683
8684 // -------------------------------------------------------------
8685 // IWindowManager API
8686 // -------------------------------------------------------------
8687
8688 public IWindowSession openSession(IInputMethodClient client,
8689 IInputContext inputContext) {
8690 if (client == null) throw new IllegalArgumentException("null client");
8691 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008692 Session session = new Session(client, inputContext);
8693 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008694 }
8695
8696 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8697 synchronized (mWindowMap) {
8698 // The focus for the client is the window immediately below
8699 // where we would place the input method window.
8700 int idx = findDesiredInputMethodWindowIndexLocked(false);
8701 WindowState imFocus;
8702 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008703 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 if (imFocus != null) {
8705 if (imFocus.mSession.mClient != null &&
8706 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8707 return true;
8708 }
8709 }
8710 }
8711 }
8712 return false;
8713 }
Romain Guy06882f82009-06-10 13:36:04 -07008714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008715 // -------------------------------------------------------------
8716 // Internals
8717 // -------------------------------------------------------------
8718
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008719 final WindowState windowForClientLocked(Session session, IWindow client,
8720 boolean throwOnError) {
8721 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008722 }
Romain Guy06882f82009-06-10 13:36:04 -07008723
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008724 final WindowState windowForClientLocked(Session session, IBinder client,
8725 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008726 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008727 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 TAG, "Looking up client " + client + ": " + win);
8729 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008730 RuntimeException ex = new IllegalArgumentException(
8731 "Requested window " + client + " does not exist");
8732 if (throwOnError) {
8733 throw ex;
8734 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008735 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008736 return null;
8737 }
8738 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008739 RuntimeException ex = new IllegalArgumentException(
8740 "Requested window " + client + " is in session " +
8741 win.mSession + ", not " + session);
8742 if (throwOnError) {
8743 throw ex;
8744 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008745 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 return null;
8747 }
8748
8749 return win;
8750 }
8751
Dianne Hackborna8f60182009-09-01 19:01:50 -07008752 final void rebuildAppWindowListLocked() {
8753 int NW = mWindows.size();
8754 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008755 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008756 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008757
Dianne Hackborna8f60182009-09-01 19:01:50 -07008758 // First remove all existing app windows.
8759 i=0;
8760 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008761 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008762 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008763 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008764 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008765 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008766 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008767 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008768 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008769 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008770 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8771 && lastWallpaper == i-1) {
8772 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008773 }
8774 i++;
8775 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008776
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008777 // The wallpaper window(s) typically live at the bottom of the stack,
8778 // so skip them before adding app tokens.
8779 lastWallpaper++;
8780 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008781
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008782 // First add all of the exiting app tokens... these are no longer
8783 // in the main app list, but still have windows shown. We put them
8784 // in the back because now that the animation is over we no longer
8785 // will care about them.
8786 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008787 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008788 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8789 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008790
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008791 // And add in the still active app tokens in Z order.
8792 NT = mAppTokens.size();
8793 for (int j=0; j<NT; j++) {
8794 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008795 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008796
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008797 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008798 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008799 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008800 + " windows but added " + i);
8801 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008802 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 private final void assignLayersLocked() {
8805 int N = mWindows.size();
8806 int curBaseLayer = 0;
8807 int curLayer = 0;
8808 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008811 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008812 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8813 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008814 curLayer += WINDOW_LAYER_MULTIPLIER;
8815 w.mLayer = curLayer;
8816 } else {
8817 curBaseLayer = curLayer = w.mBaseLayer;
8818 w.mLayer = curLayer;
8819 }
8820 if (w.mTargetAppToken != null) {
8821 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8822 } else if (w.mAppToken != null) {
8823 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8824 } else {
8825 w.mAnimLayer = w.mLayer;
8826 }
8827 if (w.mIsImWindow) {
8828 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008829 } else if (w.mIsWallpaper) {
8830 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008832 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008833 + w.mAnimLayer);
8834 //System.out.println(
8835 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8836 }
8837 }
8838
8839 private boolean mInLayout = false;
8840 private final void performLayoutAndPlaceSurfacesLocked() {
8841 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008842 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 throw new RuntimeException("Recursive call!");
8844 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008845 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008846 return;
8847 }
8848
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008849 if (mWaitingForConfig) {
8850 // Our configuration has changed (most likely rotation), but we
8851 // don't yet have the complete configuration to report to
8852 // applications. Don't do any window layout until we have it.
8853 return;
8854 }
8855
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008856 if (mDisplay == null) {
8857 // Not yet initialized, nothing to do.
8858 return;
8859 }
8860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008861 boolean recoveringMemory = false;
8862 if (mForceRemoves != null) {
8863 recoveringMemory = true;
8864 // Wait a little it for things to settle down, and off we go.
8865 for (int i=0; i<mForceRemoves.size(); i++) {
8866 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008867 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 removeWindowInnerLocked(ws.mSession, ws);
8869 }
8870 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008871 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008872 Object tmp = new Object();
8873 synchronized (tmp) {
8874 try {
8875 tmp.wait(250);
8876 } catch (InterruptedException e) {
8877 }
8878 }
8879 }
Romain Guy06882f82009-06-10 13:36:04 -07008880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008881 mInLayout = true;
8882 try {
8883 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 int i = mPendingRemove.size()-1;
8886 if (i >= 0) {
8887 while (i >= 0) {
8888 WindowState w = mPendingRemove.get(i);
8889 removeWindowInnerLocked(w.mSession, w);
8890 i--;
8891 }
8892 mPendingRemove.clear();
8893
8894 mInLayout = false;
8895 assignLayersLocked();
8896 mLayoutNeeded = true;
8897 performLayoutAndPlaceSurfacesLocked();
8898
8899 } else {
8900 mInLayout = false;
8901 if (mLayoutNeeded) {
8902 requestAnimationLocked(0);
8903 }
8904 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008905 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008906 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8907 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008909 } catch (RuntimeException e) {
8910 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008911 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008912 }
8913 }
8914
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008915 private final int performLayoutLockedInner() {
8916 if (!mLayoutNeeded) {
8917 return 0;
8918 }
8919
8920 mLayoutNeeded = false;
8921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008922 final int dw = mDisplay.getWidth();
8923 final int dh = mDisplay.getHeight();
8924
8925 final int N = mWindows.size();
8926 int i;
8927
Joe Onorato8a9b2202010-02-26 18:56:32 -08008928 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008929 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8930
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008931 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008932
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008933 int seq = mLayoutSeq+1;
8934 if (seq < 0) seq = 0;
8935 mLayoutSeq = seq;
8936
8937 // First perform layout of any root windows (not attached
8938 // to another window).
8939 int topAttached = -1;
8940 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008941 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008942
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008943 // Don't do layout of a window if it is not visible, or
8944 // soon won't be visible, to avoid wasting time and funky
8945 // changes while a window is animating away.
8946 final AppWindowToken atoken = win.mAppToken;
8947 final boolean gone = win.mViewVisibility == View.GONE
8948 || !win.mRelayoutCalled
8949 || win.mRootToken.hidden
8950 || (atoken != null && atoken.hiddenRequested)
8951 || win.mAttachedHidden
8952 || win.mExiting || win.mDestroying;
8953
8954 if (!win.mLayoutAttached) {
8955 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8956 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8957 + " mLayoutAttached=" + win.mLayoutAttached);
8958 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8959 + win.mViewVisibility + " mRelayoutCalled="
8960 + win.mRelayoutCalled + " hidden="
8961 + win.mRootToken.hidden + " hiddenRequested="
8962 + (atoken != null && atoken.hiddenRequested)
8963 + " mAttachedHidden=" + win.mAttachedHidden);
8964 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008965
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008966 // If this view is GONE, then skip it -- keep the current
8967 // frame, and let the caller know so they can ignore it
8968 // if they want. (We do the normal layout for INVISIBLE
8969 // windows, since that means "perform layout as normal,
8970 // just don't display").
8971 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008972 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008973 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8974 win.mLayoutSeq = seq;
8975 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8976 + win.mFrame + " mContainingFrame="
8977 + win.mContainingFrame + " mDisplayFrame="
8978 + win.mDisplayFrame);
8979 } else {
8980 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008981 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008983 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008984
8985 // Now perform layout of attached windows, which usually
8986 // depend on the position of the window they are attached to.
8987 // XXX does not deal with windows that are attached to windows
8988 // that are themselves attached.
8989 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008990 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008991
8992 // If this view is GONE, then skip it -- keep the current
8993 // frame, and let the caller know so they can ignore it
8994 // if they want. (We do the normal layout for INVISIBLE
8995 // windows, since that means "perform layout as normal,
8996 // just don't display").
8997 if (win.mLayoutAttached) {
8998 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8999 + " mHaveFrame=" + win.mHaveFrame
9000 + " mViewVisibility=" + win.mViewVisibility
9001 + " mRelayoutCalled=" + win.mRelayoutCalled);
9002 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9003 || !win.mHaveFrame) {
9004 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9005 win.mLayoutSeq = seq;
9006 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9007 + win.mFrame + " mContainingFrame="
9008 + win.mContainingFrame + " mDisplayFrame="
9009 + win.mDisplayFrame);
9010 }
9011 }
9012 }
Jeff Brown349703e2010-06-22 01:27:15 -07009013
9014 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009015 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009016
9017 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009018 }
Romain Guy06882f82009-06-10 13:36:04 -07009019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009020 private final void performLayoutAndPlaceSurfacesLockedInner(
9021 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009022 if (mDisplay == null) {
9023 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9024 return;
9025 }
9026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009027 final long currentTime = SystemClock.uptimeMillis();
9028 final int dw = mDisplay.getWidth();
9029 final int dh = mDisplay.getHeight();
9030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009031 int i;
9032
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009033 if (mFocusMayChange) {
9034 mFocusMayChange = false;
9035 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9036 }
9037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009038 // Initialize state of exiting tokens.
9039 for (i=mExitingTokens.size()-1; i>=0; i--) {
9040 mExitingTokens.get(i).hasVisible = false;
9041 }
9042
9043 // Initialize state of exiting applications.
9044 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9045 mExitingAppTokens.get(i).hasVisible = false;
9046 }
9047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009048 boolean orientationChangeComplete = true;
9049 Session holdScreen = null;
9050 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009051 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009052 boolean focusDisplayed = false;
9053 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009054 boolean createWatermark = false;
9055
9056 if (mFxSession == null) {
9057 mFxSession = new SurfaceSession();
9058 createWatermark = true;
9059 }
9060
9061 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009062
9063 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009064
9065 if (createWatermark) {
9066 createWatermark();
9067 }
9068 if (mWatermark != null) {
9069 mWatermark.positionSurface(dw, dh);
9070 }
9071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009072 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009073 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009074 int repeats = 0;
9075 int changes = 0;
9076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009077 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009078 repeats++;
9079 if (repeats > 6) {
9080 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9081 mLayoutNeeded = false;
9082 break;
9083 }
9084
9085 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9086 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9087 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9088 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9089 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9090 assignLayersLocked();
9091 mLayoutNeeded = true;
9092 }
9093 }
9094 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9095 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9096 if (updateOrientationFromAppTokensLocked()) {
9097 mLayoutNeeded = true;
9098 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9099 }
9100 }
9101 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9102 mLayoutNeeded = true;
9103 }
9104 }
9105
9106 // FIRST LOOP: Perform a layout, if needed.
9107 if (repeats < 4) {
9108 changes = performLayoutLockedInner();
9109 if (changes != 0) {
9110 continue;
9111 }
9112 } else {
9113 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9114 changes = 0;
9115 }
9116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009117 final int transactionSequence = ++mTransactionSequence;
9118
9119 // Update animations of all applications, including those
9120 // associated with exiting/removed apps
9121 boolean tokensAnimating = false;
9122 final int NAT = mAppTokens.size();
9123 for (i=0; i<NAT; i++) {
9124 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9125 tokensAnimating = true;
9126 }
9127 }
9128 final int NEAT = mExitingAppTokens.size();
9129 for (i=0; i<NEAT; i++) {
9130 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9131 tokensAnimating = true;
9132 }
9133 }
9134
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009135 // SECOND LOOP: Execute animations and update visibility of windows.
9136
Joe Onorato8a9b2202010-02-26 18:56:32 -08009137 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009138 + transactionSequence + " tokensAnimating="
9139 + tokensAnimating);
9140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009142
9143 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009144 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009145 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009146
9147 mPolicy.beginAnimationLw(dw, dh);
9148
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009149 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009151 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009152 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009153
9154 final WindowManager.LayoutParams attrs = w.mAttrs;
9155
9156 if (w.mSurface != null) {
9157 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009158 if (w.commitFinishDrawingLocked(currentTime)) {
9159 if ((w.mAttrs.flags
9160 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009161 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009162 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009163 wallpaperMayChange = true;
9164 }
9165 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009166
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009167 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009168 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9169 animating = true;
9170 //w.dump(" ");
9171 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009172 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9173 wallpaperMayChange = true;
9174 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009175
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009176 if (mPolicy.doesForceHide(w, attrs)) {
9177 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009178 if (DEBUG_VISIBILITY) Slog.v(TAG,
9179 "Animation done that could impact force hide: "
9180 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009181 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009182 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009183 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9184 forceHiding = true;
9185 }
9186 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9187 boolean changed;
9188 if (forceHiding) {
9189 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009190 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9191 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009192 } else {
9193 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009194 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9195 "Now policy shown: " + w);
9196 if (changed) {
9197 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009198 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009199 // Assume we will need to animate. If
9200 // we don't (because the wallpaper will
9201 // stay with the lock screen), then we will
9202 // clean up later.
9203 Animation a = mPolicy.createForceHideEnterAnimation();
9204 if (a != null) {
9205 w.setAnimation(a);
9206 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009207 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009208 if (mCurrentFocus == null ||
9209 mCurrentFocus.mLayer < w.mLayer) {
9210 // We are showing on to of the current
9211 // focus, so re-evaluate focus to make
9212 // sure it is correct.
9213 mFocusMayChange = true;
9214 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009215 }
9216 }
9217 if (changed && (attrs.flags
9218 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9219 wallpaperMayChange = true;
9220 }
9221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009223 mPolicy.animatingWindowLw(w, attrs);
9224 }
9225
9226 final AppWindowToken atoken = w.mAppToken;
9227 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9228 if (atoken.lastTransactionSequence != transactionSequence) {
9229 atoken.lastTransactionSequence = transactionSequence;
9230 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9231 atoken.startingDisplayed = false;
9232 }
9233 if ((w.isOnScreen() || w.mAttrs.type
9234 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9235 && !w.mExiting && !w.mDestroying) {
9236 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009237 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009238 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009240 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009241 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 + " pv=" + w.mPolicyVisibility
9243 + " dp=" + w.mDrawPending
9244 + " cdp=" + w.mCommitDrawPending
9245 + " ah=" + w.mAttachedHidden
9246 + " th=" + atoken.hiddenRequested
9247 + " a=" + w.mAnimating);
9248 }
9249 }
9250 if (w != atoken.startingWindow) {
9251 if (!atoken.freezingScreen || !w.mAppFreezing) {
9252 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009253 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009255 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009256 "tokenMayBeDrawn: " + atoken
9257 + " freezingScreen=" + atoken.freezingScreen
9258 + " mAppFreezing=" + w.mAppFreezing);
9259 tokenMayBeDrawn = true;
9260 }
9261 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009262 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009263 atoken.startingDisplayed = true;
9264 }
9265 }
9266 } else if (w.mReadyToShow) {
9267 w.performShowLocked();
9268 }
9269 }
9270
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009271 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009272
9273 if (tokenMayBeDrawn) {
9274 // See if any windows have been drawn, so they (and others
9275 // associated with them) can now be shown.
9276 final int NT = mTokenList.size();
9277 for (i=0; i<NT; i++) {
9278 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9279 if (wtoken == null) {
9280 continue;
9281 }
9282 if (wtoken.freezingScreen) {
9283 int numInteresting = wtoken.numInterestingWindows;
9284 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009285 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009286 "allDrawn: " + wtoken
9287 + " interesting=" + numInteresting
9288 + " drawn=" + wtoken.numDrawnWindows);
9289 wtoken.showAllWindowsLocked();
9290 unsetAppFreezingScreenLocked(wtoken, false, true);
9291 orientationChangeComplete = true;
9292 }
9293 } else if (!wtoken.allDrawn) {
9294 int numInteresting = wtoken.numInterestingWindows;
9295 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009296 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009297 "allDrawn: " + wtoken
9298 + " interesting=" + numInteresting
9299 + " drawn=" + wtoken.numDrawnWindows);
9300 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009301 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009302
9303 // We can now show all of the drawn windows!
9304 if (!mOpeningApps.contains(wtoken)) {
9305 wtoken.showAllWindowsLocked();
9306 }
9307 }
9308 }
9309 }
9310 }
9311
9312 // If we are ready to perform an app transition, check through
9313 // all of the app tokens to be shown and see if they are ready
9314 // to go.
9315 if (mAppTransitionReady) {
9316 int NN = mOpeningApps.size();
9317 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009318 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009319 "Checking " + NN + " opening apps (frozen="
9320 + mDisplayFrozen + " timeout="
9321 + mAppTransitionTimeout + ")...");
9322 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9323 // If the display isn't frozen, wait to do anything until
9324 // all of the apps are ready. Otherwise just go because
9325 // we'll unfreeze the display when everyone is ready.
9326 for (i=0; i<NN && goodToGo; i++) {
9327 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009328 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 "Check opening app" + wtoken + ": allDrawn="
9330 + wtoken.allDrawn + " startingDisplayed="
9331 + wtoken.startingDisplayed);
9332 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9333 && !wtoken.startingMoved) {
9334 goodToGo = false;
9335 }
9336 }
9337 }
9338 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009339 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 int transit = mNextAppTransition;
9341 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009342 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009343 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009344 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009345 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009346 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 mAppTransitionTimeout = false;
9348 mStartingIconInTransition = false;
9349 mSkipAppTransitionAnimation = false;
9350
9351 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9352
Dianne Hackborna8f60182009-09-01 19:01:50 -07009353 // If there are applications waiting to come to the
9354 // top of the stack, now is the time to move their windows.
9355 // (Note that we don't do apps going to the bottom
9356 // here -- we want to keep their windows in the old
9357 // Z-order until the animation completes.)
9358 if (mToTopApps.size() > 0) {
9359 NN = mAppTokens.size();
9360 for (i=0; i<NN; i++) {
9361 AppWindowToken wtoken = mAppTokens.get(i);
9362 if (wtoken.sendingToTop) {
9363 wtoken.sendingToTop = false;
9364 moveAppWindowsLocked(wtoken, NN, false);
9365 }
9366 }
9367 mToTopApps.clear();
9368 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009369
Dianne Hackborn25994b42009-09-04 14:21:19 -07009370 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009371
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009372 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009373 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009374
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009375 // The top-most window will supply the layout params,
9376 // and we will determine it below.
9377 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009378 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009379 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009380
Joe Onorato8a9b2202010-02-26 18:56:32 -08009381 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009382 "New wallpaper target=" + mWallpaperTarget
9383 + ", lower target=" + mLowerWallpaperTarget
9384 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009385 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009386 // Do a first pass through the tokens for two
9387 // things:
9388 // (1) Determine if both the closing and opening
9389 // app token sets are wallpaper targets, in which
9390 // case special animations are needed
9391 // (since the wallpaper needs to stay static
9392 // behind them).
9393 // (2) Find the layout params of the top-most
9394 // application window in the tokens, which is
9395 // what will control the animation theme.
9396 final int NC = mClosingApps.size();
9397 NN = NC + mOpeningApps.size();
9398 for (i=0; i<NN; i++) {
9399 AppWindowToken wtoken;
9400 int mode;
9401 if (i < NC) {
9402 wtoken = mClosingApps.get(i);
9403 mode = 1;
9404 } else {
9405 wtoken = mOpeningApps.get(i-NC);
9406 mode = 2;
9407 }
9408 if (mLowerWallpaperTarget != null) {
9409 if (mLowerWallpaperTarget.mAppToken == wtoken
9410 || mUpperWallpaperTarget.mAppToken == wtoken) {
9411 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009412 }
9413 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009414 if (wtoken.appFullscreen) {
9415 WindowState ws = wtoken.findMainWindow();
9416 if (ws != null) {
9417 // If this is a compatibility mode
9418 // window, we will always use its anim.
9419 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9420 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009421 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009422 bestAnimLayer = Integer.MAX_VALUE;
9423 } else if (ws.mLayer > bestAnimLayer) {
9424 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009425 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009426 bestAnimLayer = ws.mLayer;
9427 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009428 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009429 }
9430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009431
Dianne Hackborn25994b42009-09-04 14:21:19 -07009432 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009433 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009434 "Wallpaper animation!");
9435 switch (transit) {
9436 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9437 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9438 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9439 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9440 break;
9441 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9442 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9443 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9444 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9445 break;
9446 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009447 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009448 "New transit: " + transit);
9449 } else if (oldWallpaper != null) {
9450 // We are transitioning from an activity with
9451 // a wallpaper to one without.
9452 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009453 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009454 "New transit away from wallpaper: " + transit);
9455 } else if (mWallpaperTarget != null) {
9456 // We are transitioning from an activity without
9457 // a wallpaper to now showing the wallpaper
9458 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009459 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009460 "New transit into wallpaper: " + transit);
9461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009462
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009463 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9464 mLastEnterAnimToken = animToken;
9465 mLastEnterAnimParams = animLp;
9466 } else if (mLastEnterAnimParams != null) {
9467 animLp = mLastEnterAnimParams;
9468 mLastEnterAnimToken = null;
9469 mLastEnterAnimParams = null;
9470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009471
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009472 // If all closing windows are obscured, then there is
9473 // no need to do an animation. This is the case, for
9474 // example, when this transition is being done behind
9475 // the lock screen.
9476 if (!mPolicy.allowAppAnimationsLw()) {
9477 animLp = null;
9478 }
9479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 NN = mOpeningApps.size();
9481 for (i=0; i<NN; i++) {
9482 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009483 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009484 "Now opening app" + wtoken);
9485 wtoken.reportedVisible = false;
9486 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009487 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009488 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009490 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 wtoken.showAllWindowsLocked();
9492 }
9493 NN = mClosingApps.size();
9494 for (i=0; i<NN; i++) {
9495 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009496 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 "Now closing app" + wtoken);
9498 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009499 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009500 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009501 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009502 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 // Force the allDrawn flag, because we want to start
9504 // this guy's animations regardless of whether it's
9505 // gotten drawn.
9506 wtoken.allDrawn = true;
9507 }
9508
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009509 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009511 mOpeningApps.clear();
9512 mClosingApps.clear();
9513
9514 // This has changed the visibility of windows, so perform
9515 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009516 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009517 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009518 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9519 assignLayersLocked();
9520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009522 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 }
9524 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009525
Dianne Hackborn16064f92010-03-25 00:47:24 -07009526 int adjResult = 0;
9527
Dianne Hackborna8f60182009-09-01 19:01:50 -07009528 if (!animating && mAppTransitionRunning) {
9529 // We have finished the animation of an app transition. To do
9530 // this, we have delayed a lot of operations like showing and
9531 // hiding apps, moving apps in Z-order, etc. The app token list
9532 // reflects the correct Z-order, but the window list may now
9533 // be out of sync with it. So here we will just rebuild the
9534 // entire app window list. Fun!
9535 mAppTransitionRunning = false;
9536 // Clear information about apps that were moving.
9537 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009538
Dianne Hackborna8f60182009-09-01 19:01:50 -07009539 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009540 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009541 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009542 moveInputMethodWindowsIfNeededLocked(false);
9543 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009544 // Since the window list has been rebuilt, focus might
9545 // have to be recomputed since the actual order of windows
9546 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009547 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009548 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009549
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009550 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009551 // At this point, there was a window with a wallpaper that
9552 // was force hiding other windows behind it, but now it
9553 // is going away. This may be simple -- just animate
9554 // away the wallpaper and its window -- or it may be
9555 // hard -- the wallpaper now needs to be shown behind
9556 // something that was hidden.
9557 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009558 if (mLowerWallpaperTarget != null
9559 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009560 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009561 "wallpaperForceHiding changed with lower="
9562 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009563 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009564 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9565 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9566 if (mLowerWallpaperTarget.mAppToken.hidden) {
9567 // The lower target has become hidden before we
9568 // actually started the animation... let's completely
9569 // re-evaluate everything.
9570 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009571 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009572 }
9573 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009574 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009575 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009576 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009577 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009578 + " NEW: " + mWallpaperTarget
9579 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009580 if (mLowerWallpaperTarget == null) {
9581 // Whoops, we don't need a special wallpaper animation.
9582 // Clear them out.
9583 forceHiding = false;
9584 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009585 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009586 if (w.mSurface != null) {
9587 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009588 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009589 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009590 forceHiding = true;
9591 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9592 if (!w.mAnimating) {
9593 // We set the animation above so it
9594 // is not yet running.
9595 w.clearAnimation();
9596 }
9597 }
9598 }
9599 }
9600 }
9601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009603 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009604 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009605 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009606 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009607 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009608
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009609 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009610 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009611 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009612 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009613 assignLayersLocked();
9614 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009615 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009616 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009617 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009618 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009619
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009620 if (mFocusMayChange) {
9621 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009622 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009623 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009624 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009625 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009626 }
9627
9628 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009629 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009630 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009631
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009632 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9633 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009634
Jeff Browne33348b2010-07-15 23:54:05 -07009635 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009636 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009637
9638 // THIRD LOOP: Update the surfaces of all windows.
9639
9640 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9641
9642 boolean obscured = false;
9643 boolean blurring = false;
9644 boolean dimming = false;
9645 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009646 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009647 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009648
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009649 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009652 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009653
9654 boolean displayed = false;
9655 final WindowManager.LayoutParams attrs = w.mAttrs;
9656 final int attrFlags = attrs.flags;
9657
9658 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009659 // XXX NOTE: The logic here could be improved. We have
9660 // the decision about whether to resize a window separated
9661 // from whether to hide the surface. This can cause us to
9662 // resize a surface even if we are going to hide it. You
9663 // can see this by (1) holding device in landscape mode on
9664 // home screen; (2) tapping browser icon (device will rotate
9665 // to landscape; (3) tap home. The wallpaper will be resized
9666 // in step 2 but then immediately hidden, causing us to
9667 // have to resize and then redraw it again in step 3. It
9668 // would be nice to figure out how to avoid this, but it is
9669 // difficult because we do need to resize surfaces in some
9670 // cases while they are hidden such as when first showing a
9671 // window.
9672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009673 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009674 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009675 TAG, "Placing surface #" + i + " " + w.mSurface
9676 + ": new=" + w.mShownFrame + ", old="
9677 + w.mLastShownFrame);
9678
9679 boolean resize;
9680 int width, height;
9681 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9682 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9683 w.mLastRequestedHeight != w.mRequestedHeight;
9684 // for a scaled surface, we just want to use
9685 // the requested size.
9686 width = w.mRequestedWidth;
9687 height = w.mRequestedHeight;
9688 w.mLastRequestedWidth = width;
9689 w.mLastRequestedHeight = height;
9690 w.mLastShownFrame.set(w.mShownFrame);
9691 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009692 if (SHOW_TRANSACTIONS) logSurface(w,
9693 "POS " + w.mShownFrame.left
9694 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009695 w.mSurfaceX = w.mShownFrame.left;
9696 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009697 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9698 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009699 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009700 if (!recoveringMemory) {
9701 reclaimSomeSurfaceMemoryLocked(w, "position");
9702 }
9703 }
9704 } else {
9705 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9706 width = w.mShownFrame.width();
9707 height = w.mShownFrame.height();
9708 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009709 }
9710
9711 if (resize) {
9712 if (width < 1) width = 1;
9713 if (height < 1) height = 1;
9714 if (w.mSurface != null) {
9715 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009716 if (SHOW_TRANSACTIONS) logSurface(w,
9717 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009718 + w.mShownFrame.top + " SIZE "
9719 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009720 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009721 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009722 w.mSurfaceW = width;
9723 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009724 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009725 w.mSurfaceX = w.mShownFrame.left;
9726 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727 w.mSurface.setPosition(w.mShownFrame.left,
9728 w.mShownFrame.top);
9729 } catch (RuntimeException e) {
9730 // If something goes wrong with the surface (such
9731 // as running out of memory), don't take down the
9732 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009733 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009734 + "size=(" + width + "x" + height
9735 + "), pos=(" + w.mShownFrame.left
9736 + "," + w.mShownFrame.top + ")", e);
9737 if (!recoveringMemory) {
9738 reclaimSomeSurfaceMemoryLocked(w, "size");
9739 }
9740 }
9741 }
9742 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009743 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009744 w.mContentInsetsChanged =
9745 !w.mLastContentInsets.equals(w.mContentInsets);
9746 w.mVisibleInsetsChanged =
9747 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009748 boolean configChanged =
9749 w.mConfiguration != mCurConfiguration
9750 && (w.mConfiguration == null
9751 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009752 if (DEBUG_CONFIGURATION && configChanged) {
9753 Slog.v(TAG, "Win " + w + " config changed: "
9754 + mCurConfiguration);
9755 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009756 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009757 + ": configChanged=" + configChanged
9758 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009759 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009760 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009761 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009762 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009763 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 w.mLastFrame.set(w.mFrame);
9765 w.mLastContentInsets.set(w.mContentInsets);
9766 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009767 // If the screen is currently frozen, then keep
9768 // it frozen until this window draws at its new
9769 // orientation.
9770 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009771 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009772 "Resizing while display frozen: " + w);
9773 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009774 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009775 mWindowsFreezingScreen = true;
9776 // XXX should probably keep timeout from
9777 // when we first froze the display.
9778 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9779 mH.sendMessageDelayed(mH.obtainMessage(
9780 H.WINDOW_FREEZE_TIMEOUT), 2000);
9781 }
9782 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009783 // If the orientation is changing, then we need to
9784 // hold off on unfreezing the display until this
9785 // window has been redrawn; to do that, we need
9786 // to go through the process of getting informed
9787 // by the application when it has finished drawing.
9788 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009789 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009790 "Orientation start waiting for draw in "
9791 + w + ", surface " + w.mSurface);
9792 w.mDrawPending = true;
9793 w.mCommitDrawPending = false;
9794 w.mReadyToShow = false;
9795 if (w.mAppToken != null) {
9796 w.mAppToken.allDrawn = false;
9797 }
9798 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009799 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 "Resizing window " + w + " to " + w.mFrame);
9801 mResizingWindows.add(w);
9802 } else if (w.mOrientationChanging) {
9803 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009804 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 "Orientation not waiting for draw in "
9806 + w + ", surface " + w.mSurface);
9807 w.mOrientationChanging = false;
9808 }
9809 }
9810 }
9811
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009812 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 if (!w.mLastHidden) {
9814 //dump();
9815 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009816 if (SHOW_TRANSACTIONS) logSurface(w,
9817 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009819 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009820 try {
9821 w.mSurface.hide();
9822 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009823 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824 }
9825 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 }
9827 // If we are waiting for this window to handle an
9828 // orientation change, well, it is hidden, so
9829 // doesn't really matter. Note that this does
9830 // introduce a potential glitch if the window
9831 // becomes unhidden before it has drawn for the
9832 // new orientation.
9833 if (w.mOrientationChanging) {
9834 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009835 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009836 "Orientation change skips hidden " + w);
9837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009838 } else if (w.mLastLayer != w.mAnimLayer
9839 || w.mLastAlpha != w.mShownAlpha
9840 || w.mLastDsDx != w.mDsDx
9841 || w.mLastDtDx != w.mDtDx
9842 || w.mLastDsDy != w.mDsDy
9843 || w.mLastDtDy != w.mDtDy
9844 || w.mLastHScale != w.mHScale
9845 || w.mLastVScale != w.mVScale
9846 || w.mLastHidden) {
9847 displayed = true;
9848 w.mLastAlpha = w.mShownAlpha;
9849 w.mLastLayer = w.mAnimLayer;
9850 w.mLastDsDx = w.mDsDx;
9851 w.mLastDtDx = w.mDtDx;
9852 w.mLastDsDy = w.mDsDy;
9853 w.mLastDtDy = w.mDtDy;
9854 w.mLastHScale = w.mHScale;
9855 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009856 if (SHOW_TRANSACTIONS) logSurface(w,
9857 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009858 + " matrix=[" + (w.mDsDx*w.mHScale)
9859 + "," + (w.mDtDx*w.mVScale)
9860 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009861 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009862 if (w.mSurface != null) {
9863 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009864 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009865 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009866 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867 w.mSurface.setLayer(w.mAnimLayer);
9868 w.mSurface.setMatrix(
9869 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9870 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9871 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009872 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009873 if (!recoveringMemory) {
9874 reclaimSomeSurfaceMemoryLocked(w, "update");
9875 }
9876 }
9877 }
9878
9879 if (w.mLastHidden && !w.mDrawPending
9880 && !w.mCommitDrawPending
9881 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009882 if (SHOW_TRANSACTIONS) logSurface(w,
9883 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009884 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 + " during relayout");
9886 if (showSurfaceRobustlyLocked(w)) {
9887 w.mHasDrawn = true;
9888 w.mLastHidden = false;
9889 } else {
9890 w.mOrientationChanging = false;
9891 }
9892 }
9893 if (w.mSurface != null) {
9894 w.mToken.hasVisible = true;
9895 }
9896 } else {
9897 displayed = true;
9898 }
9899
9900 if (displayed) {
9901 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009902 if (attrs.width == LayoutParams.MATCH_PARENT
9903 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009904 covered = true;
9905 }
9906 }
9907 if (w.mOrientationChanging) {
9908 if (w.mDrawPending || w.mCommitDrawPending) {
9909 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009910 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009911 "Orientation continue waiting for draw in " + w);
9912 } else {
9913 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009914 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 "Orientation change complete in " + w);
9916 }
9917 }
9918 w.mToken.hasVisible = true;
9919 }
9920 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009921 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 "Orientation change skips hidden " + w);
9923 w.mOrientationChanging = false;
9924 }
9925
9926 final boolean canBeSeen = w.isDisplayedLw();
9927
9928 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9929 focusDisplayed = true;
9930 }
9931
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009932 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009934 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009935 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 if (w.mSurface != null) {
9937 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9938 holdScreen = w.mSession;
9939 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009940 if (!syswin && w.mAttrs.screenBrightness >= 0
9941 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 screenBrightness = w.mAttrs.screenBrightness;
9943 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009944 if (!syswin && w.mAttrs.buttonBrightness >= 0
9945 && buttonBrightness < 0) {
9946 buttonBrightness = w.mAttrs.buttonBrightness;
9947 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009948 if (canBeSeen
9949 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9950 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9951 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009952 syswin = true;
9953 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009954 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009955
Dianne Hackborn25994b42009-09-04 14:21:19 -07009956 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9957 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009958 // This window completely covers everything behind it,
9959 // so we want to leave all of them as unblurred (for
9960 // performance reasons).
9961 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009962 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009964 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009965 obscured = true;
9966 if (mBackgroundFillerSurface == null) {
9967 try {
9968 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009969 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009970 0, dw, dh,
9971 PixelFormat.OPAQUE,
9972 Surface.FX_SURFACE_NORMAL);
9973 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009974 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009975 }
9976 }
9977 try {
9978 mBackgroundFillerSurface.setPosition(0, 0);
9979 mBackgroundFillerSurface.setSize(dw, dh);
9980 // Using the same layer as Dim because they will never be shown at the
9981 // same time.
9982 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9983 mBackgroundFillerSurface.show();
9984 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009985 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009986 }
9987 backgroundFillerShown = true;
9988 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009989 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009990 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009991 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 + ": blurring=" + blurring
9993 + " obscured=" + obscured
9994 + " displayed=" + displayed);
9995 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9996 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009997 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009999 if (mDimAnimator == null) {
10000 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010001 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010002 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010003 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 }
10006 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10007 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010008 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010010 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010011 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010012 + mBlurSurface + ": CREATE");
10013 try {
Romain Guy06882f82009-06-10 13:36:04 -070010014 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010015 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010016 -1, 16, 16,
10017 PixelFormat.OPAQUE,
10018 Surface.FX_SURFACE_BLUR);
10019 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010020 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 }
10022 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010023 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010024 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10025 + mBlurSurface + ": pos=(0,0) (" +
10026 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010027 mBlurSurface.setPosition(0, 0);
10028 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010029 mBlurSurface.setLayer(w.mAnimLayer-2);
10030 if (!mBlurShown) {
10031 try {
10032 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10033 + mBlurSurface + ": SHOW");
10034 mBlurSurface.show();
10035 } catch (RuntimeException e) {
10036 Slog.w(TAG, "Failure showing blur surface", e);
10037 }
10038 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010039 }
10040 }
10041 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010042 }
10043 }
10044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010045
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010046 if (obscuredChanged && mWallpaperTarget == w) {
10047 // This is the wallpaper target and its obscured state
10048 // changed... make sure the current wallaper's visibility
10049 // has been updated accordingly.
10050 updateWallpaperVisibilityLocked();
10051 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010052 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010053
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010054 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10055 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010056 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010057 try {
10058 mBackgroundFillerSurface.hide();
10059 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010060 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010061 }
10062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010064 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010065 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10066 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010067 }
Romain Guy06882f82009-06-10 13:36:04 -070010068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010070 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 + ": HIDE");
10072 try {
10073 mBlurSurface.hide();
10074 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010075 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076 }
10077 mBlurShown = false;
10078 }
10079
Joe Onorato8a9b2202010-02-26 18:56:32 -080010080 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010082 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010083 }
10084
Jeff Browne33348b2010-07-15 23:54:05 -070010085 mInputMonitor.updateInputWindowsLw();
10086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010088
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010089 if (mWatermark != null) {
10090 mWatermark.drawIfNeeded();
10091 }
10092
Joe Onorato8a9b2202010-02-26 18:56:32 -080010093 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010094 "With display frozen, orientationChangeComplete="
10095 + orientationChangeComplete);
10096 if (orientationChangeComplete) {
10097 if (mWindowsFreezingScreen) {
10098 mWindowsFreezingScreen = false;
10099 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10100 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010101 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010102 }
Romain Guy06882f82009-06-10 13:36:04 -070010103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010104 i = mResizingWindows.size();
10105 if (i > 0) {
10106 do {
10107 i--;
10108 WindowState win = mResizingWindows.get(i);
10109 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010110 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10111 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010112 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010113 boolean configChanged =
10114 win.mConfiguration != mCurConfiguration
10115 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010116 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10117 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10118 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010119 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010120 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010121 + " / " + mCurConfiguration + " / 0x"
10122 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010123 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010124 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010125 win.mClient.resized(win.mFrame.width(),
10126 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010127 win.mLastVisibleInsets, win.mDrawPending,
10128 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 win.mContentInsetsChanged = false;
10130 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010131 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010132 } catch (RemoteException e) {
10133 win.mOrientationChanging = false;
10134 }
10135 } while (i > 0);
10136 mResizingWindows.clear();
10137 }
Romain Guy06882f82009-06-10 13:36:04 -070010138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010139 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010140 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010141 i = mDestroySurface.size();
10142 if (i > 0) {
10143 do {
10144 i--;
10145 WindowState win = mDestroySurface.get(i);
10146 win.mDestroying = false;
10147 if (mInputMethodWindow == win) {
10148 mInputMethodWindow = null;
10149 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010150 if (win == mWallpaperTarget) {
10151 wallpaperDestroyed = true;
10152 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010153 win.destroySurfaceLocked();
10154 } while (i > 0);
10155 mDestroySurface.clear();
10156 }
10157
10158 // Time to remove any exiting tokens?
10159 for (i=mExitingTokens.size()-1; i>=0; i--) {
10160 WindowToken token = mExitingTokens.get(i);
10161 if (!token.hasVisible) {
10162 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010163 if (token.windowType == TYPE_WALLPAPER) {
10164 mWallpaperTokens.remove(token);
10165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 }
10167 }
10168
10169 // Time to remove any exiting applications?
10170 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10171 AppWindowToken token = mExitingAppTokens.get(i);
10172 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010173 // Make sure there is no animation running on this token,
10174 // so any windows associated with it will be removed as
10175 // soon as their animations are complete
10176 token.animation = null;
10177 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010178 mAppTokens.remove(token);
10179 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010180 if (mLastEnterAnimToken == token) {
10181 mLastEnterAnimToken = null;
10182 mLastEnterAnimParams = null;
10183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010184 }
10185 }
10186
Dianne Hackborna8f60182009-09-01 19:01:50 -070010187 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010188
Dianne Hackborna8f60182009-09-01 19:01:50 -070010189 if (!animating && mAppTransitionRunning) {
10190 // We have finished the animation of an app transition. To do
10191 // this, we have delayed a lot of operations like showing and
10192 // hiding apps, moving apps in Z-order, etc. The app token list
10193 // reflects the correct Z-order, but the window list may now
10194 // be out of sync with it. So here we will just rebuild the
10195 // entire app window list. Fun!
10196 mAppTransitionRunning = false;
10197 needRelayout = true;
10198 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010199 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010200 // Clear information about apps that were moving.
10201 mToBottomApps.clear();
10202 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010204 if (focusDisplayed) {
10205 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10206 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010207 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010208 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010209 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010210 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010211 requestAnimationLocked(0);
10212 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010213 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10214 }
Jeff Browneb857f12010-07-16 10:06:33 -070010215
Jeff Browne33348b2010-07-15 23:54:05 -070010216 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010217
Jeff Brown8e03b752010-06-13 19:16:55 -070010218 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010219 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10220 mPowerManager.setScreenBrightnessOverride(-1);
10221 } else {
10222 mPowerManager.setScreenBrightnessOverride((int)
10223 (screenBrightness * Power.BRIGHTNESS_ON));
10224 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010225 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10226 mPowerManager.setButtonBrightnessOverride(-1);
10227 } else {
10228 mPowerManager.setButtonBrightnessOverride((int)
10229 (buttonBrightness * Power.BRIGHTNESS_ON));
10230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010231 if (holdScreen != mHoldingScreenOn) {
10232 mHoldingScreenOn = holdScreen;
10233 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10234 mH.sendMessage(m);
10235 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010236
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010237 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010238 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010239 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10240 LocalPowerManager.BUTTON_EVENT, true);
10241 mTurnOnScreen = false;
10242 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010243
10244 // Check to see if we are now in a state where the screen should
10245 // be enabled, because the window obscured flags have changed.
10246 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010247 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010248
10249 /**
10250 * Must be called with the main window manager lock held.
10251 */
10252 void setHoldScreenLocked(boolean holding) {
10253 boolean state = mHoldingScreenWakeLock.isHeld();
10254 if (holding != state) {
10255 if (holding) {
10256 mHoldingScreenWakeLock.acquire();
10257 } else {
10258 mPolicy.screenOnStoppedLw();
10259 mHoldingScreenWakeLock.release();
10260 }
10261 }
10262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010263
10264 void requestAnimationLocked(long delay) {
10265 if (!mAnimationPending) {
10266 mAnimationPending = true;
10267 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10268 }
10269 }
Romain Guy06882f82009-06-10 13:36:04 -070010270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010271 /**
10272 * Have the surface flinger show a surface, robustly dealing with
10273 * error conditions. In particular, if there is not enough memory
10274 * to show the surface, then we will try to get rid of other surfaces
10275 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010276 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 * @return Returns true if the surface was successfully shown.
10278 */
10279 boolean showSurfaceRobustlyLocked(WindowState win) {
10280 try {
10281 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010282 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010284 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010285 if (DEBUG_VISIBILITY) Slog.v(TAG,
10286 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010287 win.mTurnOnScreen = false;
10288 mTurnOnScreen = true;
10289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 }
10291 return true;
10292 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010293 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010294 }
Romain Guy06882f82009-06-10 13:36:04 -070010295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010296 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010298 return false;
10299 }
Romain Guy06882f82009-06-10 13:36:04 -070010300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010301 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10302 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010303
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010304 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010305 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 if (mForceRemoves == null) {
10308 mForceRemoves = new ArrayList<WindowState>();
10309 }
Romain Guy06882f82009-06-10 13:36:04 -070010310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 long callingIdentity = Binder.clearCallingIdentity();
10312 try {
10313 // There was some problem... first, do a sanity check of the
10314 // window list to make sure we haven't left any dangling surfaces
10315 // around.
10316 int N = mWindows.size();
10317 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010318 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010320 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010321 if (ws.mSurface != null) {
10322 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010323 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 + ws + " surface=" + ws.mSurface
10325 + " token=" + win.mToken
10326 + " pid=" + ws.mSession.mPid
10327 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010328 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010329 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 ws.mSurface = null;
10331 mForceRemoves.add(ws);
10332 i--;
10333 N--;
10334 leakedSurface = true;
10335 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010336 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 + ws + " surface=" + ws.mSurface
10338 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010339 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010340 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 ws.mSurface = null;
10342 leakedSurface = true;
10343 }
10344 }
10345 }
Romain Guy06882f82009-06-10 13:36:04 -070010346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 boolean killedApps = false;
10348 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010349 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010350 SparseIntArray pidCandidates = new SparseIntArray();
10351 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010352 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 if (ws.mSurface != null) {
10354 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10355 }
10356 }
10357 if (pidCandidates.size() > 0) {
10358 int[] pids = new int[pidCandidates.size()];
10359 for (int i=0; i<pids.length; i++) {
10360 pids[i] = pidCandidates.keyAt(i);
10361 }
10362 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010363 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 killedApps = true;
10365 }
10366 } catch (RemoteException e) {
10367 }
10368 }
10369 }
Romain Guy06882f82009-06-10 13:36:04 -070010370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010371 if (leakedSurface || killedApps) {
10372 // We managed to reclaim some memory, so get rid of the trouble
10373 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010374 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010375 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010376 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010377 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010378 win.mSurface = null;
10379 }
Romain Guy06882f82009-06-10 13:36:04 -070010380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010381 try {
10382 win.mClient.dispatchGetNewSurface();
10383 } catch (RemoteException e) {
10384 }
10385 }
10386 } finally {
10387 Binder.restoreCallingIdentity(callingIdentity);
10388 }
10389 }
Romain Guy06882f82009-06-10 13:36:04 -070010390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010391 private boolean updateFocusedWindowLocked(int mode) {
10392 WindowState newFocus = computeFocusedWindowLocked();
10393 if (mCurrentFocus != newFocus) {
10394 // This check makes sure that we don't already have the focus
10395 // change message pending.
10396 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10397 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010398 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010399 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10400 final WindowState oldFocus = mCurrentFocus;
10401 mCurrentFocus = newFocus;
10402 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010404 final WindowState imWindow = mInputMethodWindow;
10405 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010406 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010408 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10409 mLayoutNeeded = true;
10410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10412 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010413 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10414 // Client will do the layout, but we need to assign layers
10415 // for handleNewWindowLocked() below.
10416 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 }
10418 }
Jeff Brown349703e2010-06-22 01:27:15 -070010419
10420 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10421 // If we defer assigning layers, then the caller is responsible for
10422 // doing this part.
10423 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010425 return true;
10426 }
10427 return false;
10428 }
Jeff Brown349703e2010-06-22 01:27:15 -070010429
10430 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010431 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433
10434 private WindowState computeFocusedWindowLocked() {
10435 WindowState result = null;
10436 WindowState win;
10437
10438 int i = mWindows.size() - 1;
10439 int nextAppIndex = mAppTokens.size()-1;
10440 WindowToken nextApp = nextAppIndex >= 0
10441 ? mAppTokens.get(nextAppIndex) : null;
10442
10443 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010444 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010445
Joe Onorato8a9b2202010-02-26 18:56:32 -080010446 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010447 TAG, "Looking for focus: " + i
10448 + " = " + win
10449 + ", flags=" + win.mAttrs.flags
10450 + ", canReceive=" + win.canReceiveKeys());
10451
10452 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 // If this window's application has been removed, just skip it.
10455 if (thisApp != null && thisApp.removed) {
10456 i--;
10457 continue;
10458 }
Romain Guy06882f82009-06-10 13:36:04 -070010459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 // If there is a focused app, don't allow focus to go to any
10461 // windows below it. If this is an application window, step
10462 // through the app tokens until we find its app.
10463 if (thisApp != null && nextApp != null && thisApp != nextApp
10464 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10465 int origAppIndex = nextAppIndex;
10466 while (nextAppIndex > 0) {
10467 if (nextApp == mFocusedApp) {
10468 // Whoops, we are below the focused app... no focus
10469 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010470 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010471 TAG, "Reached focused app: " + mFocusedApp);
10472 return null;
10473 }
10474 nextAppIndex--;
10475 nextApp = mAppTokens.get(nextAppIndex);
10476 if (nextApp == thisApp) {
10477 break;
10478 }
10479 }
10480 if (thisApp != nextApp) {
10481 // Uh oh, the app token doesn't exist! This shouldn't
10482 // happen, but if it does we can get totally hosed...
10483 // so restart at the original app.
10484 nextAppIndex = origAppIndex;
10485 nextApp = mAppTokens.get(nextAppIndex);
10486 }
10487 }
10488
10489 // Dispatch to this window if it is wants key events.
10490 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010491 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010492 TAG, "Found focus @ " + i + " = " + win);
10493 result = win;
10494 break;
10495 }
10496
10497 i--;
10498 }
10499
10500 return result;
10501 }
10502
10503 private void startFreezingDisplayLocked() {
10504 if (mDisplayFrozen) {
10505 return;
10506 }
Romain Guy06882f82009-06-10 13:36:04 -070010507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010510 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010511 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010512 if (mFreezeGcPending != 0) {
10513 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010514 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 mH.removeMessages(H.FORCE_GC);
10516 Runtime.getRuntime().gc();
10517 mFreezeGcPending = now;
10518 }
10519 } else {
10520 mFreezeGcPending = now;
10521 }
Romain Guy06882f82009-06-10 13:36:04 -070010522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010523 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010524
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010525 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010526
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010527 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10528 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010529 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010530 mAppTransitionReady = true;
10531 }
Romain Guy06882f82009-06-10 13:36:04 -070010532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010533 if (PROFILE_ORIENTATION) {
10534 File file = new File("/data/system/frozen");
10535 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10536 }
10537 Surface.freezeDisplay(0);
10538 }
Romain Guy06882f82009-06-10 13:36:04 -070010539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010540 private void stopFreezingDisplayLocked() {
10541 if (!mDisplayFrozen) {
10542 return;
10543 }
Romain Guy06882f82009-06-10 13:36:04 -070010544
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010545 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10546 return;
10547 }
10548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549 mDisplayFrozen = false;
10550 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10551 if (PROFILE_ORIENTATION) {
10552 Debug.stopMethodTracing();
10553 }
10554 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010555
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010556 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010557
Christopher Tateb696aee2010-04-02 19:08:30 -070010558 // While the display is frozen we don't re-compute the orientation
10559 // to avoid inconsistent states. However, something interesting
10560 // could have actually changed during that time so re-evaluate it
10561 // now to catch that.
10562 if (updateOrientationFromAppTokensLocked()) {
10563 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10564 }
10565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010566 // A little kludge: a lot could have happened while the
10567 // display was frozen, so now that we are coming back we
10568 // do a gc so that any remote references the system
10569 // processes holds on others can be released if they are
10570 // no longer needed.
10571 mH.removeMessages(H.FORCE_GC);
10572 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10573 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010575 mScreenFrozenLock.release();
10576 }
Romain Guy06882f82009-06-10 13:36:04 -070010577
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010578 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10579 DisplayMetrics dm) {
10580 if (index < tokens.length) {
10581 String str = tokens[index];
10582 if (str != null && str.length() > 0) {
10583 try {
10584 int val = Integer.parseInt(str);
10585 return val;
10586 } catch (Exception e) {
10587 }
10588 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010589 }
10590 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10591 return defDps;
10592 }
10593 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10594 return val;
10595 }
10596
10597 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010598 final String[] mTokens;
10599 final String mText;
10600 final Paint mTextPaint;
10601 final int mTextWidth;
10602 final int mTextHeight;
10603 final int mTextAscent;
10604 final int mTextDescent;
10605 final int mDeltaX;
10606 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010607
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010608 Surface mSurface;
10609 int mLastDW;
10610 int mLastDH;
10611 boolean mDrawNeeded;
10612
10613 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010614 final DisplayMetrics dm = new DisplayMetrics();
10615 mDisplay.getMetrics(dm);
10616
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010617 if (false) {
10618 Log.i(TAG, "*********************** WATERMARK");
10619 for (int i=0; i<tokens.length; i++) {
10620 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10621 }
10622 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010623
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010624 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010625
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010626 StringBuilder builder = new StringBuilder(32);
10627 int len = mTokens[0].length();
10628 len = len & ~1;
10629 for (int i=0; i<len; i+=2) {
10630 int c1 = mTokens[0].charAt(i);
10631 int c2 = mTokens[0].charAt(i+1);
10632 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10633 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10634 else c1 -= '0';
10635 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10636 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10637 else c2 -= '0';
10638 builder.append((char)(255-((c1*16)+c2)));
10639 }
10640 mText = builder.toString();
10641 if (false) {
10642 Log.i(TAG, "Final text: " + mText);
10643 }
10644
10645 int fontSize = getPropertyInt(tokens, 1,
10646 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10647
10648 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10649 mTextPaint.setTextSize(fontSize);
10650 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10651
10652 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10653 mTextWidth = (int)mTextPaint.measureText(mText);
10654 mTextAscent = fm.ascent;
10655 mTextDescent = fm.descent;
10656 mTextHeight = fm.descent - fm.ascent;
10657
10658 mDeltaX = getPropertyInt(tokens, 2,
10659 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10660 mDeltaY = getPropertyInt(tokens, 3,
10661 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10662 int shadowColor = getPropertyInt(tokens, 4,
10663 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10664 int color = getPropertyInt(tokens, 5,
10665 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10666 int shadowRadius = getPropertyInt(tokens, 6,
10667 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10668 int shadowDx = getPropertyInt(tokens, 8,
10669 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10670 int shadowDy = getPropertyInt(tokens, 9,
10671 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10672
10673 mTextPaint.setColor(color);
10674 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010675
10676 try {
10677 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010678 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010679 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010680 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010681 mSurface.show();
10682 } catch (OutOfResourcesException e) {
10683 }
10684 }
10685
10686 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010687 if (mLastDW != dw || mLastDH != dh) {
10688 mLastDW = dw;
10689 mLastDH = dh;
10690 mSurface.setSize(dw, dh);
10691 mDrawNeeded = true;
10692 }
10693 }
10694
10695 void drawIfNeeded() {
10696 if (mDrawNeeded) {
10697 final int dw = mLastDW;
10698 final int dh = mLastDH;
10699
10700 mDrawNeeded = false;
10701 Rect dirty = new Rect(0, 0, dw, dh);
10702 Canvas c = null;
10703 try {
10704 c = mSurface.lockCanvas(dirty);
10705 } catch (IllegalArgumentException e) {
10706 } catch (OutOfResourcesException e) {
10707 }
10708 if (c != null) {
10709 int deltaX = mDeltaX;
10710 int deltaY = mDeltaY;
10711
10712 // deltaX shouldn't be close to a round fraction of our
10713 // x step, or else things will line up too much.
10714 int div = (dw+mTextWidth)/deltaX;
10715 int rem = (dw+mTextWidth) - (div*deltaX);
10716 int qdelta = deltaX/4;
10717 if (rem < qdelta || rem > (deltaX-qdelta)) {
10718 deltaX += deltaX/3;
10719 }
10720
10721 int y = -mTextHeight;
10722 int x = -mTextWidth;
10723 while (y < (dh+mTextHeight)) {
10724 c.drawText(mText, x, y, mTextPaint);
10725 x += deltaX;
10726 if (x >= dw) {
10727 x -= (dw+mTextWidth);
10728 y += deltaY;
10729 }
10730 }
10731 mSurface.unlockCanvasAndPost(c);
10732 }
10733 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010734 }
10735 }
10736
10737 void createWatermark() {
10738 if (mWatermark != null) {
10739 return;
10740 }
10741
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010742 File file = new File("/system/etc/setup.conf");
10743 FileInputStream in = null;
10744 try {
10745 in = new FileInputStream(file);
10746 DataInputStream ind = new DataInputStream(in);
10747 String line = ind.readLine();
10748 if (line != null) {
10749 String[] toks = line.split("%");
10750 if (toks != null && toks.length > 0) {
10751 mWatermark = new Watermark(mFxSession, toks);
10752 }
10753 }
10754 } catch (FileNotFoundException e) {
10755 } catch (IOException e) {
10756 } finally {
10757 if (in != null) {
10758 try {
10759 in.close();
10760 } catch (IOException e) {
10761 }
10762 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010763 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010764 }
10765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010766 @Override
10767 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10768 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10769 != PackageManager.PERMISSION_GRANTED) {
10770 pw.println("Permission Denial: can't dump WindowManager from from pid="
10771 + Binder.getCallingPid()
10772 + ", uid=" + Binder.getCallingUid());
10773 return;
10774 }
Romain Guy06882f82009-06-10 13:36:04 -070010775
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010776 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010777 pw.println(" ");
10778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 synchronized(mWindowMap) {
10780 pw.println("Current Window Manager state:");
10781 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010782 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010783 pw.print(" Window #"); pw.print(i); pw.print(' ');
10784 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 w.dump(pw, " ");
10786 }
10787 if (mInputMethodDialogs.size() > 0) {
10788 pw.println(" ");
10789 pw.println(" Input method dialogs:");
10790 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10791 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010792 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 }
10794 }
10795 if (mPendingRemove.size() > 0) {
10796 pw.println(" ");
10797 pw.println(" Remove pending for:");
10798 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10799 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010800 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10801 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010802 w.dump(pw, " ");
10803 }
10804 }
10805 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10806 pw.println(" ");
10807 pw.println(" Windows force removing:");
10808 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10809 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010810 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10811 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010812 w.dump(pw, " ");
10813 }
10814 }
10815 if (mDestroySurface.size() > 0) {
10816 pw.println(" ");
10817 pw.println(" Windows waiting to destroy their surface:");
10818 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10819 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010820 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10821 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010822 w.dump(pw, " ");
10823 }
10824 }
10825 if (mLosingFocus.size() > 0) {
10826 pw.println(" ");
10827 pw.println(" Windows losing focus:");
10828 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10829 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010830 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10831 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010832 w.dump(pw, " ");
10833 }
10834 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010835 if (mResizingWindows.size() > 0) {
10836 pw.println(" ");
10837 pw.println(" Windows waiting to resize:");
10838 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10839 WindowState w = mResizingWindows.get(i);
10840 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10841 pw.print(w); pw.println(":");
10842 w.dump(pw, " ");
10843 }
10844 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845 if (mSessions.size() > 0) {
10846 pw.println(" ");
10847 pw.println(" All active sessions:");
10848 Iterator<Session> it = mSessions.iterator();
10849 while (it.hasNext()) {
10850 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010851 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010852 s.dump(pw, " ");
10853 }
10854 }
10855 if (mTokenMap.size() > 0) {
10856 pw.println(" ");
10857 pw.println(" All tokens:");
10858 Iterator<WindowToken> it = mTokenMap.values().iterator();
10859 while (it.hasNext()) {
10860 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010861 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010862 token.dump(pw, " ");
10863 }
10864 }
10865 if (mTokenList.size() > 0) {
10866 pw.println(" ");
10867 pw.println(" Window token list:");
10868 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010869 pw.print(" #"); pw.print(i); pw.print(": ");
10870 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 }
10872 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010873 if (mWallpaperTokens.size() > 0) {
10874 pw.println(" ");
10875 pw.println(" Wallpaper tokens:");
10876 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10877 WindowToken token = mWallpaperTokens.get(i);
10878 pw.print(" Wallpaper #"); pw.print(i);
10879 pw.print(' '); pw.print(token); pw.println(':');
10880 token.dump(pw, " ");
10881 }
10882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010883 if (mAppTokens.size() > 0) {
10884 pw.println(" ");
10885 pw.println(" Application tokens in Z order:");
10886 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010887 pw.print(" App #"); pw.print(i); pw.print(": ");
10888 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010889 }
10890 }
10891 if (mFinishedStarting.size() > 0) {
10892 pw.println(" ");
10893 pw.println(" Finishing start of application tokens:");
10894 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10895 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010896 pw.print(" Finished Starting #"); pw.print(i);
10897 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 token.dump(pw, " ");
10899 }
10900 }
10901 if (mExitingTokens.size() > 0) {
10902 pw.println(" ");
10903 pw.println(" Exiting tokens:");
10904 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10905 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010906 pw.print(" Exiting #"); pw.print(i);
10907 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 token.dump(pw, " ");
10909 }
10910 }
10911 if (mExitingAppTokens.size() > 0) {
10912 pw.println(" ");
10913 pw.println(" Exiting application tokens:");
10914 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10915 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010916 pw.print(" Exiting App #"); pw.print(i);
10917 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010918 token.dump(pw, " ");
10919 }
10920 }
10921 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010922 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10923 pw.print(" mLastFocus="); pw.println(mLastFocus);
10924 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10925 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10926 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010927 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010928 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10929 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10930 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10931 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010932 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10933 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10934 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010935 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10936 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10937 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10938 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010939 if (mDimAnimator != null) {
10940 mDimAnimator.printTo(pw);
10941 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010942 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010943 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010944 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010945 pw.print(mInputMethodAnimLayerAdjustment);
10946 pw.print(" mWallpaperAnimLayerAdjustment=");
10947 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010948 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10949 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010950 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10951 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010952 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10953 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010954 pw.print(" mRotation="); pw.print(mRotation);
10955 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10956 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10957 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10958 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10959 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10960 pw.print(" mNextAppTransition=0x");
10961 pw.print(Integer.toHexString(mNextAppTransition));
10962 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010963 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010964 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010965 if (mNextAppTransitionPackage != null) {
10966 pw.print(" mNextAppTransitionPackage=");
10967 pw.print(mNextAppTransitionPackage);
10968 pw.print(", mNextAppTransitionEnter=0x");
10969 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10970 pw.print(", mNextAppTransitionExit=0x");
10971 pw.print(Integer.toHexString(mNextAppTransitionExit));
10972 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010973 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10974 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010975 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10976 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10977 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10978 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010979 if (mOpeningApps.size() > 0) {
10980 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10981 }
10982 if (mClosingApps.size() > 0) {
10983 pw.print(" mClosingApps="); pw.println(mClosingApps);
10984 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010985 if (mToTopApps.size() > 0) {
10986 pw.print(" mToTopApps="); pw.println(mToTopApps);
10987 }
10988 if (mToBottomApps.size() > 0) {
10989 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10990 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010991 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10992 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010993 }
10994 }
10995
Jeff Brown349703e2010-06-22 01:27:15 -070010996 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010997 public void monitor() {
10998 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010999 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011001
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011002 /**
11003 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011004 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011005 */
11006 private static class DimAnimator {
11007 Surface mDimSurface;
11008 boolean mDimShown = false;
11009 float mDimCurrentAlpha;
11010 float mDimTargetAlpha;
11011 float mDimDeltaPerMs;
11012 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011013
11014 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011015
11016 DimAnimator (SurfaceSession session) {
11017 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011018 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011019 + mDimSurface + ": CREATE");
11020 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011021 mDimSurface = new Surface(session, 0,
11022 "DimSurface",
11023 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011024 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011025 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011026 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011027 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011028 }
11029 }
11030 }
11031
11032 /**
11033 * Show the dim surface.
11034 */
11035 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011036 if (!mDimShown) {
11037 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11038 dw + "x" + dh + ")");
11039 mDimShown = true;
11040 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011041 mLastDimWidth = dw;
11042 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011043 mDimSurface.setPosition(0, 0);
11044 mDimSurface.setSize(dw, dh);
11045 mDimSurface.show();
11046 } catch (RuntimeException e) {
11047 Slog.w(TAG, "Failure showing dim surface", e);
11048 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011049 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11050 mLastDimWidth = dw;
11051 mLastDimHeight = dh;
11052 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011053 }
11054 }
11055
11056 /**
11057 * Set's the dim surface's layer and update dim parameters that will be used in
11058 * {@link updateSurface} after all windows are examined.
11059 */
11060 void updateParameters(WindowState w, long currentTime) {
11061 mDimSurface.setLayer(w.mAnimLayer-1);
11062
11063 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011064 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011065 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011066 if (mDimTargetAlpha != target) {
11067 // If the desired dim level has changed, then
11068 // start an animation to it.
11069 mLastDimAnimTime = currentTime;
11070 long duration = (w.mAnimating && w.mAnimation != null)
11071 ? w.mAnimation.computeDurationHint()
11072 : DEFAULT_DIM_DURATION;
11073 if (target > mDimTargetAlpha) {
11074 // This is happening behind the activity UI,
11075 // so we can make it run a little longer to
11076 // give a stronger impression without disrupting
11077 // the user.
11078 duration *= DIM_DURATION_MULTIPLIER;
11079 }
11080 if (duration < 1) {
11081 // Don't divide by zero
11082 duration = 1;
11083 }
11084 mDimTargetAlpha = target;
11085 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11086 }
11087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011088
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011089 /**
11090 * Updating the surface's alpha. Returns true if the animation continues, or returns
11091 * false when the animation is finished and the dim surface is hidden.
11092 */
11093 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11094 if (!dimming) {
11095 if (mDimTargetAlpha != 0) {
11096 mLastDimAnimTime = currentTime;
11097 mDimTargetAlpha = 0;
11098 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11099 }
11100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011101
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011102 boolean animating = false;
11103 if (mLastDimAnimTime != 0) {
11104 mDimCurrentAlpha += mDimDeltaPerMs
11105 * (currentTime-mLastDimAnimTime);
11106 boolean more = true;
11107 if (displayFrozen) {
11108 // If the display is frozen, there is no reason to animate.
11109 more = false;
11110 } else if (mDimDeltaPerMs > 0) {
11111 if (mDimCurrentAlpha > mDimTargetAlpha) {
11112 more = false;
11113 }
11114 } else if (mDimDeltaPerMs < 0) {
11115 if (mDimCurrentAlpha < mDimTargetAlpha) {
11116 more = false;
11117 }
11118 } else {
11119 more = false;
11120 }
11121
11122 // Do we need to continue animating?
11123 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011124 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011125 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11126 mLastDimAnimTime = currentTime;
11127 mDimSurface.setAlpha(mDimCurrentAlpha);
11128 animating = true;
11129 } else {
11130 mDimCurrentAlpha = mDimTargetAlpha;
11131 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011132 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011133 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11134 mDimSurface.setAlpha(mDimCurrentAlpha);
11135 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011136 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011137 + ": HIDE");
11138 try {
11139 mDimSurface.hide();
11140 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011141 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011142 }
11143 mDimShown = false;
11144 }
11145 }
11146 }
11147 return animating;
11148 }
11149
11150 public void printTo(PrintWriter pw) {
11151 pw.print(" mDimShown="); pw.print(mDimShown);
11152 pw.print(" current="); pw.print(mDimCurrentAlpha);
11153 pw.print(" target="); pw.print(mDimTargetAlpha);
11154 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11155 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11156 }
11157 }
11158
11159 /**
11160 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11161 * This is used for opening/closing transition for apps in compatible mode.
11162 */
11163 private static class FadeInOutAnimation extends Animation {
11164 int mWidth;
11165 boolean mFadeIn;
11166
11167 public FadeInOutAnimation(boolean fadeIn) {
11168 setInterpolator(new AccelerateInterpolator());
11169 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11170 mFadeIn = fadeIn;
11171 }
11172
11173 @Override
11174 protected void applyTransformation(float interpolatedTime, Transformation t) {
11175 float x = interpolatedTime;
11176 if (!mFadeIn) {
11177 x = 1.0f - x; // reverse the interpolation for fade out
11178 }
11179 if (x < 0.5) {
11180 // move the window out of the screen.
11181 t.getMatrix().setTranslate(mWidth, 0);
11182 } else {
11183 t.getMatrix().setTranslate(0, 0);// show
11184 t.setAlpha((x - 0.5f) * 2);
11185 }
11186 }
11187
11188 @Override
11189 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11190 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11191 mWidth = width;
11192 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011193
11194 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011195 public int getZAdjustment() {
11196 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011197 }
11198 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011199}