blob: ec054378eb198df9e9741b5b1b189a825379bf26 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
32import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
33import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070036import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38import com.android.internal.app.IBatteryStats;
39import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080040import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070041import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import com.android.internal.view.IInputContext;
43import com.android.internal.view.IInputMethodClient;
44import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080045import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import com.android.server.am.BatteryStatsService;
47
48import android.Manifest;
49import android.app.ActivityManagerNative;
50import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070053import android.content.ClipData;
54import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070056import android.content.Intent;
57import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070062import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070066import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.Rect;
68import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070069import android.graphics.Typeface;
70import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.BatteryStats;
72import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070073import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074import android.os.Debug;
75import android.os.Handler;
76import android.os.IBinder;
77import android.os.LocalPowerManager;
78import android.os.Looper;
79import android.os.Message;
80import android.os.Parcel;
81import android.os.ParcelFileDescriptor;
82import android.os.Power;
83import android.os.PowerManager;
84import android.os.Process;
85import android.os.RemoteException;
86import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070087import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import 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;
101import android.view.IApplicationToken;
102import android.view.IOnKeyguardExitResult;
103import android.view.IRotationWatcher;
104import android.view.IWindow;
105import android.view.IWindowManager;
106import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700107import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700108import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700109import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700110import android.view.InputHandler;
111import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112import android.view.KeyEvent;
113import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.Surface;
115import android.view.SurfaceSession;
116import android.view.View;
117import android.view.ViewTreeObserver;
118import android.view.WindowManager;
119import android.view.WindowManagerImpl;
120import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700121import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700123import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.animation.Animation;
125import android.view.animation.AnimationUtils;
126import android.view.animation.Transformation;
127
128import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.File;
131import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700132import java.io.FileInputStream;
133import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134import java.io.IOException;
135import java.io.OutputStream;
136import java.io.OutputStreamWriter;
137import java.io.PrintWriter;
138import java.io.StringWriter;
139import java.net.Socket;
140import java.util.ArrayList;
141import java.util.HashMap;
142import java.util.HashSet;
143import java.util.Iterator;
144import java.util.List;
145
146/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700147public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700148 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 static final String TAG = "WindowManager";
150 static final boolean DEBUG = false;
151 static final boolean DEBUG_FOCUS = false;
152 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800153 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800154 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_LAYERS = false;
156 static final boolean DEBUG_INPUT = false;
157 static final boolean DEBUG_INPUT_METHOD = false;
158 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700159 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700161 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_APP_TRANSITIONS = false;
163 static final boolean DEBUG_STARTING_WINDOW = false;
164 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700165 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700166 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700168 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean PROFILE_ORIENTATION = false;
171 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700172 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** How much to multiply the policy's type layer, to reserve room
175 * for multiple windows of the same type and Z-ordering adjustment
176 * with TYPE_LAYER_OFFSET. */
177 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
180 * or below others in the same layer. */
181 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** How much to increment the layer for each window, to reserve room
184 * for effect surfaces between them.
185 */
186 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 /** The maximum length we will accept for a loaded animation duration:
189 * this is 10 seconds.
190 */
191 static final int MAX_ANIMATION_DURATION = 10*1000;
192
193 /** Amount of time (in milliseconds) to animate the dim surface from one
194 * value to another, when no window animation is driving it.
195 */
196 static final int DEFAULT_DIM_DURATION = 200;
197
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700198 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
199 * compatible windows.
200 */
201 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 /** Adjustment to time to perform a dim, to make it more dramatic.
204 */
205 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700206
207 // Maximum number of milliseconds to wait for input event injection.
208 // FIXME is this value reasonable?
209 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700210
211 // Default input dispatching timeout in nanoseconds.
212 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 static final int UPDATE_FOCUS_NORMAL = 0;
215 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
216 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
217 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700220 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221
222 /**
223 * Condition waited on by {@link #reenableKeyguard} to know the call to
224 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500225 * This is set to true only if mKeyguardTokenWatcher.acquired() has
226 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500228 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229
Jim Miller284b62e2010-06-08 14:27:42 -0700230 private static final int ALLOW_DISABLE_YES = 1;
231 private static final int ALLOW_DISABLE_NO = 0;
232 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
233 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
234
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
236 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700238 if (shouldAllowDisableKeyguard()) {
239 mPolicy.enableKeyguard(false);
240 mKeyguardDisabled = true;
241 } else {
242 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700246 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500247 synchronized (mKeyguardTokenWatcher) {
248 mKeyguardDisabled = false;
249 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 }
251 }
252 };
253
Jim Miller284b62e2010-06-08 14:27:42 -0700254 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
255 @Override
256 public void onReceive(Context context, Intent intent) {
257 mPolicy.enableKeyguard(true);
258 synchronized(mKeyguardTokenWatcher) {
259 // lazily evaluate this next time we're asked to disable keyguard
260 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
261 mKeyguardDisabled = false;
262 }
263 }
264 };
265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 final Context mContext;
267
268 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
273
274 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * All currently active sessions with clients.
280 */
281 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 /**
284 * Mapping from an IWindow IBinder to the server's Window object.
285 * This is also used as the lock for all of our state.
286 */
287 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
288
289 /**
290 * Mapping from a token IBinder to a WindowToken object.
291 */
292 final HashMap<IBinder, WindowToken> mTokenMap =
293 new HashMap<IBinder, WindowToken>();
294
295 /**
296 * The same tokens as mTokenMap, stored in a list for efficient iteration
297 * over them.
298 */
299 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 /**
302 * Window tokens that are in the process of exiting, but still
303 * on screen for animations.
304 */
305 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
306
307 /**
308 * Z-ordered (bottom-most first) list of all application tokens, for
309 * controlling the ordering of windows in different applications. This
310 * contains WindowToken objects.
311 */
312 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
313
314 /**
315 * Application tokens that are in the process of exiting, but still
316 * on screen for animations.
317 */
318 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
319
320 /**
321 * List of window tokens that have finished starting their application,
322 * and now need to have the policy remove their windows.
323 */
324 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
325
326 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700327 * This was the app token that was used to retrieve the last enter
328 * animation. It will be used for the next exit animation.
329 */
330 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800331
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700332 /**
333 * These were the layout params used to retrieve the last enter animation.
334 * They will be used for the next exit animation.
335 */
336 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800337
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700338 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 * Z-ordered (bottom-most first) list of all Window objects.
340 */
Jeff Browne33348b2010-07-15 23:54:05 -0700341 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342
343 /**
344 * Windows that are being resized. Used so we can tell the client about
345 * the resize after closing the transaction in which we resized the
346 * underlying surface.
347 */
348 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
349
350 /**
351 * Windows whose animations have ended and now must be removed.
352 */
353 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
354
355 /**
356 * Windows whose surface should be destroyed.
357 */
358 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
359
360 /**
361 * Windows that have lost input focus and are waiting for the new
362 * focus window to be displayed before they are told about this.
363 */
364 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
365
366 /**
367 * This is set when we have run out of memory, and will either be an empty
368 * list or contain windows that need to be force removed.
369 */
370 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700375 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 Surface mBlurSurface;
377 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700378 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 final float[] mTmpFloats = new float[9];
383
384 boolean mSafeMode;
385 boolean mDisplayEnabled = false;
386 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700387 int mInitialDisplayWidth = 0;
388 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 int mRotation = 0;
390 int mRequestedRotation = 0;
391 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700392 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 ArrayList<IRotationWatcher> mRotationWatchers
394 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 boolean mLayoutNeeded = true;
397 boolean mAnimationPending = false;
398 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800399 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mWindowsFreezingScreen = false;
401 long mFreezeGcPending = 0;
402 int mAppsFreezingScreen = 0;
403
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800404 int mLayoutSeq = 0;
405
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800406 // State while inside of layoutAndPlaceSurfacesLocked().
407 boolean mFocusMayChange;
408
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800409 Configuration mCurConfiguration = new Configuration();
410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // This is held as long as we have the screen frozen, to give us time to
412 // perform a rotation animation when turning off shows the lock screen which
413 // changes the orientation.
414 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 // State management of app transitions. When we are preparing for a
417 // transition, mNextAppTransition will be the kind of transition to
418 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
419 // mOpeningApps and mClosingApps are the lists of tokens that will be
420 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700421 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700422 String mNextAppTransitionPackage;
423 int mNextAppTransitionEnter;
424 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700426 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionTimeout = false;
428 boolean mStartingIconInTransition = false;
429 boolean mSkipAppTransitionAnimation = false;
430 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
431 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 H mH = new H();
438
439 WindowState mCurrentFocus = null;
440 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 // This just indicates the window the input method is on top of, not
443 // necessarily the window its input is going to.
444 WindowState mInputMethodTarget = null;
445 WindowState mUpcomingInputMethodTarget = null;
446 boolean mInputMethodTargetWaitingAnim;
447 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 WindowState mInputMethodWindow = null;
450 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
451
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700452 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800453
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700454 // If non-null, this is the currently visible window that is associated
455 // with the wallpaper.
456 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700457 // If non-null, we are in the middle of animating from one wallpaper target
458 // to another, and this is the lower one in Z-order.
459 WindowState mLowerWallpaperTarget = null;
460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the higher one in Z-order.
462 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800463 // Window currently running an animation that has requested it be detached
464 // from the wallpaper. This means we need to ensure the wallpaper is
465 // visible behind it in case it animates in a way that would allow it to be
466 // seen.
467 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700468 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700469 float mLastWallpaperX = -1;
470 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800471 float mLastWallpaperXStep = -1;
472 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700473 // This is set when we are waiting for a wallpaper to tell us it is done
474 // changing its scroll position.
475 WindowState mWaitingOnWallpaper;
476 // The last time we had a timeout when waiting for a wallpaper.
477 long mLastWallpaperTimeoutTime;
478 // We give a wallpaper up to 150ms to finish scrolling.
479 static final long WALLPAPER_TIMEOUT = 150;
480 // Time we wait after a timeout before trying to wait again.
481 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 AppWindowToken mFocusedApp = null;
484
485 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 float mWindowAnimationScale = 1.0f;
488 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700489
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700490 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491
492 // Who is holding the screen on.
493 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700494 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700495
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700496 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700499 * Drag/drop state
500 */
501 class DragState {
502 IBinder mToken;
503 Surface mSurface;
504 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700505 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700506 ClipData mData;
507 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700508 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700509 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700510 float mThumbOffsetX, mThumbOffsetY;
511 InputChannel mServerChannel, mClientChannel;
512 WindowState mTargetWindow;
513 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700514 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515
516 private final Rect tmpRect = new Rect();
517
Chris Tate7b362e42010-11-04 16:02:52 -0700518 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700519 mToken = token;
520 mSurface = surface;
521 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700522 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700523 mNotifiedWindows = new ArrayList<WindowState>();
524 }
525
526 void reset() {
527 if (mSurface != null) {
528 mSurface.destroy();
529 }
530 mSurface = null;
531 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700532 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700533 mToken = null;
534 mData = null;
535 mThumbOffsetX = mThumbOffsetY = 0;
536 mNotifiedWindows = null;
537 }
538
539 void register() {
540 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
541 if (mClientChannel != null) {
542 Slog.e(TAG, "Duplicate register of drag input channel");
543 } else {
544 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
545 mServerChannel = channels[0];
546 mClientChannel = channels[1];
547 mInputManager.registerInputChannel(mServerChannel);
548 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
549 mH.getLooper().getQueue());
550 }
551 }
552
553 void unregister() {
554 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
555 if (mClientChannel == null) {
556 Slog.e(TAG, "Unregister of nonexistent drag input channel");
557 } else {
558 mInputManager.unregisterInputChannel(mServerChannel);
559 InputQueue.unregisterInputChannel(mClientChannel);
560 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700561 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700562 mClientChannel = null;
563 mServerChannel = null;
564 }
565 }
566
Chris Tatea32dcf72010-10-14 12:13:50 -0700567 int getDragLayerLw() {
568 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
569 * TYPE_LAYER_MULTIPLIER
570 + TYPE_LAYER_OFFSET;
571 }
572
Christopher Tatea53146c2010-09-07 11:57:52 -0700573 /* call out to each visible window/session informing it about the drag
574 */
Chris Tateb8203e92010-10-12 14:23:21 -0700575 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700576 // Cache a base-class instance of the clip metadata so that parceling
577 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700578 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700579 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700580 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700581
582 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700583 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 }
585
Christopher Tate2c095f32010-10-04 14:13:40 -0700586 final int N = mWindows.size();
587 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700588 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700590 }
591
592 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
593 * designated window is potentially a drop recipient. There are race situations
594 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
595 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700596 *
597 * This method clones the 'event' parameter if it's being delivered to the same
598 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700599 */
Chris Tateb478f462010-10-15 16:02:26 -0700600 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
601 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700602 // Don't actually send the event if the drag is supposed to be pinned
603 // to the originating window but 'newWin' is not that window.
604 if (mLocalOnly) {
605 final IBinder winBinder = newWin.mClient.asBinder();
606 if (winBinder != mLocalWin) {
607 if (DEBUG_DRAG) {
608 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
609 }
610 return;
611 }
612 }
613
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700614 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700615 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
616 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700617 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700618 try {
619 newWin.mClient.dispatchDragEvent(event);
620 // track each window that we've notified that the drag is starting
621 mNotifiedWindows.add(newWin);
622 } catch (RemoteException e) {
623 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700624 } finally {
625 // if the callee was local, the dispatch has already recycled the event
626 if (Process.myPid() != newWin.mSession.mPid) {
627 event.recycle();
628 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700629 }
630 }
631 }
632
633 /* helper - construct and send a DRAG_STARTED event only if the window has not
634 * previously been notified, i.e. it became visible after the drag operation
635 * was begun. This is a rare case.
636 */
637 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700638 if (mDragInProgress) {
639 // If we have sent the drag-started, we needn't do so again
640 for (WindowState ws : mNotifiedWindows) {
641 if (ws == newWin) {
642 return;
643 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700644 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700645 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700646 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700647 }
Chris Tateb478f462010-10-15 16:02:26 -0700648 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700650 }
651
Chris Tated4533f142010-10-19 15:15:08 -0700652 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700653 if (DEBUG_DRAG) {
654 Slog.d(TAG, "broadcasting DRAG_ENDED");
655 }
Chris Tated4533f142010-10-19 15:15:08 -0700656 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
657 0, 0, null, null, mDragResult);
658 for (WindowState ws: mNotifiedWindows) {
659 try {
660 ws.mClient.dispatchDragEvent(evt);
661 } catch (RemoteException e) {
662 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700664 }
Chris Tated4533f142010-10-19 15:15:08 -0700665 mNotifiedWindows.clear();
666 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700667 evt.recycle();
668 }
669
Chris Tated4533f142010-10-19 15:15:08 -0700670 void endDragLw() {
671 mDragState.broadcastDragEndedLw();
672
673 // stop intercepting input
674 mDragState.unregister();
675 mInputMonitor.updateInputWindowsLw();
676
677 // free our resources and drop all the object references
678 mDragState.reset();
679 mDragState = null;
680 }
681
Christopher Tatea53146c2010-09-07 11:57:52 -0700682 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700683 final int myPid = Process.myPid();
684
685 // Move the surface to the given touch
686 mSurface.openTransaction();
687 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
688 mSurface.closeTransaction();
689
690 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700691 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700692 if (mLocalOnly) {
693 final IBinder touchedBinder = touchedWin.mClient.asBinder();
694 if (touchedBinder != mLocalWin) {
695 // This drag is pinned only to the originating window, but the drag
696 // point is outside that window. Pretend it's over empty space.
697 touchedWin = null;
698 }
699 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700700 try {
701 // have we dragged over a new window?
702 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
703 if (DEBUG_DRAG) {
704 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
705 }
706 // force DRAG_EXITED_EVENT if appropriate
707 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700708 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700709 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700710 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700711 if (myPid != mTargetWindow.mSession.mPid) {
712 evt.recycle();
713 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700714 }
715 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700716 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700717 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
718 }
719 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700720 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700721 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700722 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700723 if (myPid != touchedWin.mSession.mPid) {
724 evt.recycle();
725 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700726 }
727 } catch (RemoteException e) {
728 Slog.w(TAG, "can't send drag notification to windows");
729 }
730 mTargetWindow = touchedWin;
731 }
732
Chris Tated4533f142010-10-19 15:15:08 -0700733 // Tell the drop target about the data. Returns 'true' if we can immediately
734 // dispatch the global drag-ended message, 'false' if we need to wait for a
735 // result from the recipient.
736 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700737 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700738 if (touchedWin == null) {
739 // "drop" outside a valid window -- no recipient to apply a
740 // timeout to, and we can send the drag-ended message immediately.
741 mDragResult = false;
742 return true;
743 }
744
745 if (DEBUG_DRAG) {
746 Slog.d(TAG, "sending DROP to " + touchedWin);
747 }
748 final int myPid = Process.myPid();
749 final IBinder token = touchedWin.mClient.asBinder();
750 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
751 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
752 null, mData, false);
753 try {
754 touchedWin.mClient.dispatchDragEvent(evt);
755
756 // 5 second timeout for this window to respond to the drop
757 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
758 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
759 mH.sendMessageDelayed(msg, 5000);
760 } catch (RemoteException e) {
761 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
762 return true;
763 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700764 if (myPid != touchedWin.mSession.mPid) {
765 evt.recycle();
766 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700767 }
Chris Tated4533f142010-10-19 15:15:08 -0700768 mToken = token;
769 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700770 }
771
772 // Find the visible, touch-deliverable window under the given point
773 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
774 WindowState touchedWin = null;
775 final int x = (int) xf;
776 final int y = (int) yf;
777 final ArrayList<WindowState> windows = mWindows;
778 final int N = windows.size();
779 for (int i = N - 1; i >= 0; i--) {
780 WindowState child = windows.get(i);
781 final int flags = child.mAttrs.flags;
782 if (!child.isVisibleLw()) {
783 // not visible == don't tell about drags
784 continue;
785 }
786 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
787 // not touchable == don't tell about drags
788 continue;
789 }
790 // account for the window's decor etc
791 tmpRect.set(child.mFrame);
792 if (child.mTouchableInsets == ViewTreeObserver
793 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
794 // The point is inside of the window if it is
795 // inside the frame, AND the content part of that
796 // frame that was given by the application.
797 tmpRect.left += child.mGivenContentInsets.left;
798 tmpRect.top += child.mGivenContentInsets.top;
799 tmpRect.right -= child.mGivenContentInsets.right;
800 tmpRect.bottom -= child.mGivenContentInsets.bottom;
801 } else if (child.mTouchableInsets == ViewTreeObserver
802 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
803 // The point is inside of the window if it is
804 // inside the frame, AND the visible part of that
805 // frame that was given by the application.
806 tmpRect.left += child.mGivenVisibleInsets.left;
807 tmpRect.top += child.mGivenVisibleInsets.top;
808 tmpRect.right -= child.mGivenVisibleInsets.right;
809 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
810 }
811 final int touchFlags = flags &
812 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
813 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
814 if (tmpRect.contains(x, y) || touchFlags == 0) {
815 // Found it
816 touchedWin = child;
817 break;
818 }
819 }
820
821 return touchedWin;
822 }
823 }
824
825 DragState mDragState = null;
826 private final InputHandler mDragInputHandler = new BaseInputHandler() {
827 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700828 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
829 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700830 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700831 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
832 && mDragState != null) {
833 boolean endDrag = false;
834 final float newX = event.getRawX();
835 final float newY = event.getRawY();
836
Christopher Tatea53146c2010-09-07 11:57:52 -0700837 switch (event.getAction()) {
838 case MotionEvent.ACTION_DOWN: {
839 if (DEBUG_DRAG) {
840 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
841 }
842 } break;
843
844 case MotionEvent.ACTION_MOVE: {
845 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700846 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700847 mDragState.notifyMoveLw(newX, newY);
848 }
849 } break;
850
851 case MotionEvent.ACTION_UP: {
852 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
853 + newX + "," + newY);
854 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700855 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700856 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700857 } break;
858
859 case MotionEvent.ACTION_CANCEL: {
860 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
861 endDrag = true;
862 } break;
863 }
864
865 if (endDrag) {
866 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
867 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700868 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700869 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700870 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700871 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700872
873 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700874 }
875 } catch (Exception e) {
876 Slog.e(TAG, "Exception caught by drag handleMotion", e);
877 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700878 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700879 }
880 }
881 };
882
883 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 * Whether the UI is currently running in touch mode (not showing
885 * navigational focus because the user is directly pressing the screen).
886 */
887 boolean mInTouchMode = false;
888
889 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700890 private ArrayList<WindowChangeListener> mWindowChangeListeners =
891 new ArrayList<WindowChangeListener>();
892 private boolean mWindowsChanged = false;
893
894 public interface WindowChangeListener {
895 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700896 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898
Dianne Hackbornc485a602009-03-24 22:39:49 -0700899 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700900 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700901
902 // The frame use to limit the size of the app running in compatibility mode.
903 Rect mCompatibleScreenFrame = new Rect();
904 // The surface used to fill the outer rim of the app running in compatibility mode.
905 Surface mBackgroundFillerSurface = null;
906 boolean mBackgroundFillerShown = false;
907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 public static WindowManagerService main(Context context,
909 PowerManagerService pm, boolean haveInputMethods) {
910 WMThread thr = new WMThread(context, pm, haveInputMethods);
911 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 synchronized (thr) {
914 while (thr.mService == null) {
915 try {
916 thr.wait();
917 } catch (InterruptedException e) {
918 }
919 }
920 }
Romain Guy06882f82009-06-10 13:36:04 -0700921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 return thr.mService;
923 }
Romain Guy06882f82009-06-10 13:36:04 -0700924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 static class WMThread extends Thread {
926 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 private final Context mContext;
929 private final PowerManagerService mPM;
930 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 public WMThread(Context context, PowerManagerService pm,
933 boolean haveInputMethods) {
934 super("WindowManager");
935 mContext = context;
936 mPM = pm;
937 mHaveInputMethods = haveInputMethods;
938 }
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 public void run() {
941 Looper.prepare();
942 WindowManagerService s = new WindowManagerService(mContext, mPM,
943 mHaveInputMethods);
944 android.os.Process.setThreadPriority(
945 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700946 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 synchronized (this) {
949 mService = s;
950 notifyAll();
951 }
Romain Guy06882f82009-06-10 13:36:04 -0700952
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700953 // For debug builds, log event loop stalls to dropbox for analysis.
954 if (StrictMode.conditionallyEnableDebugLogging()) {
955 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
956 }
957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 Looper.loop();
959 }
960 }
961
962 static class PolicyThread extends Thread {
963 private final WindowManagerPolicy mPolicy;
964 private final WindowManagerService mService;
965 private final Context mContext;
966 private final PowerManagerService mPM;
967 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 public PolicyThread(WindowManagerPolicy policy,
970 WindowManagerService service, Context context,
971 PowerManagerService pm) {
972 super("WindowManagerPolicy");
973 mPolicy = policy;
974 mService = service;
975 mContext = context;
976 mPM = pm;
977 }
Romain Guy06882f82009-06-10 13:36:04 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 public void run() {
980 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800981 WindowManagerPolicyThread.set(this, Looper.myLooper());
982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800984 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 android.os.Process.setThreadPriority(
986 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700987 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 synchronized (this) {
991 mRunning = true;
992 notifyAll();
993 }
Romain Guy06882f82009-06-10 13:36:04 -0700994
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700995 // For debug builds, log event loop stalls to dropbox for analysis.
996 if (StrictMode.conditionallyEnableDebugLogging()) {
997 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
998 }
999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 Looper.loop();
1001 }
1002 }
1003
1004 private WindowManagerService(Context context, PowerManagerService pm,
1005 boolean haveInputMethods) {
1006 mContext = context;
1007 mHaveInputMethods = haveInputMethods;
1008 mLimitedAlphaCompositing = context.getResources().getBoolean(
1009 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 mPowerManager = pm;
1012 mPowerManager.setPolicy(mPolicy);
1013 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1014 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1015 "SCREEN_FROZEN");
1016 mScreenFrozenLock.setReferenceCounted(false);
1017
1018 mActivityManager = ActivityManagerNative.getDefault();
1019 mBatteryStats = BatteryStatsService.getService();
1020
1021 // Get persisted window scale setting
1022 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1023 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1024 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1025 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001026
Jim Miller284b62e2010-06-08 14:27:42 -07001027 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1028 IntentFilter filter = new IntentFilter();
1029 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1030 mContext.registerReceiver(mBroadcastReceiver, filter);
1031
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001032 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1033 "KEEP_SCREEN_ON_FLAG");
1034 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035
Jeff Browne33348b2010-07-15 23:54:05 -07001036 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1039 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 synchronized (thr) {
1042 while (!thr.mRunning) {
1043 try {
1044 thr.wait();
1045 } catch (InterruptedException e) {
1046 }
1047 }
1048 }
Romain Guy06882f82009-06-10 13:36:04 -07001049
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001050 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 // Add ourself to the Watchdog monitors.
1053 Watchdog.getInstance().addMonitor(this);
1054 }
1055
1056 @Override
1057 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1058 throws RemoteException {
1059 try {
1060 return super.onTransact(code, data, reply, flags);
1061 } catch (RuntimeException e) {
1062 // The window manager only throws security exceptions, so let's
1063 // log all others.
1064 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001065 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
1067 throw e;
1068 }
1069 }
1070
Jeff Browne33348b2010-07-15 23:54:05 -07001071 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001073 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 TAG, "Adding window " + window + " at "
1075 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1076 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001077 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
1079
Jeff Browne33348b2010-07-15 23:54:05 -07001080 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001082 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 TAG, "Adding window " + window + " at "
1084 + i + " of " + mWindows.size() + " (before " + pos + ")");
1085 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001086 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 }
1088
1089 //This method finds out the index of a window that has the same app token as
1090 //win. used for z ordering the windows in mWindows
1091 private int findIdxBasedOnAppTokens(WindowState win) {
1092 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001093 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 int jmax = localmWindows.size();
1095 if(jmax == 0) {
1096 return -1;
1097 }
1098 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001099 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 if(wentry.mAppToken == win.mAppToken) {
1101 return j;
1102 }
1103 }
1104 return -1;
1105 }
Romain Guy06882f82009-06-10 13:36:04 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1108 final IWindow client = win.mClient;
1109 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001110 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 final int N = localmWindows.size();
1113 final WindowState attached = win.mAttachedWindow;
1114 int i;
1115 if (attached == null) {
1116 int tokenWindowsPos = token.windows.size();
1117 if (token.appWindowToken != null) {
1118 int index = tokenWindowsPos-1;
1119 if (index >= 0) {
1120 // If this application has existing windows, we
1121 // simply place the new window on top of them... but
1122 // keep the starting window on top.
1123 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1124 // Base windows go behind everything else.
1125 placeWindowBefore(token.windows.get(0), win);
1126 tokenWindowsPos = 0;
1127 } else {
1128 AppWindowToken atoken = win.mAppToken;
1129 if (atoken != null &&
1130 token.windows.get(index) == atoken.startingWindow) {
1131 placeWindowBefore(token.windows.get(index), win);
1132 tokenWindowsPos--;
1133 } else {
1134 int newIdx = findIdxBasedOnAppTokens(win);
1135 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001136 //there is a window above this one associated with the same
1137 //apptoken note that the window could be a floating window
1138 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001140 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001141 TAG, "Adding window " + win + " at "
1142 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001144 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 }
1147 }
1148 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001149 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 TAG, "Figuring out where to add app window "
1151 + client.asBinder() + " (token=" + token + ")");
1152 // Figure out where the window should go, based on the
1153 // order of applications.
1154 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001155 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 for (i=NA-1; i>=0; i--) {
1157 AppWindowToken t = mAppTokens.get(i);
1158 if (t == token) {
1159 i--;
1160 break;
1161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001162
Dianne Hackborna8f60182009-09-01 19:01:50 -07001163 // We haven't reached the token yet; if this token
1164 // is not going to the bottom and has windows, we can
1165 // use it as an anchor for when we do reach the token.
1166 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 pos = t.windows.get(0);
1168 }
1169 }
1170 // We now know the index into the apps. If we found
1171 // an app window above, that gives us the position; else
1172 // we need to look some more.
1173 if (pos != null) {
1174 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001175 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 if (atoken != null) {
1177 final int NC = atoken.windows.size();
1178 if (NC > 0) {
1179 WindowState bottom = atoken.windows.get(0);
1180 if (bottom.mSubLayer < 0) {
1181 pos = bottom;
1182 }
1183 }
1184 }
1185 placeWindowBefore(pos, win);
1186 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001187 // Continue looking down until we find the first
1188 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 while (i >= 0) {
1190 AppWindowToken t = mAppTokens.get(i);
1191 final int NW = t.windows.size();
1192 if (NW > 0) {
1193 pos = t.windows.get(NW-1);
1194 break;
1195 }
1196 i--;
1197 }
1198 if (pos != null) {
1199 // Move in front of any windows attached to this
1200 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001201 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 if (atoken != null) {
1203 final int NC = atoken.windows.size();
1204 if (NC > 0) {
1205 WindowState top = atoken.windows.get(NC-1);
1206 if (top.mSubLayer >= 0) {
1207 pos = top;
1208 }
1209 }
1210 }
1211 placeWindowAfter(pos, win);
1212 } else {
1213 // Just search for the start of this layer.
1214 final int myLayer = win.mBaseLayer;
1215 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001216 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 if (w.mBaseLayer > myLayer) {
1218 break;
1219 }
1220 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001221 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001222 TAG, "Adding window " + win + " at "
1223 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001225 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 }
1227 }
1228 }
1229 } else {
1230 // Figure out where window should go, based on layer.
1231 final int myLayer = win.mBaseLayer;
1232 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001233 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 i++;
1235 break;
1236 }
1237 }
1238 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001239 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001240 TAG, "Adding window " + win + " at "
1241 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001243 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 }
1245 if (addToToken) {
1246 token.windows.add(tokenWindowsPos, win);
1247 }
1248
1249 } else {
1250 // Figure out this window's ordering relative to the window
1251 // it is attached to.
1252 final int NA = token.windows.size();
1253 final int sublayer = win.mSubLayer;
1254 int largestSublayer = Integer.MIN_VALUE;
1255 WindowState windowWithLargestSublayer = null;
1256 for (i=0; i<NA; i++) {
1257 WindowState w = token.windows.get(i);
1258 final int wSublayer = w.mSubLayer;
1259 if (wSublayer >= largestSublayer) {
1260 largestSublayer = wSublayer;
1261 windowWithLargestSublayer = w;
1262 }
1263 if (sublayer < 0) {
1264 // For negative sublayers, we go below all windows
1265 // in the same sublayer.
1266 if (wSublayer >= sublayer) {
1267 if (addToToken) {
1268 token.windows.add(i, win);
1269 }
1270 placeWindowBefore(
1271 wSublayer >= 0 ? attached : w, win);
1272 break;
1273 }
1274 } else {
1275 // For positive sublayers, we go above all windows
1276 // in the same sublayer.
1277 if (wSublayer > sublayer) {
1278 if (addToToken) {
1279 token.windows.add(i, win);
1280 }
1281 placeWindowBefore(w, win);
1282 break;
1283 }
1284 }
1285 }
1286 if (i >= NA) {
1287 if (addToToken) {
1288 token.windows.add(win);
1289 }
1290 if (sublayer < 0) {
1291 placeWindowBefore(attached, win);
1292 } else {
1293 placeWindowAfter(largestSublayer >= 0
1294 ? windowWithLargestSublayer
1295 : attached,
1296 win);
1297 }
1298 }
1299 }
Romain Guy06882f82009-06-10 13:36:04 -07001300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 if (win.mAppToken != null && addToToken) {
1302 win.mAppToken.allAppWindows.add(win);
1303 }
1304 }
Romain Guy06882f82009-06-10 13:36:04 -07001305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 static boolean canBeImeTarget(WindowState w) {
1307 final int fl = w.mAttrs.flags
1308 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1309 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1310 return w.isVisibleOrAdding();
1311 }
1312 return false;
1313 }
Romain Guy06882f82009-06-10 13:36:04 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001316 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 final int N = localmWindows.size();
1318 WindowState w = null;
1319 int i = N;
1320 while (i > 0) {
1321 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001322 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001323
Joe Onorato8a9b2202010-02-26 18:56:32 -08001324 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 // + Integer.toHexString(w.mAttrs.flags));
1326 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001327 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 // Yet more tricksyness! If this window is a "starting"
1330 // window, we do actually want to be on top of it, but
1331 // it is not -really- where input will go. So if the caller
1332 // is not actually looking to move the IME, look down below
1333 // for a real window to target...
1334 if (!willMove
1335 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1336 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001337 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1339 i--;
1340 w = wb;
1341 }
1342 }
1343 break;
1344 }
1345 }
Romain Guy06882f82009-06-10 13:36:04 -07001346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001348
Joe Onorato8a9b2202010-02-26 18:56:32 -08001349 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 if (willMove && w != null) {
1353 final WindowState curTarget = mInputMethodTarget;
1354 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 // Now some fun for dealing with window animations that
1357 // modify the Z order. We need to look at all windows below
1358 // the current target that are in this app, finding the highest
1359 // visible one in layering.
1360 AppWindowToken token = curTarget.mAppToken;
1361 WindowState highestTarget = null;
1362 int highestPos = 0;
1363 if (token.animating || token.animation != null) {
1364 int pos = 0;
1365 pos = localmWindows.indexOf(curTarget);
1366 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001367 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 if (win.mAppToken != token) {
1369 break;
1370 }
1371 if (!win.mRemoved) {
1372 if (highestTarget == null || win.mAnimLayer >
1373 highestTarget.mAnimLayer) {
1374 highestTarget = win;
1375 highestPos = pos;
1376 }
1377 }
1378 pos--;
1379 }
1380 }
Romain Guy06882f82009-06-10 13:36:04 -07001381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001383 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 + mNextAppTransition + " " + highestTarget
1385 + " animating=" + highestTarget.isAnimating()
1386 + " layer=" + highestTarget.mAnimLayer
1387 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001388
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001389 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 // If we are currently setting up for an animation,
1391 // hold everything until we can find out what will happen.
1392 mInputMethodTargetWaitingAnim = true;
1393 mInputMethodTarget = highestTarget;
1394 return highestPos + 1;
1395 } else if (highestTarget.isAnimating() &&
1396 highestTarget.mAnimLayer > w.mAnimLayer) {
1397 // If the window we are currently targeting is involved
1398 // with an animation, and it is on top of the next target
1399 // we will be over, then hold off on moving until
1400 // that is done.
1401 mInputMethodTarget = highestTarget;
1402 return highestPos + 1;
1403 }
1404 }
1405 }
1406 }
Romain Guy06882f82009-06-10 13:36:04 -07001407
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 if (w != null) {
1410 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001411 if (DEBUG_INPUT_METHOD) {
1412 RuntimeException e = null;
1413 if (!HIDE_STACK_CRAWLS) {
1414 e = new RuntimeException();
1415 e.fillInStackTrace();
1416 }
1417 Slog.w(TAG, "Moving IM target from "
1418 + mInputMethodTarget + " to " + w, e);
1419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 mInputMethodTarget = w;
1421 if (w.mAppToken != null) {
1422 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1423 } else {
1424 setInputMethodAnimLayerAdjustment(0);
1425 }
1426 }
1427 return i+1;
1428 }
1429 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001430 if (DEBUG_INPUT_METHOD) {
1431 RuntimeException e = null;
1432 if (!HIDE_STACK_CRAWLS) {
1433 e = new RuntimeException();
1434 e.fillInStackTrace();
1435 }
1436 Slog.w(TAG, "Moving IM target from "
1437 + mInputMethodTarget + " to null", e);
1438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 mInputMethodTarget = null;
1440 setInputMethodAnimLayerAdjustment(0);
1441 }
1442 return -1;
1443 }
Romain Guy06882f82009-06-10 13:36:04 -07001444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 void addInputMethodWindowToListLocked(WindowState win) {
1446 int pos = findDesiredInputMethodWindowIndexLocked(true);
1447 if (pos >= 0) {
1448 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001449 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001450 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001452 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 moveInputMethodDialogsLocked(pos+1);
1454 return;
1455 }
1456 win.mTargetAppToken = null;
1457 addWindowToListInOrderLocked(win, true);
1458 moveInputMethodDialogsLocked(pos);
1459 }
Romain Guy06882f82009-06-10 13:36:04 -07001460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 mInputMethodAnimLayerAdjustment = adj;
1464 WindowState imw = mInputMethodWindow;
1465 if (imw != null) {
1466 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 + " anim layer: " + imw.mAnimLayer);
1469 int wi = imw.mChildWindows.size();
1470 while (wi > 0) {
1471 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001472 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001474 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 + " anim layer: " + cw.mAnimLayer);
1476 }
1477 }
1478 int di = mInputMethodDialogs.size();
1479 while (di > 0) {
1480 di --;
1481 imw = mInputMethodDialogs.get(di);
1482 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001483 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 + " anim layer: " + imw.mAnimLayer);
1485 }
1486 }
Romain Guy06882f82009-06-10 13:36:04 -07001487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1489 int wpos = mWindows.indexOf(win);
1490 if (wpos >= 0) {
1491 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001492 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001494 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 int NC = win.mChildWindows.size();
1496 while (NC > 0) {
1497 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001498 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 int cpos = mWindows.indexOf(cw);
1500 if (cpos >= 0) {
1501 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001503 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 mWindows.remove(cpos);
1505 }
1506 }
1507 }
1508 return interestingPos;
1509 }
Romain Guy06882f82009-06-10 13:36:04 -07001510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 private void reAddWindowToListInOrderLocked(WindowState win) {
1512 addWindowToListInOrderLocked(win, false);
1513 // This is a hack to get all of the child windows added as well
1514 // at the right position. Child windows should be rare and
1515 // this case should be rare, so it shouldn't be that big a deal.
1516 int wpos = mWindows.indexOf(win);
1517 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001518 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001519 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001521 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 reAddWindowLocked(wpos, win);
1523 }
1524 }
Romain Guy06882f82009-06-10 13:36:04 -07001525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 void logWindowList(String prefix) {
1527 int N = mWindows.size();
1528 while (N > 0) {
1529 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001530 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 }
1532 }
Romain Guy06882f82009-06-10 13:36:04 -07001533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 void moveInputMethodDialogsLocked(int pos) {
1535 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001538 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 for (int i=0; i<N; i++) {
1540 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1541 }
1542 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 logWindowList(" ");
1545 }
Romain Guy06882f82009-06-10 13:36:04 -07001546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 if (pos >= 0) {
1548 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1549 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001550 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 if (wp == mInputMethodWindow) {
1552 pos++;
1553 }
1554 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001555 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 for (int i=0; i<N; i++) {
1557 WindowState win = dialogs.get(i);
1558 win.mTargetAppToken = targetAppToken;
1559 pos = reAddWindowLocked(pos, win);
1560 }
1561 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 logWindowList(" ");
1564 }
1565 return;
1566 }
1567 for (int i=0; i<N; i++) {
1568 WindowState win = dialogs.get(i);
1569 win.mTargetAppToken = null;
1570 reAddWindowToListInOrderLocked(win);
1571 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001572 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 logWindowList(" ");
1574 }
1575 }
1576 }
Romain Guy06882f82009-06-10 13:36:04 -07001577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1579 final WindowState imWin = mInputMethodWindow;
1580 final int DN = mInputMethodDialogs.size();
1581 if (imWin == null && DN == 0) {
1582 return false;
1583 }
Romain Guy06882f82009-06-10 13:36:04 -07001584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1586 if (imPos >= 0) {
1587 // In this case, the input method windows are to be placed
1588 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 // First check to see if the input method windows are already
1591 // located here, and contiguous.
1592 final int N = mWindows.size();
1593 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001594 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 // Figure out the actual input method window that should be
1597 // at the bottom of their stack.
1598 WindowState baseImWin = imWin != null
1599 ? imWin : mInputMethodDialogs.get(0);
1600 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001601 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 if (cw.mSubLayer < 0) baseImWin = cw;
1603 }
Romain Guy06882f82009-06-10 13:36:04 -07001604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 if (firstImWin == baseImWin) {
1606 // The windows haven't moved... but are they still contiguous?
1607 // First find the top IM window.
1608 int pos = imPos+1;
1609 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001610 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 break;
1612 }
1613 pos++;
1614 }
1615 pos++;
1616 // Now there should be no more input method windows above.
1617 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001618 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 break;
1620 }
1621 pos++;
1622 }
1623 if (pos >= N) {
1624 // All is good!
1625 return false;
1626 }
1627 }
Romain Guy06882f82009-06-10 13:36:04 -07001628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 if (imWin != null) {
1630 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001631 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 logWindowList(" ");
1633 }
1634 imPos = tmpRemoveWindowLocked(imPos, imWin);
1635 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001636 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 logWindowList(" ");
1638 }
1639 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1640 reAddWindowLocked(imPos, imWin);
1641 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 logWindowList(" ");
1644 }
1645 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1646 } else {
1647 moveInputMethodDialogsLocked(imPos);
1648 }
Romain Guy06882f82009-06-10 13:36:04 -07001649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 } else {
1651 // In this case, the input method windows go in a fixed layer,
1652 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 tmpRemoveWindowLocked(0, imWin);
1657 imWin.mTargetAppToken = null;
1658 reAddWindowToListInOrderLocked(imWin);
1659 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001660 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 logWindowList(" ");
1662 }
1663 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1664 } else {
1665 moveInputMethodDialogsLocked(-1);;
1666 }
Romain Guy06882f82009-06-10 13:36:04 -07001667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 }
Romain Guy06882f82009-06-10 13:36:04 -07001669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 if (needAssignLayers) {
1671 assignLayersLocked();
1672 }
Romain Guy06882f82009-06-10 13:36:04 -07001673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 return true;
1675 }
Romain Guy06882f82009-06-10 13:36:04 -07001676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 void adjustInputMethodDialogsLocked() {
1678 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1679 }
Romain Guy06882f82009-06-10 13:36:04 -07001680
Dianne Hackborn25994b42009-09-04 14:21:19 -07001681 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001683 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1684 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1685 ? wallpaperTarget.mAppToken.animation : null)
1686 + " upper=" + mUpperWallpaperTarget
1687 + " lower=" + mLowerWallpaperTarget);
1688 return (wallpaperTarget != null
1689 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1690 && wallpaperTarget.mAppToken.animation != null)))
1691 || mUpperWallpaperTarget != null
1692 || mLowerWallpaperTarget != null;
1693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001694
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001695 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1696 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001697
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001698 int adjustWallpaperWindowsLocked() {
1699 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001700
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001701 final int dw = mDisplay.getWidth();
1702 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001703
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001704 // First find top-most window that has asked to be on top of the
1705 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001706 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001707 int N = localmWindows.size();
1708 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001709 WindowState foundW = null;
1710 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001711 WindowState topCurW = null;
1712 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001713 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001714 int i = N;
1715 while (i > 0) {
1716 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001717 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001718 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1719 if (topCurW == null) {
1720 topCurW = w;
1721 topCurI = i;
1722 }
1723 continue;
1724 }
1725 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001726 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001727 // If this window's app token is hidden and not animating,
1728 // it is of no interest to us.
1729 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001730 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001731 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001732 continue;
1733 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001734 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001735 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001736 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1737 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001738 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001739 && (mWallpaperTarget == w
1740 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001741 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001743 foundW = w;
1744 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001745 if (w == mWallpaperTarget && ((w.mAppToken != null
1746 && w.mAppToken.animation != null)
1747 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001748 // The current wallpaper target is animating, so we'll
1749 // look behind it for another possible target and figure
1750 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001751 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001752 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001753 continue;
1754 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001755 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001756 } else if (w == mWindowDetachedWallpaper) {
1757 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001758 }
1759 }
1760
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001761 if (foundW == null && windowDetachedI >= 0) {
1762 if (DEBUG_WALLPAPER) Slog.v(TAG,
1763 "Found animating detached wallpaper activity: #" + i + "=" + w);
1764 foundW = w;
1765 foundI = windowDetachedI;
1766 }
1767
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001768 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001769 // If we are currently waiting for an app transition, and either
1770 // the current target or the next target are involved with it,
1771 // then hold off on doing anything with the wallpaper.
1772 // Note that we are checking here for just whether the target
1773 // is part of an app token... which is potentially overly aggressive
1774 // (the app token may not be involved in the transition), but good
1775 // enough (we'll just wait until whatever transition is pending
1776 // executes).
1777 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001778 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001779 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001780 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001781 }
1782 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001783 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001785 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001786 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001787 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001788
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001789 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001790 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001791 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001792 + " oldTarget: " + mWallpaperTarget);
1793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001794
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001795 mLowerWallpaperTarget = null;
1796 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001797
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001798 WindowState oldW = mWallpaperTarget;
1799 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001800
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 // Now what is happening... if the current and new targets are
1802 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001803 if (foundW != null && oldW != null) {
1804 boolean oldAnim = oldW.mAnimation != null
1805 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1806 boolean foundAnim = foundW.mAnimation != null
1807 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001808 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001810 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001811 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001812 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001813 int oldI = localmWindows.indexOf(oldW);
1814 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 }
1817 if (oldI >= 0) {
1818 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001819 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001820 + "=" + oldW + "; new#" + foundI
1821 + "=" + foundW);
1822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001823
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001824 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001825 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001826 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001827 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001828 }
1829 mWallpaperTarget = oldW;
1830 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001831
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001832 // Now set the upper and lower wallpaper targets
1833 // correctly, and make sure that we are positioning
1834 // the wallpaper below the lower.
1835 if (foundI > oldI) {
1836 // The new target is on top of the old one.
1837 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001838 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001839 }
1840 mUpperWallpaperTarget = foundW;
1841 mLowerWallpaperTarget = oldW;
1842 foundW = oldW;
1843 foundI = oldI;
1844 } else {
1845 // The new target is below the old one.
1846 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001847 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001848 }
1849 mUpperWallpaperTarget = oldW;
1850 mLowerWallpaperTarget = foundW;
1851 }
1852 }
1853 }
1854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001855
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001856 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001857 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001858 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1859 || (mLowerWallpaperTarget.mAppToken != null
1860 && mLowerWallpaperTarget.mAppToken.animation != null);
1861 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1862 || (mUpperWallpaperTarget.mAppToken != null
1863 && mUpperWallpaperTarget.mAppToken.animation != null);
1864 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001866 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001867 }
1868 mLowerWallpaperTarget = null;
1869 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001870 }
1871 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001873 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001874 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001875 // The window is visible to the compositor... but is it visible
1876 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001877 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001880 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001881 // its layer adjustment. Only do this if we are not transfering
1882 // between two wallpaper targets.
1883 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001884 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001885 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001886
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001887 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1888 * TYPE_LAYER_MULTIPLIER
1889 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001890
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001891 // Now w is the window we are supposed to be behind... but we
1892 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001893 // AND any starting window associated with it, AND below the
1894 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001895 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001896 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001897 if (wb.mBaseLayer < maxLayer &&
1898 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001899 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001900 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001901 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001902 // This window is not related to the previous one in any
1903 // interesting way, so stop here.
1904 break;
1905 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001906 foundW = wb;
1907 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001908 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001909 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001910 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001912
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001913 if (foundW == null && topCurW != null) {
1914 // There is no wallpaper target, so it goes at the bottom.
1915 // We will assume it is the same place as last time, if known.
1916 foundW = topCurW;
1917 foundI = topCurI+1;
1918 } else {
1919 // Okay i is the position immediately above the wallpaper. Look at
1920 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001921 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001922 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001923
Dianne Hackborn284ac932009-08-28 10:34:25 -07001924 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001925 if (mWallpaperTarget.mWallpaperX >= 0) {
1926 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001927 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001928 }
1929 if (mWallpaperTarget.mWallpaperY >= 0) {
1930 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001931 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001932 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001933 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 // Start stepping backwards from here, ensuring that our wallpaper windows
1936 // are correctly placed.
1937 int curTokenIndex = mWallpaperTokens.size();
1938 while (curTokenIndex > 0) {
1939 curTokenIndex--;
1940 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001941 if (token.hidden == visible) {
1942 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1943 token.hidden = !visible;
1944 // Need to do a layout to ensure the wallpaper now has the
1945 // correct size.
1946 mLayoutNeeded = true;
1947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001948
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001949 int curWallpaperIndex = token.windows.size();
1950 while (curWallpaperIndex > 0) {
1951 curWallpaperIndex--;
1952 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001954 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001955 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001957
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001958 // First, make sure the client has the current visibility
1959 // state.
1960 if (wallpaper.mWallpaperVisible != visible) {
1961 wallpaper.mWallpaperVisible = visible;
1962 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001963 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001964 "Setting visibility of wallpaper " + wallpaper
1965 + ": " + visible);
1966 wallpaper.mClient.dispatchAppVisibility(visible);
1967 } catch (RemoteException e) {
1968 }
1969 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001970
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001971 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001972 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001973 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001974
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001975 // First, if this window is at the current index, then all
1976 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001977 if (wallpaper == foundW) {
1978 foundI--;
1979 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001980 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 continue;
1982 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001983
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001984 // The window didn't match... the current wallpaper window,
1985 // wherever it is, is in the wrong place, so make sure it is
1986 // not in the list.
1987 int oldIndex = localmWindows.indexOf(wallpaper);
1988 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001989 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001990 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001991 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001992 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001993 if (oldIndex < foundI) {
1994 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001995 }
1996 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001997
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001998 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001999 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002000 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002001 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002002
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002003 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002004 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002005 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002006 }
2007 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002008
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002009 return changed;
2010 }
2011
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002012 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002014 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002015 mWallpaperAnimLayerAdjustment = adj;
2016 int curTokenIndex = mWallpaperTokens.size();
2017 while (curTokenIndex > 0) {
2018 curTokenIndex--;
2019 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2020 int curWallpaperIndex = token.windows.size();
2021 while (curWallpaperIndex > 0) {
2022 curWallpaperIndex--;
2023 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2024 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002025 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002026 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002027 }
2028 }
2029 }
2030
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002031 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2032 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002033 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002034 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002035 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002036 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002037 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2038 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2039 changed = wallpaperWin.mXOffset != offset;
2040 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002041 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002042 + wallpaperWin + " x: " + offset);
2043 wallpaperWin.mXOffset = offset;
2044 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002045 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002046 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002047 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002048 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002049 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002050
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002051 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002052 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002053 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2054 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2055 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002056 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002057 + wallpaperWin + " y: " + offset);
2058 changed = true;
2059 wallpaperWin.mYOffset = offset;
2060 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002061 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002062 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002063 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002064 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002065 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002066
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002067 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002068 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002069 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002070 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2071 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002072 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002073 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002074 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002075 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002076 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2077 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002078 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002079 if (mWaitingOnWallpaper != null) {
2080 long start = SystemClock.uptimeMillis();
2081 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2082 < start) {
2083 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002084 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002085 "Waiting for offset complete...");
2086 mWindowMap.wait(WALLPAPER_TIMEOUT);
2087 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002088 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002089 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002090 if ((start+WALLPAPER_TIMEOUT)
2091 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002092 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002093 + wallpaperWin);
2094 mLastWallpaperTimeoutTime = start;
2095 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002096 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002097 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002098 }
2099 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002100 } catch (RemoteException e) {
2101 }
2102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002103
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002104 return changed;
2105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002106
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002107 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002108 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002109 if (mWaitingOnWallpaper != null &&
2110 mWaitingOnWallpaper.mClient.asBinder() == window) {
2111 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002112 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002113 }
2114 }
2115 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002116
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002117 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002118 final int dw = mDisplay.getWidth();
2119 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002120
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002121 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002122
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002123 WindowState target = mWallpaperTarget;
2124 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002125 if (target.mWallpaperX >= 0) {
2126 mLastWallpaperX = target.mWallpaperX;
2127 } else if (changingTarget.mWallpaperX >= 0) {
2128 mLastWallpaperX = changingTarget.mWallpaperX;
2129 }
2130 if (target.mWallpaperY >= 0) {
2131 mLastWallpaperY = target.mWallpaperY;
2132 } else if (changingTarget.mWallpaperY >= 0) {
2133 mLastWallpaperY = changingTarget.mWallpaperY;
2134 }
2135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002136
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002137 int curTokenIndex = mWallpaperTokens.size();
2138 while (curTokenIndex > 0) {
2139 curTokenIndex--;
2140 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2141 int curWallpaperIndex = token.windows.size();
2142 while (curWallpaperIndex > 0) {
2143 curWallpaperIndex--;
2144 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2145 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2146 wallpaper.computeShownFrameLocked();
2147 changed = true;
2148 // We only want to be synchronous with one wallpaper.
2149 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002150 }
2151 }
2152 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002153
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002154 return changed;
2155 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002156
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002157 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002158 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002159 final int dw = mDisplay.getWidth();
2160 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002161
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002162 int curTokenIndex = mWallpaperTokens.size();
2163 while (curTokenIndex > 0) {
2164 curTokenIndex--;
2165 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002166 if (token.hidden == visible) {
2167 token.hidden = !visible;
2168 // Need to do a layout to ensure the wallpaper now has the
2169 // correct size.
2170 mLayoutNeeded = true;
2171 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002172
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002173 int curWallpaperIndex = token.windows.size();
2174 while (curWallpaperIndex > 0) {
2175 curWallpaperIndex--;
2176 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2177 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002178 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002179 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002180
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002181 if (wallpaper.mWallpaperVisible != visible) {
2182 wallpaper.mWallpaperVisible = visible;
2183 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002185 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002186 + ": " + visible);
2187 wallpaper.mClient.dispatchAppVisibility(visible);
2188 } catch (RemoteException e) {
2189 }
2190 }
2191 }
2192 }
2193 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 public int addWindow(Session session, IWindow client,
2196 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002197 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 int res = mPolicy.checkAddPermission(attrs);
2199 if (res != WindowManagerImpl.ADD_OKAY) {
2200 return res;
2201 }
Romain Guy06882f82009-06-10 13:36:04 -07002202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 boolean reportNewConfig = false;
2204 WindowState attachedWindow = null;
2205 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002206 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002210 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 }
Romain Guy06882f82009-06-10 13:36:04 -07002212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002214 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2216 }
2217
2218 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002219 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002221 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 + attrs.token + ". Aborting.");
2223 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2224 }
2225 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2226 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002227 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 + attrs.token + ". Aborting.");
2229 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2230 }
2231 }
2232
2233 boolean addToken = false;
2234 WindowToken token = mTokenMap.get(attrs.token);
2235 if (token == null) {
2236 if (attrs.type >= FIRST_APPLICATION_WINDOW
2237 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002238 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 + attrs.token + ". Aborting.");
2240 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2241 }
2242 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002243 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 + attrs.token + ". Aborting.");
2245 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2246 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002247 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002248 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002249 + attrs.token + ". Aborting.");
2250 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 token = new WindowToken(attrs.token, -1, false);
2253 addToken = true;
2254 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2255 && attrs.type <= LAST_APPLICATION_WINDOW) {
2256 AppWindowToken atoken = token.appWindowToken;
2257 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002258 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 + token + ". Aborting.");
2260 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2261 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002262 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 + token + ". Aborting.");
2264 return WindowManagerImpl.ADD_APP_EXITING;
2265 }
2266 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2267 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002268 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2270 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2271 }
2272 } else if (attrs.type == TYPE_INPUT_METHOD) {
2273 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002274 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 + attrs.token + ". Aborting.");
2276 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2277 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002278 } else if (attrs.type == TYPE_WALLPAPER) {
2279 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002280 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002281 + attrs.token + ". Aborting.");
2282 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 }
2285
2286 win = new WindowState(session, client, token,
2287 attachedWindow, attrs, viewVisibility);
2288 if (win.mDeathRecipient == null) {
2289 // Client has apparently died, so there is no reason to
2290 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002291 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 + " that is dead, aborting.");
2293 return WindowManagerImpl.ADD_APP_EXITING;
2294 }
2295
2296 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 res = mPolicy.prepareAddWindowLw(win, attrs);
2299 if (res != WindowManagerImpl.ADD_OKAY) {
2300 return res;
2301 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002302
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002303 if (outInputChannel != null) {
2304 String name = win.makeInputChannelName();
2305 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2306 win.mInputChannel = inputChannels[0];
2307 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2308
2309 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311
2312 // From now on, no exceptions or errors allowed!
2313
2314 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002315
Dianne Hackborn5132b372010-07-29 12:51:35 -07002316 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 if (addToken) {
2319 mTokenMap.put(attrs.token, token);
2320 mTokenList.add(token);
2321 }
2322 win.attach();
2323 mWindowMap.put(client.asBinder(), win);
2324
2325 if (attrs.type == TYPE_APPLICATION_STARTING &&
2326 token.appWindowToken != null) {
2327 token.appWindowToken.startingWindow = win;
2328 }
2329
2330 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 if (attrs.type == TYPE_INPUT_METHOD) {
2333 mInputMethodWindow = win;
2334 addInputMethodWindowToListLocked(win);
2335 imMayMove = false;
2336 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2337 mInputMethodDialogs.add(win);
2338 addWindowToListInOrderLocked(win, true);
2339 adjustInputMethodDialogsLocked();
2340 imMayMove = false;
2341 } else {
2342 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002343 if (attrs.type == TYPE_WALLPAPER) {
2344 mLastWallpaperTimeoutTime = 0;
2345 adjustWallpaperWindowsLocked();
2346 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002347 adjustWallpaperWindowsLocked();
2348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 }
Romain Guy06882f82009-06-10 13:36:04 -07002350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002351 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (mInTouchMode) {
2356 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2357 }
2358 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2359 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2360 }
Romain Guy06882f82009-06-10 13:36:04 -07002361
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002362 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002364 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2365 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 imMayMove = false;
2367 }
2368 }
Romain Guy06882f82009-06-10 13:36:04 -07002369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002371 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 }
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 assignLayersLocked();
2375 // Don't do layout here, the window must call
2376 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 //dump();
2379
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002380 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002381 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002382 }
Jeff Brown349703e2010-06-22 01:27:15 -07002383
Joe Onorato8a9b2202010-02-26 18:56:32 -08002384 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 TAG, "New client " + client.asBinder()
2386 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002387
2388 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2389 reportNewConfig = true;
2390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 }
2392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 if (reportNewConfig) {
2394 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 return res;
2400 }
Romain Guy06882f82009-06-10 13:36:04 -07002401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 public void removeWindow(Session session, IWindow client) {
2403 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002404 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 if (win == null) {
2406 return;
2407 }
2408 removeWindowLocked(session, win);
2409 }
2410 }
Romain Guy06882f82009-06-10 13:36:04 -07002411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 public void removeWindowLocked(Session session, WindowState win) {
2413
Joe Onorato8a9b2202010-02-26 18:56:32 -08002414 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 TAG, "Remove " + win + " client="
2416 + Integer.toHexString(System.identityHashCode(
2417 win.mClient.asBinder()))
2418 + ", surface=" + win.mSurface);
2419
2420 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002421
2422 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002423
Joe Onorato8a9b2202010-02-26 18:56:32 -08002424 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2426 + " mExiting=" + win.mExiting
2427 + " isAnimating=" + win.isAnimating()
2428 + " app-animation="
2429 + (win.mAppToken != null ? win.mAppToken.animation : null)
2430 + " inPendingTransaction="
2431 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2432 + " mDisplayFrozen=" + mDisplayFrozen);
2433 // Visibility of the removed window. Will be used later to update orientation later on.
2434 boolean wasVisible = false;
2435 // First, see if we need to run an animation. If we do, we have
2436 // to hold off on removing the window until the animation is done.
2437 // If the display is frozen, just remove immediately, since the
2438 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002439 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 // If we are not currently running the exit animation, we
2441 // need to see about starting one.
2442 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2445 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2446 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2447 }
2448 // Try starting an animation.
2449 if (applyAnimationLocked(win, transit, false)) {
2450 win.mExiting = true;
2451 }
2452 }
2453 if (win.mExiting || win.isAnimating()) {
2454 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002455 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 win.mExiting = true;
2457 win.mRemoveOnExit = true;
2458 mLayoutNeeded = true;
2459 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2460 performLayoutAndPlaceSurfacesLocked();
2461 if (win.mAppToken != null) {
2462 win.mAppToken.updateReportedVisibilityLocked();
2463 }
2464 //dump();
2465 Binder.restoreCallingIdentity(origId);
2466 return;
2467 }
2468 }
2469
2470 removeWindowInnerLocked(session, win);
2471 // Removing a visible window will effect the computed orientation
2472 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002473 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002474 != mForcedAppOrientation
2475 && updateOrientationFromAppTokensLocked()) {
2476 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 }
2478 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2479 Binder.restoreCallingIdentity(origId);
2480 }
Romain Guy06882f82009-06-10 13:36:04 -07002481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 if (mInputMethodTarget == win) {
2486 moveInputMethodWindowsIfNeededLocked(false);
2487 }
Romain Guy06882f82009-06-10 13:36:04 -07002488
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002489 if (false) {
2490 RuntimeException e = new RuntimeException("here");
2491 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002492 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002493 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 mPolicy.removeWindowLw(win);
2496 win.removeLocked();
2497
2498 mWindowMap.remove(win.mClient.asBinder());
2499 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002500 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002501 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502
2503 if (mInputMethodWindow == win) {
2504 mInputMethodWindow = null;
2505 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2506 mInputMethodDialogs.remove(win);
2507 }
Romain Guy06882f82009-06-10 13:36:04 -07002508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 final WindowToken token = win.mToken;
2510 final AppWindowToken atoken = win.mAppToken;
2511 token.windows.remove(win);
2512 if (atoken != null) {
2513 atoken.allAppWindows.remove(win);
2514 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002515 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 TAG, "**** Removing window " + win + ": count="
2517 + token.windows.size());
2518 if (token.windows.size() == 0) {
2519 if (!token.explicit) {
2520 mTokenMap.remove(token.token);
2521 mTokenList.remove(token);
2522 } else if (atoken != null) {
2523 atoken.firstWindowDrawn = false;
2524 }
2525 }
2526
2527 if (atoken != null) {
2528 if (atoken.startingWindow == win) {
2529 atoken.startingWindow = null;
2530 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2531 // If this is the last window and we had requested a starting
2532 // transition window, well there is no point now.
2533 atoken.startingData = null;
2534 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2535 // If this is the last window except for a starting transition
2536 // window, we need to get rid of the starting transition.
2537 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002538 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 + ": no more real windows");
2540 }
2541 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2542 mH.sendMessage(m);
2543 }
2544 }
Romain Guy06882f82009-06-10 13:36:04 -07002545
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002546 if (win.mAttrs.type == TYPE_WALLPAPER) {
2547 mLastWallpaperTimeoutTime = 0;
2548 adjustWallpaperWindowsLocked();
2549 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002550 adjustWallpaperWindowsLocked();
2551 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 if (!mInLayout) {
2554 assignLayersLocked();
2555 mLayoutNeeded = true;
2556 performLayoutAndPlaceSurfacesLocked();
2557 if (win.mAppToken != null) {
2558 win.mAppToken.updateReportedVisibilityLocked();
2559 }
2560 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002561
2562 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 }
2564
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002565 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2566 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2567 + ": " + msg + " / " + w.mAttrs.getTitle();
2568 if (where != null) {
2569 Slog.i(TAG, str, where);
2570 } else {
2571 Slog.i(TAG, str);
2572 }
2573 }
2574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2576 long origId = Binder.clearCallingIdentity();
2577 try {
2578 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002579 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 Surface.openTransaction();
2583 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002584 if (SHOW_TRANSACTIONS) logSurface(w,
2585 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 w.mSurface.setTransparentRegionHint(region);
2587 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002588 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 Surface.closeTransaction();
2590 }
2591 }
2592 }
2593 } finally {
2594 Binder.restoreCallingIdentity(origId);
2595 }
2596 }
2597
2598 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002599 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 Rect visibleInsets) {
2601 long origId = Binder.clearCallingIdentity();
2602 try {
2603 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002604 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 if (w != null) {
2606 w.mGivenInsetsPending = false;
2607 w.mGivenContentInsets.set(contentInsets);
2608 w.mGivenVisibleInsets.set(visibleInsets);
2609 w.mTouchableInsets = touchableInsets;
2610 mLayoutNeeded = true;
2611 performLayoutAndPlaceSurfacesLocked();
2612 }
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(origId);
2616 }
2617 }
Romain Guy06882f82009-06-10 13:36:04 -07002618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 public void getWindowDisplayFrame(Session session, IWindow client,
2620 Rect outDisplayFrame) {
2621 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002622 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 if (win == null) {
2624 outDisplayFrame.setEmpty();
2625 return;
2626 }
2627 outDisplayFrame.set(win.mDisplayFrame);
2628 }
2629 }
2630
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002631 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2632 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002633 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2634 window.mWallpaperX = x;
2635 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002636 window.mWallpaperXStep = xStep;
2637 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002638 if (updateWallpaperOffsetLocked(window, true)) {
2639 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002640 }
2641 }
2642 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002643
Dianne Hackborn75804932009-10-20 20:15:20 -07002644 void wallpaperCommandComplete(IBinder window, Bundle result) {
2645 synchronized (mWindowMap) {
2646 if (mWaitingOnWallpaper != null &&
2647 mWaitingOnWallpaper.mClient.asBinder() == window) {
2648 mWaitingOnWallpaper = null;
2649 mWindowMap.notifyAll();
2650 }
2651 }
2652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002653
Dianne Hackborn75804932009-10-20 20:15:20 -07002654 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2655 String action, int x, int y, int z, Bundle extras, boolean sync) {
2656 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2657 || window == mUpperWallpaperTarget) {
2658 boolean doWait = sync;
2659 int curTokenIndex = mWallpaperTokens.size();
2660 while (curTokenIndex > 0) {
2661 curTokenIndex--;
2662 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2663 int curWallpaperIndex = token.windows.size();
2664 while (curWallpaperIndex > 0) {
2665 curWallpaperIndex--;
2666 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2667 try {
2668 wallpaper.mClient.dispatchWallpaperCommand(action,
2669 x, y, z, extras, sync);
2670 // We only want to be synchronous with one wallpaper.
2671 sync = false;
2672 } catch (RemoteException e) {
2673 }
2674 }
2675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002676
Dianne Hackborn75804932009-10-20 20:15:20 -07002677 if (doWait) {
2678 // XXX Need to wait for result.
2679 }
2680 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002681
Dianne Hackborn75804932009-10-20 20:15:20 -07002682 return null;
2683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 public int relayoutWindow(Session session, IWindow client,
2686 WindowManager.LayoutParams attrs, int requestedWidth,
2687 int requestedHeight, int viewVisibility, boolean insetsPending,
2688 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002689 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 boolean displayed = false;
2691 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002692 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002696 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 if (win == null) {
2698 return 0;
2699 }
2700 win.mRequestedWidth = requestedWidth;
2701 win.mRequestedHeight = requestedHeight;
2702
2703 if (attrs != null) {
2704 mPolicy.adjustWindowParamsLw(attrs);
2705 }
Romain Guy06882f82009-06-10 13:36:04 -07002706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 int attrChanges = 0;
2708 int flagChanges = 0;
2709 if (attrs != null) {
2710 flagChanges = win.mAttrs.flags ^= attrs.flags;
2711 attrChanges = win.mAttrs.copyFrom(attrs);
2712 }
2713
Joe Onorato8a9b2202010-02-26 18:56:32 -08002714 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715
2716 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2717 win.mAlpha = attrs.alpha;
2718 }
2719
2720 final boolean scaledWindow =
2721 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2722
2723 if (scaledWindow) {
2724 // requested{Width|Height} Surface's physical size
2725 // attrs.{width|height} Size on screen
2726 win.mHScale = (attrs.width != requestedWidth) ?
2727 (attrs.width / (float)requestedWidth) : 1.0f;
2728 win.mVScale = (attrs.height != requestedHeight) ?
2729 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002730 } else {
2731 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002732 }
2733
2734 boolean imMayMove = (flagChanges&(
2735 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2736 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 boolean focusMayChange = win.mViewVisibility != viewVisibility
2739 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2740 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002741
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002742 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2743 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002745 win.mRelayoutCalled = true;
2746 final int oldVisibility = win.mViewVisibility;
2747 win.mViewVisibility = viewVisibility;
2748 if (viewVisibility == View.VISIBLE &&
2749 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2750 displayed = !win.isVisibleLw();
2751 if (win.mExiting) {
2752 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002753 if (win.mAnimation != null) {
2754 win.mAnimation.cancel();
2755 win.mAnimation = null;
2756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 }
2758 if (win.mDestroying) {
2759 win.mDestroying = false;
2760 mDestroySurface.remove(win);
2761 }
2762 if (oldVisibility == View.GONE) {
2763 win.mEnterAnimationPending = true;
2764 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002765 if (displayed) {
2766 if (win.mSurface != null && !win.mDrawPending
2767 && !win.mCommitDrawPending && !mDisplayFrozen
2768 && mPolicy.isScreenOn()) {
2769 applyEnterAnimationLocked(win);
2770 }
2771 if ((win.mAttrs.flags
2772 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2773 if (DEBUG_VISIBILITY) Slog.v(TAG,
2774 "Relayout window turning screen on: " + win);
2775 win.mTurnOnScreen = true;
2776 }
2777 int diff = 0;
2778 if (win.mConfiguration != mCurConfiguration
2779 && (win.mConfiguration == null
2780 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2781 win.mConfiguration = mCurConfiguration;
2782 if (DEBUG_CONFIGURATION) {
2783 Slog.i(TAG, "Window " + win + " visible with new config: "
2784 + win.mConfiguration + " / 0x"
2785 + Integer.toHexString(diff));
2786 }
2787 outConfig.setTo(mCurConfiguration);
2788 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002789 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2791 // To change the format, we need to re-build the surface.
2792 win.destroySurfaceLocked();
2793 displayed = true;
2794 }
2795 try {
2796 Surface surface = win.createSurfaceLocked();
2797 if (surface != null) {
2798 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002799 win.mReportDestroySurface = false;
2800 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002801 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002802 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002804 // For some reason there isn't a surface. Clear the
2805 // caller's object so they see the same state.
2806 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 }
2808 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002809 mInputMonitor.updateInputWindowsLw();
2810
Joe Onorato8a9b2202010-02-26 18:56:32 -08002811 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002812 + client + " (" + win.mAttrs.getTitle() + ")",
2813 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 Binder.restoreCallingIdentity(origId);
2815 return 0;
2816 }
2817 if (displayed) {
2818 focusMayChange = true;
2819 }
2820 if (win.mAttrs.type == TYPE_INPUT_METHOD
2821 && mInputMethodWindow == null) {
2822 mInputMethodWindow = win;
2823 imMayMove = true;
2824 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002825 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2826 && win.mAppToken != null
2827 && win.mAppToken.startingWindow != null) {
2828 // Special handling of starting window over the base
2829 // window of the app: propagate lock screen flags to it,
2830 // to provide the correct semantics while starting.
2831 final int mask =
2832 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002833 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2834 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002835 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2836 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 } else {
2839 win.mEnterAnimationPending = false;
2840 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002841 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002842 + ": mExiting=" + win.mExiting
2843 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 // If we are not currently running the exit animation, we
2845 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002846 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 // Try starting an animation; if there isn't one, we
2848 // can destroy the surface right away.
2849 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2850 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2851 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2852 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002853 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002855 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 } else if (win.isAnimating()) {
2858 // Currently in a hide animation... turn this into
2859 // an exit.
2860 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002861 } else if (win == mWallpaperTarget) {
2862 // If the wallpaper is currently behind this
2863 // window, we need to change both of them inside
2864 // of a transaction to avoid artifacts.
2865 win.mExiting = true;
2866 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 } else {
2868 if (mInputMethodWindow == win) {
2869 mInputMethodWindow = null;
2870 }
2871 win.destroySurfaceLocked();
2872 }
2873 }
2874 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002875
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002876 if (win.mSurface == null || (win.getAttrs().flags
2877 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2878 || win.mSurfacePendingDestroy) {
2879 // We are being called from a local process, which
2880 // means outSurface holds its current surface. Ensure the
2881 // surface object is cleared, but we don't want it actually
2882 // destroyed at this point.
2883 win.mSurfacePendingDestroy = false;
2884 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002885 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002886 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002887 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002888 "Keeping surface, will report destroy: " + win);
2889 win.mReportDestroySurface = true;
2890 outSurface.copyFrom(win.mSurface);
2891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 }
2893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 if (focusMayChange) {
2895 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2896 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 imMayMove = false;
2898 }
2899 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2900 }
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002902 // updateFocusedWindowLocked() already assigned layers so we only need to
2903 // reassign them at this point if the IM window state gets shuffled
2904 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002907 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2908 // Little hack here -- we -should- be able to rely on the
2909 // function to return true if the IME has moved and needs
2910 // its layer recomputed. However, if the IME was hidden
2911 // and isn't actually moved in the list, its layer may be
2912 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 assignLayers = true;
2914 }
2915 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002916 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002917 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002918 assignLayers = true;
2919 }
2920 }
Romain Guy06882f82009-06-10 13:36:04 -07002921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 mLayoutNeeded = true;
2923 win.mGivenInsetsPending = insetsPending;
2924 if (assignLayers) {
2925 assignLayersLocked();
2926 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002927 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002929 if (displayed && win.mIsWallpaper) {
2930 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002931 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 if (win.mAppToken != null) {
2934 win.mAppToken.updateReportedVisibilityLocked();
2935 }
2936 outFrame.set(win.mFrame);
2937 outContentInsets.set(win.mContentInsets);
2938 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002939 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002941 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 + ", requestedHeight=" + requestedHeight
2943 + ", viewVisibility=" + viewVisibility
2944 + "\nRelayout returning frame=" + outFrame
2945 + ", surface=" + outSurface);
2946
Joe Onorato8a9b2202010-02-26 18:56:32 -08002947 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2949
2950 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002951
2952 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 }
2954
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002955 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 sendNewConfiguration();
2957 }
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2962 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2963 }
2964
2965 public void finishDrawingWindow(Session session, IWindow client) {
2966 final long origId = Binder.clearCallingIdentity();
2967 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002968 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002970 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2971 adjustWallpaperWindowsLocked();
2972 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 mLayoutNeeded = true;
2974 performLayoutAndPlaceSurfacesLocked();
2975 }
2976 }
2977 Binder.restoreCallingIdentity(origId);
2978 }
2979
2980 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002981 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 + (lp != null ? lp.packageName : null)
2983 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2984 if (lp != null && lp.windowAnimations != 0) {
2985 // If this is a system resource, don't try to load it from the
2986 // application resources. It is nice to avoid loading application
2987 // resources if we can.
2988 String packageName = lp.packageName != null ? lp.packageName : "android";
2989 int resId = lp.windowAnimations;
2990 if ((resId&0xFF000000) == 0x01000000) {
2991 packageName = "android";
2992 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002993 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 + packageName);
2995 return AttributeCache.instance().get(packageName, resId,
2996 com.android.internal.R.styleable.WindowAnimation);
2997 }
2998 return null;
2999 }
Romain Guy06882f82009-06-10 13:36:04 -07003000
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003001 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003002 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003003 + packageName + " resId=0x" + Integer.toHexString(resId));
3004 if (packageName != null) {
3005 if ((resId&0xFF000000) == 0x01000000) {
3006 packageName = "android";
3007 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003008 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003009 + packageName);
3010 return AttributeCache.instance().get(packageName, resId,
3011 com.android.internal.R.styleable.WindowAnimation);
3012 }
3013 return null;
3014 }
3015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 private void applyEnterAnimationLocked(WindowState win) {
3017 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3018 if (win.mEnterAnimationPending) {
3019 win.mEnterAnimationPending = false;
3020 transit = WindowManagerPolicy.TRANSIT_ENTER;
3021 }
3022
3023 applyAnimationLocked(win, transit, true);
3024 }
3025
3026 private boolean applyAnimationLocked(WindowState win,
3027 int transit, boolean isEntrance) {
3028 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3029 // If we are trying to apply an animation, but already running
3030 // an animation of the same type, then just leave that one alone.
3031 return true;
3032 }
Romain Guy06882f82009-06-10 13:36:04 -07003033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 // Only apply an animation if the display isn't frozen. If it is
3035 // frozen, there is no reason to animate and it can cause strange
3036 // artifacts when we unfreeze the display if some different animation
3037 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003038 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 int anim = mPolicy.selectAnimationLw(win, transit);
3040 int attr = -1;
3041 Animation a = null;
3042 if (anim != 0) {
3043 a = AnimationUtils.loadAnimation(mContext, anim);
3044 } else {
3045 switch (transit) {
3046 case WindowManagerPolicy.TRANSIT_ENTER:
3047 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3048 break;
3049 case WindowManagerPolicy.TRANSIT_EXIT:
3050 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3051 break;
3052 case WindowManagerPolicy.TRANSIT_SHOW:
3053 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3054 break;
3055 case WindowManagerPolicy.TRANSIT_HIDE:
3056 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3057 break;
3058 }
3059 if (attr >= 0) {
3060 a = loadAnimation(win.mAttrs, attr);
3061 }
3062 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003063 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3065 + " mAnimation=" + win.mAnimation
3066 + " isEntrance=" + isEntrance);
3067 if (a != null) {
3068 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003069 RuntimeException e = null;
3070 if (!HIDE_STACK_CRAWLS) {
3071 e = new RuntimeException();
3072 e.fillInStackTrace();
3073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003074 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003075 }
3076 win.setAnimation(a);
3077 win.mAnimationIsEntrance = isEntrance;
3078 }
3079 } else {
3080 win.clearAnimation();
3081 }
3082
3083 return win.mAnimation != null;
3084 }
3085
3086 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3087 int anim = 0;
3088 Context context = mContext;
3089 if (animAttr >= 0) {
3090 AttributeCache.Entry ent = getCachedAnimations(lp);
3091 if (ent != null) {
3092 context = ent.context;
3093 anim = ent.array.getResourceId(animAttr, 0);
3094 }
3095 }
3096 if (anim != 0) {
3097 return AnimationUtils.loadAnimation(context, anim);
3098 }
3099 return null;
3100 }
Romain Guy06882f82009-06-10 13:36:04 -07003101
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003102 private Animation loadAnimation(String packageName, int resId) {
3103 int anim = 0;
3104 Context context = mContext;
3105 if (resId >= 0) {
3106 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3107 if (ent != null) {
3108 context = ent.context;
3109 anim = resId;
3110 }
3111 }
3112 if (anim != 0) {
3113 return AnimationUtils.loadAnimation(context, anim);
3114 }
3115 return null;
3116 }
3117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 private boolean applyAnimationLocked(AppWindowToken wtoken,
3119 WindowManager.LayoutParams lp, int transit, boolean enter) {
3120 // Only apply an animation if the display isn't frozen. If it is
3121 // frozen, there is no reason to animate and it can cause strange
3122 // artifacts when we unfreeze the display if some different animation
3123 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003124 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003125 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003126 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003127 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003128 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003129 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003130 } else if (mNextAppTransitionPackage != null) {
3131 a = loadAnimation(mNextAppTransitionPackage, enter ?
3132 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003133 } else {
3134 int animAttr = 0;
3135 switch (transit) {
3136 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3137 animAttr = enter
3138 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3139 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3140 break;
3141 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3142 animAttr = enter
3143 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3144 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3145 break;
3146 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3147 animAttr = enter
3148 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3149 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3150 break;
3151 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3152 animAttr = enter
3153 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3154 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3155 break;
3156 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3157 animAttr = enter
3158 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3159 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3160 break;
3161 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3162 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003163 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003164 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3165 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003166 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003167 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003168 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3169 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003170 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003171 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003172 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003173 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3174 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3175 break;
3176 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3177 animAttr = enter
3178 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3179 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3180 break;
3181 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3182 animAttr = enter
3183 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3184 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003185 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003186 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003187 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003188 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003189 + " anim=" + a
3190 + " animAttr=0x" + Integer.toHexString(animAttr)
3191 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 if (a != null) {
3194 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003195 RuntimeException e = null;
3196 if (!HIDE_STACK_CRAWLS) {
3197 e = new RuntimeException();
3198 e.fillInStackTrace();
3199 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003200 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 }
3202 wtoken.setAnimation(a);
3203 }
3204 } else {
3205 wtoken.clearAnimation();
3206 }
3207
3208 return wtoken.animation != null;
3209 }
3210
3211 // -------------------------------------------------------------
3212 // Application Window Tokens
3213 // -------------------------------------------------------------
3214
3215 public void validateAppTokens(List tokens) {
3216 int v = tokens.size()-1;
3217 int m = mAppTokens.size()-1;
3218 while (v >= 0 && m >= 0) {
3219 AppWindowToken wtoken = mAppTokens.get(m);
3220 if (wtoken.removed) {
3221 m--;
3222 continue;
3223 }
3224 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003225 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3227 }
3228 v--;
3229 m--;
3230 }
3231 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003232 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 v--;
3234 }
3235 while (m >= 0) {
3236 AppWindowToken wtoken = mAppTokens.get(m);
3237 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003238 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 }
3240 m--;
3241 }
3242 }
3243
3244 boolean checkCallingPermission(String permission, String func) {
3245 // Quick check: if the calling permission is me, it's all okay.
3246 if (Binder.getCallingPid() == Process.myPid()) {
3247 return true;
3248 }
Romain Guy06882f82009-06-10 13:36:04 -07003249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 if (mContext.checkCallingPermission(permission)
3251 == PackageManager.PERMISSION_GRANTED) {
3252 return true;
3253 }
3254 String msg = "Permission Denial: " + func + " from pid="
3255 + Binder.getCallingPid()
3256 + ", uid=" + Binder.getCallingUid()
3257 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003258 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 return false;
3260 }
Romain Guy06882f82009-06-10 13:36:04 -07003261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 AppWindowToken findAppWindowToken(IBinder token) {
3263 WindowToken wtoken = mTokenMap.get(token);
3264 if (wtoken == null) {
3265 return null;
3266 }
3267 return wtoken.appWindowToken;
3268 }
Romain Guy06882f82009-06-10 13:36:04 -07003269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 public void addWindowToken(IBinder token, int type) {
3271 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3272 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003273 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 }
Romain Guy06882f82009-06-10 13:36:04 -07003275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 synchronized(mWindowMap) {
3277 WindowToken wtoken = mTokenMap.get(token);
3278 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003279 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 return;
3281 }
3282 wtoken = new WindowToken(token, type, true);
3283 mTokenMap.put(token, wtoken);
3284 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003285 if (type == TYPE_WALLPAPER) {
3286 mWallpaperTokens.add(wtoken);
3287 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 }
3289 }
Romain Guy06882f82009-06-10 13:36:04 -07003290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 public void removeWindowToken(IBinder token) {
3292 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3293 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003294 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 }
3296
3297 final long origId = Binder.clearCallingIdentity();
3298 synchronized(mWindowMap) {
3299 WindowToken wtoken = mTokenMap.remove(token);
3300 mTokenList.remove(wtoken);
3301 if (wtoken != null) {
3302 boolean delayed = false;
3303 if (!wtoken.hidden) {
3304 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 final int N = wtoken.windows.size();
3307 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 for (int i=0; i<N; i++) {
3310 WindowState win = wtoken.windows.get(i);
3311
3312 if (win.isAnimating()) {
3313 delayed = true;
3314 }
Romain Guy06882f82009-06-10 13:36:04 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 if (win.isVisibleNow()) {
3317 applyAnimationLocked(win,
3318 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 changed = true;
3320 }
3321 }
3322
3323 if (changed) {
3324 mLayoutNeeded = true;
3325 performLayoutAndPlaceSurfacesLocked();
3326 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3327 }
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 if (delayed) {
3330 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003331 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3332 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 }
3334 }
Romain Guy06882f82009-06-10 13:36:04 -07003335
Jeff Brownc5ed5912010-07-14 18:48:53 -07003336 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003338 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 }
3340 }
3341 Binder.restoreCallingIdentity(origId);
3342 }
3343
3344 public void addAppToken(int addPos, IApplicationToken token,
3345 int groupId, int requestedOrientation, boolean fullscreen) {
3346 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3347 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003348 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 }
Jeff Brown349703e2010-06-22 01:27:15 -07003350
3351 // Get the dispatching timeout here while we are not holding any locks so that it
3352 // can be cached by the AppWindowToken. The timeout value is used later by the
3353 // input dispatcher in code that does hold locks. If we did not cache the value
3354 // here we would run the chance of introducing a deadlock between the window manager
3355 // (which holds locks while updating the input dispatcher state) and the activity manager
3356 // (which holds locks while querying the application token).
3357 long inputDispatchingTimeoutNanos;
3358 try {
3359 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3360 } catch (RemoteException ex) {
3361 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3362 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3363 }
Romain Guy06882f82009-06-10 13:36:04 -07003364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 synchronized(mWindowMap) {
3366 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3367 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003368 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 return;
3370 }
3371 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003372 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 wtoken.groupId = groupId;
3374 wtoken.appFullscreen = fullscreen;
3375 wtoken.requestedOrientation = requestedOrientation;
3376 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003377 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 mTokenMap.put(token.asBinder(), wtoken);
3379 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 // Application tokens start out hidden.
3382 wtoken.hidden = true;
3383 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 //dump();
3386 }
3387 }
Romain Guy06882f82009-06-10 13:36:04 -07003388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 public void setAppGroupId(IBinder token, int groupId) {
3390 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3391 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003392 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 }
3394
3395 synchronized(mWindowMap) {
3396 AppWindowToken wtoken = findAppWindowToken(token);
3397 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003398 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 return;
3400 }
3401 wtoken.groupId = groupId;
3402 }
3403 }
Romain Guy06882f82009-06-10 13:36:04 -07003404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 public int getOrientationFromWindowsLocked() {
3406 int pos = mWindows.size() - 1;
3407 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003408 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 pos--;
3410 if (wtoken.mAppToken != null) {
3411 // We hit an application window. so the orientation will be determined by the
3412 // app window. No point in continuing further.
3413 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3414 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003415 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003416 continue;
3417 }
3418 int req = wtoken.mAttrs.screenOrientation;
3419 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3420 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3421 continue;
3422 } else {
3423 return req;
3424 }
3425 }
3426 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3427 }
Romain Guy06882f82009-06-10 13:36:04 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003430 int pos = mAppTokens.size() - 1;
3431 int curGroup = 0;
3432 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3433 boolean findingBehind = false;
3434 boolean haveGroup = false;
3435 boolean lastFullscreen = false;
3436 while (pos >= 0) {
3437 AppWindowToken wtoken = mAppTokens.get(pos);
3438 pos--;
3439 // if we're about to tear down this window and not seek for
3440 // the behind activity, don't use it for orientation
3441 if (!findingBehind
3442 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3443 continue;
3444 }
3445
3446 if (!haveGroup) {
3447 // We ignore any hidden applications on the top.
3448 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003449 continue;
3450 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003451 haveGroup = true;
3452 curGroup = wtoken.groupId;
3453 lastOrientation = wtoken.requestedOrientation;
3454 } else if (curGroup != wtoken.groupId) {
3455 // If we have hit a new application group, and the bottom
3456 // of the previous group didn't explicitly say to use
3457 // the orientation behind it, and the last app was
3458 // full screen, then we'll stick with the
3459 // user's orientation.
3460 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3461 && lastFullscreen) {
3462 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003465 int or = wtoken.requestedOrientation;
3466 // If this application is fullscreen, and didn't explicitly say
3467 // to use the orientation behind it, then just take whatever
3468 // orientation it has and ignores whatever is under it.
3469 lastFullscreen = wtoken.appFullscreen;
3470 if (lastFullscreen
3471 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3472 return or;
3473 }
3474 // If this application has requested an explicit orientation,
3475 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003476 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3477 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003478 return or;
3479 }
3480 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3481 }
3482 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 }
Romain Guy06882f82009-06-10 13:36:04 -07003484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003486 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003487 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3488 "updateOrientationFromAppTokens()")) {
3489 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3490 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003491
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003492 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003494
3495 synchronized(mWindowMap) {
3496 if (updateOrientationFromAppTokensLocked()) {
3497 if (freezeThisOneIfNeeded != null) {
3498 AppWindowToken wtoken = findAppWindowToken(
3499 freezeThisOneIfNeeded);
3500 if (wtoken != null) {
3501 startAppFreezingScreenLocked(wtoken,
3502 ActivityInfo.CONFIG_ORIENTATION);
3503 }
3504 }
3505 config = computeNewConfigurationLocked();
3506
3507 } else if (currentConfig != null) {
3508 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003509 // state mismatches the activity manager's, update it,
3510 // disregarding font scale, which should remain set to
3511 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003512 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003513 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003514 if (computeNewConfigurationLocked(mTempConfiguration)) {
3515 if (currentConfig.diff(mTempConfiguration) != 0) {
3516 mWaitingForConfig = true;
3517 mLayoutNeeded = true;
3518 startFreezingDisplayLocked();
3519 config = new Configuration(mTempConfiguration);
3520 }
3521 }
3522 }
3523 }
3524
Dianne Hackborncfaef692009-06-15 14:24:44 -07003525 Binder.restoreCallingIdentity(ident);
3526 return config;
3527 }
3528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003530 * Determine the new desired orientation of the display, returning
3531 * a non-null new Configuration if it has changed from the current
3532 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3533 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3534 * SCREEN. This will typically be done for you if you call
3535 * sendNewConfiguration().
3536 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 * The orientation is computed from non-application windows first. If none of
3538 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003539 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3541 * android.os.IBinder)
3542 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003543 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003544 if (mDisplayFrozen) {
3545 // If the display is frozen, some activities may be in the middle
3546 // of restarting, and thus have removed their old window. If the
3547 // window has the flag to hide the lock screen, then the lock screen
3548 // can re-appear and inflict its own orientation on us. Keep the
3549 // orientation stable until this all settles down.
3550 return false;
3551 }
3552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 long ident = Binder.clearCallingIdentity();
3555 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003556 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 mForcedAppOrientation = req;
3560 //send a message to Policy indicating orientation change to take
3561 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003562 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003563 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3564 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3565 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 }
3567 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003568
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003569 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 } finally {
3571 Binder.restoreCallingIdentity(ident);
3572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003573 }
Romain Guy06882f82009-06-10 13:36:04 -07003574
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003575 int computeForcedAppOrientationLocked() {
3576 int req = getOrientationFromWindowsLocked();
3577 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3578 req = getOrientationFromAppTokensLocked();
3579 }
3580 return req;
3581 }
Romain Guy06882f82009-06-10 13:36:04 -07003582
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003583 public void setNewConfiguration(Configuration config) {
3584 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3585 "setNewConfiguration()")) {
3586 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3587 }
3588
3589 synchronized(mWindowMap) {
3590 mCurConfiguration = new Configuration(config);
3591 mWaitingForConfig = false;
3592 performLayoutAndPlaceSurfacesLocked();
3593 }
3594 }
3595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3598 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 }
Romain Guy06882f82009-06-10 13:36:04 -07003601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 synchronized(mWindowMap) {
3603 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3604 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003605 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 return;
3607 }
Romain Guy06882f82009-06-10 13:36:04 -07003608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 wtoken.requestedOrientation = requestedOrientation;
3610 }
3611 }
Romain Guy06882f82009-06-10 13:36:04 -07003612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 public int getAppOrientation(IApplicationToken token) {
3614 synchronized(mWindowMap) {
3615 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3616 if (wtoken == null) {
3617 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3618 }
Romain Guy06882f82009-06-10 13:36:04 -07003619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 return wtoken.requestedOrientation;
3621 }
3622 }
Romain Guy06882f82009-06-10 13:36:04 -07003623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3625 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3626 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003627 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 }
3629
3630 synchronized(mWindowMap) {
3631 boolean changed = false;
3632 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003633 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 changed = mFocusedApp != null;
3635 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003636 if (changed) {
3637 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 } else {
3640 AppWindowToken newFocus = findAppWindowToken(token);
3641 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003642 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003643 return;
3644 }
3645 changed = mFocusedApp != newFocus;
3646 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003647 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003648 if (changed) {
3649 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 }
3652
3653 if (moveFocusNow && changed) {
3654 final long origId = Binder.clearCallingIdentity();
3655 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3656 Binder.restoreCallingIdentity(origId);
3657 }
3658 }
3659 }
3660
3661 public void prepareAppTransition(int transit) {
3662 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3663 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003664 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 }
Romain Guy06882f82009-06-10 13:36:04 -07003666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003668 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 TAG, "Prepare app transition: transit=" + transit
3670 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003671 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003672 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3673 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003675 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3676 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3677 // Opening a new task always supersedes a close for the anim.
3678 mNextAppTransition = transit;
3679 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3680 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3681 // Opening a new activity always supersedes a close for the anim.
3682 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 }
3684 mAppTransitionReady = false;
3685 mAppTransitionTimeout = false;
3686 mStartingIconInTransition = false;
3687 mSkipAppTransitionAnimation = false;
3688 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3689 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3690 5000);
3691 }
3692 }
3693 }
3694
3695 public int getPendingAppTransition() {
3696 return mNextAppTransition;
3697 }
Romain Guy06882f82009-06-10 13:36:04 -07003698
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003699 public void overridePendingAppTransition(String packageName,
3700 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003701 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003702 mNextAppTransitionPackage = packageName;
3703 mNextAppTransitionEnter = enterAnim;
3704 mNextAppTransitionExit = exitAnim;
3705 }
3706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 public void executeAppTransition() {
3709 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3710 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003711 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 }
Romain Guy06882f82009-06-10 13:36:04 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003715 if (DEBUG_APP_TRANSITIONS) {
3716 RuntimeException e = new RuntimeException("here");
3717 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003718 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003719 + mNextAppTransition, e);
3720 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003721 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 mAppTransitionReady = true;
3723 final long origId = Binder.clearCallingIdentity();
3724 performLayoutAndPlaceSurfacesLocked();
3725 Binder.restoreCallingIdentity(origId);
3726 }
3727 }
3728 }
3729
3730 public void setAppStartingWindow(IBinder token, String pkg,
3731 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003732 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3734 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003735 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 }
3737
3738 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003739 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3741 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 AppWindowToken wtoken = findAppWindowToken(token);
3744 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003745 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 return;
3747 }
3748
3749 // If the display is frozen, we won't do anything until the
3750 // actual window is displayed so there is no reason to put in
3751 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003752 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 return;
3754 }
Romain Guy06882f82009-06-10 13:36:04 -07003755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 if (wtoken.startingData != null) {
3757 return;
3758 }
Romain Guy06882f82009-06-10 13:36:04 -07003759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 if (transferFrom != null) {
3761 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3762 if (ttoken != null) {
3763 WindowState startingWindow = ttoken.startingWindow;
3764 if (startingWindow != null) {
3765 if (mStartingIconInTransition) {
3766 // In this case, the starting icon has already
3767 // been displayed, so start letting windows get
3768 // shown immediately without any more transitions.
3769 mSkipAppTransitionAnimation = true;
3770 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003771 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 "Moving existing starting from " + ttoken
3773 + " to " + wtoken);
3774 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 // Transfer the starting window over to the new
3777 // token.
3778 wtoken.startingData = ttoken.startingData;
3779 wtoken.startingView = ttoken.startingView;
3780 wtoken.startingWindow = startingWindow;
3781 ttoken.startingData = null;
3782 ttoken.startingView = null;
3783 ttoken.startingWindow = null;
3784 ttoken.startingMoved = true;
3785 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003786 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003788 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003789 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003791 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 ttoken.windows.remove(startingWindow);
3793 ttoken.allAppWindows.remove(startingWindow);
3794 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 // Propagate other interesting state between the
3797 // tokens. If the old token is displayed, we should
3798 // immediately force the new one to be displayed. If
3799 // it is animating, we need to move that animation to
3800 // the new one.
3801 if (ttoken.allDrawn) {
3802 wtoken.allDrawn = true;
3803 }
3804 if (ttoken.firstWindowDrawn) {
3805 wtoken.firstWindowDrawn = true;
3806 }
3807 if (!ttoken.hidden) {
3808 wtoken.hidden = false;
3809 wtoken.hiddenRequested = false;
3810 wtoken.willBeHidden = false;
3811 }
3812 if (wtoken.clientHidden != ttoken.clientHidden) {
3813 wtoken.clientHidden = ttoken.clientHidden;
3814 wtoken.sendAppVisibilityToClients();
3815 }
3816 if (ttoken.animation != null) {
3817 wtoken.animation = ttoken.animation;
3818 wtoken.animating = ttoken.animating;
3819 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3820 ttoken.animation = null;
3821 ttoken.animLayerAdjustment = 0;
3822 wtoken.updateLayers();
3823 ttoken.updateLayers();
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 mLayoutNeeded = true;
3828 performLayoutAndPlaceSurfacesLocked();
3829 Binder.restoreCallingIdentity(origId);
3830 return;
3831 } else if (ttoken.startingData != null) {
3832 // The previous app was getting ready to show a
3833 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003834 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 "Moving pending starting from " + ttoken
3836 + " to " + wtoken);
3837 wtoken.startingData = ttoken.startingData;
3838 ttoken.startingData = null;
3839 ttoken.startingMoved = true;
3840 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3841 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3842 // want to process the message ASAP, before any other queued
3843 // messages.
3844 mH.sendMessageAtFrontOfQueue(m);
3845 return;
3846 }
3847 }
3848 }
3849
3850 // There is no existing starting window, and the caller doesn't
3851 // want us to create one, so that's it!
3852 if (!createIfNeeded) {
3853 return;
3854 }
Romain Guy06882f82009-06-10 13:36:04 -07003855
Dianne Hackborn284ac932009-08-28 10:34:25 -07003856 // If this is a translucent or wallpaper window, then don't
3857 // show a starting window -- the current effect (a full-screen
3858 // opaque starting window that fades away to the real contents
3859 // when it is ready) does not work for this.
3860 if (theme != 0) {
3861 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3862 com.android.internal.R.styleable.Window);
3863 if (ent.array.getBoolean(
3864 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3865 return;
3866 }
3867 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003868 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3869 return;
3870 }
3871 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003872 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3873 return;
3874 }
3875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003877 mStartingIconInTransition = true;
3878 wtoken.startingData = new StartingData(
3879 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003880 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003881 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3882 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3883 // want to process the message ASAP, before any other queued
3884 // messages.
3885 mH.sendMessageAtFrontOfQueue(m);
3886 }
3887 }
3888
3889 public void setAppWillBeHidden(IBinder token) {
3890 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3891 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003892 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 }
3894
3895 AppWindowToken wtoken;
3896
3897 synchronized(mWindowMap) {
3898 wtoken = findAppWindowToken(token);
3899 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003900 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 -08003901 return;
3902 }
3903 wtoken.willBeHidden = true;
3904 }
3905 }
Romain Guy06882f82009-06-10 13:36:04 -07003906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3908 boolean visible, int transit, boolean performLayout) {
3909 boolean delayed = false;
3910
3911 if (wtoken.clientHidden == visible) {
3912 wtoken.clientHidden = !visible;
3913 wtoken.sendAppVisibilityToClients();
3914 }
Romain Guy06882f82009-06-10 13:36:04 -07003915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 wtoken.willBeHidden = false;
3917 if (wtoken.hidden == visible) {
3918 final int N = wtoken.allAppWindows.size();
3919 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003920 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3922 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003924 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003925
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003926 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 if (wtoken.animation == sDummyAnimation) {
3928 wtoken.animation = null;
3929 }
3930 applyAnimationLocked(wtoken, lp, transit, visible);
3931 changed = true;
3932 if (wtoken.animation != null) {
3933 delayed = runningAppAnimation = true;
3934 }
3935 }
Romain Guy06882f82009-06-10 13:36:04 -07003936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003937 for (int i=0; i<N; i++) {
3938 WindowState win = wtoken.allAppWindows.get(i);
3939 if (win == wtoken.startingWindow) {
3940 continue;
3941 }
3942
3943 if (win.isAnimating()) {
3944 delayed = true;
3945 }
Romain Guy06882f82009-06-10 13:36:04 -07003946
Joe Onorato8a9b2202010-02-26 18:56:32 -08003947 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 //win.dump(" ");
3949 if (visible) {
3950 if (!win.isVisibleNow()) {
3951 if (!runningAppAnimation) {
3952 applyAnimationLocked(win,
3953 WindowManagerPolicy.TRANSIT_ENTER, true);
3954 }
3955 changed = true;
3956 }
3957 } else if (win.isVisibleNow()) {
3958 if (!runningAppAnimation) {
3959 applyAnimationLocked(win,
3960 WindowManagerPolicy.TRANSIT_EXIT, false);
3961 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 changed = true;
3963 }
3964 }
3965
3966 wtoken.hidden = wtoken.hiddenRequested = !visible;
3967 if (!visible) {
3968 unsetAppFreezingScreenLocked(wtoken, true, true);
3969 } else {
3970 // If we are being set visible, and the starting window is
3971 // not yet displayed, then make sure it doesn't get displayed.
3972 WindowState swin = wtoken.startingWindow;
3973 if (swin != null && (swin.mDrawPending
3974 || swin.mCommitDrawPending)) {
3975 swin.mPolicyVisibility = false;
3976 swin.mPolicyVisibilityAfterAnim = false;
3977 }
3978 }
Romain Guy06882f82009-06-10 13:36:04 -07003979
Joe Onorato8a9b2202010-02-26 18:56:32 -08003980 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3982 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003983
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003984 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003986 if (performLayout) {
3987 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3988 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003989 } else {
3990 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 }
3993 }
3994
3995 if (wtoken.animation != null) {
3996 delayed = true;
3997 }
Romain Guy06882f82009-06-10 13:36:04 -07003998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 return delayed;
4000 }
4001
4002 public void setAppVisibility(IBinder token, boolean visible) {
4003 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4004 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004005 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 }
4007
4008 AppWindowToken wtoken;
4009
4010 synchronized(mWindowMap) {
4011 wtoken = findAppWindowToken(token);
4012 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 return;
4015 }
4016
4017 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004018 RuntimeException e = null;
4019 if (!HIDE_STACK_CRAWLS) {
4020 e = new RuntimeException();
4021 e.fillInStackTrace();
4022 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004023 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 + "): mNextAppTransition=" + mNextAppTransition
4025 + " hidden=" + wtoken.hidden
4026 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4027 }
Romain Guy06882f82009-06-10 13:36:04 -07004028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 // If we are preparing an app transition, then delay changing
4030 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004031 if (!mDisplayFrozen && mPolicy.isScreenOn()
4032 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 // Already in requested state, don't do anything more.
4034 if (wtoken.hiddenRequested != visible) {
4035 return;
4036 }
4037 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004038
Joe Onorato8a9b2202010-02-26 18:56:32 -08004039 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 TAG, "Setting dummy animation on: " + wtoken);
4041 wtoken.setDummyAnimation();
4042 mOpeningApps.remove(wtoken);
4043 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004044 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 wtoken.inPendingTransaction = true;
4046 if (visible) {
4047 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 wtoken.startingDisplayed = false;
4049 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004050
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004051 // If the token is currently hidden (should be the
4052 // common case), then we need to set up to wait for
4053 // its windows to be ready.
4054 if (wtoken.hidden) {
4055 wtoken.allDrawn = false;
4056 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004057
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004058 if (wtoken.clientHidden) {
4059 // In the case where we are making an app visible
4060 // but holding off for a transition, we still need
4061 // to tell the client to make its windows visible so
4062 // they get drawn. Otherwise, we will wait on
4063 // performing the transition until all windows have
4064 // been drawn, they never will be, and we are sad.
4065 wtoken.clientHidden = false;
4066 wtoken.sendAppVisibilityToClients();
4067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 }
4069 } else {
4070 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004071
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004072 // If the token is currently visible (should be the
4073 // common case), then set up to wait for it to be hidden.
4074 if (!wtoken.hidden) {
4075 wtoken.waitingToHide = true;
4076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 }
4078 return;
4079 }
Romain Guy06882f82009-06-10 13:36:04 -07004080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004082 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 wtoken.updateReportedVisibilityLocked();
4084 Binder.restoreCallingIdentity(origId);
4085 }
4086 }
4087
4088 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4089 boolean unfreezeSurfaceNow, boolean force) {
4090 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004091 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 + " force=" + force);
4093 final int N = wtoken.allAppWindows.size();
4094 boolean unfrozeWindows = false;
4095 for (int i=0; i<N; i++) {
4096 WindowState w = wtoken.allAppWindows.get(i);
4097 if (w.mAppFreezing) {
4098 w.mAppFreezing = false;
4099 if (w.mSurface != null && !w.mOrientationChanging) {
4100 w.mOrientationChanging = true;
4101 }
4102 unfrozeWindows = true;
4103 }
4104 }
4105 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004106 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004107 wtoken.freezingScreen = false;
4108 mAppsFreezingScreen--;
4109 }
4110 if (unfreezeSurfaceNow) {
4111 if (unfrozeWindows) {
4112 mLayoutNeeded = true;
4113 performLayoutAndPlaceSurfacesLocked();
4114 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004115 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117 }
4118 }
Romain Guy06882f82009-06-10 13:36:04 -07004119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004120 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4121 int configChanges) {
4122 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004123 RuntimeException e = null;
4124 if (!HIDE_STACK_CRAWLS) {
4125 e = new RuntimeException();
4126 e.fillInStackTrace();
4127 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004128 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 + ": hidden=" + wtoken.hidden + " freezing="
4130 + wtoken.freezingScreen, e);
4131 }
4132 if (!wtoken.hiddenRequested) {
4133 if (!wtoken.freezingScreen) {
4134 wtoken.freezingScreen = true;
4135 mAppsFreezingScreen++;
4136 if (mAppsFreezingScreen == 1) {
4137 startFreezingDisplayLocked();
4138 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4139 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4140 5000);
4141 }
4142 }
4143 final int N = wtoken.allAppWindows.size();
4144 for (int i=0; i<N; i++) {
4145 WindowState w = wtoken.allAppWindows.get(i);
4146 w.mAppFreezing = true;
4147 }
4148 }
4149 }
Romain Guy06882f82009-06-10 13:36:04 -07004150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 public void startAppFreezingScreen(IBinder token, int configChanges) {
4152 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4153 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004154 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004155 }
4156
4157 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004158 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004159 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 return;
4161 }
Romain Guy06882f82009-06-10 13:36:04 -07004162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 AppWindowToken wtoken = findAppWindowToken(token);
4164 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004165 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 return;
4167 }
4168 final long origId = Binder.clearCallingIdentity();
4169 startAppFreezingScreenLocked(wtoken, configChanges);
4170 Binder.restoreCallingIdentity(origId);
4171 }
4172 }
Romain Guy06882f82009-06-10 13:36:04 -07004173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 public void stopAppFreezingScreen(IBinder token, boolean force) {
4175 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4176 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004177 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004178 }
4179
4180 synchronized(mWindowMap) {
4181 AppWindowToken wtoken = findAppWindowToken(token);
4182 if (wtoken == null || wtoken.appToken == null) {
4183 return;
4184 }
4185 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004186 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4188 unsetAppFreezingScreenLocked(wtoken, true, force);
4189 Binder.restoreCallingIdentity(origId);
4190 }
4191 }
Romain Guy06882f82009-06-10 13:36:04 -07004192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 public void removeAppToken(IBinder token) {
4194 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4195 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004196 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 }
4198
4199 AppWindowToken wtoken = null;
4200 AppWindowToken startingToken = null;
4201 boolean delayed = false;
4202
4203 final long origId = Binder.clearCallingIdentity();
4204 synchronized(mWindowMap) {
4205 WindowToken basewtoken = mTokenMap.remove(token);
4206 mTokenList.remove(basewtoken);
4207 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004208 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004209 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 wtoken.inPendingTransaction = false;
4211 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004212 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 if (mClosingApps.contains(wtoken)) {
4214 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004215 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004217 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 delayed = true;
4219 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004220 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 TAG, "Removing app " + wtoken + " delayed=" + delayed
4222 + " animation=" + wtoken.animation
4223 + " animating=" + wtoken.animating);
4224 if (delayed) {
4225 // set the token aside because it has an active animation to be finished
4226 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004227 } else {
4228 // Make sure there is no animation running on this token,
4229 // so any windows associated with it will be removed as
4230 // soon as their animations are complete
4231 wtoken.animation = null;
4232 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004233 }
4234 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004235 if (mLastEnterAnimToken == wtoken) {
4236 mLastEnterAnimToken = null;
4237 mLastEnterAnimParams = null;
4238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 wtoken.removed = true;
4240 if (wtoken.startingData != null) {
4241 startingToken = wtoken;
4242 }
4243 unsetAppFreezingScreenLocked(wtoken, true, true);
4244 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004245 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 mFocusedApp = null;
4247 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004248 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 }
4250 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004251 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 if (!delayed && wtoken != null) {
4255 wtoken.updateReportedVisibilityLocked();
4256 }
4257 }
4258 Binder.restoreCallingIdentity(origId);
4259
4260 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004261 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 + startingToken + ": app token removed");
4263 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4264 mH.sendMessage(m);
4265 }
4266 }
4267
4268 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4269 final int NW = token.windows.size();
4270 for (int i=0; i<NW; i++) {
4271 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004272 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004274 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 int j = win.mChildWindows.size();
4276 while (j > 0) {
4277 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004278 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004279 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004280 "Tmp removing child window " + cwin);
4281 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 }
4283 }
4284 return NW > 0;
4285 }
4286
4287 void dumpAppTokensLocked() {
4288 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004289 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 }
4291 }
Romain Guy06882f82009-06-10 13:36:04 -07004292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 void dumpWindowsLocked() {
4294 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004295 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 }
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 private int findWindowOffsetLocked(int tokenPos) {
4300 final int NW = mWindows.size();
4301
4302 if (tokenPos >= mAppTokens.size()) {
4303 int i = NW;
4304 while (i > 0) {
4305 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004306 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 if (win.getAppToken() != null) {
4308 return i+1;
4309 }
4310 }
4311 }
4312
4313 while (tokenPos > 0) {
4314 // Find the first app token below the new position that has
4315 // a window displayed.
4316 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004317 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004319 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004320 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004321 "Skipping token -- currently sending to bottom");
4322 tokenPos--;
4323 continue;
4324 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 int i = wtoken.windows.size();
4326 while (i > 0) {
4327 i--;
4328 WindowState win = wtoken.windows.get(i);
4329 int j = win.mChildWindows.size();
4330 while (j > 0) {
4331 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004332 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004333 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 for (int pos=NW-1; pos>=0; pos--) {
4335 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004336 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 "Found child win @" + (pos+1));
4338 return pos+1;
4339 }
4340 }
4341 }
4342 }
4343 for (int pos=NW-1; pos>=0; pos--) {
4344 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004345 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 return pos+1;
4347 }
4348 }
4349 }
4350 tokenPos--;
4351 }
4352
4353 return 0;
4354 }
4355
4356 private final int reAddWindowLocked(int index, WindowState win) {
4357 final int NCW = win.mChildWindows.size();
4358 boolean added = false;
4359 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004360 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004363 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 mWindows.add(index, win);
4365 index++;
4366 added = true;
4367 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004368 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004369 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 mWindows.add(index, cwin);
4371 index++;
4372 }
4373 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004374 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004375 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 mWindows.add(index, win);
4377 index++;
4378 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004379 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 return index;
4381 }
Romain Guy06882f82009-06-10 13:36:04 -07004382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4384 final int NW = token.windows.size();
4385 for (int i=0; i<NW; i++) {
4386 index = reAddWindowLocked(index, token.windows.get(i));
4387 }
4388 return index;
4389 }
4390
4391 public void moveAppToken(int index, IBinder token) {
4392 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4393 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004394 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 }
4396
4397 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004398 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004399 if (DEBUG_REORDER) dumpAppTokensLocked();
4400 final AppWindowToken wtoken = findAppWindowToken(token);
4401 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004402 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 + token + " (" + wtoken + ")");
4404 return;
4405 }
4406 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004407 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004411 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004412 if (DEBUG_REORDER) dumpWindowsLocked();
4413 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004414 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 if (DEBUG_REORDER) dumpWindowsLocked();
4416 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004417 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 if (DEBUG_REORDER) dumpWindowsLocked();
4419 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 mLayoutNeeded = true;
4421 performLayoutAndPlaceSurfacesLocked();
4422 }
4423 Binder.restoreCallingIdentity(origId);
4424 }
4425 }
4426
4427 private void removeAppTokensLocked(List<IBinder> tokens) {
4428 // XXX This should be done more efficiently!
4429 // (take advantage of the fact that both lists should be
4430 // ordered in the same way.)
4431 int N = tokens.size();
4432 for (int i=0; i<N; i++) {
4433 IBinder token = tokens.get(i);
4434 final AppWindowToken wtoken = findAppWindowToken(token);
4435 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004436 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 + token + " (" + wtoken + ")");
4438 i--;
4439 N--;
4440 }
4441 }
4442 }
4443
Dianne Hackborna8f60182009-09-01 19:01:50 -07004444 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4445 boolean updateFocusAndLayout) {
4446 // First remove all of the windows from the list.
4447 tmpRemoveAppWindowsLocked(wtoken);
4448
4449 // Where to start adding?
4450 int pos = findWindowOffsetLocked(tokenPos);
4451
4452 // And now add them back at the correct place.
4453 pos = reAddAppWindowsLocked(pos, wtoken);
4454
4455 if (updateFocusAndLayout) {
4456 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4457 assignLayersLocked();
4458 }
4459 mLayoutNeeded = true;
4460 performLayoutAndPlaceSurfacesLocked();
4461 }
4462 }
4463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4465 // First remove all of the windows from the list.
4466 final int N = tokens.size();
4467 int i;
4468 for (i=0; i<N; i++) {
4469 WindowToken token = mTokenMap.get(tokens.get(i));
4470 if (token != null) {
4471 tmpRemoveAppWindowsLocked(token);
4472 }
4473 }
4474
4475 // Where to start adding?
4476 int pos = findWindowOffsetLocked(tokenPos);
4477
4478 // And now add them back at the correct place.
4479 for (i=0; i<N; i++) {
4480 WindowToken token = mTokenMap.get(tokens.get(i));
4481 if (token != null) {
4482 pos = reAddAppWindowsLocked(pos, token);
4483 }
4484 }
4485
Dianne Hackborna8f60182009-09-01 19:01:50 -07004486 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4487 assignLayersLocked();
4488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 mLayoutNeeded = true;
4490 performLayoutAndPlaceSurfacesLocked();
4491
4492 //dump();
4493 }
4494
4495 public void moveAppTokensToTop(List<IBinder> tokens) {
4496 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4497 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004498 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 }
4500
4501 final long origId = Binder.clearCallingIdentity();
4502 synchronized(mWindowMap) {
4503 removeAppTokensLocked(tokens);
4504 final int N = tokens.size();
4505 for (int i=0; i<N; i++) {
4506 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4507 if (wt != null) {
4508 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004509 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004510 mToTopApps.remove(wt);
4511 mToBottomApps.remove(wt);
4512 mToTopApps.add(wt);
4513 wt.sendingToBottom = false;
4514 wt.sendingToTop = true;
4515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 }
4517 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004518
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004519 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004520 moveAppWindowsLocked(tokens, mAppTokens.size());
4521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 }
4523 Binder.restoreCallingIdentity(origId);
4524 }
4525
4526 public void moveAppTokensToBottom(List<IBinder> tokens) {
4527 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4528 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004529 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 }
4531
4532 final long origId = Binder.clearCallingIdentity();
4533 synchronized(mWindowMap) {
4534 removeAppTokensLocked(tokens);
4535 final int N = tokens.size();
4536 int pos = 0;
4537 for (int i=0; i<N; i++) {
4538 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4539 if (wt != null) {
4540 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004541 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004542 mToTopApps.remove(wt);
4543 mToBottomApps.remove(wt);
4544 mToBottomApps.add(i, wt);
4545 wt.sendingToTop = false;
4546 wt.sendingToBottom = true;
4547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 pos++;
4549 }
4550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004551
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004552 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004553 moveAppWindowsLocked(tokens, 0);
4554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 }
4556 Binder.restoreCallingIdentity(origId);
4557 }
4558
4559 // -------------------------------------------------------------
4560 // Misc IWindowSession methods
4561 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004562
Jim Miller284b62e2010-06-08 14:27:42 -07004563 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004564 {
Jim Miller284b62e2010-06-08 14:27:42 -07004565 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4566 // called before DevicePolicyManagerService has started.
4567 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4568 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4569 Context.DEVICE_POLICY_SERVICE);
4570 if (dpm != null) {
4571 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4572 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4573 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4574 }
Jim Millerd6b57052010-06-07 17:52:42 -07004575 }
Jim Miller284b62e2010-06-08 14:27:42 -07004576 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004577 }
4578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004580 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 != PackageManager.PERMISSION_GRANTED) {
4582 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4583 }
Jim Millerd6b57052010-06-07 17:52:42 -07004584
Jim Miller284b62e2010-06-08 14:27:42 -07004585 synchronized (mKeyguardTokenWatcher) {
4586 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 }
4589
4590 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004591 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 != PackageManager.PERMISSION_GRANTED) {
4593 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595
Jim Miller284b62e2010-06-08 14:27:42 -07004596 synchronized (mKeyguardTokenWatcher) {
4597 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004598
Jim Miller284b62e2010-06-08 14:27:42 -07004599 if (!mKeyguardTokenWatcher.isAcquired()) {
4600 // If we are the last one to reenable the keyguard wait until
4601 // we have actually finished reenabling until returning.
4602 // It is possible that reenableKeyguard() can be called before
4603 // the previous disableKeyguard() is handled, in which case
4604 // neither mKeyguardTokenWatcher.acquired() or released() would
4605 // be called. In that case mKeyguardDisabled will be false here
4606 // and we have nothing to wait for.
4607 while (mKeyguardDisabled) {
4608 try {
4609 mKeyguardTokenWatcher.wait();
4610 } catch (InterruptedException e) {
4611 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 }
4613 }
4614 }
4615 }
4616 }
4617
4618 /**
4619 * @see android.app.KeyguardManager#exitKeyguardSecurely
4620 */
4621 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004622 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 != PackageManager.PERMISSION_GRANTED) {
4624 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4625 }
4626 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4627 public void onKeyguardExitResult(boolean success) {
4628 try {
4629 callback.onKeyguardExitResult(success);
4630 } catch (RemoteException e) {
4631 // Client has died, we don't care.
4632 }
4633 }
4634 });
4635 }
4636
4637 public boolean inKeyguardRestrictedInputMode() {
4638 return mPolicy.inKeyguardRestrictedKeyInputMode();
4639 }
Romain Guy06882f82009-06-10 13:36:04 -07004640
Dianne Hackbornffa42482009-09-23 22:20:11 -07004641 public void closeSystemDialogs(String reason) {
4642 synchronized(mWindowMap) {
4643 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004644 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004645 if (w.mSurface != null) {
4646 try {
4647 w.mClient.closeSystemDialogs(reason);
4648 } catch (RemoteException e) {
4649 }
4650 }
4651 }
4652 }
4653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 static float fixScale(float scale) {
4656 if (scale < 0) scale = 0;
4657 else if (scale > 20) scale = 20;
4658 return Math.abs(scale);
4659 }
Romain Guy06882f82009-06-10 13:36:04 -07004660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 public void setAnimationScale(int which, float scale) {
4662 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4663 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004664 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 }
4666
4667 if (scale < 0) scale = 0;
4668 else if (scale > 20) scale = 20;
4669 scale = Math.abs(scale);
4670 switch (which) {
4671 case 0: mWindowAnimationScale = fixScale(scale); break;
4672 case 1: mTransitionAnimationScale = fixScale(scale); break;
4673 }
Romain Guy06882f82009-06-10 13:36:04 -07004674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004675 // Persist setting
4676 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4677 }
Romain Guy06882f82009-06-10 13:36:04 -07004678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 public void setAnimationScales(float[] scales) {
4680 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4681 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004682 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
4684
4685 if (scales != null) {
4686 if (scales.length >= 1) {
4687 mWindowAnimationScale = fixScale(scales[0]);
4688 }
4689 if (scales.length >= 2) {
4690 mTransitionAnimationScale = fixScale(scales[1]);
4691 }
4692 }
Romain Guy06882f82009-06-10 13:36:04 -07004693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 // Persist setting
4695 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4696 }
Romain Guy06882f82009-06-10 13:36:04 -07004697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004698 public float getAnimationScale(int which) {
4699 switch (which) {
4700 case 0: return mWindowAnimationScale;
4701 case 1: return mTransitionAnimationScale;
4702 }
4703 return 0;
4704 }
Romain Guy06882f82009-06-10 13:36:04 -07004705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 public float[] getAnimationScales() {
4707 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4708 }
Romain Guy06882f82009-06-10 13:36:04 -07004709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 public int getSwitchState(int sw) {
4711 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4712 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004713 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004715 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 }
Romain Guy06882f82009-06-10 13:36:04 -07004717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 public int getSwitchStateForDevice(int devid, int sw) {
4719 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4720 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004721 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004723 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 }
Romain Guy06882f82009-06-10 13:36:04 -07004725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004726 public int getScancodeState(int sw) {
4727 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4728 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004729 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004730 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004731 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 }
Romain Guy06882f82009-06-10 13:36:04 -07004733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004734 public int getScancodeStateForDevice(int devid, int sw) {
4735 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4736 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004737 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004739 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004740 }
Romain Guy06882f82009-06-10 13:36:04 -07004741
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004742 public int getTrackballScancodeState(int sw) {
4743 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4744 "getTrackballScancodeState()")) {
4745 throw new SecurityException("Requires READ_INPUT_STATE permission");
4746 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004747 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004748 }
4749
4750 public int getDPadScancodeState(int sw) {
4751 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4752 "getDPadScancodeState()")) {
4753 throw new SecurityException("Requires READ_INPUT_STATE permission");
4754 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004755 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004756 }
4757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004758 public int getKeycodeState(int sw) {
4759 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4760 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004761 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004762 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004763 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 public int getKeycodeStateForDevice(int devid, int sw) {
4767 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4768 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004769 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004771 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004772 }
Romain Guy06882f82009-06-10 13:36:04 -07004773
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004774 public int getTrackballKeycodeState(int sw) {
4775 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4776 "getTrackballKeycodeState()")) {
4777 throw new SecurityException("Requires READ_INPUT_STATE permission");
4778 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004779 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004780 }
4781
4782 public int getDPadKeycodeState(int sw) {
4783 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4784 "getDPadKeycodeState()")) {
4785 throw new SecurityException("Requires READ_INPUT_STATE permission");
4786 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004787 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004788 }
Jeff Browna41ca772010-08-11 14:46:32 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004791 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 }
Romain Guy06882f82009-06-10 13:36:04 -07004793
Jeff Browna41ca772010-08-11 14:46:32 -07004794 public InputChannel monitorInput(String inputChannelName) {
4795 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4796 "monitorInput()")) {
4797 throw new SecurityException("Requires READ_INPUT_STATE permission");
4798 }
4799 return mInputManager.monitorInput(inputChannelName);
4800 }
4801
Jeff Brown8d608662010-08-30 03:02:23 -07004802 public InputDevice getInputDevice(int deviceId) {
4803 return mInputManager.getInputDevice(deviceId);
4804 }
4805
4806 public int[] getInputDeviceIds() {
4807 return mInputManager.getInputDeviceIds();
4808 }
4809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 public void enableScreenAfterBoot() {
4811 synchronized(mWindowMap) {
4812 if (mSystemBooted) {
4813 return;
4814 }
4815 mSystemBooted = true;
4816 }
Romain Guy06882f82009-06-10 13:36:04 -07004817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 performEnableScreen();
4819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 public void enableScreenIfNeededLocked() {
4822 if (mDisplayEnabled) {
4823 return;
4824 }
4825 if (!mSystemBooted) {
4826 return;
4827 }
4828 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4829 }
Romain Guy06882f82009-06-10 13:36:04 -07004830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 public void performEnableScreen() {
4832 synchronized(mWindowMap) {
4833 if (mDisplayEnabled) {
4834 return;
4835 }
4836 if (!mSystemBooted) {
4837 return;
4838 }
Romain Guy06882f82009-06-10 13:36:04 -07004839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004840 // Don't enable the screen until all existing windows
4841 // have been drawn.
4842 final int N = mWindows.size();
4843 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004844 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004845 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 return;
4847 }
4848 }
Romain Guy06882f82009-06-10 13:36:04 -07004849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 mDisplayEnabled = true;
4851 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004852 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 StringWriter sw = new StringWriter();
4854 PrintWriter pw = new PrintWriter(sw);
4855 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004856 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 }
4858 try {
4859 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4860 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004861 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 Parcel data = Parcel.obtain();
4863 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4864 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4865 data, null, 0);
4866 data.recycle();
4867 }
4868 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004869 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 }
4871 }
Romain Guy06882f82009-06-10 13:36:04 -07004872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004876 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4877 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004878 }
Romain Guy06882f82009-06-10 13:36:04 -07004879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 public void setInTouchMode(boolean mode) {
4881 synchronized(mWindowMap) {
4882 mInTouchMode = mode;
4883 }
4884 }
4885
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004886 public void freezeRotation() {
4887 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4888 "setRotation()")) {
4889 throw new SecurityException("Requires SET_ORIENTATION permission");
4890 }
4891
4892 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4893 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4894 }
4895
4896 public void thawRotation() {
4897 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4898 "setRotation()")) {
4899 throw new SecurityException("Requires SET_ORIENTATION permission");
4900 }
4901
4902 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4903 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4904 }
4905
Romain Guy06882f82009-06-10 13:36:04 -07004906 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004907 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004909 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004910 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 }
4912
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004913 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914 }
Romain Guy06882f82009-06-10 13:36:04 -07004915
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004916 public void setRotationUnchecked(int rotation,
4917 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004918 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 long origId = Binder.clearCallingIdentity();
4922 boolean changed;
4923 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004924 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 }
Romain Guy06882f82009-06-10 13:36:04 -07004926
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004927 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 sendNewConfiguration();
4929 }
Romain Guy06882f82009-06-10 13:36:04 -07004930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 Binder.restoreCallingIdentity(origId);
4932 }
Romain Guy06882f82009-06-10 13:36:04 -07004933
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004934 /**
4935 * Apply a new rotation to the screen, respecting the requests of
4936 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4937 * re-evaluate the desired rotation.
4938 *
4939 * Returns null if the rotation has been changed. In this case YOU
4940 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4941 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004942 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004943 boolean changed;
4944 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4945 rotation = mRequestedRotation;
4946 } else {
4947 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004948 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004950 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004951 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004953 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004954 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004956 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004957 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004958 "Rotation changed to " + rotation
4959 + " from " + mRotation
4960 + " (forceApp=" + mForcedAppOrientation
4961 + ", req=" + mRequestedRotation + ")");
4962 mRotation = rotation;
4963 mWindowsFreezingScreen = true;
4964 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4965 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4966 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004967 mWaitingForConfig = true;
4968 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004969 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004970 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004971 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004972 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004973 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004974 }
4975 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004976 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004977 if (w.mSurface != null) {
4978 w.mOrientationChanging = true;
4979 }
4980 }
4981 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4982 try {
4983 mRotationWatchers.get(i).onRotationChanged(rotation);
4984 } catch (RemoteException e) {
4985 }
4986 }
4987 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004989 return changed;
4990 }
Romain Guy06882f82009-06-10 13:36:04 -07004991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004992 public int getRotation() {
4993 return mRotation;
4994 }
4995
4996 public int watchRotation(IRotationWatcher watcher) {
4997 final IBinder watcherBinder = watcher.asBinder();
4998 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4999 public void binderDied() {
5000 synchronized (mWindowMap) {
5001 for (int i=0; i<mRotationWatchers.size(); i++) {
5002 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005003 IRotationWatcher removed = mRotationWatchers.remove(i);
5004 if (removed != null) {
5005 removed.asBinder().unlinkToDeath(this, 0);
5006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005007 i--;
5008 }
5009 }
5010 }
5011 }
5012 };
Romain Guy06882f82009-06-10 13:36:04 -07005013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005014 synchronized (mWindowMap) {
5015 try {
5016 watcher.asBinder().linkToDeath(dr, 0);
5017 mRotationWatchers.add(watcher);
5018 } catch (RemoteException e) {
5019 // Client died, no cleanup needed.
5020 }
Romain Guy06882f82009-06-10 13:36:04 -07005021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005022 return mRotation;
5023 }
5024 }
5025
5026 /**
5027 * Starts the view server on the specified port.
5028 *
5029 * @param port The port to listener to.
5030 *
5031 * @return True if the server was successfully started, false otherwise.
5032 *
5033 * @see com.android.server.ViewServer
5034 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5035 */
5036 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005037 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005038 return false;
5039 }
5040
5041 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5042 return false;
5043 }
5044
5045 if (port < 1024) {
5046 return false;
5047 }
5048
5049 if (mViewServer != null) {
5050 if (!mViewServer.isRunning()) {
5051 try {
5052 return mViewServer.start();
5053 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005054 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 }
5056 }
5057 return false;
5058 }
5059
5060 try {
5061 mViewServer = new ViewServer(this, port);
5062 return mViewServer.start();
5063 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005064 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 }
5066 return false;
5067 }
5068
Romain Guy06882f82009-06-10 13:36:04 -07005069 private boolean isSystemSecure() {
5070 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5071 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5072 }
5073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005074 /**
5075 * Stops the view server if it exists.
5076 *
5077 * @return True if the server stopped, false if it wasn't started or
5078 * couldn't be stopped.
5079 *
5080 * @see com.android.server.ViewServer
5081 */
5082 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005083 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005084 return false;
5085 }
5086
5087 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5088 return false;
5089 }
5090
5091 if (mViewServer != null) {
5092 return mViewServer.stop();
5093 }
5094 return false;
5095 }
5096
5097 /**
5098 * Indicates whether the view server is running.
5099 *
5100 * @return True if the server is running, false otherwise.
5101 *
5102 * @see com.android.server.ViewServer
5103 */
5104 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005105 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 return false;
5107 }
5108
5109 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5110 return false;
5111 }
5112
5113 return mViewServer != null && mViewServer.isRunning();
5114 }
5115
5116 /**
5117 * Lists all availble windows in the system. The listing is written in the
5118 * specified Socket's output stream with the following syntax:
5119 * windowHashCodeInHexadecimal windowName
5120 * Each line of the ouput represents a different window.
5121 *
5122 * @param client The remote client to send the listing to.
5123 * @return False if an error occured, true otherwise.
5124 */
5125 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005126 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005127 return false;
5128 }
5129
5130 boolean result = true;
5131
Jeff Browne33348b2010-07-15 23:54:05 -07005132 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005133 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005135 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 }
5137
5138 BufferedWriter out = null;
5139
5140 // Any uncaught exception will crash the system process
5141 try {
5142 OutputStream clientStream = client.getOutputStream();
5143 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5144
5145 final int count = windows.length;
5146 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005147 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005148 out.write(Integer.toHexString(System.identityHashCode(w)));
5149 out.write(' ');
5150 out.append(w.mAttrs.getTitle());
5151 out.write('\n');
5152 }
5153
5154 out.write("DONE.\n");
5155 out.flush();
5156 } catch (Exception e) {
5157 result = false;
5158 } finally {
5159 if (out != null) {
5160 try {
5161 out.close();
5162 } catch (IOException e) {
5163 result = false;
5164 }
5165 }
5166 }
5167
5168 return result;
5169 }
5170
5171 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005172 * Returns the focused window in the following format:
5173 * windowHashCodeInHexadecimal windowName
5174 *
5175 * @param client The remote client to send the listing to.
5176 * @return False if an error occurred, true otherwise.
5177 */
5178 boolean viewServerGetFocusedWindow(Socket client) {
5179 if (isSystemSecure()) {
5180 return false;
5181 }
5182
5183 boolean result = true;
5184
5185 WindowState focusedWindow = getFocusedWindow();
5186
5187 BufferedWriter out = null;
5188
5189 // Any uncaught exception will crash the system process
5190 try {
5191 OutputStream clientStream = client.getOutputStream();
5192 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5193
5194 if(focusedWindow != null) {
5195 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5196 out.write(' ');
5197 out.append(focusedWindow.mAttrs.getTitle());
5198 }
5199 out.write('\n');
5200 out.flush();
5201 } catch (Exception e) {
5202 result = false;
5203 } finally {
5204 if (out != null) {
5205 try {
5206 out.close();
5207 } catch (IOException e) {
5208 result = false;
5209 }
5210 }
5211 }
5212
5213 return result;
5214 }
5215
5216 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005217 * Sends a command to a target window. The result of the command, if any, will be
5218 * written in the output stream of the specified socket.
5219 *
5220 * The parameters must follow this syntax:
5221 * windowHashcode extra
5222 *
5223 * Where XX is the length in characeters of the windowTitle.
5224 *
5225 * The first parameter is the target window. The window with the specified hashcode
5226 * will be the target. If no target can be found, nothing happens. The extra parameters
5227 * will be delivered to the target window and as parameters to the command itself.
5228 *
5229 * @param client The remote client to sent the result, if any, to.
5230 * @param command The command to execute.
5231 * @param parameters The command parameters.
5232 *
5233 * @return True if the command was successfully delivered, false otherwise. This does
5234 * not indicate whether the command itself was successful.
5235 */
5236 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005237 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 return false;
5239 }
5240
5241 boolean success = true;
5242 Parcel data = null;
5243 Parcel reply = null;
5244
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005245 BufferedWriter out = null;
5246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 // Any uncaught exception will crash the system process
5248 try {
5249 // Find the hashcode of the window
5250 int index = parameters.indexOf(' ');
5251 if (index == -1) {
5252 index = parameters.length();
5253 }
5254 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005255 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256
5257 // Extract the command's parameter after the window description
5258 if (index < parameters.length()) {
5259 parameters = parameters.substring(index + 1);
5260 } else {
5261 parameters = "";
5262 }
5263
5264 final WindowManagerService.WindowState window = findWindow(hashCode);
5265 if (window == null) {
5266 return false;
5267 }
5268
5269 data = Parcel.obtain();
5270 data.writeInterfaceToken("android.view.IWindow");
5271 data.writeString(command);
5272 data.writeString(parameters);
5273 data.writeInt(1);
5274 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5275
5276 reply = Parcel.obtain();
5277
5278 final IBinder binder = window.mClient.asBinder();
5279 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5280 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5281
5282 reply.readException();
5283
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005284 if (!client.isOutputShutdown()) {
5285 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5286 out.write("DONE\n");
5287 out.flush();
5288 }
5289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005290 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005291 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005292 success = false;
5293 } finally {
5294 if (data != null) {
5295 data.recycle();
5296 }
5297 if (reply != null) {
5298 reply.recycle();
5299 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005300 if (out != null) {
5301 try {
5302 out.close();
5303 } catch (IOException e) {
5304
5305 }
5306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005307 }
5308
5309 return success;
5310 }
5311
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005312 public void addWindowChangeListener(WindowChangeListener listener) {
5313 synchronized(mWindowMap) {
5314 mWindowChangeListeners.add(listener);
5315 }
5316 }
5317
5318 public void removeWindowChangeListener(WindowChangeListener listener) {
5319 synchronized(mWindowMap) {
5320 mWindowChangeListeners.remove(listener);
5321 }
5322 }
5323
5324 private void notifyWindowsChanged() {
5325 WindowChangeListener[] windowChangeListeners;
5326 synchronized(mWindowMap) {
5327 if(mWindowChangeListeners.isEmpty()) {
5328 return;
5329 }
5330 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5331 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5332 }
5333 int N = windowChangeListeners.length;
5334 for(int i = 0; i < N; i++) {
5335 windowChangeListeners[i].windowsChanged();
5336 }
5337 }
5338
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005339 private void notifyFocusChanged() {
5340 WindowChangeListener[] windowChangeListeners;
5341 synchronized(mWindowMap) {
5342 if(mWindowChangeListeners.isEmpty()) {
5343 return;
5344 }
5345 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5346 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5347 }
5348 int N = windowChangeListeners.length;
5349 for(int i = 0; i < N; i++) {
5350 windowChangeListeners[i].focusChanged();
5351 }
5352 }
5353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 private WindowState findWindow(int hashCode) {
5355 if (hashCode == -1) {
5356 return getFocusedWindow();
5357 }
5358
5359 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005360 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005361 final int count = windows.size();
5362
5363 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005364 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005365 if (System.identityHashCode(w) == hashCode) {
5366 return w;
5367 }
5368 }
5369 }
5370
5371 return null;
5372 }
5373
5374 /*
5375 * Instruct the Activity Manager to fetch the current configuration and broadcast
5376 * that to config-changed listeners if appropriate.
5377 */
5378 void sendNewConfiguration() {
5379 try {
5380 mActivityManager.updateConfiguration(null);
5381 } catch (RemoteException e) {
5382 }
5383 }
Romain Guy06882f82009-06-10 13:36:04 -07005384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 public Configuration computeNewConfiguration() {
5386 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005387 return computeNewConfigurationLocked();
5388 }
5389 }
Romain Guy06882f82009-06-10 13:36:04 -07005390
Dianne Hackbornc485a602009-03-24 22:39:49 -07005391 Configuration computeNewConfigurationLocked() {
5392 Configuration config = new Configuration();
5393 if (!computeNewConfigurationLocked(config)) {
5394 return null;
5395 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005396 return config;
5397 }
Romain Guy06882f82009-06-10 13:36:04 -07005398
Dianne Hackbornc485a602009-03-24 22:39:49 -07005399 boolean computeNewConfigurationLocked(Configuration config) {
5400 if (mDisplay == null) {
5401 return false;
5402 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005403
5404 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005405
5406 // Use the effective "visual" dimensions based on current rotation
5407 final boolean rotated = (mRotation == Surface.ROTATION_90
5408 || mRotation == Surface.ROTATION_270);
5409 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5410 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5411
Dianne Hackbornc485a602009-03-24 22:39:49 -07005412 int orientation = Configuration.ORIENTATION_SQUARE;
5413 if (dw < dh) {
5414 orientation = Configuration.ORIENTATION_PORTRAIT;
5415 } else if (dw > dh) {
5416 orientation = Configuration.ORIENTATION_LANDSCAPE;
5417 }
5418 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005419
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005420 DisplayMetrics dm = new DisplayMetrics();
5421 mDisplay.getMetrics(dm);
5422 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5423
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005424 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005425 // Note we only do this once because at this point we don't
5426 // expect the screen to change in this way at runtime, and want
5427 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005428 int longSize = dw;
5429 int shortSize = dh;
5430 if (longSize < shortSize) {
5431 int tmp = longSize;
5432 longSize = shortSize;
5433 shortSize = tmp;
5434 }
5435 longSize = (int)(longSize/dm.density);
5436 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005437
Dianne Hackborn723738c2009-06-25 19:48:04 -07005438 // These semi-magic numbers define our compatibility modes for
5439 // applications with different screens. Don't change unless you
5440 // make sure to test lots and lots of apps!
5441 if (longSize < 470) {
5442 // This is shorter than an HVGA normal density screen (which
5443 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005444 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5445 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005446 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005447 // What size is this screen screen?
5448 if (longSize >= 800 && shortSize >= 600) {
5449 // SVGA or larger screens at medium density are the point
5450 // at which we consider it to be an extra large screen.
5451 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005452 } else if (longSize >= 530 && shortSize >= 400) {
5453 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005454 // at which we consider it to be a large screen.
5455 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5456 } else {
5457 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005458
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005459 // If this screen is wider than normal HVGA, or taller
5460 // than FWVGA, then for old apps we want to run in size
5461 // compatibility mode.
5462 if (shortSize > 321 || longSize > 570) {
5463 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5464 }
5465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005466
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005467 // Is this a long screen?
5468 if (((longSize*3)/5) >= (shortSize-1)) {
5469 // Anything wider than WVGA (5:3) is considering to be long.
5470 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5471 } else {
5472 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5473 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005474 }
5475 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005476 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005477
Dianne Hackbornc485a602009-03-24 22:39:49 -07005478 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5479 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5480 mPolicy.adjustConfigurationLw(config);
5481 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005483
5484 // -------------------------------------------------------------
5485 // Drag and drop
5486 // -------------------------------------------------------------
5487
5488 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5489 boolean localOnly, int width, int height, Surface outSurface) {
5490 if (DEBUG_DRAG) {
5491 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5492 + " local=" + localOnly + " win=" + window
5493 + " asbinder=" + window.asBinder());
5494 }
5495
5496 final int callerPid = Binder.getCallingPid();
5497 final long origId = Binder.clearCallingIdentity();
5498 IBinder token = null;
5499
5500 try {
5501 synchronized (mWindowMap) {
5502 try {
5503 // !!! TODO: fail if the given window does not currently have touch focus?
5504
5505 if (mDragState == null) {
5506 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5507 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5508 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005509 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005510 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005511 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005512 mDragState.mSurface = surface;
5513 mDragState.mLocalOnly = localOnly;
5514 token = mDragState.mToken = new Binder();
5515
5516 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005517 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5518 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005519 mH.sendMessageDelayed(msg, 5000);
5520 } else {
5521 Slog.w(TAG, "Drag already in progress");
5522 }
5523 } catch (Surface.OutOfResourcesException e) {
5524 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5525 if (mDragState != null) {
5526 mDragState.reset();
5527 mDragState = null;
5528 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005529 }
5530 }
5531 } finally {
5532 Binder.restoreCallingIdentity(origId);
5533 }
5534
5535 return token;
5536 }
5537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005538 // -------------------------------------------------------------
5539 // Input Events and Focus Management
5540 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005541
Jeff Brown349703e2010-06-22 01:27:15 -07005542 InputMonitor mInputMonitor = new InputMonitor();
5543
5544 /* Tracks the progress of input dispatch and ensures that input dispatch state
5545 * is kept in sync with changes in window focus, visibility, registration, and
5546 * other relevant Window Manager state transitions. */
5547 final class InputMonitor {
5548 // Current window with input focus for keys and other non-touch events. May be null.
5549 private WindowState mInputFocus;
5550
5551 // When true, prevents input dispatch from proceeding until set to false again.
5552 private boolean mInputDispatchFrozen;
5553
5554 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5555 private boolean mInputDispatchEnabled = true;
5556
5557 // Temporary list of windows information to provide to the input dispatcher.
5558 private InputWindowList mTempInputWindows = new InputWindowList();
5559
5560 // Temporary input application object to provide to the input dispatcher.
5561 private InputApplication mTempInputApplication = new InputApplication();
5562
5563 /* Notifies the window manager about a broken input channel.
5564 *
5565 * Called by the InputManager.
5566 */
5567 public void notifyInputChannelBroken(InputChannel inputChannel) {
5568 synchronized (mWindowMap) {
5569 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5570 if (windowState == null) {
5571 return; // irrelevant
5572 }
5573
5574 Slog.i(TAG, "WINDOW DIED " + windowState);
5575 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005576 }
5577 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005578
Jeff Brown519e0242010-09-15 15:18:56 -07005579 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005580 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005581 *
5582 * Called by the InputManager.
5583 */
Jeff Brown519e0242010-09-15 15:18:56 -07005584 public long notifyANR(Object token, InputChannel inputChannel) {
5585 AppWindowToken appWindowToken = null;
5586 if (inputChannel != null) {
5587 synchronized (mWindowMap) {
5588 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5589 if (windowState != null) {
5590 Slog.i(TAG, "Input event dispatching timed out sending to "
5591 + windowState.mAttrs.getTitle());
5592 appWindowToken = windowState.mAppToken;
5593 }
Jeff Brown349703e2010-06-22 01:27:15 -07005594 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005595 }
5596
Jeff Brown519e0242010-09-15 15:18:56 -07005597 if (appWindowToken == null && token != null) {
5598 appWindowToken = (AppWindowToken) token;
5599 Slog.i(TAG, "Input event dispatching timed out sending to application "
5600 + appWindowToken.stringName);
5601 }
Jeff Brown349703e2010-06-22 01:27:15 -07005602
Jeff Brown519e0242010-09-15 15:18:56 -07005603 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005604 try {
5605 // Notify the activity manager about the timeout and let it decide whether
5606 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005607 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005608 if (! abort) {
5609 // The activity manager declined to abort dispatching.
5610 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005611 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005612 }
Jeff Brown349703e2010-06-22 01:27:15 -07005613 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005614 }
5615 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005616 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005617 }
5618
Jeff Brown349703e2010-06-22 01:27:15 -07005619 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5620 synchronized (mWindowMap) {
5621 return getWindowStateForInputChannelLocked(inputChannel);
5622 }
5623 }
5624
5625 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5626 int windowCount = mWindows.size();
5627 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005628 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005629 if (windowState.mInputChannel == inputChannel) {
5630 return windowState;
5631 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005632 }
5633
Jeff Brown349703e2010-06-22 01:27:15 -07005634 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005635 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005636
Chris Tatea32dcf72010-10-14 12:13:50 -07005637 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005638 final InputWindow inputWindow = windowList.add();
5639 inputWindow.inputChannel = mDragState.mServerChannel;
5640 inputWindow.name = "drag";
5641 inputWindow.layoutParamsFlags = 0;
5642 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5643 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5644 inputWindow.visible = true;
5645 inputWindow.canReceiveKeys = false;
5646 inputWindow.hasFocus = true;
5647 inputWindow.hasWallpaper = false;
5648 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005649 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005650 inputWindow.ownerPid = Process.myPid();
5651 inputWindow.ownerUid = Process.myUid();
5652
5653 // The drag window covers the entire display
5654 inputWindow.frameLeft = 0;
5655 inputWindow.frameTop = 0;
5656 inputWindow.frameRight = mDisplay.getWidth();
5657 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005658
Christopher Tatea53146c2010-09-07 11:57:52 -07005659 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5660 inputWindow.visibleFrameTop = inputWindow.frameTop;
5661 inputWindow.visibleFrameRight = inputWindow.frameRight;
5662 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5663
5664 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5665 inputWindow.touchableAreaTop = inputWindow.frameTop;
5666 inputWindow.touchableAreaRight = inputWindow.frameRight;
5667 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5668 }
5669
Jeff Brown349703e2010-06-22 01:27:15 -07005670 /* Updates the cached window information provided to the input dispatcher. */
5671 public void updateInputWindowsLw() {
5672 // Populate the input window list with information about all of the windows that
5673 // could potentially receive input.
5674 // As an optimization, we could try to prune the list of windows but this turns
5675 // out to be difficult because only the native code knows for sure which window
5676 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005677 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005678
5679 // If there's a drag in flight, provide a pseudowindow to catch drag input
5680 final boolean inDrag = (mDragState != null);
5681 if (inDrag) {
5682 if (DEBUG_DRAG) {
5683 Log.d(TAG, "Inserting drag window");
5684 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005685 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005686 }
5687
Jeff Brown7fbdc842010-06-17 20:52:56 -07005688 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005689 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005690 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005691 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005692 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005693 continue;
5694 }
5695
Jeff Brown349703e2010-06-22 01:27:15 -07005696 final int flags = child.mAttrs.flags;
5697 final int type = child.mAttrs.type;
5698
5699 final boolean hasFocus = (child == mInputFocus);
5700 final boolean isVisible = child.isVisibleLw();
5701 final boolean hasWallpaper = (child == mWallpaperTarget)
5702 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005703
5704 // If there's a drag in progress and 'child' is a potential drop target,
5705 // make sure it's been told about the drag
5706 if (inDrag && isVisible) {
5707 mDragState.sendDragStartedIfNeededLw(child);
5708 }
5709
Jeff Brown349703e2010-06-22 01:27:15 -07005710 // Add a window to our list of input windows.
5711 final InputWindow inputWindow = mTempInputWindows.add();
5712 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005713 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005714 inputWindow.layoutParamsFlags = flags;
5715 inputWindow.layoutParamsType = type;
5716 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5717 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005718 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005719 inputWindow.hasFocus = hasFocus;
5720 inputWindow.hasWallpaper = hasWallpaper;
5721 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005722 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005723 inputWindow.ownerPid = child.mSession.mPid;
5724 inputWindow.ownerUid = child.mSession.mUid;
5725
5726 final Rect frame = child.mFrame;
5727 inputWindow.frameLeft = frame.left;
5728 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005729 inputWindow.frameRight = frame.right;
5730 inputWindow.frameBottom = frame.bottom;
5731
5732 final Rect visibleFrame = child.mVisibleFrame;
5733 inputWindow.visibleFrameLeft = visibleFrame.left;
5734 inputWindow.visibleFrameTop = visibleFrame.top;
5735 inputWindow.visibleFrameRight = visibleFrame.right;
5736 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005737
5738 switch (child.mTouchableInsets) {
5739 default:
5740 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5741 inputWindow.touchableAreaLeft = frame.left;
5742 inputWindow.touchableAreaTop = frame.top;
5743 inputWindow.touchableAreaRight = frame.right;
5744 inputWindow.touchableAreaBottom = frame.bottom;
5745 break;
5746
5747 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5748 Rect inset = child.mGivenContentInsets;
5749 inputWindow.touchableAreaLeft = frame.left + inset.left;
5750 inputWindow.touchableAreaTop = frame.top + inset.top;
5751 inputWindow.touchableAreaRight = frame.right - inset.right;
5752 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5753 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005754 }
Jeff Brown349703e2010-06-22 01:27:15 -07005755
5756 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5757 Rect inset = child.mGivenVisibleInsets;
5758 inputWindow.touchableAreaLeft = frame.left + inset.left;
5759 inputWindow.touchableAreaTop = frame.top + inset.top;
5760 inputWindow.touchableAreaRight = frame.right - inset.right;
5761 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005762 break;
5763 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005764 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005765 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005766
Jeff Brown349703e2010-06-22 01:27:15 -07005767 // Send windows to native code.
5768 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005769
Jeff Brown349703e2010-06-22 01:27:15 -07005770 // Clear the list in preparation for the next round.
5771 // Also avoids keeping InputChannel objects referenced unnecessarily.
5772 mTempInputWindows.clear();
5773 }
5774
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005775 /* Notifies that the lid switch changed state. */
5776 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5777 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5778 }
5779
Jeff Brown349703e2010-06-22 01:27:15 -07005780 /* Provides an opportunity for the window manager policy to intercept early key
5781 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005782 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5783 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5784 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5785 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005786 }
5787
5788 /* Provides an opportunity for the window manager policy to process a key before
5789 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005790 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005791 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005792 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005793 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005794 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005795 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005796 }
5797
Jeff Brown3915bb82010-11-05 15:02:16 -07005798 /* Provides an opportunity for the window manager policy to process a key that
5799 * the application did not handle. */
5800 public boolean dispatchUnhandledKey(InputChannel focus,
5801 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
5802 int policyFlags) {
5803 WindowState windowState = getWindowStateForInputChannel(focus);
5804 return mPolicy.dispatchUnhandledKey(windowState, action, flags,
5805 keyCode, scanCode, metaState, repeatCount, policyFlags);
5806 }
5807
Jeff Brown349703e2010-06-22 01:27:15 -07005808 /* Called when the current input focus changes.
5809 * Layer assignment is assumed to be complete by the time this is called.
5810 */
5811 public void setInputFocusLw(WindowState newWindow) {
5812 if (DEBUG_INPUT) {
5813 Slog.d(TAG, "Input focus has changed to " + newWindow);
5814 }
5815
5816 if (newWindow != mInputFocus) {
5817 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005818 // Displaying a window implicitly causes dispatching to be unpaused.
5819 // This is to protect against bugs if someone pauses dispatching but
5820 // forgets to resume.
5821 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005822 }
Jeff Brown349703e2010-06-22 01:27:15 -07005823
5824 mInputFocus = newWindow;
5825 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005826 }
5827 }
5828
Jeff Brown349703e2010-06-22 01:27:15 -07005829 public void setFocusedAppLw(AppWindowToken newApp) {
5830 // Focused app has changed.
5831 if (newApp == null) {
5832 mInputManager.setFocusedApplication(null);
5833 } else {
5834 mTempInputApplication.name = newApp.toString();
5835 mTempInputApplication.dispatchingTimeoutNanos =
5836 newApp.inputDispatchingTimeoutNanos;
5837 mTempInputApplication.token = newApp;
5838
5839 mInputManager.setFocusedApplication(mTempInputApplication);
5840 }
5841 }
5842
Jeff Brown349703e2010-06-22 01:27:15 -07005843 public void pauseDispatchingLw(WindowToken window) {
5844 if (! window.paused) {
5845 if (DEBUG_INPUT) {
5846 Slog.v(TAG, "Pausing WindowToken " + window);
5847 }
5848
5849 window.paused = true;
5850 updateInputWindowsLw();
5851 }
5852 }
5853
5854 public void resumeDispatchingLw(WindowToken window) {
5855 if (window.paused) {
5856 if (DEBUG_INPUT) {
5857 Slog.v(TAG, "Resuming WindowToken " + window);
5858 }
5859
5860 window.paused = false;
5861 updateInputWindowsLw();
5862 }
5863 }
5864
5865 public void freezeInputDispatchingLw() {
5866 if (! mInputDispatchFrozen) {
5867 if (DEBUG_INPUT) {
5868 Slog.v(TAG, "Freezing input dispatching");
5869 }
5870
5871 mInputDispatchFrozen = true;
5872 updateInputDispatchModeLw();
5873 }
5874 }
5875
5876 public void thawInputDispatchingLw() {
5877 if (mInputDispatchFrozen) {
5878 if (DEBUG_INPUT) {
5879 Slog.v(TAG, "Thawing input dispatching");
5880 }
5881
5882 mInputDispatchFrozen = false;
5883 updateInputDispatchModeLw();
5884 }
5885 }
5886
5887 public void setEventDispatchingLw(boolean enabled) {
5888 if (mInputDispatchEnabled != enabled) {
5889 if (DEBUG_INPUT) {
5890 Slog.v(TAG, "Setting event dispatching to " + enabled);
5891 }
5892
5893 mInputDispatchEnabled = enabled;
5894 updateInputDispatchModeLw();
5895 }
5896 }
5897
5898 private void updateInputDispatchModeLw() {
5899 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5900 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005903 public void pauseKeyDispatching(IBinder _token) {
5904 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5905 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005906 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 }
5908
5909 synchronized (mWindowMap) {
5910 WindowToken token = mTokenMap.get(_token);
5911 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005912 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005913 }
5914 }
5915 }
5916
5917 public void resumeKeyDispatching(IBinder _token) {
5918 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5919 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005920 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005921 }
5922
5923 synchronized (mWindowMap) {
5924 WindowToken token = mTokenMap.get(_token);
5925 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005926 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 }
5928 }
5929 }
5930
5931 public void setEventDispatching(boolean enabled) {
5932 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5933 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005934 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935 }
5936
5937 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005938 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005939 }
5940 }
Romain Guy06882f82009-06-10 13:36:04 -07005941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005942 /**
5943 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005944 * Even when sync is false, this method may block while waiting for current
5945 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005946 *
5947 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005948 * {@link SystemClock#uptimeMillis()} as the timebase.)
5949 * @param sync If true, wait for the event to be completed before returning to the caller.
5950 * @return Returns true if event was dispatched, false if it was dropped for any reason
5951 */
5952 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5953 long downTime = ev.getDownTime();
5954 long eventTime = ev.getEventTime();
5955
5956 int action = ev.getAction();
5957 int code = ev.getKeyCode();
5958 int repeatCount = ev.getRepeatCount();
5959 int metaState = ev.getMetaState();
5960 int deviceId = ev.getDeviceId();
5961 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005962 int source = ev.getSource();
5963
5964 if (source == InputDevice.SOURCE_UNKNOWN) {
5965 source = InputDevice.SOURCE_KEYBOARD;
5966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005967
5968 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5969 if (downTime == 0) downTime = eventTime;
5970
5971 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005972 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005973
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005974 final int pid = Binder.getCallingPid();
5975 final int uid = Binder.getCallingUid();
5976 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005977
Jeff Brownbbda99d2010-07-28 15:48:59 -07005978 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5979 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5980 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5981 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005982
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005983 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005984 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005985 }
5986
5987 /**
5988 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005989 * Even when sync is false, this method may block while waiting for current
5990 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005991 *
5992 * @param ev A motion event describing the pointer (touch) action. (As noted in
5993 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005994 * {@link SystemClock#uptimeMillis()} as the timebase.)
5995 * @param sync If true, wait for the event to be completed before returning to the caller.
5996 * @return Returns true if event was dispatched, false if it was dropped for any reason
5997 */
5998 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005999 final int pid = Binder.getCallingPid();
6000 final int uid = Binder.getCallingUid();
6001 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006002
Jeff Brownc5ed5912010-07-14 18:48:53 -07006003 MotionEvent newEvent = MotionEvent.obtain(ev);
6004 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6005 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6006 }
6007
Jeff Brownbbda99d2010-07-28 15:48:59 -07006008 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6009 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6010 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6011 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006012
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006013 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006014 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006015 }
Romain Guy06882f82009-06-10 13:36:04 -07006016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 /**
6018 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006019 * Even when sync is false, this method may block while waiting for current
6020 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006021 *
6022 * @param ev A motion event describing the trackball action. (As noted in
6023 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006024 * {@link SystemClock#uptimeMillis()} as the timebase.)
6025 * @param sync If true, wait for the event to be completed before returning to the caller.
6026 * @return Returns true if event was dispatched, false if it was dropped for any reason
6027 */
6028 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006029 final int pid = Binder.getCallingPid();
6030 final int uid = Binder.getCallingUid();
6031 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006032
Jeff Brownc5ed5912010-07-14 18:48:53 -07006033 MotionEvent newEvent = MotionEvent.obtain(ev);
6034 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6035 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6036 }
6037
Jeff Brownbbda99d2010-07-28 15:48:59 -07006038 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6039 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6040 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6041 INJECTION_TIMEOUT_MILLIS);
6042
6043 Binder.restoreCallingIdentity(ident);
6044 return reportInjectionResult(result);
6045 }
6046
6047 /**
6048 * Inject an input event into the UI without waiting for dispatch to commence.
6049 * This variant is useful for fire-and-forget input event injection. It does not
6050 * block any longer than it takes to enqueue the input event.
6051 *
6052 * @param ev An input event. (Be sure to set the input source correctly.)
6053 * @return Returns true if event was dispatched, false if it was dropped for any reason
6054 */
6055 public boolean injectInputEventNoWait(InputEvent ev) {
6056 final int pid = Binder.getCallingPid();
6057 final int uid = Binder.getCallingUid();
6058 final long ident = Binder.clearCallingIdentity();
6059
6060 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6061 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6062 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006063
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006064 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006065 return reportInjectionResult(result);
6066 }
6067
6068 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006069 switch (result) {
6070 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6071 Slog.w(TAG, "Input event injection permission denied.");
6072 throw new SecurityException(
6073 "Injecting to another application requires INJECT_EVENTS permission");
6074 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006075 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006076 return true;
6077 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6078 Slog.w(TAG, "Input event injection timed out.");
6079 return false;
6080 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6081 default:
6082 Slog.w(TAG, "Input event injection failed.");
6083 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 }
Romain Guy06882f82009-06-10 13:36:04 -07006086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006087 private WindowState getFocusedWindow() {
6088 synchronized (mWindowMap) {
6089 return getFocusedWindowLocked();
6090 }
6091 }
6092
6093 private WindowState getFocusedWindowLocked() {
6094 return mCurrentFocus;
6095 }
Romain Guy06882f82009-06-10 13:36:04 -07006096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006097 public boolean detectSafeMode() {
6098 mSafeMode = mPolicy.detectSafeMode();
6099 return mSafeMode;
6100 }
Romain Guy06882f82009-06-10 13:36:04 -07006101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006102 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006103 synchronized(mWindowMap) {
6104 if (mDisplay != null) {
6105 throw new IllegalStateException("Display already initialized");
6106 }
6107 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6108 mDisplay = wm.getDefaultDisplay();
6109 mInitialDisplayWidth = mDisplay.getWidth();
6110 mInitialDisplayHeight = mDisplay.getHeight();
6111 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6112 }
6113
6114 try {
6115 mActivityManager.updateConfiguration(null);
6116 } catch (RemoteException e) {
6117 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006118
6119 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006120 }
6121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 // -------------------------------------------------------------
6123 // Client Session State
6124 // -------------------------------------------------------------
6125
6126 private final class Session extends IWindowSession.Stub
6127 implements IBinder.DeathRecipient {
6128 final IInputMethodClient mClient;
6129 final IInputContext mInputContext;
6130 final int mUid;
6131 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006132 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 SurfaceSession mSurfaceSession;
6134 int mNumWindow = 0;
6135 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 public Session(IInputMethodClient client, IInputContext inputContext) {
6138 mClient = client;
6139 mInputContext = inputContext;
6140 mUid = Binder.getCallingUid();
6141 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006142 StringBuilder sb = new StringBuilder();
6143 sb.append("Session{");
6144 sb.append(Integer.toHexString(System.identityHashCode(this)));
6145 sb.append(" uid ");
6146 sb.append(mUid);
6147 sb.append("}");
6148 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 synchronized (mWindowMap) {
6151 if (mInputMethodManager == null && mHaveInputMethods) {
6152 IBinder b = ServiceManager.getService(
6153 Context.INPUT_METHOD_SERVICE);
6154 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6155 }
6156 }
6157 long ident = Binder.clearCallingIdentity();
6158 try {
6159 // Note: it is safe to call in to the input method manager
6160 // here because we are not holding our lock.
6161 if (mInputMethodManager != null) {
6162 mInputMethodManager.addClient(client, inputContext,
6163 mUid, mPid);
6164 } else {
6165 client.setUsingInputMethod(false);
6166 }
6167 client.asBinder().linkToDeath(this, 0);
6168 } catch (RemoteException e) {
6169 // The caller has died, so we can just forget about this.
6170 try {
6171 if (mInputMethodManager != null) {
6172 mInputMethodManager.removeClient(client);
6173 }
6174 } catch (RemoteException ee) {
6175 }
6176 } finally {
6177 Binder.restoreCallingIdentity(ident);
6178 }
6179 }
Romain Guy06882f82009-06-10 13:36:04 -07006180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181 @Override
6182 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6183 throws RemoteException {
6184 try {
6185 return super.onTransact(code, data, reply, flags);
6186 } catch (RuntimeException e) {
6187 // Log all 'real' exceptions thrown to the caller
6188 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006189 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006190 }
6191 throw e;
6192 }
6193 }
6194
6195 public void binderDied() {
6196 // Note: it is safe to call in to the input method manager
6197 // here because we are not holding our lock.
6198 try {
6199 if (mInputMethodManager != null) {
6200 mInputMethodManager.removeClient(mClient);
6201 }
6202 } catch (RemoteException e) {
6203 }
6204 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006205 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 mClientDead = true;
6207 killSessionLocked();
6208 }
6209 }
6210
6211 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006212 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6213 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6214 outInputChannel);
6215 }
6216
6217 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006219 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006220 }
Romain Guy06882f82009-06-10 13:36:04 -07006221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 public void remove(IWindow window) {
6223 removeWindow(this, window);
6224 }
Romain Guy06882f82009-06-10 13:36:04 -07006225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006226 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6227 int requestedWidth, int requestedHeight, int viewFlags,
6228 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006229 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006230 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6231 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006232 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006233 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006234 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6235 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006236 }
Romain Guy06882f82009-06-10 13:36:04 -07006237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006238 public void setTransparentRegion(IWindow window, Region region) {
6239 setTransparentRegionWindow(this, window, region);
6240 }
Romain Guy06882f82009-06-10 13:36:04 -07006241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006242 public void setInsets(IWindow window, int touchableInsets,
6243 Rect contentInsets, Rect visibleInsets) {
6244 setInsetsWindow(this, window, touchableInsets, contentInsets,
6245 visibleInsets);
6246 }
Romain Guy06882f82009-06-10 13:36:04 -07006247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006248 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6249 getWindowDisplayFrame(this, window, outDisplayFrame);
6250 }
Romain Guy06882f82009-06-10 13:36:04 -07006251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006252 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006253 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254 TAG, "IWindow finishDrawing called for " + window);
6255 finishDrawingWindow(this, window);
6256 }
6257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258 public void setInTouchMode(boolean mode) {
6259 synchronized(mWindowMap) {
6260 mInTouchMode = mode;
6261 }
6262 }
6263
6264 public boolean getInTouchMode() {
6265 synchronized(mWindowMap) {
6266 return mInTouchMode;
6267 }
6268 }
6269
6270 public boolean performHapticFeedback(IWindow window, int effectId,
6271 boolean always) {
6272 synchronized(mWindowMap) {
6273 long ident = Binder.clearCallingIdentity();
6274 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006275 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006276 windowForClientLocked(this, window, true),
6277 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 } finally {
6279 Binder.restoreCallingIdentity(ident);
6280 }
6281 }
6282 }
Romain Guy06882f82009-06-10 13:36:04 -07006283
Christopher Tatea53146c2010-09-07 11:57:52 -07006284 /* Drag/drop */
6285 public IBinder prepareDrag(IWindow window, boolean localOnly,
6286 int width, int height, Surface outSurface) {
6287 return prepareDragSurface(window, mSurfaceSession, localOnly,
6288 width, height, outSurface);
6289 }
6290
6291 public boolean performDrag(IWindow window, IBinder dragToken,
6292 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6293 ClipData data) {
6294 if (DEBUG_DRAG) {
6295 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6296 }
6297
6298 synchronized (mWindowMap) {
6299 if (mDragState == null) {
6300 Slog.w(TAG, "No drag prepared");
6301 throw new IllegalStateException("performDrag() without prepareDrag()");
6302 }
6303
6304 if (dragToken != mDragState.mToken) {
6305 Slog.w(TAG, "Performing mismatched drag");
6306 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6307 }
6308
6309 WindowState callingWin = windowForClientLocked(null, window, false);
6310 if (callingWin == null) {
6311 Slog.w(TAG, "Bad requesting window " + window);
6312 return false; // !!! TODO: throw here?
6313 }
6314
6315 // !!! TODO: if input is not still focused on the initiating window, fail
6316 // the drag initiation (e.g. an alarm window popped up just as the application
6317 // called performDrag()
6318
6319 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6320
Christopher Tate2c095f32010-10-04 14:13:40 -07006321 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6322 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006323
Chris Tateb478f462010-10-15 16:02:26 -07006324 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6325 // the actual drag event dispatch stuff in the dragstate
6326
Christopher Tatea53146c2010-09-07 11:57:52 -07006327 mDragState.register();
6328 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006329 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6330 mDragState.mServerChannel)) {
6331 Slog.e(TAG, "Unable to transfer touch focus");
6332 mDragState.unregister();
6333 mDragState = null;
6334 mInputMonitor.updateInputWindowsLw();
6335 return false;
6336 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006337
6338 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006339 mDragState.mCurrentX = touchX;
6340 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006341 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006342
6343 // remember the thumb offsets for later
6344 mDragState.mThumbOffsetX = thumbCenterX;
6345 mDragState.mThumbOffsetY = thumbCenterY;
6346
6347 // Make the surface visible at the proper location
6348 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006349 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006350 try {
6351 surface.setPosition((int)(touchX - thumbCenterX),
6352 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006353 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006354 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006355 surface.show();
6356 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006357 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006358 }
6359 }
6360
6361 return true; // success!
6362 }
6363
Chris Tated4533f142010-10-19 15:15:08 -07006364 public void reportDropResult(IWindow window, boolean consumed) {
6365 IBinder token = window.asBinder();
6366 if (DEBUG_DRAG) {
6367 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6368 }
6369
6370 synchronized (mWindowMap) {
6371 if (mDragState.mToken != token) {
6372 Slog.w(TAG, "Invalid drop-result claim by " + window);
6373 throw new IllegalStateException("reportDropResult() by non-recipient");
6374 }
6375
6376 // The right window has responded, even if it's no longer around,
6377 // so be sure to halt the timeout even if the later WindowState
6378 // lookup fails.
6379 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6380
6381 WindowState callingWin = windowForClientLocked(null, window, false);
6382 if (callingWin == null) {
6383 Slog.w(TAG, "Bad result-reporting window " + window);
6384 return; // !!! TODO: throw here?
6385 }
6386
6387 mDragState.mDragResult = consumed;
6388 mDragState.endDragLw();
6389 }
6390 }
6391
Christopher Tatea53146c2010-09-07 11:57:52 -07006392 public void dragRecipientEntered(IWindow window) {
6393 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006394 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006395 }
6396 }
6397
6398 public void dragRecipientExited(IWindow window) {
6399 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006400 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006401 }
6402 }
6403
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006404 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006405 synchronized(mWindowMap) {
6406 long ident = Binder.clearCallingIdentity();
6407 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006408 setWindowWallpaperPositionLocked(
6409 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006410 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006411 } finally {
6412 Binder.restoreCallingIdentity(ident);
6413 }
6414 }
6415 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006416
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006417 public void wallpaperOffsetsComplete(IBinder window) {
6418 WindowManagerService.this.wallpaperOffsetsComplete(window);
6419 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006420
Dianne Hackborn75804932009-10-20 20:15:20 -07006421 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6422 int z, Bundle extras, boolean sync) {
6423 synchronized(mWindowMap) {
6424 long ident = Binder.clearCallingIdentity();
6425 try {
6426 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006427 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006428 action, x, y, z, extras, sync);
6429 } finally {
6430 Binder.restoreCallingIdentity(ident);
6431 }
6432 }
6433 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006434
Dianne Hackborn75804932009-10-20 20:15:20 -07006435 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6436 WindowManagerService.this.wallpaperCommandComplete(window, result);
6437 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 void windowAddedLocked() {
6440 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006441 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 TAG, "First window added to " + this + ", creating SurfaceSession");
6443 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006444 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006445 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006446 mSessions.add(this);
6447 }
6448 mNumWindow++;
6449 }
6450
6451 void windowRemovedLocked() {
6452 mNumWindow--;
6453 killSessionLocked();
6454 }
Romain Guy06882f82009-06-10 13:36:04 -07006455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 void killSessionLocked() {
6457 if (mNumWindow <= 0 && mClientDead) {
6458 mSessions.remove(this);
6459 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006460 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006461 TAG, "Last window removed from " + this
6462 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006463 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006464 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 try {
6466 mSurfaceSession.kill();
6467 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006468 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 + mSurfaceSession + " in session " + this
6470 + ": " + e.toString());
6471 }
6472 mSurfaceSession = null;
6473 }
6474 }
6475 }
Romain Guy06882f82009-06-10 13:36:04 -07006476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006477 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006478 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6479 pw.print(" mClientDead="); pw.print(mClientDead);
6480 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 }
6482
6483 @Override
6484 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006485 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 }
6487 }
6488
6489 // -------------------------------------------------------------
6490 // Client Window State
6491 // -------------------------------------------------------------
6492
6493 private final class WindowState implements WindowManagerPolicy.WindowState {
6494 final Session mSession;
6495 final IWindow mClient;
6496 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006497 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 AppWindowToken mAppToken;
6499 AppWindowToken mTargetAppToken;
6500 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6501 final DeathRecipient mDeathRecipient;
6502 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006503 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006504 final int mBaseLayer;
6505 final int mSubLayer;
6506 final boolean mLayoutAttached;
6507 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006508 final boolean mIsWallpaper;
6509 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 int mViewVisibility;
6511 boolean mPolicyVisibility = true;
6512 boolean mPolicyVisibilityAfterAnim = true;
6513 boolean mAppFreezing;
6514 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006515 boolean mReportDestroySurface;
6516 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 boolean mAttachedHidden; // is our parent window hidden?
6518 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006519 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520 int mRequestedWidth;
6521 int mRequestedHeight;
6522 int mLastRequestedWidth;
6523 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006524 int mLayer;
6525 int mAnimLayer;
6526 int mLastLayer;
6527 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006528 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006529 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006530
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006531 int mLayoutSeq = -1;
6532
6533 Configuration mConfiguration = null;
6534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006535 // Actual frame shown on-screen (may be modified by animation)
6536 final Rect mShownFrame = new Rect();
6537 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006539 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006540 * Set when we have changed the size of the surface, to know that
6541 * we must tell them application to resize (and thus redraw itself).
6542 */
6543 boolean mSurfaceResized;
6544
6545 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006546 * Insets that determine the actually visible area
6547 */
6548 final Rect mVisibleInsets = new Rect();
6549 final Rect mLastVisibleInsets = new Rect();
6550 boolean mVisibleInsetsChanged;
6551
6552 /**
6553 * Insets that are covered by system windows
6554 */
6555 final Rect mContentInsets = new Rect();
6556 final Rect mLastContentInsets = new Rect();
6557 boolean mContentInsetsChanged;
6558
6559 /**
6560 * Set to true if we are waiting for this window to receive its
6561 * given internal insets before laying out other windows based on it.
6562 */
6563 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 /**
6566 * These are the content insets that were given during layout for
6567 * this window, to be applied to windows behind it.
6568 */
6569 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 /**
6572 * These are the visible insets that were given during layout for
6573 * this window, to be applied to windows behind it.
6574 */
6575 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577 /**
6578 * Flag indicating whether the touchable region should be adjusted by
6579 * the visible insets; if false the area outside the visible insets is
6580 * NOT touchable, so we must use those to adjust the frame during hit
6581 * tests.
6582 */
6583 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 // Current transformation being applied.
6586 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6587 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6588 float mHScale=1, mVScale=1;
6589 float mLastHScale=1, mLastVScale=1;
6590 final Matrix mTmpMatrix = new Matrix();
6591
6592 // "Real" frame that the application sees.
6593 final Rect mFrame = new Rect();
6594 final Rect mLastFrame = new Rect();
6595
6596 final Rect mContainingFrame = new Rect();
6597 final Rect mDisplayFrame = new Rect();
6598 final Rect mContentFrame = new Rect();
6599 final Rect mVisibleFrame = new Rect();
6600
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006601 boolean mContentChanged;
6602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 float mShownAlpha = 1;
6604 float mAlpha = 1;
6605 float mLastAlpha = 1;
6606
6607 // Set to true if, when the window gets displayed, it should perform
6608 // an enter animation.
6609 boolean mEnterAnimationPending;
6610
6611 // Currently running animation.
6612 boolean mAnimating;
6613 boolean mLocalAnimating;
6614 Animation mAnimation;
6615 boolean mAnimationIsEntrance;
6616 boolean mHasTransformation;
6617 boolean mHasLocalTransformation;
6618 final Transformation mTransformation = new Transformation();
6619
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006620 // If a window showing a wallpaper: the requested offset for the
6621 // wallpaper; if a wallpaper window: the currently applied offset.
6622 float mWallpaperX = -1;
6623 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006624
6625 // If a window showing a wallpaper: what fraction of the offset
6626 // range corresponds to a full virtual screen.
6627 float mWallpaperXStep = -1;
6628 float mWallpaperYStep = -1;
6629
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006630 // Wallpaper windows: pixels offset based on above variables.
6631 int mXOffset;
6632 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006634 // This is set after IWindowSession.relayout() has been called at
6635 // least once for the window. It allows us to detect the situation
6636 // where we don't yet have a surface, but should have one soon, so
6637 // we can give the window focus before waiting for the relayout.
6638 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 // This is set after the Surface has been created but before the
6641 // window has been drawn. During this time the surface is hidden.
6642 boolean mDrawPending;
6643
6644 // This is set after the window has finished drawing for the first
6645 // time but before its surface is shown. The surface will be
6646 // displayed when the next layout is run.
6647 boolean mCommitDrawPending;
6648
6649 // This is set during the time after the window's drawing has been
6650 // committed, and before its surface is actually shown. It is used
6651 // to delay showing the surface until all windows in a token are ready
6652 // to be shown.
6653 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 // Set when the window has been shown in the screen the first time.
6656 boolean mHasDrawn;
6657
6658 // Currently running an exit animation?
6659 boolean mExiting;
6660
6661 // Currently on the mDestroySurface list?
6662 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006664 // Completely remove from window manager after exit animation?
6665 boolean mRemoveOnExit;
6666
6667 // Set when the orientation is changing and this window has not yet
6668 // been updated for the new orientation.
6669 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 // Is this window now (or just being) removed?
6672 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006673
Dianne Hackborn16064f92010-03-25 00:47:24 -07006674 // For debugging, this is the last information given to the surface flinger.
6675 boolean mSurfaceShown;
6676 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6677 int mSurfaceLayer;
6678 float mSurfaceAlpha;
6679
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006680 // Input channel
6681 InputChannel mInputChannel;
6682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 WindowState(Session s, IWindow c, WindowToken token,
6684 WindowState attachedWindow, WindowManager.LayoutParams a,
6685 int viewVisibility) {
6686 mSession = s;
6687 mClient = c;
6688 mToken = token;
6689 mAttrs.copyFrom(a);
6690 mViewVisibility = viewVisibility;
6691 DeathRecipient deathRecipient = new DeathRecipient();
6692 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006693 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006694 TAG, "Window " + this + " client=" + c.asBinder()
6695 + " token=" + token + " (" + mAttrs.token + ")");
6696 try {
6697 c.asBinder().linkToDeath(deathRecipient, 0);
6698 } catch (RemoteException e) {
6699 mDeathRecipient = null;
6700 mAttachedWindow = null;
6701 mLayoutAttached = false;
6702 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006703 mIsWallpaper = false;
6704 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006705 mBaseLayer = 0;
6706 mSubLayer = 0;
6707 return;
6708 }
6709 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006711 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6712 mAttrs.type <= LAST_SUB_WINDOW)) {
6713 // The multiplier here is to reserve space for multiple
6714 // windows in the same type layer.
6715 mBaseLayer = mPolicy.windowTypeToLayerLw(
6716 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6717 + TYPE_LAYER_OFFSET;
6718 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6719 mAttachedWindow = attachedWindow;
6720 mAttachedWindow.mChildWindows.add(this);
6721 mLayoutAttached = mAttrs.type !=
6722 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6723 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6724 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006725 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6726 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 } else {
6728 // The multiplier here is to reserve space for multiple
6729 // windows in the same type layer.
6730 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6731 * TYPE_LAYER_MULTIPLIER
6732 + TYPE_LAYER_OFFSET;
6733 mSubLayer = 0;
6734 mAttachedWindow = null;
6735 mLayoutAttached = false;
6736 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6737 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006738 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6739 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740 }
6741
6742 WindowState appWin = this;
6743 while (appWin.mAttachedWindow != null) {
6744 appWin = mAttachedWindow;
6745 }
6746 WindowToken appToken = appWin.mToken;
6747 while (appToken.appWindowToken == null) {
6748 WindowToken parent = mTokenMap.get(appToken.token);
6749 if (parent == null || appToken == parent) {
6750 break;
6751 }
6752 appToken = parent;
6753 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006754 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 mAppToken = appToken.appWindowToken;
6756
6757 mSurface = null;
6758 mRequestedWidth = 0;
6759 mRequestedHeight = 0;
6760 mLastRequestedWidth = 0;
6761 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006762 mXOffset = 0;
6763 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764 mLayer = 0;
6765 mAnimLayer = 0;
6766 mLastLayer = 0;
6767 }
6768
6769 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006770 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 TAG, "Attaching " + this + " token=" + mToken
6772 + ", list=" + mToken.windows);
6773 mSession.windowAddedLocked();
6774 }
6775
6776 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6777 mHaveFrame = true;
6778
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006779 final Rect container = mContainingFrame;
6780 container.set(pf);
6781
6782 final Rect display = mDisplayFrame;
6783 display.set(df);
6784
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006785 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006786 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006787 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6788 display.intersect(mCompatibleScreenFrame);
6789 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006790 }
6791
6792 final int pw = container.right - container.left;
6793 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006794
6795 int w,h;
6796 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6797 w = mAttrs.width < 0 ? pw : mAttrs.width;
6798 h = mAttrs.height< 0 ? ph : mAttrs.height;
6799 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006800 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6801 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 }
Romain Guy06882f82009-06-10 13:36:04 -07006803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006804 final Rect content = mContentFrame;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006805 mContentChanged |= !content.equals(cf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 final Rect visible = mVisibleFrame;
6809 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006811 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006812 final int fw = frame.width();
6813 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6816 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6817
6818 Gravity.apply(mAttrs.gravity, w, h, container,
6819 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6820 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6821
6822 //System.out.println("Out: " + mFrame);
6823
6824 // Now make sure the window fits in the overall display.
6825 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 // Make sure the content and visible frames are inside of the
6828 // final window frame.
6829 if (content.left < frame.left) content.left = frame.left;
6830 if (content.top < frame.top) content.top = frame.top;
6831 if (content.right > frame.right) content.right = frame.right;
6832 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6833 if (visible.left < frame.left) visible.left = frame.left;
6834 if (visible.top < frame.top) visible.top = frame.top;
6835 if (visible.right > frame.right) visible.right = frame.right;
6836 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 final Rect contentInsets = mContentInsets;
6839 contentInsets.left = content.left-frame.left;
6840 contentInsets.top = content.top-frame.top;
6841 contentInsets.right = frame.right-content.right;
6842 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844 final Rect visibleInsets = mVisibleInsets;
6845 visibleInsets.left = visible.left-frame.left;
6846 visibleInsets.top = visible.top-frame.top;
6847 visibleInsets.right = frame.right-visible.right;
6848 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006849
Dianne Hackborn284ac932009-08-28 10:34:25 -07006850 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6851 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006852 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006853 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006855 if (localLOGV) {
6856 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6857 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006858 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 + mRequestedWidth + ", mRequestedheight="
6860 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6861 + "): frame=" + mFrame.toShortString()
6862 + " ci=" + contentInsets.toShortString()
6863 + " vi=" + visibleInsets.toShortString());
6864 //}
6865 }
6866 }
Romain Guy06882f82009-06-10 13:36:04 -07006867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006868 public Rect getFrameLw() {
6869 return mFrame;
6870 }
6871
6872 public Rect getShownFrameLw() {
6873 return mShownFrame;
6874 }
6875
6876 public Rect getDisplayFrameLw() {
6877 return mDisplayFrame;
6878 }
6879
6880 public Rect getContentFrameLw() {
6881 return mContentFrame;
6882 }
6883
6884 public Rect getVisibleFrameLw() {
6885 return mVisibleFrame;
6886 }
6887
6888 public boolean getGivenInsetsPendingLw() {
6889 return mGivenInsetsPending;
6890 }
6891
6892 public Rect getGivenContentInsetsLw() {
6893 return mGivenContentInsets;
6894 }
Romain Guy06882f82009-06-10 13:36:04 -07006895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 public Rect getGivenVisibleInsetsLw() {
6897 return mGivenVisibleInsets;
6898 }
Romain Guy06882f82009-06-10 13:36:04 -07006899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006900 public WindowManager.LayoutParams getAttrs() {
6901 return mAttrs;
6902 }
6903
6904 public int getSurfaceLayer() {
6905 return mLayer;
6906 }
Romain Guy06882f82009-06-10 13:36:04 -07006907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 public IApplicationToken getAppToken() {
6909 return mAppToken != null ? mAppToken.appToken : null;
6910 }
Jeff Brown349703e2010-06-22 01:27:15 -07006911
6912 public long getInputDispatchingTimeoutNanos() {
6913 return mAppToken != null
6914 ? mAppToken.inputDispatchingTimeoutNanos
6915 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006917
6918 public boolean hasAppShownWindows() {
6919 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6920 }
6921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006923 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006924 TAG, "Setting animation in " + this + ": " + anim);
6925 mAnimating = false;
6926 mLocalAnimating = false;
6927 mAnimation = anim;
6928 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6929 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6930 }
6931
6932 public void clearAnimation() {
6933 if (mAnimation != null) {
6934 mAnimating = true;
6935 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07006936 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006937 mAnimation = null;
6938 }
6939 }
Romain Guy06882f82009-06-10 13:36:04 -07006940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 Surface createSurfaceLocked() {
6942 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006943 mReportDestroySurface = false;
6944 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 mDrawPending = true;
6946 mCommitDrawPending = false;
6947 mReadyToShow = false;
6948 if (mAppToken != null) {
6949 mAppToken.allDrawn = false;
6950 }
6951
6952 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006953 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006954 flags |= Surface.PUSH_BUFFERS;
6955 }
6956
6957 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6958 flags |= Surface.SECURE;
6959 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006960 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006961 TAG, "Creating surface in session "
6962 + mSession.mSurfaceSession + " window " + this
6963 + " w=" + mFrame.width()
6964 + " h=" + mFrame.height() + " format="
6965 + mAttrs.format + " flags=" + flags);
6966
6967 int w = mFrame.width();
6968 int h = mFrame.height();
6969 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6970 // for a scaled surface, we always want the requested
6971 // size.
6972 w = mRequestedWidth;
6973 h = mRequestedHeight;
6974 }
6975
Romain Guy9825ec62009-10-01 00:58:09 -07006976 // Something is wrong and SurfaceFlinger will not like this,
6977 // try to revert to sane values
6978 if (w <= 0) w = 1;
6979 if (h <= 0) h = 1;
6980
Dianne Hackborn16064f92010-03-25 00:47:24 -07006981 mSurfaceShown = false;
6982 mSurfaceLayer = 0;
6983 mSurfaceAlpha = 1;
6984 mSurfaceX = 0;
6985 mSurfaceY = 0;
6986 mSurfaceW = w;
6987 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006988 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006989 final boolean isHwAccelerated = (mAttrs.flags &
6990 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6991 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6992 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6993 flags |= Surface.OPAQUE;
6994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006996 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006997 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006998 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006999 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007000 + mSurface + " IN SESSION "
7001 + mSession.mSurfaceSession
7002 + ": pid=" + mSession.mPid + " format="
7003 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007004 + Integer.toHexString(flags)
7005 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007006 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007007 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 reclaimSomeSurfaceMemoryLocked(this, "create");
7009 return null;
7010 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007011 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 return null;
7013 }
Romain Guy06882f82009-06-10 13:36:04 -07007014
Joe Onorato8a9b2202010-02-26 18:56:32 -08007015 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 TAG, "Got surface: " + mSurface
7017 + ", set left=" + mFrame.left + " top=" + mFrame.top
7018 + ", animLayer=" + mAnimLayer);
7019 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007020 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007021 if (SHOW_TRANSACTIONS) logSurface(this,
7022 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7023 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7024 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007025 }
7026 Surface.openTransaction();
7027 try {
7028 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007029 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007030 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007031 mSurface.setPosition(mSurfaceX, mSurfaceY);
7032 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007033 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007034 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 mSurface.hide();
7036 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007037 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 mSurface.setFlags(Surface.SURFACE_DITHER,
7039 Surface.SURFACE_DITHER);
7040 }
7041 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007042 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7044 }
7045 mLastHidden = true;
7046 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007047 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048 Surface.closeTransaction();
7049 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007050 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007051 TAG, "Created surface " + this);
7052 }
7053 return mSurface;
7054 }
Romain Guy06882f82009-06-10 13:36:04 -07007055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007056 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 if (mAppToken != null && this == mAppToken.startingWindow) {
7058 mAppToken.startingDisplayed = false;
7059 }
Romain Guy06882f82009-06-10 13:36:04 -07007060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007062 mDrawPending = false;
7063 mCommitDrawPending = false;
7064 mReadyToShow = false;
7065
7066 int i = mChildWindows.size();
7067 while (i > 0) {
7068 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007069 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007070 c.mAttachedHidden = true;
7071 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007072
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007073 if (mReportDestroySurface) {
7074 mReportDestroySurface = false;
7075 mSurfacePendingDestroy = true;
7076 try {
7077 mClient.dispatchGetNewSurface();
7078 // We'll really destroy on the next time around.
7079 return;
7080 } catch (RemoteException e) {
7081 }
7082 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007085 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007086 RuntimeException e = null;
7087 if (!HIDE_STACK_CRAWLS) {
7088 e = new RuntimeException();
7089 e.fillInStackTrace();
7090 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007091 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007092 + mSurface + ", session " + mSession, e);
7093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007095 RuntimeException e = null;
7096 if (!HIDE_STACK_CRAWLS) {
7097 e = new RuntimeException();
7098 e.fillInStackTrace();
7099 }
7100 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007102 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007104 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007105 + " surface " + mSurface + " session " + mSession
7106 + ": " + e.toString());
7107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007108
Dianne Hackborn16064f92010-03-25 00:47:24 -07007109 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007110 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 }
7112 }
7113
7114 boolean finishDrawingLocked() {
7115 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007116 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007117 TAG, "finishDrawingLocked: " + mSurface);
7118 mCommitDrawPending = true;
7119 mDrawPending = false;
7120 return true;
7121 }
7122 return false;
7123 }
7124
7125 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007126 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007127 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007128 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007129 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 }
7131 mCommitDrawPending = false;
7132 mReadyToShow = true;
7133 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7134 final AppWindowToken atoken = mAppToken;
7135 if (atoken == null || atoken.allDrawn || starting) {
7136 performShowLocked();
7137 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007138 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007139 }
7140
7141 // This must be called while inside a transaction.
7142 boolean performShowLocked() {
7143 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007144 RuntimeException e = null;
7145 if (!HIDE_STACK_CRAWLS) {
7146 e = new RuntimeException();
7147 e.fillInStackTrace();
7148 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007149 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7151 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7152 }
7153 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007154 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7155 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007156 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007157 + " during animation: policyVis=" + mPolicyVisibility
7158 + " attHidden=" + mAttachedHidden
7159 + " tok.hiddenRequested="
7160 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007161 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 + (mAppToken != null ? mAppToken.hidden : false)
7163 + " animating=" + mAnimating
7164 + " tok animating="
7165 + (mAppToken != null ? mAppToken.animating : false));
7166 if (!showSurfaceRobustlyLocked(this)) {
7167 return false;
7168 }
7169 mLastAlpha = -1;
7170 mHasDrawn = true;
7171 mLastHidden = false;
7172 mReadyToShow = false;
7173 enableScreenIfNeededLocked();
7174
7175 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007177 int i = mChildWindows.size();
7178 while (i > 0) {
7179 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007180 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007181 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007183 if (c.mSurface != null) {
7184 c.performShowLocked();
7185 // It hadn't been shown, which means layout not
7186 // performed on it, so now we want to make sure to
7187 // do a layout. If called from within the transaction
7188 // loop, this will cause it to restart with a new
7189 // layout.
7190 mLayoutNeeded = true;
7191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 }
7193 }
Romain Guy06882f82009-06-10 13:36:04 -07007194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 if (mAttrs.type != TYPE_APPLICATION_STARTING
7196 && mAppToken != null) {
7197 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007198
Dianne Hackborn248b1882009-09-16 16:46:44 -07007199 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007200 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007201 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007203 // If this initial window is animating, stop it -- we
7204 // will do an animation to reveal it from behind the
7205 // starting window, so there is no need for it to also
7206 // be doing its own stuff.
7207 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007208 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007209 mAnimation = null;
7210 // Make sure we clean up the animation.
7211 mAnimating = true;
7212 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007213 mFinishedStarting.add(mAppToken);
7214 mH.sendEmptyMessage(H.FINISHED_STARTING);
7215 }
7216 mAppToken.updateReportedVisibilityLocked();
7217 }
7218 }
7219 return true;
7220 }
Romain Guy06882f82009-06-10 13:36:04 -07007221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007222 // This must be called while inside a transaction. Returns true if
7223 // there is more animation to run.
7224 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007225 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007226 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7229 mHasTransformation = true;
7230 mHasLocalTransformation = true;
7231 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007232 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007233 TAG, "Starting animation in " + this +
7234 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7235 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7236 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7237 mAnimation.setStartTime(currentTime);
7238 mLocalAnimating = true;
7239 mAnimating = true;
7240 }
7241 mTransformation.clear();
7242 final boolean more = mAnimation.getTransformation(
7243 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007244 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007245 TAG, "Stepped animation in " + this +
7246 ": more=" + more + ", xform=" + mTransformation);
7247 if (more) {
7248 // we're not done!
7249 return true;
7250 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007251 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 TAG, "Finished animation in " + this +
7253 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007254
7255 if (mAnimation != null) {
7256 mAnimation.cancel();
7257 mAnimation = null;
7258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 //WindowManagerService.this.dump();
7260 }
7261 mHasLocalTransformation = false;
7262 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007263 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007264 // When our app token is animating, we kind-of pretend like
7265 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7266 // part of this check means that we will only do this if
7267 // our window is not currently exiting, or it is not
7268 // locally animating itself. The idea being that one that
7269 // is exiting and doing a local animation should be removed
7270 // once that animation is done.
7271 mAnimating = true;
7272 mHasTransformation = true;
7273 mTransformation.clear();
7274 return false;
7275 } else if (mHasTransformation) {
7276 // Little trick to get through the path below to act like
7277 // we have finished an animation.
7278 mAnimating = true;
7279 } else if (isAnimating()) {
7280 mAnimating = true;
7281 }
7282 } else if (mAnimation != null) {
7283 // If the display is frozen, and there is a pending animation,
7284 // clear it and make sure we run the cleanup code.
7285 mAnimating = true;
7286 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007287 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007288 mAnimation = null;
7289 }
Romain Guy06882f82009-06-10 13:36:04 -07007290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 if (!mAnimating && !mLocalAnimating) {
7292 return false;
7293 }
7294
Joe Onorato8a9b2202010-02-26 18:56:32 -08007295 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007296 TAG, "Animation done in " + this + ": exiting=" + mExiting
7297 + ", reportedVisible="
7298 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 mAnimating = false;
7301 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007302 if (mAnimation != null) {
7303 mAnimation.cancel();
7304 mAnimation = null;
7305 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007306 mAnimLayer = mLayer;
7307 if (mIsImWindow) {
7308 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007309 } else if (mIsWallpaper) {
7310 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007311 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007312 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007313 + " anim layer: " + mAnimLayer);
7314 mHasTransformation = false;
7315 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007316 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7317 if (DEBUG_VISIBILITY) {
7318 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7319 + mPolicyVisibilityAfterAnim);
7320 }
7321 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7322 if (!mPolicyVisibility) {
7323 if (mCurrentFocus == this) {
7324 mFocusMayChange = true;
7325 }
7326 // Window is no longer visible -- make sure if we were waiting
7327 // for it to be displayed before enabling the display, that
7328 // we allow the display to be enabled now.
7329 enableScreenIfNeededLocked();
7330 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 mTransformation.clear();
7333 if (mHasDrawn
7334 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7335 && mAppToken != null
7336 && mAppToken.firstWindowDrawn
7337 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007338 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 + mToken + ": first real window done animating");
7340 mFinishedStarting.add(mAppToken);
7341 mH.sendEmptyMessage(H.FINISHED_STARTING);
7342 }
Romain Guy06882f82009-06-10 13:36:04 -07007343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 finishExit();
7345
7346 if (mAppToken != null) {
7347 mAppToken.updateReportedVisibilityLocked();
7348 }
7349
7350 return false;
7351 }
7352
7353 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007354 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 TAG, "finishExit in " + this
7356 + ": exiting=" + mExiting
7357 + " remove=" + mRemoveOnExit
7358 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 final int N = mChildWindows.size();
7361 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007362 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 }
Romain Guy06882f82009-06-10 13:36:04 -07007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 if (!mExiting) {
7366 return;
7367 }
Romain Guy06882f82009-06-10 13:36:04 -07007368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 if (isWindowAnimating()) {
7370 return;
7371 }
7372
Joe Onorato8a9b2202010-02-26 18:56:32 -08007373 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007374 TAG, "Exit animation finished in " + this
7375 + ": remove=" + mRemoveOnExit);
7376 if (mSurface != null) {
7377 mDestroySurface.add(this);
7378 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007379 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007380 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007381 try {
7382 mSurface.hide();
7383 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007384 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 }
7386 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 }
7388 mExiting = false;
7389 if (mRemoveOnExit) {
7390 mPendingRemove.add(this);
7391 mRemoveOnExit = false;
7392 }
7393 }
Romain Guy06882f82009-06-10 13:36:04 -07007394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007395 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7396 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7397 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7398 if (dtdx < -.000001f || dtdx > .000001f) return false;
7399 if (dsdy < -.000001f || dsdy > .000001f) return false;
7400 return true;
7401 }
Romain Guy06882f82009-06-10 13:36:04 -07007402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007403 void computeShownFrameLocked() {
7404 final boolean selfTransformation = mHasLocalTransformation;
7405 Transformation attachedTransformation =
7406 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7407 ? mAttachedWindow.mTransformation : null;
7408 Transformation appTransformation =
7409 (mAppToken != null && mAppToken.hasTransformation)
7410 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007411
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007412 // Wallpapers are animated based on the "real" window they
7413 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007414 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007415 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007416 if (mWallpaperTarget.mHasLocalTransformation &&
7417 mWallpaperTarget.mAnimation != null &&
7418 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007419 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007420 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007421 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007422 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007423 }
7424 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007425 mWallpaperTarget.mAppToken.hasTransformation &&
7426 mWallpaperTarget.mAppToken.animation != null &&
7427 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007428 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007429 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007430 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007431 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007432 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007433 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 if (selfTransformation || attachedTransformation != null
7436 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007437 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 final Rect frame = mFrame;
7439 final float tmpFloats[] = mTmpFloats;
7440 final Matrix tmpMatrix = mTmpMatrix;
7441
7442 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007443 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007445 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007447 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007449 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 }
7451 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007452 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 }
7454
7455 // "convert" it into SurfaceFlinger's format
7456 // (a 2x2 matrix + an offset)
7457 // Here we must not transform the position of the surface
7458 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007459 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 tmpMatrix.getValues(tmpFloats);
7462 mDsDx = tmpFloats[Matrix.MSCALE_X];
7463 mDtDx = tmpFloats[Matrix.MSKEW_X];
7464 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7465 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007466 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7467 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007468 int w = frame.width();
7469 int h = frame.height();
7470 mShownFrame.set(x, y, x+w, y+h);
7471
7472 // Now set the alpha... but because our current hardware
7473 // can't do alpha transformation on a non-opaque surface,
7474 // turn it off if we are running an animation that is also
7475 // transforming since it is more important to have that
7476 // animation be smooth.
7477 mShownAlpha = mAlpha;
7478 if (!mLimitedAlphaCompositing
7479 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7480 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7481 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007482 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 if (selfTransformation) {
7484 mShownAlpha *= mTransformation.getAlpha();
7485 }
7486 if (attachedTransformation != null) {
7487 mShownAlpha *= attachedTransformation.getAlpha();
7488 }
7489 if (appTransformation != null) {
7490 mShownAlpha *= appTransformation.getAlpha();
7491 }
7492 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007493 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 }
Romain Guy06882f82009-06-10 13:36:04 -07007495
Joe Onorato8a9b2202010-02-26 18:56:32 -08007496 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 TAG, "Continuing animation in " + this +
7498 ": " + mShownFrame +
7499 ", alpha=" + mTransformation.getAlpha());
7500 return;
7501 }
Romain Guy06882f82009-06-10 13:36:04 -07007502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007504 if (mXOffset != 0 || mYOffset != 0) {
7505 mShownFrame.offset(mXOffset, mYOffset);
7506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 mShownAlpha = mAlpha;
7508 mDsDx = 1;
7509 mDtDx = 0;
7510 mDsDy = 0;
7511 mDtDy = 1;
7512 }
Romain Guy06882f82009-06-10 13:36:04 -07007513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007514 /**
7515 * Is this window visible? It is not visible if there is no
7516 * surface, or we are in the process of running an exit animation
7517 * that will remove the surface, or its app token has been hidden.
7518 */
7519 public boolean isVisibleLw() {
7520 final AppWindowToken atoken = mAppToken;
7521 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7522 && (atoken == null || !atoken.hiddenRequested)
7523 && !mExiting && !mDestroying;
7524 }
7525
7526 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007527 * Like {@link #isVisibleLw}, but also counts a window that is currently
7528 * "hidden" behind the keyguard as visible. This allows us to apply
7529 * things like window flags that impact the keyguard.
7530 * XXX I am starting to think we need to have ANOTHER visibility flag
7531 * for this "hidden behind keyguard" state rather than overloading
7532 * mPolicyVisibility. Ungh.
7533 */
7534 public boolean isVisibleOrBehindKeyguardLw() {
7535 final AppWindowToken atoken = mAppToken;
7536 return mSurface != null && !mAttachedHidden
7537 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007538 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007539 && !mExiting && !mDestroying;
7540 }
7541
7542 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 * Is this window visible, ignoring its app token? It is not visible
7544 * if there is no surface, or we are in the process of running an exit animation
7545 * that will remove the surface.
7546 */
7547 public boolean isWinVisibleLw() {
7548 final AppWindowToken atoken = mAppToken;
7549 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7550 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7551 && !mExiting && !mDestroying;
7552 }
7553
7554 /**
7555 * The same as isVisible(), but follows the current hidden state of
7556 * the associated app token, not the pending requested hidden state.
7557 */
7558 boolean isVisibleNow() {
7559 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007560 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007561 }
7562
7563 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007564 * Can this window possibly be a drag/drop target? The test here is
7565 * a combination of the above "visible now" with the check that the
7566 * Input Manager uses when discarding windows from input consideration.
7567 */
7568 boolean isPotentialDragTarget() {
7569 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7570 }
7571
7572 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 * Same as isVisible(), but we also count it as visible between the
7574 * call to IWindowSession.add() and the first relayout().
7575 */
7576 boolean isVisibleOrAdding() {
7577 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007578 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007579 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7580 && mPolicyVisibility && !mAttachedHidden
7581 && (atoken == null || !atoken.hiddenRequested)
7582 && !mExiting && !mDestroying;
7583 }
7584
7585 /**
7586 * Is this window currently on-screen? It is on-screen either if it
7587 * is visible or it is currently running an animation before no longer
7588 * being visible.
7589 */
7590 boolean isOnScreen() {
7591 final AppWindowToken atoken = mAppToken;
7592 if (atoken != null) {
7593 return mSurface != null && mPolicyVisibility && !mDestroying
7594 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007595 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 } else {
7597 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007598 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 }
7600 }
Romain Guy06882f82009-06-10 13:36:04 -07007601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 /**
7603 * Like isOnScreen(), but we don't return true if the window is part
7604 * of a transition that has not yet been started.
7605 */
7606 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007607 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007608 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007609 return false;
7610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007612 final boolean animating = atoken != null
7613 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007615 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7616 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007617 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 }
7619
7620 /** Is the window or its container currently animating? */
7621 boolean isAnimating() {
7622 final WindowState attached = mAttachedWindow;
7623 final AppWindowToken atoken = mAppToken;
7624 return mAnimation != null
7625 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007626 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 (atoken.animation != null
7628 || atoken.inPendingTransaction));
7629 }
7630
7631 /** Is this window currently animating? */
7632 boolean isWindowAnimating() {
7633 return mAnimation != null;
7634 }
7635
7636 /**
7637 * Like isOnScreen, but returns false if the surface hasn't yet
7638 * been drawn.
7639 */
7640 public boolean isDisplayedLw() {
7641 final AppWindowToken atoken = mAppToken;
7642 return mSurface != null && mPolicyVisibility && !mDestroying
7643 && !mDrawPending && !mCommitDrawPending
7644 && ((!mAttachedHidden &&
7645 (atoken == null || !atoken.hiddenRequested))
7646 || mAnimating);
7647 }
7648
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007649 /**
7650 * Returns true if the window has a surface that it has drawn a
7651 * complete UI in to.
7652 */
7653 public boolean isDrawnLw() {
7654 final AppWindowToken atoken = mAppToken;
7655 return mSurface != null && !mDestroying
7656 && !mDrawPending && !mCommitDrawPending;
7657 }
7658
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007659 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007660 * Return true if the window is opaque and fully drawn. This indicates
7661 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007662 */
7663 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007664 return (mAttrs.format == PixelFormat.OPAQUE
7665 || mAttrs.type == TYPE_WALLPAPER)
7666 && mSurface != null && mAnimation == null
7667 && (mAppToken == null || mAppToken.animation == null)
7668 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007669 }
7670
7671 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7672 return
7673 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007674 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7675 // only if it's visible
7676 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007677 // and only if the application fills the compatible screen
7678 mFrame.left <= mCompatibleScreenFrame.left &&
7679 mFrame.top <= mCompatibleScreenFrame.top &&
7680 mFrame.right >= mCompatibleScreenFrame.right &&
7681 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007682 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007683 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007684 }
7685
7686 boolean isFullscreen(int screenWidth, int screenHeight) {
7687 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007688 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 }
7690
7691 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007692 disposeInputChannel();
7693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 if (mAttachedWindow != null) {
7695 mAttachedWindow.mChildWindows.remove(this);
7696 }
7697 destroySurfaceLocked();
7698 mSession.windowRemovedLocked();
7699 try {
7700 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7701 } catch (RuntimeException e) {
7702 // Ignore if it has already been removed (usually because
7703 // we are doing this as part of processing a death note.)
7704 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007705 }
7706
7707 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007708 if (mInputChannel != null) {
7709 mInputManager.unregisterInputChannel(mInputChannel);
7710
7711 mInputChannel.dispose();
7712 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007714 }
7715
7716 private class DeathRecipient implements IBinder.DeathRecipient {
7717 public void binderDied() {
7718 try {
7719 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007720 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007721 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007722 if (win != null) {
7723 removeWindowLocked(mSession, win);
7724 }
7725 }
7726 } catch (IllegalArgumentException ex) {
7727 // This will happen if the window has already been
7728 // removed.
7729 }
7730 }
7731 }
7732
7733 /** Returns true if this window desires key events. */
7734 public final boolean canReceiveKeys() {
7735 return isVisibleOrAdding()
7736 && (mViewVisibility == View.VISIBLE)
7737 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7738 }
7739
7740 public boolean hasDrawnLw() {
7741 return mHasDrawn;
7742 }
7743
7744 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007745 return showLw(doAnimation, true);
7746 }
7747
7748 boolean showLw(boolean doAnimation, boolean requestAnim) {
7749 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7750 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007752 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007753 if (doAnimation) {
7754 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7755 + mPolicyVisibility + " mAnimation=" + mAnimation);
7756 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7757 doAnimation = false;
7758 } else if (mPolicyVisibility && mAnimation == null) {
7759 // Check for the case where we are currently visible and
7760 // not animating; we do not want to do animation at such a
7761 // point to become visible when we already are.
7762 doAnimation = false;
7763 }
7764 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007765 mPolicyVisibility = true;
7766 mPolicyVisibilityAfterAnim = true;
7767 if (doAnimation) {
7768 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7769 }
7770 if (requestAnim) {
7771 requestAnimationLocked(0);
7772 }
7773 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 }
7775
7776 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007777 return hideLw(doAnimation, true);
7778 }
7779
7780 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007781 if (doAnimation) {
7782 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7783 doAnimation = false;
7784 }
7785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7787 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007788 if (!current) {
7789 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007791 if (doAnimation) {
7792 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7793 if (mAnimation == null) {
7794 doAnimation = false;
7795 }
7796 }
7797 if (doAnimation) {
7798 mPolicyVisibilityAfterAnim = false;
7799 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007800 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007801 mPolicyVisibilityAfterAnim = false;
7802 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007803 // Window is no longer visible -- make sure if we were waiting
7804 // for it to be displayed before enabling the display, that
7805 // we allow the display to be enabled now.
7806 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007807 if (mCurrentFocus == this) {
7808 mFocusMayChange = true;
7809 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007810 }
7811 if (requestAnim) {
7812 requestAnimationLocked(0);
7813 }
7814 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007815 }
7816
7817 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007818 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7819 pw.print(" mClient="); pw.println(mClient.asBinder());
7820 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7821 if (mAttachedWindow != null || mLayoutAttached) {
7822 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7823 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7824 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007825 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7826 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7827 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007828 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7829 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007830 }
7831 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7832 pw.print(" mSubLayer="); pw.print(mSubLayer);
7833 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7834 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7835 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7836 pw.print("="); pw.print(mAnimLayer);
7837 pw.print(" mLastLayer="); pw.println(mLastLayer);
7838 if (mSurface != null) {
7839 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007840 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7841 pw.print(" layer="); pw.print(mSurfaceLayer);
7842 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7843 pw.print(" rect=("); pw.print(mSurfaceX);
7844 pw.print(","); pw.print(mSurfaceY);
7845 pw.print(") "); pw.print(mSurfaceW);
7846 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007847 }
7848 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7849 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7850 if (mAppToken != null) {
7851 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7852 }
7853 if (mTargetAppToken != null) {
7854 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7855 }
7856 pw.print(prefix); pw.print("mViewVisibility=0x");
7857 pw.print(Integer.toHexString(mViewVisibility));
7858 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007859 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7860 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007861 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7862 pw.print(prefix); pw.print("mPolicyVisibility=");
7863 pw.print(mPolicyVisibility);
7864 pw.print(" mPolicyVisibilityAfterAnim=");
7865 pw.print(mPolicyVisibilityAfterAnim);
7866 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7867 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007868 if (!mRelayoutCalled) {
7869 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7870 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007871 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007872 pw.print(" h="); pw.print(mRequestedHeight);
7873 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007874 if (mXOffset != 0 || mYOffset != 0) {
7875 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7876 pw.print(" y="); pw.println(mYOffset);
7877 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007878 pw.print(prefix); pw.print("mGivenContentInsets=");
7879 mGivenContentInsets.printShortString(pw);
7880 pw.print(" mGivenVisibleInsets=");
7881 mGivenVisibleInsets.printShortString(pw);
7882 pw.println();
7883 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7884 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7885 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7886 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007887 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007888 pw.print(prefix); pw.print("mShownFrame=");
7889 mShownFrame.printShortString(pw);
7890 pw.print(" last="); mLastShownFrame.printShortString(pw);
7891 pw.println();
7892 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7893 pw.print(" last="); mLastFrame.printShortString(pw);
7894 pw.println();
7895 pw.print(prefix); pw.print("mContainingFrame=");
7896 mContainingFrame.printShortString(pw);
7897 pw.print(" mDisplayFrame=");
7898 mDisplayFrame.printShortString(pw);
7899 pw.println();
7900 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7901 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7902 pw.println();
7903 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7904 pw.print(" last="); mLastContentInsets.printShortString(pw);
7905 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7906 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7907 pw.println();
7908 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7909 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7910 pw.print(" mAlpha="); pw.print(mAlpha);
7911 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7912 }
7913 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7914 || mAnimation != null) {
7915 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7916 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7917 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7918 pw.print(" mAnimation="); pw.println(mAnimation);
7919 }
7920 if (mHasTransformation || mHasLocalTransformation) {
7921 pw.print(prefix); pw.print("XForm: has=");
7922 pw.print(mHasTransformation);
7923 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7924 pw.print(" "); mTransformation.printShortString(pw);
7925 pw.println();
7926 }
7927 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7928 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7929 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7930 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7931 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7932 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7933 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7934 pw.print(" mDestroying="); pw.print(mDestroying);
7935 pw.print(" mRemoved="); pw.println(mRemoved);
7936 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007937 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007938 pw.print(prefix); pw.print("mOrientationChanging=");
7939 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007940 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7941 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007942 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007943 if (mHScale != 1 || mVScale != 1) {
7944 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7945 pw.print(" mVScale="); pw.println(mVScale);
7946 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007947 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007948 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7949 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7950 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007951 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7952 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7953 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007955 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007956
7957 String makeInputChannelName() {
7958 return Integer.toHexString(System.identityHashCode(this))
7959 + " " + mAttrs.getTitle();
7960 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007961
7962 @Override
7963 public String toString() {
7964 return "Window{"
7965 + Integer.toHexString(System.identityHashCode(this))
7966 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7967 }
7968 }
Romain Guy06882f82009-06-10 13:36:04 -07007969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007970 // -------------------------------------------------------------
7971 // Window Token State
7972 // -------------------------------------------------------------
7973
7974 class WindowToken {
7975 // The actual token.
7976 final IBinder token;
7977
7978 // The type of window this token is for, as per WindowManager.LayoutParams.
7979 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007981 // Set if this token was explicitly added by a client, so should
7982 // not be removed when all windows are removed.
7983 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007984
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007985 // For printing.
7986 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 // If this is an AppWindowToken, this is non-null.
7989 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007991 // All of the windows associated with this token.
7992 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7993
7994 // Is key dispatching paused for this token?
7995 boolean paused = false;
7996
7997 // Should this token's windows be hidden?
7998 boolean hidden;
7999
8000 // Temporary for finding which tokens no longer have visible windows.
8001 boolean hasVisible;
8002
Dianne Hackborna8f60182009-09-01 19:01:50 -07008003 // Set to true when this token is in a pending transaction where it
8004 // will be shown.
8005 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008006
Dianne Hackborna8f60182009-09-01 19:01:50 -07008007 // Set to true when this token is in a pending transaction where it
8008 // will be hidden.
8009 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008010
Dianne Hackborna8f60182009-09-01 19:01:50 -07008011 // Set to true when this token is in a pending transaction where its
8012 // windows will be put to the bottom of the list.
8013 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008014
Dianne Hackborna8f60182009-09-01 19:01:50 -07008015 // Set to true when this token is in a pending transaction where its
8016 // windows will be put to the top of the list.
8017 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 WindowToken(IBinder _token, int type, boolean _explicit) {
8020 token = _token;
8021 windowType = type;
8022 explicit = _explicit;
8023 }
8024
8025 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008026 pw.print(prefix); pw.print("token="); pw.println(token);
8027 pw.print(prefix); pw.print("windows="); pw.println(windows);
8028 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8029 pw.print(" hidden="); pw.print(hidden);
8030 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008031 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8032 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8033 pw.print(" waitingToHide="); pw.print(waitingToHide);
8034 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8035 pw.print(" sendingToTop="); pw.println(sendingToTop);
8036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008037 }
8038
8039 @Override
8040 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008041 if (stringName == null) {
8042 StringBuilder sb = new StringBuilder();
8043 sb.append("WindowToken{");
8044 sb.append(Integer.toHexString(System.identityHashCode(this)));
8045 sb.append(" token="); sb.append(token); sb.append('}');
8046 stringName = sb.toString();
8047 }
8048 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008049 }
8050 };
8051
8052 class AppWindowToken extends WindowToken {
8053 // Non-null only for application tokens.
8054 final IApplicationToken appToken;
8055
8056 // All of the windows and child windows that are included in this
8057 // application token. Note this list is NOT sorted!
8058 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8059
8060 int groupId = -1;
8061 boolean appFullscreen;
8062 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008063
8064 // The input dispatching timeout for this application token in nanoseconds.
8065 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 // These are used for determining when all windows associated with
8068 // an activity have been drawn, so they can be made visible together
8069 // at the same time.
8070 int lastTransactionSequence = mTransactionSequence-1;
8071 int numInterestingWindows;
8072 int numDrawnWindows;
8073 boolean inPendingTransaction;
8074 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 // Is this token going to be hidden in a little while? If so, it
8077 // won't be taken into account for setting the screen orientation.
8078 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008080 // Is this window's surface needed? This is almost like hidden, except
8081 // it will sometimes be true a little earlier: when the token has
8082 // been shown, but is still waiting for its app transition to execute
8083 // before making its windows shown.
8084 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008086 // Have we told the window clients to hide themselves?
8087 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 // Last visibility state we reported to the app token.
8090 boolean reportedVisible;
8091
8092 // Set to true when the token has been removed from the window mgr.
8093 boolean removed;
8094
8095 // Have we been asked to have this token keep the screen frozen?
8096 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 boolean animating;
8099 Animation animation;
8100 boolean hasTransformation;
8101 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 // Offset to the window of all layers in the token, for use by
8104 // AppWindowToken animations.
8105 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 // Information about an application starting window if displayed.
8108 StartingData startingData;
8109 WindowState startingWindow;
8110 View startingView;
8111 boolean startingDisplayed;
8112 boolean startingMoved;
8113 boolean firstWindowDrawn;
8114
8115 AppWindowToken(IApplicationToken _token) {
8116 super(_token.asBinder(),
8117 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8118 appWindowToken = this;
8119 appToken = _token;
8120 }
Romain Guy06882f82009-06-10 13:36:04 -07008121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008122 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008123 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124 TAG, "Setting animation in " + this + ": " + anim);
8125 animation = anim;
8126 animating = false;
8127 anim.restrictDuration(MAX_ANIMATION_DURATION);
8128 anim.scaleCurrentDuration(mTransitionAnimationScale);
8129 int zorder = anim.getZAdjustment();
8130 int adj = 0;
8131 if (zorder == Animation.ZORDER_TOP) {
8132 adj = TYPE_LAYER_OFFSET;
8133 } else if (zorder == Animation.ZORDER_BOTTOM) {
8134 adj = -TYPE_LAYER_OFFSET;
8135 }
Romain Guy06882f82009-06-10 13:36:04 -07008136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 if (animLayerAdjustment != adj) {
8138 animLayerAdjustment = adj;
8139 updateLayers();
8140 }
8141 }
Romain Guy06882f82009-06-10 13:36:04 -07008142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008143 public void setDummyAnimation() {
8144 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008145 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008146 TAG, "Setting dummy animation in " + this);
8147 animation = sDummyAnimation;
8148 }
8149 }
8150
8151 public void clearAnimation() {
8152 if (animation != null) {
8153 animation = null;
8154 animating = true;
8155 }
8156 }
Romain Guy06882f82009-06-10 13:36:04 -07008157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 void updateLayers() {
8159 final int N = allAppWindows.size();
8160 final int adj = animLayerAdjustment;
8161 for (int i=0; i<N; i++) {
8162 WindowState w = allAppWindows.get(i);
8163 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008164 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008165 + w.mAnimLayer);
8166 if (w == mInputMethodTarget) {
8167 setInputMethodAnimLayerAdjustment(adj);
8168 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008169 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008170 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008171 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008172 }
8173 }
Romain Guy06882f82009-06-10 13:36:04 -07008174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 void sendAppVisibilityToClients() {
8176 final int N = allAppWindows.size();
8177 for (int i=0; i<N; i++) {
8178 WindowState win = allAppWindows.get(i);
8179 if (win == startingWindow && clientHidden) {
8180 // Don't hide the starting window.
8181 continue;
8182 }
8183 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008184 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008185 "Setting visibility of " + win + ": " + (!clientHidden));
8186 win.mClient.dispatchAppVisibility(!clientHidden);
8187 } catch (RemoteException e) {
8188 }
8189 }
8190 }
Romain Guy06882f82009-06-10 13:36:04 -07008191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 void showAllWindowsLocked() {
8193 final int NW = allAppWindows.size();
8194 for (int i=0; i<NW; i++) {
8195 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008196 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008197 "performing show on: " + w);
8198 w.performShowLocked();
8199 }
8200 }
Romain Guy06882f82009-06-10 13:36:04 -07008201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008202 // This must be called while inside a transaction.
8203 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008204 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008207 if (animation == sDummyAnimation) {
8208 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008209 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008210 // when it is really time to animate, this will be set to
8211 // a real animation and the next call will execute normally.
8212 return false;
8213 }
Romain Guy06882f82009-06-10 13:36:04 -07008214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008215 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8216 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008217 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008218 TAG, "Starting animation in " + this +
8219 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8220 + " scale=" + mTransitionAnimationScale
8221 + " allDrawn=" + allDrawn + " animating=" + animating);
8222 animation.initialize(dw, dh, dw, dh);
8223 animation.setStartTime(currentTime);
8224 animating = true;
8225 }
8226 transformation.clear();
8227 final boolean more = animation.getTransformation(
8228 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008229 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008230 TAG, "Stepped animation in " + this +
8231 ": more=" + more + ", xform=" + transformation);
8232 if (more) {
8233 // we're done!
8234 hasTransformation = true;
8235 return true;
8236 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008237 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 TAG, "Finished animation in " + this +
8239 " @ " + currentTime);
8240 animation = null;
8241 }
8242 } else if (animation != null) {
8243 // If the display is frozen, and there is a pending animation,
8244 // clear it and make sure we run the cleanup code.
8245 animating = true;
8246 animation = null;
8247 }
8248
8249 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 if (!animating) {
8252 return false;
8253 }
8254
8255 clearAnimation();
8256 animating = false;
8257 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8258 moveInputMethodWindowsIfNeededLocked(true);
8259 }
Romain Guy06882f82009-06-10 13:36:04 -07008260
Joe Onorato8a9b2202010-02-26 18:56:32 -08008261 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262 TAG, "Animation done in " + this
8263 + ": reportedVisible=" + reportedVisible);
8264
8265 transformation.clear();
8266 if (animLayerAdjustment != 0) {
8267 animLayerAdjustment = 0;
8268 updateLayers();
8269 }
Romain Guy06882f82009-06-10 13:36:04 -07008270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 final int N = windows.size();
8272 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008273 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008274 }
8275 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277 return false;
8278 }
8279
8280 void updateReportedVisibilityLocked() {
8281 if (appToken == null) {
8282 return;
8283 }
Romain Guy06882f82009-06-10 13:36:04 -07008284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008285 int numInteresting = 0;
8286 int numVisible = 0;
8287 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008288
Joe Onorato8a9b2202010-02-26 18:56:32 -08008289 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008290 final int N = allAppWindows.size();
8291 for (int i=0; i<N; i++) {
8292 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008293 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008294 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008295 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8296 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008297 continue;
8298 }
8299 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008300 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008301 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008302 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008303 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008304 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008305 + " pv=" + win.mPolicyVisibility
8306 + " dp=" + win.mDrawPending
8307 + " cdp=" + win.mCommitDrawPending
8308 + " ah=" + win.mAttachedHidden
8309 + " th="
8310 + (win.mAppToken != null
8311 ? win.mAppToken.hiddenRequested : false)
8312 + " a=" + win.mAnimating);
8313 }
8314 }
8315 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008316 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008317 if (!win.isAnimating()) {
8318 numVisible++;
8319 }
8320 nowGone = false;
8321 } else if (win.isAnimating()) {
8322 nowGone = false;
8323 }
8324 }
Romain Guy06882f82009-06-10 13:36:04 -07008325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008326 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008327 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 + numInteresting + " visible=" + numVisible);
8329 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008330 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008331 TAG, "Visibility changed in " + this
8332 + ": vis=" + nowVisible);
8333 reportedVisible = nowVisible;
8334 Message m = mH.obtainMessage(
8335 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8336 nowVisible ? 1 : 0,
8337 nowGone ? 1 : 0,
8338 this);
8339 mH.sendMessage(m);
8340 }
8341 }
Romain Guy06882f82009-06-10 13:36:04 -07008342
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008343 WindowState findMainWindow() {
8344 int j = windows.size();
8345 while (j > 0) {
8346 j--;
8347 WindowState win = windows.get(j);
8348 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8349 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8350 return win;
8351 }
8352 }
8353 return null;
8354 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356 void dump(PrintWriter pw, String prefix) {
8357 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008358 if (appToken != null) {
8359 pw.print(prefix); pw.println("app=true");
8360 }
8361 if (allAppWindows.size() > 0) {
8362 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8363 }
8364 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008365 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008366 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8367 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8368 pw.print(" clientHidden="); pw.print(clientHidden);
8369 pw.print(" willBeHidden="); pw.print(willBeHidden);
8370 pw.print(" reportedVisible="); pw.println(reportedVisible);
8371 if (paused || freezingScreen) {
8372 pw.print(prefix); pw.print("paused="); pw.print(paused);
8373 pw.print(" freezingScreen="); pw.println(freezingScreen);
8374 }
8375 if (numInterestingWindows != 0 || numDrawnWindows != 0
8376 || inPendingTransaction || allDrawn) {
8377 pw.print(prefix); pw.print("numInterestingWindows=");
8378 pw.print(numInterestingWindows);
8379 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8380 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8381 pw.print(" allDrawn="); pw.println(allDrawn);
8382 }
8383 if (animating || animation != null) {
8384 pw.print(prefix); pw.print("animating="); pw.print(animating);
8385 pw.print(" animation="); pw.println(animation);
8386 }
8387 if (animLayerAdjustment != 0) {
8388 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8389 }
8390 if (hasTransformation) {
8391 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8392 pw.print(" transformation="); transformation.printShortString(pw);
8393 pw.println();
8394 }
8395 if (startingData != null || removed || firstWindowDrawn) {
8396 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8397 pw.print(" removed="); pw.print(removed);
8398 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8399 }
8400 if (startingWindow != null || startingView != null
8401 || startingDisplayed || startingMoved) {
8402 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8403 pw.print(" startingView="); pw.print(startingView);
8404 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8405 pw.print(" startingMoved"); pw.println(startingMoved);
8406 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008407 }
8408
8409 @Override
8410 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008411 if (stringName == null) {
8412 StringBuilder sb = new StringBuilder();
8413 sb.append("AppWindowToken{");
8414 sb.append(Integer.toHexString(System.identityHashCode(this)));
8415 sb.append(" token="); sb.append(token); sb.append('}');
8416 stringName = sb.toString();
8417 }
8418 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419 }
8420 }
Romain Guy06882f82009-06-10 13:36:04 -07008421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008422 // -------------------------------------------------------------
8423 // DummyAnimation
8424 // -------------------------------------------------------------
8425
8426 // This is an animation that does nothing: it just immediately finishes
8427 // itself every time it is called. It is used as a stub animation in cases
8428 // where we want to synchronize multiple things that may be animating.
8429 static final class DummyAnimation extends Animation {
8430 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8431 return false;
8432 }
8433 }
8434 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 // -------------------------------------------------------------
8437 // Async Handler
8438 // -------------------------------------------------------------
8439
8440 static final class StartingData {
8441 final String pkg;
8442 final int theme;
8443 final CharSequence nonLocalizedLabel;
8444 final int labelRes;
8445 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008446 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008448 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008449 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 pkg = _pkg;
8451 theme = _theme;
8452 nonLocalizedLabel = _nonLocalizedLabel;
8453 labelRes = _labelRes;
8454 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008455 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008456 }
8457 }
8458
8459 private final class H extends Handler {
8460 public static final int REPORT_FOCUS_CHANGE = 2;
8461 public static final int REPORT_LOSING_FOCUS = 3;
8462 public static final int ANIMATE = 4;
8463 public static final int ADD_STARTING = 5;
8464 public static final int REMOVE_STARTING = 6;
8465 public static final int FINISHED_STARTING = 7;
8466 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8468 public static final int HOLD_SCREEN_CHANGED = 12;
8469 public static final int APP_TRANSITION_TIMEOUT = 13;
8470 public static final int PERSIST_ANIMATION_SCALE = 14;
8471 public static final int FORCE_GC = 15;
8472 public static final int ENABLE_SCREEN = 16;
8473 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008474 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008475 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008476 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008477 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008481 public H() {
8482 }
Romain Guy06882f82009-06-10 13:36:04 -07008483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008484 @Override
8485 public void handleMessage(Message msg) {
8486 switch (msg.what) {
8487 case REPORT_FOCUS_CHANGE: {
8488 WindowState lastFocus;
8489 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 synchronized(mWindowMap) {
8492 lastFocus = mLastFocus;
8493 newFocus = mCurrentFocus;
8494 if (lastFocus == newFocus) {
8495 // Focus is not changing, so nothing to do.
8496 return;
8497 }
8498 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008499 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008500 // + " to " + newFocus);
8501 if (newFocus != null && lastFocus != null
8502 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008503 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008504 mLosingFocus.add(lastFocus);
8505 lastFocus = null;
8506 }
8507 }
8508
8509 if (lastFocus != newFocus) {
8510 //System.out.println("Changing focus from " + lastFocus
8511 // + " to " + newFocus);
8512 if (newFocus != null) {
8513 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008514 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008515 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8516 } catch (RemoteException e) {
8517 // Ignore if process has died.
8518 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008519 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520 }
8521
8522 if (lastFocus != null) {
8523 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008524 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8526 } catch (RemoteException e) {
8527 // Ignore if process has died.
8528 }
8529 }
8530 }
8531 } break;
8532
8533 case REPORT_LOSING_FOCUS: {
8534 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 synchronized(mWindowMap) {
8537 losers = mLosingFocus;
8538 mLosingFocus = new ArrayList<WindowState>();
8539 }
8540
8541 final int N = losers.size();
8542 for (int i=0; i<N; i++) {
8543 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008544 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8546 } catch (RemoteException e) {
8547 // Ignore if process has died.
8548 }
8549 }
8550 } break;
8551
8552 case ANIMATE: {
8553 synchronized(mWindowMap) {
8554 mAnimationPending = false;
8555 performLayoutAndPlaceSurfacesLocked();
8556 }
8557 } break;
8558
8559 case ADD_STARTING: {
8560 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8561 final StartingData sd = wtoken.startingData;
8562
8563 if (sd == null) {
8564 // Animation has been canceled... do nothing.
8565 return;
8566 }
Romain Guy06882f82009-06-10 13:36:04 -07008567
Joe Onorato8a9b2202010-02-26 18:56:32 -08008568 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008569 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008571 View view = null;
8572 try {
8573 view = mPolicy.addStartingWindow(
8574 wtoken.token, sd.pkg,
8575 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008576 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008578 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579 }
8580
8581 if (view != null) {
8582 boolean abort = false;
8583
8584 synchronized(mWindowMap) {
8585 if (wtoken.removed || wtoken.startingData == null) {
8586 // If the window was successfully added, then
8587 // we need to remove it.
8588 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008589 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 "Aborted starting " + wtoken
8591 + ": removed=" + wtoken.removed
8592 + " startingData=" + wtoken.startingData);
8593 wtoken.startingWindow = null;
8594 wtoken.startingData = null;
8595 abort = true;
8596 }
8597 } else {
8598 wtoken.startingView = view;
8599 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008600 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008601 "Added starting " + wtoken
8602 + ": startingWindow="
8603 + wtoken.startingWindow + " startingView="
8604 + wtoken.startingView);
8605 }
8606
8607 if (abort) {
8608 try {
8609 mPolicy.removeStartingWindow(wtoken.token, view);
8610 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008611 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612 }
8613 }
8614 }
8615 } break;
8616
8617 case REMOVE_STARTING: {
8618 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8619 IBinder token = null;
8620 View view = null;
8621 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008622 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 + wtoken + ": startingWindow="
8624 + wtoken.startingWindow + " startingView="
8625 + wtoken.startingView);
8626 if (wtoken.startingWindow != null) {
8627 view = wtoken.startingView;
8628 token = wtoken.token;
8629 wtoken.startingData = null;
8630 wtoken.startingView = null;
8631 wtoken.startingWindow = null;
8632 }
8633 }
8634 if (view != null) {
8635 try {
8636 mPolicy.removeStartingWindow(token, view);
8637 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008638 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008639 }
8640 }
8641 } break;
8642
8643 case FINISHED_STARTING: {
8644 IBinder token = null;
8645 View view = null;
8646 while (true) {
8647 synchronized (mWindowMap) {
8648 final int N = mFinishedStarting.size();
8649 if (N <= 0) {
8650 break;
8651 }
8652 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8653
Joe Onorato8a9b2202010-02-26 18:56:32 -08008654 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 "Finished starting " + wtoken
8656 + ": startingWindow=" + wtoken.startingWindow
8657 + " startingView=" + wtoken.startingView);
8658
8659 if (wtoken.startingWindow == null) {
8660 continue;
8661 }
8662
8663 view = wtoken.startingView;
8664 token = wtoken.token;
8665 wtoken.startingData = null;
8666 wtoken.startingView = null;
8667 wtoken.startingWindow = null;
8668 }
8669
8670 try {
8671 mPolicy.removeStartingWindow(token, view);
8672 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008673 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008674 }
8675 }
8676 } break;
8677
8678 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8679 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8680
8681 boolean nowVisible = msg.arg1 != 0;
8682 boolean nowGone = msg.arg2 != 0;
8683
8684 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008685 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 TAG, "Reporting visible in " + wtoken
8687 + " visible=" + nowVisible
8688 + " gone=" + nowGone);
8689 if (nowVisible) {
8690 wtoken.appToken.windowsVisible();
8691 } else {
8692 wtoken.appToken.windowsGone();
8693 }
8694 } catch (RemoteException ex) {
8695 }
8696 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 case WINDOW_FREEZE_TIMEOUT: {
8699 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008700 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008701 int i = mWindows.size();
8702 while (i > 0) {
8703 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008704 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008705 if (w.mOrientationChanging) {
8706 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008707 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008708 }
8709 }
8710 performLayoutAndPlaceSurfacesLocked();
8711 }
8712 break;
8713 }
Romain Guy06882f82009-06-10 13:36:04 -07008714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008715 case HOLD_SCREEN_CHANGED: {
8716 Session oldHold;
8717 Session newHold;
8718 synchronized (mWindowMap) {
8719 oldHold = mLastReportedHold;
8720 newHold = (Session)msg.obj;
8721 mLastReportedHold = newHold;
8722 }
Romain Guy06882f82009-06-10 13:36:04 -07008723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 if (oldHold != newHold) {
8725 try {
8726 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008727 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 "window",
8729 BatteryStats.WAKE_TYPE_WINDOW);
8730 }
8731 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008732 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008733 "window",
8734 BatteryStats.WAKE_TYPE_WINDOW);
8735 }
8736 } catch (RemoteException e) {
8737 }
8738 }
8739 break;
8740 }
Romain Guy06882f82009-06-10 13:36:04 -07008741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742 case APP_TRANSITION_TIMEOUT: {
8743 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008744 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008745 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 "*** APP TRANSITION TIMEOUT");
8747 mAppTransitionReady = true;
8748 mAppTransitionTimeout = true;
8749 performLayoutAndPlaceSurfacesLocked();
8750 }
8751 }
8752 break;
8753 }
Romain Guy06882f82009-06-10 13:36:04 -07008754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008755 case PERSIST_ANIMATION_SCALE: {
8756 Settings.System.putFloat(mContext.getContentResolver(),
8757 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8758 Settings.System.putFloat(mContext.getContentResolver(),
8759 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8760 break;
8761 }
Romain Guy06882f82009-06-10 13:36:04 -07008762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008763 case FORCE_GC: {
8764 synchronized(mWindowMap) {
8765 if (mAnimationPending) {
8766 // If we are animating, don't do the gc now but
8767 // delay a bit so we don't interrupt the animation.
8768 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8769 2000);
8770 return;
8771 }
8772 // If we are currently rotating the display, it will
8773 // schedule a new message when done.
8774 if (mDisplayFrozen) {
8775 return;
8776 }
8777 mFreezeGcPending = 0;
8778 }
8779 Runtime.getRuntime().gc();
8780 break;
8781 }
Romain Guy06882f82009-06-10 13:36:04 -07008782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 case ENABLE_SCREEN: {
8784 performEnableScreen();
8785 break;
8786 }
Romain Guy06882f82009-06-10 13:36:04 -07008787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008788 case APP_FREEZE_TIMEOUT: {
8789 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008790 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008791 int i = mAppTokens.size();
8792 while (i > 0) {
8793 i--;
8794 AppWindowToken tok = mAppTokens.get(i);
8795 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008796 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 unsetAppFreezingScreenLocked(tok, true, true);
8798 }
8799 }
8800 }
8801 break;
8802 }
Romain Guy06882f82009-06-10 13:36:04 -07008803
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008804 case SEND_NEW_CONFIGURATION: {
8805 removeMessages(SEND_NEW_CONFIGURATION);
8806 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008807 break;
8808 }
Romain Guy06882f82009-06-10 13:36:04 -07008809
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008810 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008811 if (mWindowsChanged) {
8812 synchronized (mWindowMap) {
8813 mWindowsChanged = false;
8814 }
8815 notifyWindowsChanged();
8816 }
8817 break;
8818 }
8819
Christopher Tatea53146c2010-09-07 11:57:52 -07008820 case DRAG_START_TIMEOUT: {
8821 IBinder win = (IBinder)msg.obj;
8822 if (DEBUG_DRAG) {
8823 Slog.w(TAG, "Timeout starting drag by win " + win);
8824 }
8825 synchronized (mWindowMap) {
8826 // !!! TODO: ANR the app that has failed to start the drag in time
8827 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008828 mDragState.unregister();
8829 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008830 mDragState.reset();
8831 mDragState = null;
8832 }
8833 }
Chris Tated4533f142010-10-19 15:15:08 -07008834 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008835 }
8836
Chris Tated4533f142010-10-19 15:15:08 -07008837 case DRAG_END_TIMEOUT: {
8838 IBinder win = (IBinder)msg.obj;
8839 if (DEBUG_DRAG) {
8840 Slog.w(TAG, "Timeout ending drag to win " + win);
8841 }
8842 synchronized (mWindowMap) {
8843 // !!! TODO: ANR the drag-receiving app
8844 mDragState.mDragResult = false;
8845 mDragState.endDragLw();
8846 }
8847 break;
8848 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008849 }
8850 }
8851 }
8852
8853 // -------------------------------------------------------------
8854 // IWindowManager API
8855 // -------------------------------------------------------------
8856
8857 public IWindowSession openSession(IInputMethodClient client,
8858 IInputContext inputContext) {
8859 if (client == null) throw new IllegalArgumentException("null client");
8860 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008861 Session session = new Session(client, inputContext);
8862 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008863 }
8864
8865 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8866 synchronized (mWindowMap) {
8867 // The focus for the client is the window immediately below
8868 // where we would place the input method window.
8869 int idx = findDesiredInputMethodWindowIndexLocked(false);
8870 WindowState imFocus;
8871 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008872 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 if (imFocus != null) {
8874 if (imFocus.mSession.mClient != null &&
8875 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8876 return true;
8877 }
8878 }
8879 }
8880 }
8881 return false;
8882 }
Romain Guy06882f82009-06-10 13:36:04 -07008883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008884 // -------------------------------------------------------------
8885 // Internals
8886 // -------------------------------------------------------------
8887
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008888 final WindowState windowForClientLocked(Session session, IWindow client,
8889 boolean throwOnError) {
8890 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 }
Romain Guy06882f82009-06-10 13:36:04 -07008892
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008893 final WindowState windowForClientLocked(Session session, IBinder client,
8894 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008896 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008897 TAG, "Looking up client " + client + ": " + win);
8898 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008899 RuntimeException ex = new IllegalArgumentException(
8900 "Requested window " + client + " does not exist");
8901 if (throwOnError) {
8902 throw ex;
8903 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008904 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 return null;
8906 }
8907 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008908 RuntimeException ex = new IllegalArgumentException(
8909 "Requested window " + client + " is in session " +
8910 win.mSession + ", not " + session);
8911 if (throwOnError) {
8912 throw ex;
8913 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008914 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008915 return null;
8916 }
8917
8918 return win;
8919 }
8920
Dianne Hackborna8f60182009-09-01 19:01:50 -07008921 final void rebuildAppWindowListLocked() {
8922 int NW = mWindows.size();
8923 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008924 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008925 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008926
Dianne Hackborna8f60182009-09-01 19:01:50 -07008927 // First remove all existing app windows.
8928 i=0;
8929 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008930 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008931 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008932 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008933 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008934 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008935 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008936 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008937 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008938 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008939 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8940 && lastWallpaper == i-1) {
8941 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008942 }
8943 i++;
8944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008945
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008946 // The wallpaper window(s) typically live at the bottom of the stack,
8947 // so skip them before adding app tokens.
8948 lastWallpaper++;
8949 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008950
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008951 // First add all of the exiting app tokens... these are no longer
8952 // in the main app list, but still have windows shown. We put them
8953 // in the back because now that the animation is over we no longer
8954 // will care about them.
8955 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008956 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008957 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8958 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008959
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008960 // And add in the still active app tokens in Z order.
8961 NT = mAppTokens.size();
8962 for (int j=0; j<NT; j++) {
8963 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008964 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008965
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008966 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008967 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008968 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008969 + " windows but added " + i);
8970 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008971 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 private final void assignLayersLocked() {
8974 int N = mWindows.size();
8975 int curBaseLayer = 0;
8976 int curLayer = 0;
8977 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008978
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08008979 if (DEBUG_LAYERS) {
8980 RuntimeException here = new RuntimeException("here");
8981 here.fillInStackTrace();
8982 Log.v(TAG, "Assigning layers", here);
8983 }
8984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008985 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008986 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008987 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8988 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008989 curLayer += WINDOW_LAYER_MULTIPLIER;
8990 w.mLayer = curLayer;
8991 } else {
8992 curBaseLayer = curLayer = w.mBaseLayer;
8993 w.mLayer = curLayer;
8994 }
8995 if (w.mTargetAppToken != null) {
8996 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8997 } else if (w.mAppToken != null) {
8998 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8999 } else {
9000 w.mAnimLayer = w.mLayer;
9001 }
9002 if (w.mIsImWindow) {
9003 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009004 } else if (w.mIsWallpaper) {
9005 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009006 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009007 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 + w.mAnimLayer);
9009 //System.out.println(
9010 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9011 }
9012 }
9013
9014 private boolean mInLayout = false;
9015 private final void performLayoutAndPlaceSurfacesLocked() {
9016 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009017 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009018 throw new RuntimeException("Recursive call!");
9019 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009020 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021 return;
9022 }
9023
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009024 if (mWaitingForConfig) {
9025 // Our configuration has changed (most likely rotation), but we
9026 // don't yet have the complete configuration to report to
9027 // applications. Don't do any window layout until we have it.
9028 return;
9029 }
9030
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009031 if (mDisplay == null) {
9032 // Not yet initialized, nothing to do.
9033 return;
9034 }
9035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036 boolean recoveringMemory = false;
9037 if (mForceRemoves != null) {
9038 recoveringMemory = true;
9039 // Wait a little it for things to settle down, and off we go.
9040 for (int i=0; i<mForceRemoves.size(); i++) {
9041 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009042 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 removeWindowInnerLocked(ws.mSession, ws);
9044 }
9045 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009046 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047 Object tmp = new Object();
9048 synchronized (tmp) {
9049 try {
9050 tmp.wait(250);
9051 } catch (InterruptedException e) {
9052 }
9053 }
9054 }
Romain Guy06882f82009-06-10 13:36:04 -07009055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056 mInLayout = true;
9057 try {
9058 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009060 int i = mPendingRemove.size()-1;
9061 if (i >= 0) {
9062 while (i >= 0) {
9063 WindowState w = mPendingRemove.get(i);
9064 removeWindowInnerLocked(w.mSession, w);
9065 i--;
9066 }
9067 mPendingRemove.clear();
9068
9069 mInLayout = false;
9070 assignLayersLocked();
9071 mLayoutNeeded = true;
9072 performLayoutAndPlaceSurfacesLocked();
9073
9074 } else {
9075 mInLayout = false;
9076 if (mLayoutNeeded) {
9077 requestAnimationLocked(0);
9078 }
9079 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009080 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009081 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9082 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 } catch (RuntimeException e) {
9085 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009086 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009087 }
9088 }
9089
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009090 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009091 if (!mLayoutNeeded) {
9092 return 0;
9093 }
9094
9095 mLayoutNeeded = false;
9096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009097 final int dw = mDisplay.getWidth();
9098 final int dh = mDisplay.getHeight();
9099
9100 final int N = mWindows.size();
9101 int i;
9102
Joe Onorato8a9b2202010-02-26 18:56:32 -08009103 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009104 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9105
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009106 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009107
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009108 int seq = mLayoutSeq+1;
9109 if (seq < 0) seq = 0;
9110 mLayoutSeq = seq;
9111
9112 // First perform layout of any root windows (not attached
9113 // to another window).
9114 int topAttached = -1;
9115 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009116 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009117
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009118 // Don't do layout of a window if it is not visible, or
9119 // soon won't be visible, to avoid wasting time and funky
9120 // changes while a window is animating away.
9121 final AppWindowToken atoken = win.mAppToken;
9122 final boolean gone = win.mViewVisibility == View.GONE
9123 || !win.mRelayoutCalled
9124 || win.mRootToken.hidden
9125 || (atoken != null && atoken.hiddenRequested)
9126 || win.mAttachedHidden
9127 || win.mExiting || win.mDestroying;
9128
9129 if (!win.mLayoutAttached) {
9130 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9131 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9132 + " mLayoutAttached=" + win.mLayoutAttached);
9133 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9134 + win.mViewVisibility + " mRelayoutCalled="
9135 + win.mRelayoutCalled + " hidden="
9136 + win.mRootToken.hidden + " hiddenRequested="
9137 + (atoken != null && atoken.hiddenRequested)
9138 + " mAttachedHidden=" + win.mAttachedHidden);
9139 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009140
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009141 // If this view is GONE, then skip it -- keep the current
9142 // frame, and let the caller know so they can ignore it
9143 // if they want. (We do the normal layout for INVISIBLE
9144 // windows, since that means "perform layout as normal,
9145 // just don't display").
9146 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009147 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009148 if (initial) {
9149 win.mContentChanged = false;
9150 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009151 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9152 win.mLayoutSeq = seq;
9153 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9154 + win.mFrame + " mContainingFrame="
9155 + win.mContainingFrame + " mDisplayFrame="
9156 + win.mDisplayFrame);
9157 } else {
9158 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009159 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009161 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009162
9163 // Now perform layout of attached windows, which usually
9164 // depend on the position of the window they are attached to.
9165 // XXX does not deal with windows that are attached to windows
9166 // that are themselves attached.
9167 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009168 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009169
9170 // If this view is GONE, then skip it -- keep the current
9171 // frame, and let the caller know so they can ignore it
9172 // if they want. (We do the normal layout for INVISIBLE
9173 // windows, since that means "perform layout as normal,
9174 // just don't display").
9175 if (win.mLayoutAttached) {
9176 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9177 + " mHaveFrame=" + win.mHaveFrame
9178 + " mViewVisibility=" + win.mViewVisibility
9179 + " mRelayoutCalled=" + win.mRelayoutCalled);
9180 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9181 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009182 if (initial) {
9183 win.mContentChanged = false;
9184 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009185 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9186 win.mLayoutSeq = seq;
9187 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9188 + win.mFrame + " mContainingFrame="
9189 + win.mContainingFrame + " mDisplayFrame="
9190 + win.mDisplayFrame);
9191 }
9192 }
9193 }
Jeff Brown349703e2010-06-22 01:27:15 -07009194
9195 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009196 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009197
9198 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 }
Romain Guy06882f82009-06-10 13:36:04 -07009200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009201 private final void performLayoutAndPlaceSurfacesLockedInner(
9202 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009203 if (mDisplay == null) {
9204 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9205 return;
9206 }
9207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009208 final long currentTime = SystemClock.uptimeMillis();
9209 final int dw = mDisplay.getWidth();
9210 final int dh = mDisplay.getHeight();
9211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 int i;
9213
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009214 if (mFocusMayChange) {
9215 mFocusMayChange = false;
9216 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9217 }
9218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 // Initialize state of exiting tokens.
9220 for (i=mExitingTokens.size()-1; i>=0; i--) {
9221 mExitingTokens.get(i).hasVisible = false;
9222 }
9223
9224 // Initialize state of exiting applications.
9225 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9226 mExitingAppTokens.get(i).hasVisible = false;
9227 }
9228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009229 boolean orientationChangeComplete = true;
9230 Session holdScreen = null;
9231 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009232 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009233 boolean focusDisplayed = false;
9234 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009235 boolean createWatermark = false;
9236
9237 if (mFxSession == null) {
9238 mFxSession = new SurfaceSession();
9239 createWatermark = true;
9240 }
9241
9242 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243
9244 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009245
9246 if (createWatermark) {
9247 createWatermark();
9248 }
9249 if (mWatermark != null) {
9250 mWatermark.positionSurface(dw, dh);
9251 }
9252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009254 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009255 int repeats = 0;
9256 int changes = 0;
9257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009259 repeats++;
9260 if (repeats > 6) {
9261 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9262 mLayoutNeeded = false;
9263 break;
9264 }
9265
9266 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9267 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9268 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9269 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9270 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9271 assignLayersLocked();
9272 mLayoutNeeded = true;
9273 }
9274 }
9275 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9276 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9277 if (updateOrientationFromAppTokensLocked()) {
9278 mLayoutNeeded = true;
9279 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9280 }
9281 }
9282 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9283 mLayoutNeeded = true;
9284 }
9285 }
9286
9287 // FIRST LOOP: Perform a layout, if needed.
9288 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009289 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009290 if (changes != 0) {
9291 continue;
9292 }
9293 } else {
9294 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9295 changes = 0;
9296 }
9297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009298 final int transactionSequence = ++mTransactionSequence;
9299
9300 // Update animations of all applications, including those
9301 // associated with exiting/removed apps
9302 boolean tokensAnimating = false;
9303 final int NAT = mAppTokens.size();
9304 for (i=0; i<NAT; i++) {
9305 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9306 tokensAnimating = true;
9307 }
9308 }
9309 final int NEAT = mExitingAppTokens.size();
9310 for (i=0; i<NEAT; i++) {
9311 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9312 tokensAnimating = true;
9313 }
9314 }
9315
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009316 // SECOND LOOP: Execute animations and update visibility of windows.
9317
Joe Onorato8a9b2202010-02-26 18:56:32 -08009318 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009319 + transactionSequence + " tokensAnimating="
9320 + tokensAnimating);
9321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323
9324 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009325 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009326 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009327 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009328
9329 mPolicy.beginAnimationLw(dw, dh);
9330
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009331 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009334 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335
9336 final WindowManager.LayoutParams attrs = w.mAttrs;
9337
9338 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009339 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009340 if (w.commitFinishDrawingLocked(currentTime)) {
9341 if ((w.mAttrs.flags
9342 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009343 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009344 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009345 wallpaperMayChange = true;
9346 }
9347 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009348
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009349 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009350
9351 int animDw = dw;
9352 int animDh = dh;
9353
9354 // If the window has moved due to its containing
9355 // content frame changing, then we'd like to animate
9356 // it. The checks here are ordered by what is least
9357 //Êlikely to be true first.
9358 if (w.mContentChanged && !wasAnimating && !w.mLastHidden && !mDisplayFrozen
9359 && (w.mFrame.top != w.mLastFrame.top
9360 || w.mFrame.left != w.mLastFrame.left)
9361 && mPolicy.isScreenOn()) {
9362 // Frame has moved, containing content frame
9363 // has also moved, and we're not currently animating...
9364 // let's do something.
9365 Animation a = AnimationUtils.loadAnimation(mContext,
9366 com.android.internal.R.anim.window_move_from_decor);
9367 w.setAnimation(a);
9368 animDw = w.mLastFrame.left - w.mFrame.left;
9369 animDh = w.mLastFrame.top - w.mFrame.top;
9370 }
9371
9372 // Execute animation.
9373 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9374 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009375
9376 // If this window is animating, make a note that we have
9377 // an animating window and take care of a request to run
9378 // a detached wallpaper animation.
9379 if (nowAnimating) {
9380 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9381 windowDetachedWallpaper = w;
9382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009385
9386 // If this window's app token is running a detached wallpaper
9387 // animation, make a note so we can ensure the wallpaper is
9388 // displayed behind it.
9389 if (w.mAppToken != null && w.mAppToken.animation != null
9390 && w.mAppToken.animation.getDetachWallpaper()) {
9391 windowDetachedWallpaper = w;
9392 }
9393
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009394 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9395 wallpaperMayChange = true;
9396 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009397
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009398 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009399 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009400 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009401 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009402 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009403 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009404 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009405 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9406 forceHiding = true;
9407 }
9408 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9409 boolean changed;
9410 if (forceHiding) {
9411 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009412 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9413 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009414 } else {
9415 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009416 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9417 "Now policy shown: " + w);
9418 if (changed) {
9419 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009420 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009421 // Assume we will need to animate. If
9422 // we don't (because the wallpaper will
9423 // stay with the lock screen), then we will
9424 // clean up later.
9425 Animation a = mPolicy.createForceHideEnterAnimation();
9426 if (a != null) {
9427 w.setAnimation(a);
9428 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009429 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009430 if (mCurrentFocus == null ||
9431 mCurrentFocus.mLayer < w.mLayer) {
9432 // We are showing on to of the current
9433 // focus, so re-evaluate focus to make
9434 // sure it is correct.
9435 mFocusMayChange = true;
9436 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009437 }
9438 }
9439 if (changed && (attrs.flags
9440 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9441 wallpaperMayChange = true;
9442 }
9443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 mPolicy.animatingWindowLw(w, attrs);
9446 }
9447
9448 final AppWindowToken atoken = w.mAppToken;
9449 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9450 if (atoken.lastTransactionSequence != transactionSequence) {
9451 atoken.lastTransactionSequence = transactionSequence;
9452 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9453 atoken.startingDisplayed = false;
9454 }
9455 if ((w.isOnScreen() || w.mAttrs.type
9456 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9457 && !w.mExiting && !w.mDestroying) {
9458 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009459 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009460 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009461 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009462 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009463 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009464 + " pv=" + w.mPolicyVisibility
9465 + " dp=" + w.mDrawPending
9466 + " cdp=" + w.mCommitDrawPending
9467 + " ah=" + w.mAttachedHidden
9468 + " th=" + atoken.hiddenRequested
9469 + " a=" + w.mAnimating);
9470 }
9471 }
9472 if (w != atoken.startingWindow) {
9473 if (!atoken.freezingScreen || !w.mAppFreezing) {
9474 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009475 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009477 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009478 "tokenMayBeDrawn: " + atoken
9479 + " freezingScreen=" + atoken.freezingScreen
9480 + " mAppFreezing=" + w.mAppFreezing);
9481 tokenMayBeDrawn = true;
9482 }
9483 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009484 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 atoken.startingDisplayed = true;
9486 }
9487 }
9488 } else if (w.mReadyToShow) {
9489 w.performShowLocked();
9490 }
9491 }
9492
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009493 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494
9495 if (tokenMayBeDrawn) {
9496 // See if any windows have been drawn, so they (and others
9497 // associated with them) can now be shown.
9498 final int NT = mTokenList.size();
9499 for (i=0; i<NT; i++) {
9500 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9501 if (wtoken == null) {
9502 continue;
9503 }
9504 if (wtoken.freezingScreen) {
9505 int numInteresting = wtoken.numInterestingWindows;
9506 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009507 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009508 "allDrawn: " + wtoken
9509 + " interesting=" + numInteresting
9510 + " drawn=" + wtoken.numDrawnWindows);
9511 wtoken.showAllWindowsLocked();
9512 unsetAppFreezingScreenLocked(wtoken, false, true);
9513 orientationChangeComplete = true;
9514 }
9515 } else if (!wtoken.allDrawn) {
9516 int numInteresting = wtoken.numInterestingWindows;
9517 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009518 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 "allDrawn: " + wtoken
9520 + " interesting=" + numInteresting
9521 + " drawn=" + wtoken.numDrawnWindows);
9522 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009523 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009524
9525 // We can now show all of the drawn windows!
9526 if (!mOpeningApps.contains(wtoken)) {
9527 wtoken.showAllWindowsLocked();
9528 }
9529 }
9530 }
9531 }
9532 }
9533
9534 // If we are ready to perform an app transition, check through
9535 // all of the app tokens to be shown and see if they are ready
9536 // to go.
9537 if (mAppTransitionReady) {
9538 int NN = mOpeningApps.size();
9539 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009540 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009541 "Checking " + NN + " opening apps (frozen="
9542 + mDisplayFrozen + " timeout="
9543 + mAppTransitionTimeout + ")...");
9544 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9545 // If the display isn't frozen, wait to do anything until
9546 // all of the apps are ready. Otherwise just go because
9547 // we'll unfreeze the display when everyone is ready.
9548 for (i=0; i<NN && goodToGo; i++) {
9549 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009550 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 "Check opening app" + wtoken + ": allDrawn="
9552 + wtoken.allDrawn + " startingDisplayed="
9553 + wtoken.startingDisplayed);
9554 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9555 && !wtoken.startingMoved) {
9556 goodToGo = false;
9557 }
9558 }
9559 }
9560 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009561 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562 int transit = mNextAppTransition;
9563 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009564 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009566 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009567 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009568 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009569 mAppTransitionTimeout = false;
9570 mStartingIconInTransition = false;
9571 mSkipAppTransitionAnimation = false;
9572
9573 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9574
Dianne Hackborna8f60182009-09-01 19:01:50 -07009575 // If there are applications waiting to come to the
9576 // top of the stack, now is the time to move their windows.
9577 // (Note that we don't do apps going to the bottom
9578 // here -- we want to keep their windows in the old
9579 // Z-order until the animation completes.)
9580 if (mToTopApps.size() > 0) {
9581 NN = mAppTokens.size();
9582 for (i=0; i<NN; i++) {
9583 AppWindowToken wtoken = mAppTokens.get(i);
9584 if (wtoken.sendingToTop) {
9585 wtoken.sendingToTop = false;
9586 moveAppWindowsLocked(wtoken, NN, false);
9587 }
9588 }
9589 mToTopApps.clear();
9590 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009591
Dianne Hackborn25994b42009-09-04 14:21:19 -07009592 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009593
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009594 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009595 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009596
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009597 // The top-most window will supply the layout params,
9598 // and we will determine it below.
9599 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009600 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009601 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Joe Onorato8a9b2202010-02-26 18:56:32 -08009603 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009604 "New wallpaper target=" + mWallpaperTarget
9605 + ", lower target=" + mLowerWallpaperTarget
9606 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009607 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009608 // Do a first pass through the tokens for two
9609 // things:
9610 // (1) Determine if both the closing and opening
9611 // app token sets are wallpaper targets, in which
9612 // case special animations are needed
9613 // (since the wallpaper needs to stay static
9614 // behind them).
9615 // (2) Find the layout params of the top-most
9616 // application window in the tokens, which is
9617 // what will control the animation theme.
9618 final int NC = mClosingApps.size();
9619 NN = NC + mOpeningApps.size();
9620 for (i=0; i<NN; i++) {
9621 AppWindowToken wtoken;
9622 int mode;
9623 if (i < NC) {
9624 wtoken = mClosingApps.get(i);
9625 mode = 1;
9626 } else {
9627 wtoken = mOpeningApps.get(i-NC);
9628 mode = 2;
9629 }
9630 if (mLowerWallpaperTarget != null) {
9631 if (mLowerWallpaperTarget.mAppToken == wtoken
9632 || mUpperWallpaperTarget.mAppToken == wtoken) {
9633 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009634 }
9635 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009636 if (wtoken.appFullscreen) {
9637 WindowState ws = wtoken.findMainWindow();
9638 if (ws != null) {
9639 // If this is a compatibility mode
9640 // window, we will always use its anim.
9641 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9642 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009643 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009644 bestAnimLayer = Integer.MAX_VALUE;
9645 } else if (ws.mLayer > bestAnimLayer) {
9646 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009647 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009648 bestAnimLayer = ws.mLayer;
9649 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009650 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009651 }
9652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009653
Dianne Hackborn25994b42009-09-04 14:21:19 -07009654 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009655 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009656 "Wallpaper animation!");
9657 switch (transit) {
9658 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9659 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9660 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9661 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9662 break;
9663 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9664 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9665 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9666 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9667 break;
9668 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009669 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009670 "New transit: " + transit);
9671 } else if (oldWallpaper != null) {
9672 // We are transitioning from an activity with
9673 // a wallpaper to one without.
9674 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009675 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009676 "New transit away from wallpaper: " + transit);
9677 } else if (mWallpaperTarget != null) {
9678 // We are transitioning from an activity without
9679 // a wallpaper to now showing the wallpaper
9680 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009681 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009682 "New transit into wallpaper: " + transit);
9683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009684
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009685 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9686 mLastEnterAnimToken = animToken;
9687 mLastEnterAnimParams = animLp;
9688 } else if (mLastEnterAnimParams != null) {
9689 animLp = mLastEnterAnimParams;
9690 mLastEnterAnimToken = null;
9691 mLastEnterAnimParams = null;
9692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009693
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009694 // If all closing windows are obscured, then there is
9695 // no need to do an animation. This is the case, for
9696 // example, when this transition is being done behind
9697 // the lock screen.
9698 if (!mPolicy.allowAppAnimationsLw()) {
9699 animLp = null;
9700 }
9701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 NN = mOpeningApps.size();
9703 for (i=0; i<NN; i++) {
9704 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009705 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009706 "Now opening app" + wtoken);
9707 wtoken.reportedVisible = false;
9708 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009709 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009710 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009711 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009712 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009713 wtoken.showAllWindowsLocked();
9714 }
9715 NN = mClosingApps.size();
9716 for (i=0; i<NN; i++) {
9717 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009718 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719 "Now closing app" + wtoken);
9720 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009721 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009722 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009723 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009724 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009725 // Force the allDrawn flag, because we want to start
9726 // this guy's animations regardless of whether it's
9727 // gotten drawn.
9728 wtoken.allDrawn = true;
9729 }
9730
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009731 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009733 mOpeningApps.clear();
9734 mClosingApps.clear();
9735
9736 // This has changed the visibility of windows, so perform
9737 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009738 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009740 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9741 assignLayersLocked();
9742 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009743 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009744 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009745 }
9746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009747
Dianne Hackborn16064f92010-03-25 00:47:24 -07009748 int adjResult = 0;
9749
Dianne Hackborna8f60182009-09-01 19:01:50 -07009750 if (!animating && mAppTransitionRunning) {
9751 // We have finished the animation of an app transition. To do
9752 // this, we have delayed a lot of operations like showing and
9753 // hiding apps, moving apps in Z-order, etc. The app token list
9754 // reflects the correct Z-order, but the window list may now
9755 // be out of sync with it. So here we will just rebuild the
9756 // entire app window list. Fun!
9757 mAppTransitionRunning = false;
9758 // Clear information about apps that were moving.
9759 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009760
Dianne Hackborna8f60182009-09-01 19:01:50 -07009761 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009762 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009763 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009764 moveInputMethodWindowsIfNeededLocked(false);
9765 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009766 // Since the window list has been rebuilt, focus might
9767 // have to be recomputed since the actual order of windows
9768 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009769 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009770 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009771
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009772 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009773 // At this point, there was a window with a wallpaper that
9774 // was force hiding other windows behind it, but now it
9775 // is going away. This may be simple -- just animate
9776 // away the wallpaper and its window -- or it may be
9777 // hard -- the wallpaper now needs to be shown behind
9778 // something that was hidden.
9779 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009780 if (mLowerWallpaperTarget != null
9781 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009782 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009783 "wallpaperForceHiding changed with lower="
9784 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009785 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009786 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9787 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9788 if (mLowerWallpaperTarget.mAppToken.hidden) {
9789 // The lower target has become hidden before we
9790 // actually started the animation... let's completely
9791 // re-evaluate everything.
9792 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009793 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009794 }
9795 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009796 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009797 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009798 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009799 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009800 + " NEW: " + mWallpaperTarget
9801 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009802 if (mLowerWallpaperTarget == null) {
9803 // Whoops, we don't need a special wallpaper animation.
9804 // Clear them out.
9805 forceHiding = false;
9806 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009807 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009808 if (w.mSurface != null) {
9809 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009810 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009811 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009812 forceHiding = true;
9813 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9814 if (!w.mAnimating) {
9815 // We set the animation above so it
9816 // is not yet running.
9817 w.clearAnimation();
9818 }
9819 }
9820 }
9821 }
9822 }
9823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009824
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009825 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
9826 if (DEBUG_WALLPAPER) Slog.v(TAG,
9827 "Detached wallpaper changed from " + mWindowDetachedWallpaper
9828 + windowDetachedWallpaper);
9829 mWindowDetachedWallpaper = windowDetachedWallpaper;
9830 wallpaperMayChange = true;
9831 }
9832
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009833 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009834 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009835 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009836 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009837 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009838
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009839 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009840 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009841 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009842 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009843 assignLayersLocked();
9844 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009845 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009846 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009847 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009848 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009849
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009850 if (mFocusMayChange) {
9851 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009852 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009853 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009854 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009855 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009856 }
9857
9858 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009859 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009860 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009861
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009862 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9863 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009864
Jeff Browne33348b2010-07-15 23:54:05 -07009865 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009866 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867
9868 // THIRD LOOP: Update the surfaces of all windows.
9869
9870 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9871
9872 boolean obscured = false;
9873 boolean blurring = false;
9874 boolean dimming = false;
9875 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009876 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009877 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009878
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009879 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009881 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009882 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883
9884 boolean displayed = false;
9885 final WindowManager.LayoutParams attrs = w.mAttrs;
9886 final int attrFlags = attrs.flags;
9887
9888 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009889 // XXX NOTE: The logic here could be improved. We have
9890 // the decision about whether to resize a window separated
9891 // from whether to hide the surface. This can cause us to
9892 // resize a surface even if we are going to hide it. You
9893 // can see this by (1) holding device in landscape mode on
9894 // home screen; (2) tapping browser icon (device will rotate
9895 // to landscape; (3) tap home. The wallpaper will be resized
9896 // in step 2 but then immediately hidden, causing us to
9897 // have to resize and then redraw it again in step 3. It
9898 // would be nice to figure out how to avoid this, but it is
9899 // difficult because we do need to resize surfaces in some
9900 // cases while they are hidden such as when first showing a
9901 // window.
9902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009904 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 TAG, "Placing surface #" + i + " " + w.mSurface
9906 + ": new=" + w.mShownFrame + ", old="
9907 + w.mLastShownFrame);
9908
9909 boolean resize;
9910 int width, height;
9911 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9912 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9913 w.mLastRequestedHeight != w.mRequestedHeight;
9914 // for a scaled surface, we just want to use
9915 // the requested size.
9916 width = w.mRequestedWidth;
9917 height = w.mRequestedHeight;
9918 w.mLastRequestedWidth = width;
9919 w.mLastRequestedHeight = height;
9920 w.mLastShownFrame.set(w.mShownFrame);
9921 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009922 if (SHOW_TRANSACTIONS) logSurface(w,
9923 "POS " + w.mShownFrame.left
9924 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009925 w.mSurfaceX = w.mShownFrame.left;
9926 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009927 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9928 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009929 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930 if (!recoveringMemory) {
9931 reclaimSomeSurfaceMemoryLocked(w, "position");
9932 }
9933 }
9934 } else {
9935 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9936 width = w.mShownFrame.width();
9937 height = w.mShownFrame.height();
9938 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 }
9940
9941 if (resize) {
9942 if (width < 1) width = 1;
9943 if (height < 1) height = 1;
9944 if (w.mSurface != null) {
9945 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009946 if (SHOW_TRANSACTIONS) logSurface(w,
9947 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009948 + w.mShownFrame.top + " SIZE "
9949 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009950 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009951 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009952 w.mSurfaceW = width;
9953 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009954 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009955 w.mSurfaceX = w.mShownFrame.left;
9956 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009957 w.mSurface.setPosition(w.mShownFrame.left,
9958 w.mShownFrame.top);
9959 } catch (RuntimeException e) {
9960 // If something goes wrong with the surface (such
9961 // as running out of memory), don't take down the
9962 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 + "size=(" + width + "x" + height
9965 + "), pos=(" + w.mShownFrame.left
9966 + "," + w.mShownFrame.top + ")", e);
9967 if (!recoveringMemory) {
9968 reclaimSomeSurfaceMemoryLocked(w, "size");
9969 }
9970 }
9971 }
9972 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009973 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009974 w.mContentInsetsChanged =
9975 !w.mLastContentInsets.equals(w.mContentInsets);
9976 w.mVisibleInsetsChanged =
9977 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009978 boolean configChanged =
9979 w.mConfiguration != mCurConfiguration
9980 && (w.mConfiguration == null
9981 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009982 if (DEBUG_CONFIGURATION && configChanged) {
9983 Slog.v(TAG, "Win " + w + " config changed: "
9984 + mCurConfiguration);
9985 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009986 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009987 + ": configChanged=" + configChanged
9988 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009989 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009990 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009991 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009992 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009993 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009994 w.mLastFrame.set(w.mFrame);
9995 w.mLastContentInsets.set(w.mContentInsets);
9996 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009997 // If the screen is currently frozen, then keep
9998 // it frozen until this window draws at its new
9999 // orientation.
10000 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010001 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010002 "Resizing while display frozen: " + w);
10003 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010004 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010005 mWindowsFreezingScreen = true;
10006 // XXX should probably keep timeout from
10007 // when we first froze the display.
10008 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10009 mH.sendMessageDelayed(mH.obtainMessage(
10010 H.WINDOW_FREEZE_TIMEOUT), 2000);
10011 }
10012 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 // If the orientation is changing, then we need to
10014 // hold off on unfreezing the display until this
10015 // window has been redrawn; to do that, we need
10016 // to go through the process of getting informed
10017 // by the application when it has finished drawing.
10018 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010019 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010020 "Orientation start waiting for draw in "
10021 + w + ", surface " + w.mSurface);
10022 w.mDrawPending = true;
10023 w.mCommitDrawPending = false;
10024 w.mReadyToShow = false;
10025 if (w.mAppToken != null) {
10026 w.mAppToken.allDrawn = false;
10027 }
10028 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010029 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 "Resizing window " + w + " to " + w.mFrame);
10031 mResizingWindows.add(w);
10032 } else if (w.mOrientationChanging) {
10033 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010034 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010035 "Orientation not waiting for draw in "
10036 + w + ", surface " + w.mSurface);
10037 w.mOrientationChanging = false;
10038 }
10039 }
10040 }
10041
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010042 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010043 if (!w.mLastHidden) {
10044 //dump();
10045 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010046 if (SHOW_TRANSACTIONS) logSurface(w,
10047 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010048 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010049 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 try {
10051 w.mSurface.hide();
10052 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010053 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 }
10055 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010056 }
10057 // If we are waiting for this window to handle an
10058 // orientation change, well, it is hidden, so
10059 // doesn't really matter. Note that this does
10060 // introduce a potential glitch if the window
10061 // becomes unhidden before it has drawn for the
10062 // new orientation.
10063 if (w.mOrientationChanging) {
10064 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010065 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010066 "Orientation change skips hidden " + w);
10067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068 } else if (w.mLastLayer != w.mAnimLayer
10069 || w.mLastAlpha != w.mShownAlpha
10070 || w.mLastDsDx != w.mDsDx
10071 || w.mLastDtDx != w.mDtDx
10072 || w.mLastDsDy != w.mDsDy
10073 || w.mLastDtDy != w.mDtDy
10074 || w.mLastHScale != w.mHScale
10075 || w.mLastVScale != w.mVScale
10076 || w.mLastHidden) {
10077 displayed = true;
10078 w.mLastAlpha = w.mShownAlpha;
10079 w.mLastLayer = w.mAnimLayer;
10080 w.mLastDsDx = w.mDsDx;
10081 w.mLastDtDx = w.mDtDx;
10082 w.mLastDsDy = w.mDsDy;
10083 w.mLastDtDy = w.mDtDy;
10084 w.mLastHScale = w.mHScale;
10085 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010086 if (SHOW_TRANSACTIONS) logSurface(w,
10087 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010088 + " matrix=[" + (w.mDsDx*w.mHScale)
10089 + "," + (w.mDtDx*w.mVScale)
10090 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010091 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010092 if (w.mSurface != null) {
10093 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010094 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010095 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010096 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010097 w.mSurface.setLayer(w.mAnimLayer);
10098 w.mSurface.setMatrix(
10099 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10100 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10101 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010102 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 if (!recoveringMemory) {
10104 reclaimSomeSurfaceMemoryLocked(w, "update");
10105 }
10106 }
10107 }
10108
10109 if (w.mLastHidden && !w.mDrawPending
10110 && !w.mCommitDrawPending
10111 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010112 if (SHOW_TRANSACTIONS) logSurface(w,
10113 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010114 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 + " during relayout");
10116 if (showSurfaceRobustlyLocked(w)) {
10117 w.mHasDrawn = true;
10118 w.mLastHidden = false;
10119 } else {
10120 w.mOrientationChanging = false;
10121 }
10122 }
10123 if (w.mSurface != null) {
10124 w.mToken.hasVisible = true;
10125 }
10126 } else {
10127 displayed = true;
10128 }
10129
10130 if (displayed) {
10131 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010132 if (attrs.width == LayoutParams.MATCH_PARENT
10133 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010134 covered = true;
10135 }
10136 }
10137 if (w.mOrientationChanging) {
10138 if (w.mDrawPending || w.mCommitDrawPending) {
10139 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010140 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010141 "Orientation continue waiting for draw in " + w);
10142 } else {
10143 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010144 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010145 "Orientation change complete in " + w);
10146 }
10147 }
10148 w.mToken.hasVisible = true;
10149 }
10150 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010151 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010152 "Orientation change skips hidden " + w);
10153 w.mOrientationChanging = false;
10154 }
10155
10156 final boolean canBeSeen = w.isDisplayedLw();
10157
10158 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10159 focusDisplayed = true;
10160 }
10161
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010162 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010164 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010165 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 if (w.mSurface != null) {
10167 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10168 holdScreen = w.mSession;
10169 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010170 if (!syswin && w.mAttrs.screenBrightness >= 0
10171 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010172 screenBrightness = w.mAttrs.screenBrightness;
10173 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010174 if (!syswin && w.mAttrs.buttonBrightness >= 0
10175 && buttonBrightness < 0) {
10176 buttonBrightness = w.mAttrs.buttonBrightness;
10177 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010178 if (canBeSeen
10179 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10180 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10181 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010182 syswin = true;
10183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010184 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010185
Dianne Hackborn25994b42009-09-04 14:21:19 -070010186 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10187 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010188 // This window completely covers everything behind it,
10189 // so we want to leave all of them as unblurred (for
10190 // performance reasons).
10191 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010192 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010193 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010194 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010195 obscured = true;
10196 if (mBackgroundFillerSurface == null) {
10197 try {
10198 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010199 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010200 0, dw, dh,
10201 PixelFormat.OPAQUE,
10202 Surface.FX_SURFACE_NORMAL);
10203 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010204 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010205 }
10206 }
10207 try {
10208 mBackgroundFillerSurface.setPosition(0, 0);
10209 mBackgroundFillerSurface.setSize(dw, dh);
10210 // Using the same layer as Dim because they will never be shown at the
10211 // same time.
10212 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10213 mBackgroundFillerSurface.show();
10214 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010215 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010216 }
10217 backgroundFillerShown = true;
10218 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010219 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010220 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010221 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010222 + ": blurring=" + blurring
10223 + " obscured=" + obscured
10224 + " displayed=" + displayed);
10225 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10226 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010227 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010228 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010229 if (mDimAnimator == null) {
10230 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010231 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010232 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010233 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 }
10236 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10237 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010238 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010239 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010240 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010241 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242 + mBlurSurface + ": CREATE");
10243 try {
Romain Guy06882f82009-06-10 13:36:04 -070010244 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010245 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246 -1, 16, 16,
10247 PixelFormat.OPAQUE,
10248 Surface.FX_SURFACE_BLUR);
10249 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010250 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010251 }
10252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010253 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010254 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10255 + mBlurSurface + ": pos=(0,0) (" +
10256 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010257 mBlurSurface.setPosition(0, 0);
10258 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010259 mBlurSurface.setLayer(w.mAnimLayer-2);
10260 if (!mBlurShown) {
10261 try {
10262 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10263 + mBlurSurface + ": SHOW");
10264 mBlurSurface.show();
10265 } catch (RuntimeException e) {
10266 Slog.w(TAG, "Failure showing blur surface", e);
10267 }
10268 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 }
10270 }
10271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 }
10273 }
10274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010275
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010276 if (obscuredChanged && mWallpaperTarget == w) {
10277 // This is the wallpaper target and its obscured state
10278 // changed... make sure the current wallaper's visibility
10279 // has been updated accordingly.
10280 updateWallpaperVisibilityLocked();
10281 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010282 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010283
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010284 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10285 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010286 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010287 try {
10288 mBackgroundFillerSurface.hide();
10289 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010290 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010291 }
10292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010294 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010295 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10296 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 }
Romain Guy06882f82009-06-10 13:36:04 -070010298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010300 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010301 + ": HIDE");
10302 try {
10303 mBlurSurface.hide();
10304 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010305 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 }
10307 mBlurShown = false;
10308 }
10309
Joe Onorato8a9b2202010-02-26 18:56:32 -080010310 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010312 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 }
10314
Jeff Browne33348b2010-07-15 23:54:05 -070010315 mInputMonitor.updateInputWindowsLw();
10316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010317 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010318
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010319 if (mWatermark != null) {
10320 mWatermark.drawIfNeeded();
10321 }
10322
Joe Onorato8a9b2202010-02-26 18:56:32 -080010323 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 "With display frozen, orientationChangeComplete="
10325 + orientationChangeComplete);
10326 if (orientationChangeComplete) {
10327 if (mWindowsFreezingScreen) {
10328 mWindowsFreezingScreen = false;
10329 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10330 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010331 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010332 }
Romain Guy06882f82009-06-10 13:36:04 -070010333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010334 i = mResizingWindows.size();
10335 if (i > 0) {
10336 do {
10337 i--;
10338 WindowState win = mResizingWindows.get(i);
10339 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010340 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10341 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010342 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010343 boolean configChanged =
10344 win.mConfiguration != mCurConfiguration
10345 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010346 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10347 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10348 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010349 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010350 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010351 + " / " + mCurConfiguration + " / 0x"
10352 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010353 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010354 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010355 win.mClient.resized(win.mFrame.width(),
10356 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010357 win.mLastVisibleInsets, win.mDrawPending,
10358 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 win.mContentInsetsChanged = false;
10360 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010361 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010362 } catch (RemoteException e) {
10363 win.mOrientationChanging = false;
10364 }
10365 } while (i > 0);
10366 mResizingWindows.clear();
10367 }
Romain Guy06882f82009-06-10 13:36:04 -070010368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010369 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010370 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010371 i = mDestroySurface.size();
10372 if (i > 0) {
10373 do {
10374 i--;
10375 WindowState win = mDestroySurface.get(i);
10376 win.mDestroying = false;
10377 if (mInputMethodWindow == win) {
10378 mInputMethodWindow = null;
10379 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010380 if (win == mWallpaperTarget) {
10381 wallpaperDestroyed = true;
10382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010383 win.destroySurfaceLocked();
10384 } while (i > 0);
10385 mDestroySurface.clear();
10386 }
10387
10388 // Time to remove any exiting tokens?
10389 for (i=mExitingTokens.size()-1; i>=0; i--) {
10390 WindowToken token = mExitingTokens.get(i);
10391 if (!token.hasVisible) {
10392 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010393 if (token.windowType == TYPE_WALLPAPER) {
10394 mWallpaperTokens.remove(token);
10395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010396 }
10397 }
10398
10399 // Time to remove any exiting applications?
10400 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10401 AppWindowToken token = mExitingAppTokens.get(i);
10402 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010403 // Make sure there is no animation running on this token,
10404 // so any windows associated with it will be removed as
10405 // soon as their animations are complete
10406 token.animation = null;
10407 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408 mAppTokens.remove(token);
10409 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010410 if (mLastEnterAnimToken == token) {
10411 mLastEnterAnimToken = null;
10412 mLastEnterAnimParams = null;
10413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010414 }
10415 }
10416
Dianne Hackborna8f60182009-09-01 19:01:50 -070010417 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010418
Dianne Hackborna8f60182009-09-01 19:01:50 -070010419 if (!animating && mAppTransitionRunning) {
10420 // We have finished the animation of an app transition. To do
10421 // this, we have delayed a lot of operations like showing and
10422 // hiding apps, moving apps in Z-order, etc. The app token list
10423 // reflects the correct Z-order, but the window list may now
10424 // be out of sync with it. So here we will just rebuild the
10425 // entire app window list. Fun!
10426 mAppTransitionRunning = false;
10427 needRelayout = true;
10428 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010429 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010430 // Clear information about apps that were moving.
10431 mToBottomApps.clear();
10432 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010434 if (focusDisplayed) {
10435 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10436 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010437 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010438 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010439 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010440 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010441 requestAnimationLocked(0);
10442 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010443 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10444 }
Jeff Browneb857f12010-07-16 10:06:33 -070010445
Jeff Browne33348b2010-07-15 23:54:05 -070010446 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010447
Jeff Brown8e03b752010-06-13 19:16:55 -070010448 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010449 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10450 mPowerManager.setScreenBrightnessOverride(-1);
10451 } else {
10452 mPowerManager.setScreenBrightnessOverride((int)
10453 (screenBrightness * Power.BRIGHTNESS_ON));
10454 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010455 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10456 mPowerManager.setButtonBrightnessOverride(-1);
10457 } else {
10458 mPowerManager.setButtonBrightnessOverride((int)
10459 (buttonBrightness * Power.BRIGHTNESS_ON));
10460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 if (holdScreen != mHoldingScreenOn) {
10462 mHoldingScreenOn = holdScreen;
10463 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10464 mH.sendMessage(m);
10465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010466
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010467 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010468 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010469 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10470 LocalPowerManager.BUTTON_EVENT, true);
10471 mTurnOnScreen = false;
10472 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010473
10474 // Check to see if we are now in a state where the screen should
10475 // be enabled, because the window obscured flags have changed.
10476 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010478
10479 /**
10480 * Must be called with the main window manager lock held.
10481 */
10482 void setHoldScreenLocked(boolean holding) {
10483 boolean state = mHoldingScreenWakeLock.isHeld();
10484 if (holding != state) {
10485 if (holding) {
10486 mHoldingScreenWakeLock.acquire();
10487 } else {
10488 mPolicy.screenOnStoppedLw();
10489 mHoldingScreenWakeLock.release();
10490 }
10491 }
10492 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493
10494 void requestAnimationLocked(long delay) {
10495 if (!mAnimationPending) {
10496 mAnimationPending = true;
10497 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10498 }
10499 }
Romain Guy06882f82009-06-10 13:36:04 -070010500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 /**
10502 * Have the surface flinger show a surface, robustly dealing with
10503 * error conditions. In particular, if there is not enough memory
10504 * to show the surface, then we will try to get rid of other surfaces
10505 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010506 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 * @return Returns true if the surface was successfully shown.
10508 */
10509 boolean showSurfaceRobustlyLocked(WindowState win) {
10510 try {
10511 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010512 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010514 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010515 if (DEBUG_VISIBILITY) Slog.v(TAG,
10516 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010517 win.mTurnOnScreen = false;
10518 mTurnOnScreen = true;
10519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010520 }
10521 return true;
10522 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010523 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 }
Romain Guy06882f82009-06-10 13:36:04 -070010525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010526 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010528 return false;
10529 }
Romain Guy06882f82009-06-10 13:36:04 -070010530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10532 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010533
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010534 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010535 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010537 if (mForceRemoves == null) {
10538 mForceRemoves = new ArrayList<WindowState>();
10539 }
Romain Guy06882f82009-06-10 13:36:04 -070010540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010541 long callingIdentity = Binder.clearCallingIdentity();
10542 try {
10543 // There was some problem... first, do a sanity check of the
10544 // window list to make sure we haven't left any dangling surfaces
10545 // around.
10546 int N = mWindows.size();
10547 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010548 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010550 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551 if (ws.mSurface != null) {
10552 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010553 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010554 + ws + " surface=" + ws.mSurface
10555 + " token=" + win.mToken
10556 + " pid=" + ws.mSession.mPid
10557 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010558 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010559 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010560 ws.mSurface = null;
10561 mForceRemoves.add(ws);
10562 i--;
10563 N--;
10564 leakedSurface = true;
10565 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010566 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010567 + ws + " surface=" + ws.mSurface
10568 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010569 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010570 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010571 ws.mSurface = null;
10572 leakedSurface = true;
10573 }
10574 }
10575 }
Romain Guy06882f82009-06-10 13:36:04 -070010576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010577 boolean killedApps = false;
10578 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 SparseIntArray pidCandidates = new SparseIntArray();
10581 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010582 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010583 if (ws.mSurface != null) {
10584 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10585 }
10586 }
10587 if (pidCandidates.size() > 0) {
10588 int[] pids = new int[pidCandidates.size()];
10589 for (int i=0; i<pids.length; i++) {
10590 pids[i] = pidCandidates.keyAt(i);
10591 }
10592 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010593 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 killedApps = true;
10595 }
10596 } catch (RemoteException e) {
10597 }
10598 }
10599 }
Romain Guy06882f82009-06-10 13:36:04 -070010600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 if (leakedSurface || killedApps) {
10602 // We managed to reclaim some memory, so get rid of the trouble
10603 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010604 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010605 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010606 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010607 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010608 win.mSurface = null;
10609 }
Romain Guy06882f82009-06-10 13:36:04 -070010610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 try {
10612 win.mClient.dispatchGetNewSurface();
10613 } catch (RemoteException e) {
10614 }
10615 }
10616 } finally {
10617 Binder.restoreCallingIdentity(callingIdentity);
10618 }
10619 }
Romain Guy06882f82009-06-10 13:36:04 -070010620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010621 private boolean updateFocusedWindowLocked(int mode) {
10622 WindowState newFocus = computeFocusedWindowLocked();
10623 if (mCurrentFocus != newFocus) {
10624 // This check makes sure that we don't already have the focus
10625 // change message pending.
10626 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10627 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010628 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010629 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10630 final WindowState oldFocus = mCurrentFocus;
10631 mCurrentFocus = newFocus;
10632 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010634 final WindowState imWindow = mInputMethodWindow;
10635 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010636 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010638 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10639 mLayoutNeeded = true;
10640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010641 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010642 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010643 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10644 // Client will do the layout, but we need to assign layers
10645 // for handleNewWindowLocked() below.
10646 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 }
10648 }
Jeff Brown349703e2010-06-22 01:27:15 -070010649
10650 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10651 // If we defer assigning layers, then the caller is responsible for
10652 // doing this part.
10653 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 return true;
10656 }
10657 return false;
10658 }
Jeff Brown349703e2010-06-22 01:27:15 -070010659
10660 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010661 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010663
10664 private WindowState computeFocusedWindowLocked() {
10665 WindowState result = null;
10666 WindowState win;
10667
10668 int i = mWindows.size() - 1;
10669 int nextAppIndex = mAppTokens.size()-1;
10670 WindowToken nextApp = nextAppIndex >= 0
10671 ? mAppTokens.get(nextAppIndex) : null;
10672
10673 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010674 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675
Joe Onorato8a9b2202010-02-26 18:56:32 -080010676 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010677 TAG, "Looking for focus: " + i
10678 + " = " + win
10679 + ", flags=" + win.mAttrs.flags
10680 + ", canReceive=" + win.canReceiveKeys());
10681
10682 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010684 // If this window's application has been removed, just skip it.
10685 if (thisApp != null && thisApp.removed) {
10686 i--;
10687 continue;
10688 }
Romain Guy06882f82009-06-10 13:36:04 -070010689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010690 // If there is a focused app, don't allow focus to go to any
10691 // windows below it. If this is an application window, step
10692 // through the app tokens until we find its app.
10693 if (thisApp != null && nextApp != null && thisApp != nextApp
10694 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10695 int origAppIndex = nextAppIndex;
10696 while (nextAppIndex > 0) {
10697 if (nextApp == mFocusedApp) {
10698 // Whoops, we are below the focused app... no focus
10699 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010700 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010701 TAG, "Reached focused app: " + mFocusedApp);
10702 return null;
10703 }
10704 nextAppIndex--;
10705 nextApp = mAppTokens.get(nextAppIndex);
10706 if (nextApp == thisApp) {
10707 break;
10708 }
10709 }
10710 if (thisApp != nextApp) {
10711 // Uh oh, the app token doesn't exist! This shouldn't
10712 // happen, but if it does we can get totally hosed...
10713 // so restart at the original app.
10714 nextAppIndex = origAppIndex;
10715 nextApp = mAppTokens.get(nextAppIndex);
10716 }
10717 }
10718
10719 // Dispatch to this window if it is wants key events.
10720 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010721 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 TAG, "Found focus @ " + i + " = " + win);
10723 result = win;
10724 break;
10725 }
10726
10727 i--;
10728 }
10729
10730 return result;
10731 }
10732
10733 private void startFreezingDisplayLocked() {
10734 if (mDisplayFrozen) {
10735 return;
10736 }
Romain Guy06882f82009-06-10 13:36:04 -070010737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010740 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010741 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010742 if (mFreezeGcPending != 0) {
10743 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010744 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010745 mH.removeMessages(H.FORCE_GC);
10746 Runtime.getRuntime().gc();
10747 mFreezeGcPending = now;
10748 }
10749 } else {
10750 mFreezeGcPending = now;
10751 }
Romain Guy06882f82009-06-10 13:36:04 -070010752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010753 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010754
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010755 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010756
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010757 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10758 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010759 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010760 mAppTransitionReady = true;
10761 }
Romain Guy06882f82009-06-10 13:36:04 -070010762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010763 if (PROFILE_ORIENTATION) {
10764 File file = new File("/data/system/frozen");
10765 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10766 }
10767 Surface.freezeDisplay(0);
10768 }
Romain Guy06882f82009-06-10 13:36:04 -070010769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 private void stopFreezingDisplayLocked() {
10771 if (!mDisplayFrozen) {
10772 return;
10773 }
Romain Guy06882f82009-06-10 13:36:04 -070010774
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010775 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10776 return;
10777 }
10778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 mDisplayFrozen = false;
10780 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10781 if (PROFILE_ORIENTATION) {
10782 Debug.stopMethodTracing();
10783 }
10784 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010785
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010786 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010787
Christopher Tateb696aee2010-04-02 19:08:30 -070010788 // While the display is frozen we don't re-compute the orientation
10789 // to avoid inconsistent states. However, something interesting
10790 // could have actually changed during that time so re-evaluate it
10791 // now to catch that.
10792 if (updateOrientationFromAppTokensLocked()) {
10793 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10794 }
10795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 // A little kludge: a lot could have happened while the
10797 // display was frozen, so now that we are coming back we
10798 // do a gc so that any remote references the system
10799 // processes holds on others can be released if they are
10800 // no longer needed.
10801 mH.removeMessages(H.FORCE_GC);
10802 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10803 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010805 mScreenFrozenLock.release();
10806 }
Romain Guy06882f82009-06-10 13:36:04 -070010807
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010808 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10809 DisplayMetrics dm) {
10810 if (index < tokens.length) {
10811 String str = tokens[index];
10812 if (str != null && str.length() > 0) {
10813 try {
10814 int val = Integer.parseInt(str);
10815 return val;
10816 } catch (Exception e) {
10817 }
10818 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010819 }
10820 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10821 return defDps;
10822 }
10823 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10824 return val;
10825 }
10826
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010827 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010828 final String[] mTokens;
10829 final String mText;
10830 final Paint mTextPaint;
10831 final int mTextWidth;
10832 final int mTextHeight;
10833 final int mTextAscent;
10834 final int mTextDescent;
10835 final int mDeltaX;
10836 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010837
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010838 Surface mSurface;
10839 int mLastDW;
10840 int mLastDH;
10841 boolean mDrawNeeded;
10842
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010843 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010844 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010845 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010846
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010847 if (false) {
10848 Log.i(TAG, "*********************** WATERMARK");
10849 for (int i=0; i<tokens.length; i++) {
10850 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10851 }
10852 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010853
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010854 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010855
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010856 StringBuilder builder = new StringBuilder(32);
10857 int len = mTokens[0].length();
10858 len = len & ~1;
10859 for (int i=0; i<len; i+=2) {
10860 int c1 = mTokens[0].charAt(i);
10861 int c2 = mTokens[0].charAt(i+1);
10862 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10863 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10864 else c1 -= '0';
10865 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10866 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10867 else c2 -= '0';
10868 builder.append((char)(255-((c1*16)+c2)));
10869 }
10870 mText = builder.toString();
10871 if (false) {
10872 Log.i(TAG, "Final text: " + mText);
10873 }
10874
10875 int fontSize = getPropertyInt(tokens, 1,
10876 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10877
10878 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10879 mTextPaint.setTextSize(fontSize);
10880 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10881
10882 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10883 mTextWidth = (int)mTextPaint.measureText(mText);
10884 mTextAscent = fm.ascent;
10885 mTextDescent = fm.descent;
10886 mTextHeight = fm.descent - fm.ascent;
10887
10888 mDeltaX = getPropertyInt(tokens, 2,
10889 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10890 mDeltaY = getPropertyInt(tokens, 3,
10891 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10892 int shadowColor = getPropertyInt(tokens, 4,
10893 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10894 int color = getPropertyInt(tokens, 5,
10895 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10896 int shadowRadius = getPropertyInt(tokens, 6,
10897 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10898 int shadowDx = getPropertyInt(tokens, 8,
10899 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10900 int shadowDy = getPropertyInt(tokens, 9,
10901 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10902
10903 mTextPaint.setColor(color);
10904 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010905
10906 try {
10907 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010908 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010909 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010910 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010911 mSurface.show();
10912 } catch (OutOfResourcesException e) {
10913 }
10914 }
10915
10916 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010917 if (mLastDW != dw || mLastDH != dh) {
10918 mLastDW = dw;
10919 mLastDH = dh;
10920 mSurface.setSize(dw, dh);
10921 mDrawNeeded = true;
10922 }
10923 }
10924
10925 void drawIfNeeded() {
10926 if (mDrawNeeded) {
10927 final int dw = mLastDW;
10928 final int dh = mLastDH;
10929
10930 mDrawNeeded = false;
10931 Rect dirty = new Rect(0, 0, dw, dh);
10932 Canvas c = null;
10933 try {
10934 c = mSurface.lockCanvas(dirty);
10935 } catch (IllegalArgumentException e) {
10936 } catch (OutOfResourcesException e) {
10937 }
10938 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010939 c.drawColor(0, PorterDuff.Mode.CLEAR);
10940
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010941 int deltaX = mDeltaX;
10942 int deltaY = mDeltaY;
10943
10944 // deltaX shouldn't be close to a round fraction of our
10945 // x step, or else things will line up too much.
10946 int div = (dw+mTextWidth)/deltaX;
10947 int rem = (dw+mTextWidth) - (div*deltaX);
10948 int qdelta = deltaX/4;
10949 if (rem < qdelta || rem > (deltaX-qdelta)) {
10950 deltaX += deltaX/3;
10951 }
10952
10953 int y = -mTextHeight;
10954 int x = -mTextWidth;
10955 while (y < (dh+mTextHeight)) {
10956 c.drawText(mText, x, y, mTextPaint);
10957 x += deltaX;
10958 if (x >= dw) {
10959 x -= (dw+mTextWidth);
10960 y += deltaY;
10961 }
10962 }
10963 mSurface.unlockCanvasAndPost(c);
10964 }
10965 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010966 }
10967 }
10968
10969 void createWatermark() {
10970 if (mWatermark != null) {
10971 return;
10972 }
10973
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010974 File file = new File("/system/etc/setup.conf");
10975 FileInputStream in = null;
10976 try {
10977 in = new FileInputStream(file);
10978 DataInputStream ind = new DataInputStream(in);
10979 String line = ind.readLine();
10980 if (line != null) {
10981 String[] toks = line.split("%");
10982 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010983 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010984 }
10985 }
10986 } catch (FileNotFoundException e) {
10987 } catch (IOException e) {
10988 } finally {
10989 if (in != null) {
10990 try {
10991 in.close();
10992 } catch (IOException e) {
10993 }
10994 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010995 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010996 }
10997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010998 @Override
10999 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11000 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11001 != PackageManager.PERMISSION_GRANTED) {
11002 pw.println("Permission Denial: can't dump WindowManager from from pid="
11003 + Binder.getCallingPid()
11004 + ", uid=" + Binder.getCallingUid());
11005 return;
11006 }
Romain Guy06882f82009-06-10 13:36:04 -070011007
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011008 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011009 pw.println(" ");
11010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011011 synchronized(mWindowMap) {
11012 pw.println("Current Window Manager state:");
11013 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011014 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011015 pw.print(" Window #"); pw.print(i); pw.print(' ');
11016 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011017 w.dump(pw, " ");
11018 }
11019 if (mInputMethodDialogs.size() > 0) {
11020 pw.println(" ");
11021 pw.println(" Input method dialogs:");
11022 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11023 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011024 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011025 }
11026 }
11027 if (mPendingRemove.size() > 0) {
11028 pw.println(" ");
11029 pw.println(" Remove pending for:");
11030 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11031 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011032 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11033 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011034 w.dump(pw, " ");
11035 }
11036 }
11037 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11038 pw.println(" ");
11039 pw.println(" Windows force removing:");
11040 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11041 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011042 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11043 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011044 w.dump(pw, " ");
11045 }
11046 }
11047 if (mDestroySurface.size() > 0) {
11048 pw.println(" ");
11049 pw.println(" Windows waiting to destroy their surface:");
11050 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11051 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011052 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11053 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011054 w.dump(pw, " ");
11055 }
11056 }
11057 if (mLosingFocus.size() > 0) {
11058 pw.println(" ");
11059 pw.println(" Windows losing focus:");
11060 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11061 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011062 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11063 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011064 w.dump(pw, " ");
11065 }
11066 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011067 if (mResizingWindows.size() > 0) {
11068 pw.println(" ");
11069 pw.println(" Windows waiting to resize:");
11070 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11071 WindowState w = mResizingWindows.get(i);
11072 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11073 pw.print(w); pw.println(":");
11074 w.dump(pw, " ");
11075 }
11076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011077 if (mSessions.size() > 0) {
11078 pw.println(" ");
11079 pw.println(" All active sessions:");
11080 Iterator<Session> it = mSessions.iterator();
11081 while (it.hasNext()) {
11082 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011083 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011084 s.dump(pw, " ");
11085 }
11086 }
11087 if (mTokenMap.size() > 0) {
11088 pw.println(" ");
11089 pw.println(" All tokens:");
11090 Iterator<WindowToken> it = mTokenMap.values().iterator();
11091 while (it.hasNext()) {
11092 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011093 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011094 token.dump(pw, " ");
11095 }
11096 }
11097 if (mTokenList.size() > 0) {
11098 pw.println(" ");
11099 pw.println(" Window token list:");
11100 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011101 pw.print(" #"); pw.print(i); pw.print(": ");
11102 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011103 }
11104 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011105 if (mWallpaperTokens.size() > 0) {
11106 pw.println(" ");
11107 pw.println(" Wallpaper tokens:");
11108 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11109 WindowToken token = mWallpaperTokens.get(i);
11110 pw.print(" Wallpaper #"); pw.print(i);
11111 pw.print(' '); pw.print(token); pw.println(':');
11112 token.dump(pw, " ");
11113 }
11114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 if (mAppTokens.size() > 0) {
11116 pw.println(" ");
11117 pw.println(" Application tokens in Z order:");
11118 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011119 pw.print(" App #"); pw.print(i); pw.print(": ");
11120 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011121 }
11122 }
11123 if (mFinishedStarting.size() > 0) {
11124 pw.println(" ");
11125 pw.println(" Finishing start of application tokens:");
11126 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11127 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011128 pw.print(" Finished Starting #"); pw.print(i);
11129 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011130 token.dump(pw, " ");
11131 }
11132 }
11133 if (mExitingTokens.size() > 0) {
11134 pw.println(" ");
11135 pw.println(" Exiting tokens:");
11136 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11137 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011138 pw.print(" Exiting #"); pw.print(i);
11139 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011140 token.dump(pw, " ");
11141 }
11142 }
11143 if (mExitingAppTokens.size() > 0) {
11144 pw.println(" ");
11145 pw.println(" Exiting application tokens:");
11146 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11147 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011148 pw.print(" Exiting App #"); pw.print(i);
11149 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011150 token.dump(pw, " ");
11151 }
11152 }
11153 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011154 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11155 pw.print(" mLastFocus="); pw.println(mLastFocus);
11156 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11157 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11158 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011159 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011160 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11161 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11162 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11163 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011164 if (mWindowDetachedWallpaper != null) {
11165 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11166 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011167 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11168 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11169 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011170 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11171 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11172 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11173 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011174 if (mDimAnimator != null) {
11175 mDimAnimator.printTo(pw);
11176 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011177 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011178 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011179 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011180 pw.print(mInputMethodAnimLayerAdjustment);
11181 pw.print(" mWallpaperAnimLayerAdjustment=");
11182 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011183 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11184 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011185 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11186 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011187 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11188 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011189 pw.print(" mRotation="); pw.print(mRotation);
11190 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11191 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11192 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11193 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11194 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11195 pw.print(" mNextAppTransition=0x");
11196 pw.print(Integer.toHexString(mNextAppTransition));
11197 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011198 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011199 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011200 if (mNextAppTransitionPackage != null) {
11201 pw.print(" mNextAppTransitionPackage=");
11202 pw.print(mNextAppTransitionPackage);
11203 pw.print(", mNextAppTransitionEnter=0x");
11204 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11205 pw.print(", mNextAppTransitionExit=0x");
11206 pw.print(Integer.toHexString(mNextAppTransitionExit));
11207 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011208 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11209 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011210 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11211 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11212 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11213 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011214 if (mOpeningApps.size() > 0) {
11215 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11216 }
11217 if (mClosingApps.size() > 0) {
11218 pw.print(" mClosingApps="); pw.println(mClosingApps);
11219 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011220 if (mToTopApps.size() > 0) {
11221 pw.print(" mToTopApps="); pw.println(mToTopApps);
11222 }
11223 if (mToBottomApps.size() > 0) {
11224 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11225 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011226 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11227 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011228 }
11229 }
11230
Jeff Brown349703e2010-06-22 01:27:15 -070011231 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011232 public void monitor() {
11233 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011234 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011235 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011236
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011237 /**
11238 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011239 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011240 */
11241 private static class DimAnimator {
11242 Surface mDimSurface;
11243 boolean mDimShown = false;
11244 float mDimCurrentAlpha;
11245 float mDimTargetAlpha;
11246 float mDimDeltaPerMs;
11247 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011248
11249 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011250
11251 DimAnimator (SurfaceSession session) {
11252 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011253 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011254 + mDimSurface + ": CREATE");
11255 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011256 mDimSurface = new Surface(session, 0,
11257 "DimSurface",
11258 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011259 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011260 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011261 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011262 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011263 }
11264 }
11265 }
11266
11267 /**
11268 * Show the dim surface.
11269 */
11270 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011271 if (!mDimShown) {
11272 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11273 dw + "x" + dh + ")");
11274 mDimShown = true;
11275 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011276 mLastDimWidth = dw;
11277 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011278 mDimSurface.setPosition(0, 0);
11279 mDimSurface.setSize(dw, dh);
11280 mDimSurface.show();
11281 } catch (RuntimeException e) {
11282 Slog.w(TAG, "Failure showing dim surface", e);
11283 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011284 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11285 mLastDimWidth = dw;
11286 mLastDimHeight = dh;
11287 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011288 }
11289 }
11290
11291 /**
11292 * Set's the dim surface's layer and update dim parameters that will be used in
11293 * {@link updateSurface} after all windows are examined.
11294 */
11295 void updateParameters(WindowState w, long currentTime) {
11296 mDimSurface.setLayer(w.mAnimLayer-1);
11297
11298 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011299 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011300 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011301 if (mDimTargetAlpha != target) {
11302 // If the desired dim level has changed, then
11303 // start an animation to it.
11304 mLastDimAnimTime = currentTime;
11305 long duration = (w.mAnimating && w.mAnimation != null)
11306 ? w.mAnimation.computeDurationHint()
11307 : DEFAULT_DIM_DURATION;
11308 if (target > mDimTargetAlpha) {
11309 // This is happening behind the activity UI,
11310 // so we can make it run a little longer to
11311 // give a stronger impression without disrupting
11312 // the user.
11313 duration *= DIM_DURATION_MULTIPLIER;
11314 }
11315 if (duration < 1) {
11316 // Don't divide by zero
11317 duration = 1;
11318 }
11319 mDimTargetAlpha = target;
11320 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11321 }
11322 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011323
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011324 /**
11325 * Updating the surface's alpha. Returns true if the animation continues, or returns
11326 * false when the animation is finished and the dim surface is hidden.
11327 */
11328 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11329 if (!dimming) {
11330 if (mDimTargetAlpha != 0) {
11331 mLastDimAnimTime = currentTime;
11332 mDimTargetAlpha = 0;
11333 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11334 }
11335 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011336
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011337 boolean animating = false;
11338 if (mLastDimAnimTime != 0) {
11339 mDimCurrentAlpha += mDimDeltaPerMs
11340 * (currentTime-mLastDimAnimTime);
11341 boolean more = true;
11342 if (displayFrozen) {
11343 // If the display is frozen, there is no reason to animate.
11344 more = false;
11345 } else if (mDimDeltaPerMs > 0) {
11346 if (mDimCurrentAlpha > mDimTargetAlpha) {
11347 more = false;
11348 }
11349 } else if (mDimDeltaPerMs < 0) {
11350 if (mDimCurrentAlpha < mDimTargetAlpha) {
11351 more = false;
11352 }
11353 } else {
11354 more = false;
11355 }
11356
11357 // Do we need to continue animating?
11358 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011359 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011360 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11361 mLastDimAnimTime = currentTime;
11362 mDimSurface.setAlpha(mDimCurrentAlpha);
11363 animating = true;
11364 } else {
11365 mDimCurrentAlpha = mDimTargetAlpha;
11366 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011367 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011368 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11369 mDimSurface.setAlpha(mDimCurrentAlpha);
11370 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011371 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011372 + ": HIDE");
11373 try {
11374 mDimSurface.hide();
11375 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011376 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011377 }
11378 mDimShown = false;
11379 }
11380 }
11381 }
11382 return animating;
11383 }
11384
11385 public void printTo(PrintWriter pw) {
11386 pw.print(" mDimShown="); pw.print(mDimShown);
11387 pw.print(" current="); pw.print(mDimCurrentAlpha);
11388 pw.print(" target="); pw.print(mDimTargetAlpha);
11389 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11390 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11391 }
11392 }
11393
11394 /**
11395 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11396 * This is used for opening/closing transition for apps in compatible mode.
11397 */
11398 private static class FadeInOutAnimation extends Animation {
11399 int mWidth;
11400 boolean mFadeIn;
11401
11402 public FadeInOutAnimation(boolean fadeIn) {
11403 setInterpolator(new AccelerateInterpolator());
11404 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11405 mFadeIn = fadeIn;
11406 }
11407
11408 @Override
11409 protected void applyTransformation(float interpolatedTime, Transformation t) {
11410 float x = interpolatedTime;
11411 if (!mFadeIn) {
11412 x = 1.0f - x; // reverse the interpolation for fade out
11413 }
11414 if (x < 0.5) {
11415 // move the window out of the screen.
11416 t.getMatrix().setTranslate(mWidth, 0);
11417 } else {
11418 t.getMatrix().setTranslate(0, 0);// show
11419 t.setAlpha((x - 0.5f) * 2);
11420 }
11421 }
11422
11423 @Override
11424 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11425 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11426 mWidth = width;
11427 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011428
11429 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011430 public int getZAdjustment() {
11431 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011432 }
11433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011434}