blob: 94b010b9afde25c5f7800b287a799c0ee257aeae [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import com.android.internal.view.IInputContext;
44import com.android.internal.view.IInputMethodClient;
45import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080046import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.server.am.BatteryStatsService;
48
49import android.Manifest;
50import android.app.ActivityManagerNative;
51import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070052import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070053import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070061import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.PixelFormat;
65import android.graphics.Rect;
66import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070067import android.graphics.Typeface;
68import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
75import android.os.LocalPowerManager;
76import android.os.Looper;
77import android.os.Message;
78import android.os.Parcel;
79import android.os.ParcelFileDescriptor;
80import android.os.Power;
81import android.os.PowerManager;
82import android.os.Process;
83import android.os.RemoteException;
84import android.os.ServiceManager;
85import android.os.SystemClock;
86import android.os.SystemProperties;
87import android.os.TokenWatcher;
88import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070089import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070091import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080092import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070094import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700106import android.view.InputEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107import android.view.KeyEvent;
108import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109import android.view.Surface;
110import android.view.SurfaceSession;
111import android.view.View;
112import android.view.ViewTreeObserver;
113import android.view.WindowManager;
114import android.view.WindowManagerImpl;
115import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700116import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700118import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119import android.view.animation.Animation;
120import android.view.animation.AnimationUtils;
121import android.view.animation.Transformation;
122
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700123import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700125import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import java.io.File;
127import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700128import java.io.FileInputStream;
129import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.IOException;
131import java.io.OutputStream;
132import java.io.OutputStreamWriter;
133import java.io.PrintWriter;
134import java.io.StringWriter;
135import java.net.Socket;
136import java.util.ArrayList;
137import java.util.HashMap;
138import java.util.HashSet;
139import java.util.Iterator;
140import java.util.List;
141
142/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700143public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700144 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 static final String TAG = "WindowManager";
146 static final boolean DEBUG = false;
147 static final boolean DEBUG_FOCUS = false;
148 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800149 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800150 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final boolean DEBUG_LAYERS = false;
152 static final boolean DEBUG_INPUT = false;
153 static final boolean DEBUG_INPUT_METHOD = false;
154 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700155 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700157 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean DEBUG_APP_TRANSITIONS = false;
159 static final boolean DEBUG_STARTING_WINDOW = false;
160 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700161 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700163 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean PROFILE_ORIENTATION = false;
166 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700167 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** How much to multiply the policy's type layer, to reserve room
170 * for multiple windows of the same type and Z-ordering adjustment
171 * with TYPE_LAYER_OFFSET. */
172 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
175 * or below others in the same layer. */
176 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to increment the layer for each window, to reserve room
179 * for effect surfaces between them.
180 */
181 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** The maximum length we will accept for a loaded animation duration:
184 * this is 10 seconds.
185 */
186 static final int MAX_ANIMATION_DURATION = 10*1000;
187
188 /** Amount of time (in milliseconds) to animate the dim surface from one
189 * value to another, when no window animation is driving it.
190 */
191 static final int DEFAULT_DIM_DURATION = 200;
192
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700193 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
194 * compatible windows.
195 */
196 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 /** Adjustment to time to perform a dim, to make it more dramatic.
199 */
200 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700201
202 // Maximum number of milliseconds to wait for input event injection.
203 // FIXME is this value reasonable?
204 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700205
206 // Default input dispatching timeout in nanoseconds.
207 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 static final int UPDATE_FOCUS_NORMAL = 0;
210 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
211 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
212 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700215 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
217 /**
218 * Condition waited on by {@link #reenableKeyguard} to know the call to
219 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500220 * This is set to true only if mKeyguardTokenWatcher.acquired() has
221 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500223 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
Jim Miller284b62e2010-06-08 14:27:42 -0700225 private static final int ALLOW_DISABLE_YES = 1;
226 private static final int ALLOW_DISABLE_NO = 0;
227 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
228 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
229
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
231 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700233 if (shouldAllowDisableKeyguard()) {
234 mPolicy.enableKeyguard(false);
235 mKeyguardDisabled = true;
236 } else {
237 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 }
240 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700241 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500242 synchronized (mKeyguardTokenWatcher) {
243 mKeyguardDisabled = false;
244 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 }
246 }
247 };
248
Jim Miller284b62e2010-06-08 14:27:42 -0700249 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
250 @Override
251 public void onReceive(Context context, Intent intent) {
252 mPolicy.enableKeyguard(true);
253 synchronized(mKeyguardTokenWatcher) {
254 // lazily evaluate this next time we're asked to disable keyguard
255 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
256 mKeyguardDisabled = false;
257 }
258 }
259 };
260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 final Context mContext;
262
263 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
268
269 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 /**
274 * All currently active sessions with clients.
275 */
276 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * Mapping from an IWindow IBinder to the server's Window object.
280 * This is also used as the lock for all of our state.
281 */
282 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
283
284 /**
285 * Mapping from a token IBinder to a WindowToken object.
286 */
287 final HashMap<IBinder, WindowToken> mTokenMap =
288 new HashMap<IBinder, WindowToken>();
289
290 /**
291 * The same tokens as mTokenMap, stored in a list for efficient iteration
292 * over them.
293 */
294 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 /**
297 * Window tokens that are in the process of exiting, but still
298 * on screen for animations.
299 */
300 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
301
302 /**
303 * Z-ordered (bottom-most first) list of all application tokens, for
304 * controlling the ordering of windows in different applications. This
305 * contains WindowToken objects.
306 */
307 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
308
309 /**
310 * Application tokens that are in the process of exiting, but still
311 * on screen for animations.
312 */
313 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
314
315 /**
316 * List of window tokens that have finished starting their application,
317 * and now need to have the policy remove their windows.
318 */
319 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
320
321 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700322 * This was the app token that was used to retrieve the last enter
323 * animation. It will be used for the next exit animation.
324 */
325 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800326
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700327 /**
328 * These were the layout params used to retrieve the last enter animation.
329 * They will be used for the next exit animation.
330 */
331 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800332
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700333 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 * Z-ordered (bottom-most first) list of all Window objects.
335 */
Jeff Browne33348b2010-07-15 23:54:05 -0700336 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337
338 /**
339 * Windows that are being resized. Used so we can tell the client about
340 * the resize after closing the transaction in which we resized the
341 * underlying surface.
342 */
343 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
344
345 /**
346 * Windows whose animations have ended and now must be removed.
347 */
348 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
349
350 /**
351 * Windows whose surface should be destroyed.
352 */
353 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
354
355 /**
356 * Windows that have lost input focus and are waiting for the new
357 * focus window to be displayed before they are told about this.
358 */
359 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
360
361 /**
362 * This is set when we have run out of memory, and will either be an empty
363 * list or contain windows that need to be force removed.
364 */
365 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700370 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 Surface mBlurSurface;
372 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700373 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 final float[] mTmpFloats = new float[9];
378
379 boolean mSafeMode;
380 boolean mDisplayEnabled = false;
381 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700382 int mInitialDisplayWidth = 0;
383 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mRotation = 0;
385 int mRequestedRotation = 0;
386 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700387 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 ArrayList<IRotationWatcher> mRotationWatchers
389 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 boolean mLayoutNeeded = true;
392 boolean mAnimationPending = false;
393 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800394 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 boolean mWindowsFreezingScreen = false;
396 long mFreezeGcPending = 0;
397 int mAppsFreezingScreen = 0;
398
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800399 int mLayoutSeq = 0;
400
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800401 // State while inside of layoutAndPlaceSurfacesLocked().
402 boolean mFocusMayChange;
403
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800404 Configuration mCurConfiguration = new Configuration();
405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 // This is held as long as we have the screen frozen, to give us time to
407 // perform a rotation animation when turning off shows the lock screen which
408 // changes the orientation.
409 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // State management of app transitions. When we are preparing for a
412 // transition, mNextAppTransition will be the kind of transition to
413 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
414 // mOpeningApps and mClosingApps are the lists of tokens that will be
415 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700416 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700417 String mNextAppTransitionPackage;
418 int mNextAppTransitionEnter;
419 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700421 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 boolean mAppTransitionTimeout = false;
423 boolean mStartingIconInTransition = false;
424 boolean mSkipAppTransitionAnimation = false;
425 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
426 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700427 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
428 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 H mH = new H();
433
434 WindowState mCurrentFocus = null;
435 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 // This just indicates the window the input method is on top of, not
438 // necessarily the window its input is going to.
439 WindowState mInputMethodTarget = null;
440 WindowState mUpcomingInputMethodTarget = null;
441 boolean mInputMethodTargetWaitingAnim;
442 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 WindowState mInputMethodWindow = null;
445 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
446
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700447 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800448
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700449 // If non-null, this is the currently visible window that is associated
450 // with the wallpaper.
451 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700452 // If non-null, we are in the middle of animating from one wallpaper target
453 // to another, and this is the lower one in Z-order.
454 WindowState mLowerWallpaperTarget = null;
455 // If non-null, we are in the middle of animating from one wallpaper target
456 // to another, and this is the higher one in Z-order.
457 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700458 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700459 float mLastWallpaperX = -1;
460 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800461 float mLastWallpaperXStep = -1;
462 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700463 // This is set when we are waiting for a wallpaper to tell us it is done
464 // changing its scroll position.
465 WindowState mWaitingOnWallpaper;
466 // The last time we had a timeout when waiting for a wallpaper.
467 long mLastWallpaperTimeoutTime;
468 // We give a wallpaper up to 150ms to finish scrolling.
469 static final long WALLPAPER_TIMEOUT = 150;
470 // Time we wait after a timeout before trying to wait again.
471 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 AppWindowToken mFocusedApp = null;
474
475 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 float mWindowAnimationScale = 1.0f;
478 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700479
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700480 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481
482 // Who is holding the screen on.
483 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700484 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700485
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700486 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 /**
489 * Whether the UI is currently running in touch mode (not showing
490 * navigational focus because the user is directly pressing the screen).
491 */
492 boolean mInTouchMode = false;
493
494 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700495 private ArrayList<WindowChangeListener> mWindowChangeListeners =
496 new ArrayList<WindowChangeListener>();
497 private boolean mWindowsChanged = false;
498
499 public interface WindowChangeListener {
500 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700501 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503
Dianne Hackbornc485a602009-03-24 22:39:49 -0700504 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700505 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700506
507 // The frame use to limit the size of the app running in compatibility mode.
508 Rect mCompatibleScreenFrame = new Rect();
509 // The surface used to fill the outer rim of the app running in compatibility mode.
510 Surface mBackgroundFillerSurface = null;
511 boolean mBackgroundFillerShown = false;
512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 public static WindowManagerService main(Context context,
514 PowerManagerService pm, boolean haveInputMethods) {
515 WMThread thr = new WMThread(context, pm, haveInputMethods);
516 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 synchronized (thr) {
519 while (thr.mService == null) {
520 try {
521 thr.wait();
522 } catch (InterruptedException e) {
523 }
524 }
525 }
Romain Guy06882f82009-06-10 13:36:04 -0700526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 return thr.mService;
528 }
Romain Guy06882f82009-06-10 13:36:04 -0700529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 static class WMThread extends Thread {
531 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 private final Context mContext;
534 private final PowerManagerService mPM;
535 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 public WMThread(Context context, PowerManagerService pm,
538 boolean haveInputMethods) {
539 super("WindowManager");
540 mContext = context;
541 mPM = pm;
542 mHaveInputMethods = haveInputMethods;
543 }
Romain Guy06882f82009-06-10 13:36:04 -0700544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 public void run() {
546 Looper.prepare();
547 WindowManagerService s = new WindowManagerService(mContext, mPM,
548 mHaveInputMethods);
549 android.os.Process.setThreadPriority(
550 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700551 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 synchronized (this) {
554 mService = s;
555 notifyAll();
556 }
Romain Guy06882f82009-06-10 13:36:04 -0700557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 Looper.loop();
559 }
560 }
561
562 static class PolicyThread extends Thread {
563 private final WindowManagerPolicy mPolicy;
564 private final WindowManagerService mService;
565 private final Context mContext;
566 private final PowerManagerService mPM;
567 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 public PolicyThread(WindowManagerPolicy policy,
570 WindowManagerService service, Context context,
571 PowerManagerService pm) {
572 super("WindowManagerPolicy");
573 mPolicy = policy;
574 mService = service;
575 mContext = context;
576 mPM = pm;
577 }
Romain Guy06882f82009-06-10 13:36:04 -0700578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 public void run() {
580 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800581 WindowManagerPolicyThread.set(this, Looper.myLooper());
582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800584 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 android.os.Process.setThreadPriority(
586 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700587 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 synchronized (this) {
591 mRunning = true;
592 notifyAll();
593 }
Romain Guy06882f82009-06-10 13:36:04 -0700594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 Looper.loop();
596 }
597 }
598
599 private WindowManagerService(Context context, PowerManagerService pm,
600 boolean haveInputMethods) {
601 mContext = context;
602 mHaveInputMethods = haveInputMethods;
603 mLimitedAlphaCompositing = context.getResources().getBoolean(
604 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 mPowerManager = pm;
607 mPowerManager.setPolicy(mPolicy);
608 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
609 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
610 "SCREEN_FROZEN");
611 mScreenFrozenLock.setReferenceCounted(false);
612
613 mActivityManager = ActivityManagerNative.getDefault();
614 mBatteryStats = BatteryStatsService.getService();
615
616 // Get persisted window scale setting
617 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
618 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
619 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
620 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700621
Jim Miller284b62e2010-06-08 14:27:42 -0700622 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
623 IntentFilter filter = new IntentFilter();
624 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
625 mContext.registerReceiver(mBroadcastReceiver, filter);
626
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700627 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
628 "KEEP_SCREEN_ON_FLAG");
629 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630
Jeff Browne33348b2010-07-15 23:54:05 -0700631 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
634 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 synchronized (thr) {
637 while (!thr.mRunning) {
638 try {
639 thr.wait();
640 } catch (InterruptedException e) {
641 }
642 }
643 }
Romain Guy06882f82009-06-10 13:36:04 -0700644
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700645 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 // Add ourself to the Watchdog monitors.
648 Watchdog.getInstance().addMonitor(this);
649 }
650
651 @Override
652 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
653 throws RemoteException {
654 try {
655 return super.onTransact(code, data, reply, flags);
656 } catch (RuntimeException e) {
657 // The window manager only throws security exceptions, so let's
658 // log all others.
659 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800660 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 }
662 throw e;
663 }
664 }
665
Jeff Browne33348b2010-07-15 23:54:05 -0700666 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800668 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 TAG, "Adding window " + window + " at "
670 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
671 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700672 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
674
Jeff Browne33348b2010-07-15 23:54:05 -0700675 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800677 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 TAG, "Adding window " + window + " at "
679 + i + " of " + mWindows.size() + " (before " + pos + ")");
680 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700681 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 }
683
684 //This method finds out the index of a window that has the same app token as
685 //win. used for z ordering the windows in mWindows
686 private int findIdxBasedOnAppTokens(WindowState win) {
687 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700688 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 int jmax = localmWindows.size();
690 if(jmax == 0) {
691 return -1;
692 }
693 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700694 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 if(wentry.mAppToken == win.mAppToken) {
696 return j;
697 }
698 }
699 return -1;
700 }
Romain Guy06882f82009-06-10 13:36:04 -0700701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
703 final IWindow client = win.mClient;
704 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700705 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 final int N = localmWindows.size();
708 final WindowState attached = win.mAttachedWindow;
709 int i;
710 if (attached == null) {
711 int tokenWindowsPos = token.windows.size();
712 if (token.appWindowToken != null) {
713 int index = tokenWindowsPos-1;
714 if (index >= 0) {
715 // If this application has existing windows, we
716 // simply place the new window on top of them... but
717 // keep the starting window on top.
718 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
719 // Base windows go behind everything else.
720 placeWindowBefore(token.windows.get(0), win);
721 tokenWindowsPos = 0;
722 } else {
723 AppWindowToken atoken = win.mAppToken;
724 if (atoken != null &&
725 token.windows.get(index) == atoken.startingWindow) {
726 placeWindowBefore(token.windows.get(index), win);
727 tokenWindowsPos--;
728 } else {
729 int newIdx = findIdxBasedOnAppTokens(win);
730 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700731 //there is a window above this one associated with the same
732 //apptoken note that the window could be a floating window
733 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800735 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700736 TAG, "Adding window " + win + " at "
737 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700739 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 }
742 }
743 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800744 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 TAG, "Figuring out where to add app window "
746 + client.asBinder() + " (token=" + token + ")");
747 // Figure out where the window should go, based on the
748 // order of applications.
749 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700750 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 for (i=NA-1; i>=0; i--) {
752 AppWindowToken t = mAppTokens.get(i);
753 if (t == token) {
754 i--;
755 break;
756 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800757
Dianne Hackborna8f60182009-09-01 19:01:50 -0700758 // We haven't reached the token yet; if this token
759 // is not going to the bottom and has windows, we can
760 // use it as an anchor for when we do reach the token.
761 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 pos = t.windows.get(0);
763 }
764 }
765 // We now know the index into the apps. If we found
766 // an app window above, that gives us the position; else
767 // we need to look some more.
768 if (pos != null) {
769 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700770 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 if (atoken != null) {
772 final int NC = atoken.windows.size();
773 if (NC > 0) {
774 WindowState bottom = atoken.windows.get(0);
775 if (bottom.mSubLayer < 0) {
776 pos = bottom;
777 }
778 }
779 }
780 placeWindowBefore(pos, win);
781 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700782 // Continue looking down until we find the first
783 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 while (i >= 0) {
785 AppWindowToken t = mAppTokens.get(i);
786 final int NW = t.windows.size();
787 if (NW > 0) {
788 pos = t.windows.get(NW-1);
789 break;
790 }
791 i--;
792 }
793 if (pos != null) {
794 // Move in front of any windows attached to this
795 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700796 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 if (atoken != null) {
798 final int NC = atoken.windows.size();
799 if (NC > 0) {
800 WindowState top = atoken.windows.get(NC-1);
801 if (top.mSubLayer >= 0) {
802 pos = top;
803 }
804 }
805 }
806 placeWindowAfter(pos, win);
807 } else {
808 // Just search for the start of this layer.
809 final int myLayer = win.mBaseLayer;
810 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700811 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 if (w.mBaseLayer > myLayer) {
813 break;
814 }
815 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800816 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700817 TAG, "Adding window " + win + " at "
818 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700820 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 }
822 }
823 }
824 } else {
825 // Figure out where window should go, based on layer.
826 final int myLayer = win.mBaseLayer;
827 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700828 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 i++;
830 break;
831 }
832 }
833 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800834 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700835 TAG, "Adding window " + win + " at "
836 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700838 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
840 if (addToToken) {
841 token.windows.add(tokenWindowsPos, win);
842 }
843
844 } else {
845 // Figure out this window's ordering relative to the window
846 // it is attached to.
847 final int NA = token.windows.size();
848 final int sublayer = win.mSubLayer;
849 int largestSublayer = Integer.MIN_VALUE;
850 WindowState windowWithLargestSublayer = null;
851 for (i=0; i<NA; i++) {
852 WindowState w = token.windows.get(i);
853 final int wSublayer = w.mSubLayer;
854 if (wSublayer >= largestSublayer) {
855 largestSublayer = wSublayer;
856 windowWithLargestSublayer = w;
857 }
858 if (sublayer < 0) {
859 // For negative sublayers, we go below all windows
860 // in the same sublayer.
861 if (wSublayer >= sublayer) {
862 if (addToToken) {
863 token.windows.add(i, win);
864 }
865 placeWindowBefore(
866 wSublayer >= 0 ? attached : w, win);
867 break;
868 }
869 } else {
870 // For positive sublayers, we go above all windows
871 // in the same sublayer.
872 if (wSublayer > sublayer) {
873 if (addToToken) {
874 token.windows.add(i, win);
875 }
876 placeWindowBefore(w, win);
877 break;
878 }
879 }
880 }
881 if (i >= NA) {
882 if (addToToken) {
883 token.windows.add(win);
884 }
885 if (sublayer < 0) {
886 placeWindowBefore(attached, win);
887 } else {
888 placeWindowAfter(largestSublayer >= 0
889 ? windowWithLargestSublayer
890 : attached,
891 win);
892 }
893 }
894 }
Romain Guy06882f82009-06-10 13:36:04 -0700895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 if (win.mAppToken != null && addToToken) {
897 win.mAppToken.allAppWindows.add(win);
898 }
899 }
Romain Guy06882f82009-06-10 13:36:04 -0700900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 static boolean canBeImeTarget(WindowState w) {
902 final int fl = w.mAttrs.flags
903 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
904 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
905 return w.isVisibleOrAdding();
906 }
907 return false;
908 }
Romain Guy06882f82009-06-10 13:36:04 -0700909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700911 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 final int N = localmWindows.size();
913 WindowState w = null;
914 int i = N;
915 while (i > 0) {
916 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700917 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700918
Joe Onorato8a9b2202010-02-26 18:56:32 -0800919 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 // + Integer.toHexString(w.mAttrs.flags));
921 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800922 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 // Yet more tricksyness! If this window is a "starting"
925 // window, we do actually want to be on top of it, but
926 // it is not -really- where input will go. So if the caller
927 // is not actually looking to move the IME, look down below
928 // for a real window to target...
929 if (!willMove
930 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
931 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700932 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
934 i--;
935 w = wb;
936 }
937 }
938 break;
939 }
940 }
Romain Guy06882f82009-06-10 13:36:04 -0700941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700943
Joe Onorato8a9b2202010-02-26 18:56:32 -0800944 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 if (willMove && w != null) {
948 final WindowState curTarget = mInputMethodTarget;
949 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 // Now some fun for dealing with window animations that
952 // modify the Z order. We need to look at all windows below
953 // the current target that are in this app, finding the highest
954 // visible one in layering.
955 AppWindowToken token = curTarget.mAppToken;
956 WindowState highestTarget = null;
957 int highestPos = 0;
958 if (token.animating || token.animation != null) {
959 int pos = 0;
960 pos = localmWindows.indexOf(curTarget);
961 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700962 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 if (win.mAppToken != token) {
964 break;
965 }
966 if (!win.mRemoved) {
967 if (highestTarget == null || win.mAnimLayer >
968 highestTarget.mAnimLayer) {
969 highestTarget = win;
970 highestPos = pos;
971 }
972 }
973 pos--;
974 }
975 }
Romain Guy06882f82009-06-10 13:36:04 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800978 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 + mNextAppTransition + " " + highestTarget
980 + " animating=" + highestTarget.isAnimating()
981 + " layer=" + highestTarget.mAnimLayer
982 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700983
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700984 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 // If we are currently setting up for an animation,
986 // hold everything until we can find out what will happen.
987 mInputMethodTargetWaitingAnim = true;
988 mInputMethodTarget = highestTarget;
989 return highestPos + 1;
990 } else if (highestTarget.isAnimating() &&
991 highestTarget.mAnimLayer > w.mAnimLayer) {
992 // If the window we are currently targeting is involved
993 // with an animation, and it is on top of the next target
994 // we will be over, then hold off on moving until
995 // that is done.
996 mInputMethodTarget = highestTarget;
997 return highestPos + 1;
998 }
999 }
1000 }
1001 }
Romain Guy06882f82009-06-10 13:36:04 -07001002
Joe Onorato8a9b2202010-02-26 18:56:32 -08001003 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 if (w != null) {
1005 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001006 if (DEBUG_INPUT_METHOD) {
1007 RuntimeException e = null;
1008 if (!HIDE_STACK_CRAWLS) {
1009 e = new RuntimeException();
1010 e.fillInStackTrace();
1011 }
1012 Slog.w(TAG, "Moving IM target from "
1013 + mInputMethodTarget + " to " + w, e);
1014 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 mInputMethodTarget = w;
1016 if (w.mAppToken != null) {
1017 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1018 } else {
1019 setInputMethodAnimLayerAdjustment(0);
1020 }
1021 }
1022 return i+1;
1023 }
1024 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001025 if (DEBUG_INPUT_METHOD) {
1026 RuntimeException e = null;
1027 if (!HIDE_STACK_CRAWLS) {
1028 e = new RuntimeException();
1029 e.fillInStackTrace();
1030 }
1031 Slog.w(TAG, "Moving IM target from "
1032 + mInputMethodTarget + " to null", e);
1033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 mInputMethodTarget = null;
1035 setInputMethodAnimLayerAdjustment(0);
1036 }
1037 return -1;
1038 }
Romain Guy06882f82009-06-10 13:36:04 -07001039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 void addInputMethodWindowToListLocked(WindowState win) {
1041 int pos = findDesiredInputMethodWindowIndexLocked(true);
1042 if (pos >= 0) {
1043 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001044 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001045 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001047 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 moveInputMethodDialogsLocked(pos+1);
1049 return;
1050 }
1051 win.mTargetAppToken = null;
1052 addWindowToListInOrderLocked(win, true);
1053 moveInputMethodDialogsLocked(pos);
1054 }
Romain Guy06882f82009-06-10 13:36:04 -07001055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001057 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 mInputMethodAnimLayerAdjustment = adj;
1059 WindowState imw = mInputMethodWindow;
1060 if (imw != null) {
1061 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001062 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 + " anim layer: " + imw.mAnimLayer);
1064 int wi = imw.mChildWindows.size();
1065 while (wi > 0) {
1066 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001067 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001069 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 + " anim layer: " + cw.mAnimLayer);
1071 }
1072 }
1073 int di = mInputMethodDialogs.size();
1074 while (di > 0) {
1075 di --;
1076 imw = mInputMethodDialogs.get(di);
1077 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001078 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 + " anim layer: " + imw.mAnimLayer);
1080 }
1081 }
Romain Guy06882f82009-06-10 13:36:04 -07001082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1084 int wpos = mWindows.indexOf(win);
1085 if (wpos >= 0) {
1086 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001087 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001089 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 int NC = win.mChildWindows.size();
1091 while (NC > 0) {
1092 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001093 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 int cpos = mWindows.indexOf(cw);
1095 if (cpos >= 0) {
1096 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001098 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 mWindows.remove(cpos);
1100 }
1101 }
1102 }
1103 return interestingPos;
1104 }
Romain Guy06882f82009-06-10 13:36:04 -07001105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 private void reAddWindowToListInOrderLocked(WindowState win) {
1107 addWindowToListInOrderLocked(win, false);
1108 // This is a hack to get all of the child windows added as well
1109 // at the right position. Child windows should be rare and
1110 // this case should be rare, so it shouldn't be that big a deal.
1111 int wpos = mWindows.indexOf(win);
1112 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001113 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001114 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001116 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 reAddWindowLocked(wpos, win);
1118 }
1119 }
Romain Guy06882f82009-06-10 13:36:04 -07001120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 void logWindowList(String prefix) {
1122 int N = mWindows.size();
1123 while (N > 0) {
1124 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001125 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 }
1127 }
Romain Guy06882f82009-06-10 13:36:04 -07001128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 void moveInputMethodDialogsLocked(int pos) {
1130 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001133 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 for (int i=0; i<N; i++) {
1135 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1136 }
1137 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001138 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 logWindowList(" ");
1140 }
Romain Guy06882f82009-06-10 13:36:04 -07001141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 if (pos >= 0) {
1143 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1144 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001145 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 if (wp == mInputMethodWindow) {
1147 pos++;
1148 }
1149 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001150 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 for (int i=0; i<N; i++) {
1152 WindowState win = dialogs.get(i);
1153 win.mTargetAppToken = targetAppToken;
1154 pos = reAddWindowLocked(pos, win);
1155 }
1156 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001157 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 logWindowList(" ");
1159 }
1160 return;
1161 }
1162 for (int i=0; i<N; i++) {
1163 WindowState win = dialogs.get(i);
1164 win.mTargetAppToken = null;
1165 reAddWindowToListInOrderLocked(win);
1166 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001167 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 logWindowList(" ");
1169 }
1170 }
1171 }
Romain Guy06882f82009-06-10 13:36:04 -07001172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1174 final WindowState imWin = mInputMethodWindow;
1175 final int DN = mInputMethodDialogs.size();
1176 if (imWin == null && DN == 0) {
1177 return false;
1178 }
Romain Guy06882f82009-06-10 13:36:04 -07001179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1181 if (imPos >= 0) {
1182 // In this case, the input method windows are to be placed
1183 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 // First check to see if the input method windows are already
1186 // located here, and contiguous.
1187 final int N = mWindows.size();
1188 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001189 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 // Figure out the actual input method window that should be
1192 // at the bottom of their stack.
1193 WindowState baseImWin = imWin != null
1194 ? imWin : mInputMethodDialogs.get(0);
1195 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001196 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 if (cw.mSubLayer < 0) baseImWin = cw;
1198 }
Romain Guy06882f82009-06-10 13:36:04 -07001199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 if (firstImWin == baseImWin) {
1201 // The windows haven't moved... but are they still contiguous?
1202 // First find the top IM window.
1203 int pos = imPos+1;
1204 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001205 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 break;
1207 }
1208 pos++;
1209 }
1210 pos++;
1211 // Now there should be no more input method windows above.
1212 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001213 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 break;
1215 }
1216 pos++;
1217 }
1218 if (pos >= N) {
1219 // All is good!
1220 return false;
1221 }
1222 }
Romain Guy06882f82009-06-10 13:36:04 -07001223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 if (imWin != null) {
1225 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001226 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 logWindowList(" ");
1228 }
1229 imPos = tmpRemoveWindowLocked(imPos, imWin);
1230 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001231 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 logWindowList(" ");
1233 }
1234 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1235 reAddWindowLocked(imPos, imWin);
1236 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001237 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 logWindowList(" ");
1239 }
1240 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1241 } else {
1242 moveInputMethodDialogsLocked(imPos);
1243 }
Romain Guy06882f82009-06-10 13:36:04 -07001244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 } else {
1246 // In this case, the input method windows go in a fixed layer,
1247 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001250 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 tmpRemoveWindowLocked(0, imWin);
1252 imWin.mTargetAppToken = null;
1253 reAddWindowToListInOrderLocked(imWin);
1254 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001255 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 logWindowList(" ");
1257 }
1258 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1259 } else {
1260 moveInputMethodDialogsLocked(-1);;
1261 }
Romain Guy06882f82009-06-10 13:36:04 -07001262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 }
Romain Guy06882f82009-06-10 13:36:04 -07001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 if (needAssignLayers) {
1266 assignLayersLocked();
1267 }
Romain Guy06882f82009-06-10 13:36:04 -07001268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 return true;
1270 }
Romain Guy06882f82009-06-10 13:36:04 -07001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 void adjustInputMethodDialogsLocked() {
1273 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1274 }
Romain Guy06882f82009-06-10 13:36:04 -07001275
Dianne Hackborn25994b42009-09-04 14:21:19 -07001276 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001277 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001278 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1279 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1280 ? wallpaperTarget.mAppToken.animation : null)
1281 + " upper=" + mUpperWallpaperTarget
1282 + " lower=" + mLowerWallpaperTarget);
1283 return (wallpaperTarget != null
1284 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1285 && wallpaperTarget.mAppToken.animation != null)))
1286 || mUpperWallpaperTarget != null
1287 || mLowerWallpaperTarget != null;
1288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001289
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001290 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1291 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001292
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001293 int adjustWallpaperWindowsLocked() {
1294 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001295
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001296 final int dw = mDisplay.getWidth();
1297 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001298
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001299 // First find top-most window that has asked to be on top of the
1300 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001301 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001302 int N = localmWindows.size();
1303 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001304 WindowState foundW = null;
1305 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001306 WindowState topCurW = null;
1307 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001308 int i = N;
1309 while (i > 0) {
1310 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001311 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001312 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1313 if (topCurW == null) {
1314 topCurW = w;
1315 topCurI = i;
1316 }
1317 continue;
1318 }
1319 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001320 if (w.mAppToken != null) {
1321 // If this window's app token is hidden and not animating,
1322 // it is of no interest to us.
1323 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001324 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001325 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001326 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001327 continue;
1328 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001329 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001330 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001331 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1332 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001333 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001334 && (mWallpaperTarget == w
1335 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001336 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001337 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001338 foundW = w;
1339 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001340 if (w == mWallpaperTarget && ((w.mAppToken != null
1341 && w.mAppToken.animation != null)
1342 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001343 // The current wallpaper target is animating, so we'll
1344 // look behind it for another possible target and figure
1345 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001346 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001347 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001348 continue;
1349 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001350 break;
1351 }
1352 }
1353
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001354 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001355 // If we are currently waiting for an app transition, and either
1356 // the current target or the next target are involved with it,
1357 // then hold off on doing anything with the wallpaper.
1358 // Note that we are checking here for just whether the target
1359 // is part of an app token... which is potentially overly aggressive
1360 // (the app token may not be involved in the transition), but good
1361 // enough (we'll just wait until whatever transition is pending
1362 // executes).
1363 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001364 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001365 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001366 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001367 }
1368 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001369 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001370 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001371 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001372 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001373 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001374
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001375 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001376 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001377 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001378 + " oldTarget: " + mWallpaperTarget);
1379 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001380
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 mLowerWallpaperTarget = null;
1382 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001383
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 WindowState oldW = mWallpaperTarget;
1385 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001386
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001387 // Now what is happening... if the current and new targets are
1388 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001389 if (foundW != null && oldW != null) {
1390 boolean oldAnim = oldW.mAnimation != null
1391 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1392 boolean foundAnim = foundW.mAnimation != null
1393 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001394 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001395 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001396 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001399 int oldI = localmWindows.indexOf(oldW);
1400 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001401 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001402 }
1403 if (oldI >= 0) {
1404 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001406 + "=" + oldW + "; new#" + foundI
1407 + "=" + foundW);
1408 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001409
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001410 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001411 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001413 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001414 }
1415 mWallpaperTarget = oldW;
1416 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001417
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001418 // Now set the upper and lower wallpaper targets
1419 // correctly, and make sure that we are positioning
1420 // the wallpaper below the lower.
1421 if (foundI > oldI) {
1422 // The new target is on top of the old one.
1423 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001424 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001425 }
1426 mUpperWallpaperTarget = foundW;
1427 mLowerWallpaperTarget = oldW;
1428 foundW = oldW;
1429 foundI = oldI;
1430 } else {
1431 // The new target is below the old one.
1432 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001434 }
1435 mUpperWallpaperTarget = oldW;
1436 mLowerWallpaperTarget = foundW;
1437 }
1438 }
1439 }
1440 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001441
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001442 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001443 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001444 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1445 || (mLowerWallpaperTarget.mAppToken != null
1446 && mLowerWallpaperTarget.mAppToken.animation != null);
1447 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1448 || (mUpperWallpaperTarget.mAppToken != null
1449 && mUpperWallpaperTarget.mAppToken.animation != null);
1450 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001451 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001452 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001453 }
1454 mLowerWallpaperTarget = null;
1455 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001456 }
1457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001458
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001459 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001460 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001461 // The window is visible to the compositor... but is it visible
1462 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001463 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001464 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001465
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001466 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001467 // its layer adjustment. Only do this if we are not transfering
1468 // between two wallpaper targets.
1469 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001470 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001471 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001472
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001473 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1474 * TYPE_LAYER_MULTIPLIER
1475 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001476
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001477 // Now w is the window we are supposed to be behind... but we
1478 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001479 // AND any starting window associated with it, AND below the
1480 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001481 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001482 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001483 if (wb.mBaseLayer < maxLayer &&
1484 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001485 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001486 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001487 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001488 // This window is not related to the previous one in any
1489 // interesting way, so stop here.
1490 break;
1491 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001492 foundW = wb;
1493 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001494 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001495 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001496 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001497 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001498
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001499 if (foundW == null && topCurW != null) {
1500 // There is no wallpaper target, so it goes at the bottom.
1501 // We will assume it is the same place as last time, if known.
1502 foundW = topCurW;
1503 foundI = topCurI+1;
1504 } else {
1505 // Okay i is the position immediately above the wallpaper. Look at
1506 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001507 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001509
Dianne Hackborn284ac932009-08-28 10:34:25 -07001510 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001511 if (mWallpaperTarget.mWallpaperX >= 0) {
1512 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001513 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001514 }
1515 if (mWallpaperTarget.mWallpaperY >= 0) {
1516 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001517 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001518 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001520
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001521 // Start stepping backwards from here, ensuring that our wallpaper windows
1522 // are correctly placed.
1523 int curTokenIndex = mWallpaperTokens.size();
1524 while (curTokenIndex > 0) {
1525 curTokenIndex--;
1526 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001527 if (token.hidden == visible) {
1528 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1529 token.hidden = !visible;
1530 // Need to do a layout to ensure the wallpaper now has the
1531 // correct size.
1532 mLayoutNeeded = true;
1533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001534
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001535 int curWallpaperIndex = token.windows.size();
1536 while (curWallpaperIndex > 0) {
1537 curWallpaperIndex--;
1538 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001539
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001540 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001541 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001542 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001543
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001544 // First, make sure the client has the current visibility
1545 // state.
1546 if (wallpaper.mWallpaperVisible != visible) {
1547 wallpaper.mWallpaperVisible = visible;
1548 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001549 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001550 "Setting visibility of wallpaper " + wallpaper
1551 + ": " + visible);
1552 wallpaper.mClient.dispatchAppVisibility(visible);
1553 } catch (RemoteException e) {
1554 }
1555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001556
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001557 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001558 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001559 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001560
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001561 // First, if this window is at the current index, then all
1562 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001563 if (wallpaper == foundW) {
1564 foundI--;
1565 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001566 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001567 continue;
1568 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001569
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001570 // The window didn't match... the current wallpaper window,
1571 // wherever it is, is in the wrong place, so make sure it is
1572 // not in the list.
1573 int oldIndex = localmWindows.indexOf(wallpaper);
1574 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001575 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001576 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001577 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001578 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001579 if (oldIndex < foundI) {
1580 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001581 }
1582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001583
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001584 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001585 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001586 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001587 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001588
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001589 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001590 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001591 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001592 }
1593 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001594
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001595 return changed;
1596 }
1597
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001598 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001599 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001600 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001601 mWallpaperAnimLayerAdjustment = adj;
1602 int curTokenIndex = mWallpaperTokens.size();
1603 while (curTokenIndex > 0) {
1604 curTokenIndex--;
1605 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1606 int curWallpaperIndex = token.windows.size();
1607 while (curWallpaperIndex > 0) {
1608 curWallpaperIndex--;
1609 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1610 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001611 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001612 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001613 }
1614 }
1615 }
1616
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001617 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1618 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001619 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001620 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001621 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001622 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1624 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1625 changed = wallpaperWin.mXOffset != offset;
1626 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001627 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001628 + wallpaperWin + " x: " + offset);
1629 wallpaperWin.mXOffset = offset;
1630 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001631 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001632 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001636
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001637 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001638 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001639 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1640 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1641 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001643 + wallpaperWin + " y: " + offset);
1644 changed = true;
1645 wallpaperWin.mYOffset = offset;
1646 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001647 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001648 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001652
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001653 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001654 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001656 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1657 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001659 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001661 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001662 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1663 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001664 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001665 if (mWaitingOnWallpaper != null) {
1666 long start = SystemClock.uptimeMillis();
1667 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1668 < start) {
1669 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001670 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001671 "Waiting for offset complete...");
1672 mWindowMap.wait(WALLPAPER_TIMEOUT);
1673 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001674 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001675 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001676 if ((start+WALLPAPER_TIMEOUT)
1677 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001679 + wallpaperWin);
1680 mLastWallpaperTimeoutTime = start;
1681 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001682 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001683 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001684 }
1685 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001686 } catch (RemoteException e) {
1687 }
1688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001689
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001690 return changed;
1691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001693 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001694 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001695 if (mWaitingOnWallpaper != null &&
1696 mWaitingOnWallpaper.mClient.asBinder() == window) {
1697 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001698 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001699 }
1700 }
1701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001702
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001703 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001704 final int dw = mDisplay.getWidth();
1705 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001707 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001709 WindowState target = mWallpaperTarget;
1710 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001711 if (target.mWallpaperX >= 0) {
1712 mLastWallpaperX = target.mWallpaperX;
1713 } else if (changingTarget.mWallpaperX >= 0) {
1714 mLastWallpaperX = changingTarget.mWallpaperX;
1715 }
1716 if (target.mWallpaperY >= 0) {
1717 mLastWallpaperY = target.mWallpaperY;
1718 } else if (changingTarget.mWallpaperY >= 0) {
1719 mLastWallpaperY = changingTarget.mWallpaperY;
1720 }
1721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001723 int curTokenIndex = mWallpaperTokens.size();
1724 while (curTokenIndex > 0) {
1725 curTokenIndex--;
1726 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1727 int curWallpaperIndex = token.windows.size();
1728 while (curWallpaperIndex > 0) {
1729 curWallpaperIndex--;
1730 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1731 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1732 wallpaper.computeShownFrameLocked();
1733 changed = true;
1734 // We only want to be synchronous with one wallpaper.
1735 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001736 }
1737 }
1738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001740 return changed;
1741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001743 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001744 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 final int dw = mDisplay.getWidth();
1746 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001748 int curTokenIndex = mWallpaperTokens.size();
1749 while (curTokenIndex > 0) {
1750 curTokenIndex--;
1751 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001752 if (token.hidden == visible) {
1753 token.hidden = !visible;
1754 // Need to do a layout to ensure the wallpaper now has the
1755 // correct size.
1756 mLayoutNeeded = true;
1757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001758
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001759 int curWallpaperIndex = token.windows.size();
1760 while (curWallpaperIndex > 0) {
1761 curWallpaperIndex--;
1762 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1763 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001764 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001765 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001766
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 if (wallpaper.mWallpaperVisible != visible) {
1768 wallpaper.mWallpaperVisible = visible;
1769 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001770 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001771 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001772 + ": " + visible);
1773 wallpaper.mClient.dispatchAppVisibility(visible);
1774 } catch (RemoteException e) {
1775 }
1776 }
1777 }
1778 }
1779 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001781 public int addWindow(Session session, IWindow client,
1782 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001783 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001784 int res = mPolicy.checkAddPermission(attrs);
1785 if (res != WindowManagerImpl.ADD_OKAY) {
1786 return res;
1787 }
Romain Guy06882f82009-06-10 13:36:04 -07001788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 boolean reportNewConfig = false;
1790 WindowState attachedWindow = null;
1791 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001792 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001796 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 }
Romain Guy06882f82009-06-10 13:36:04 -07001798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1802 }
1803
1804 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001805 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 + attrs.token + ". Aborting.");
1809 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1810 }
1811 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1812 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 + attrs.token + ". Aborting.");
1815 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1816 }
1817 }
1818
1819 boolean addToken = false;
1820 WindowToken token = mTokenMap.get(attrs.token);
1821 if (token == null) {
1822 if (attrs.type >= FIRST_APPLICATION_WINDOW
1823 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001824 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 + attrs.token + ". Aborting.");
1826 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1827 }
1828 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001829 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 + attrs.token + ". Aborting.");
1831 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1832 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001833 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001834 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001835 + attrs.token + ". Aborting.");
1836 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 token = new WindowToken(attrs.token, -1, false);
1839 addToken = true;
1840 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1841 && attrs.type <= LAST_APPLICATION_WINDOW) {
1842 AppWindowToken atoken = token.appWindowToken;
1843 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001844 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 + token + ". Aborting.");
1846 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1847 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001848 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 + token + ". Aborting.");
1850 return WindowManagerImpl.ADD_APP_EXITING;
1851 }
1852 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1853 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1856 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1857 }
1858 } else if (attrs.type == TYPE_INPUT_METHOD) {
1859 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 + attrs.token + ". Aborting.");
1862 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1863 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001864 } else if (attrs.type == TYPE_WALLPAPER) {
1865 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001866 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001867 + attrs.token + ". Aborting.");
1868 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 }
1871
1872 win = new WindowState(session, client, token,
1873 attachedWindow, attrs, viewVisibility);
1874 if (win.mDeathRecipient == null) {
1875 // Client has apparently died, so there is no reason to
1876 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001877 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 + " that is dead, aborting.");
1879 return WindowManagerImpl.ADD_APP_EXITING;
1880 }
1881
1882 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 res = mPolicy.prepareAddWindowLw(win, attrs);
1885 if (res != WindowManagerImpl.ADD_OKAY) {
1886 return res;
1887 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001888
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001889 if (outInputChannel != null) {
1890 String name = win.makeInputChannelName();
1891 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1892 win.mInputChannel = inputChannels[0];
1893 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1894
1895 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897
1898 // From now on, no exceptions or errors allowed!
1899
1900 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001901
Dianne Hackborn5132b372010-07-29 12:51:35 -07001902 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 if (addToken) {
1905 mTokenMap.put(attrs.token, token);
1906 mTokenList.add(token);
1907 }
1908 win.attach();
1909 mWindowMap.put(client.asBinder(), win);
1910
1911 if (attrs.type == TYPE_APPLICATION_STARTING &&
1912 token.appWindowToken != null) {
1913 token.appWindowToken.startingWindow = win;
1914 }
1915
1916 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 if (attrs.type == TYPE_INPUT_METHOD) {
1919 mInputMethodWindow = win;
1920 addInputMethodWindowToListLocked(win);
1921 imMayMove = false;
1922 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1923 mInputMethodDialogs.add(win);
1924 addWindowToListInOrderLocked(win, true);
1925 adjustInputMethodDialogsLocked();
1926 imMayMove = false;
1927 } else {
1928 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001929 if (attrs.type == TYPE_WALLPAPER) {
1930 mLastWallpaperTimeoutTime = 0;
1931 adjustWallpaperWindowsLocked();
1932 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001933 adjustWallpaperWindowsLocked();
1934 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 }
Romain Guy06882f82009-06-10 13:36:04 -07001936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 if (mInTouchMode) {
1942 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1943 }
1944 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1945 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1946 }
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001948 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001950 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1951 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 imMayMove = false;
1953 }
1954 }
Romain Guy06882f82009-06-10 13:36:04 -07001955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001957 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 }
Romain Guy06882f82009-06-10 13:36:04 -07001959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 assignLayersLocked();
1961 // Don't do layout here, the window must call
1962 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 //dump();
1965
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001966 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001967 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001968 }
Jeff Brown349703e2010-06-22 01:27:15 -07001969
Joe Onorato8a9b2202010-02-26 18:56:32 -08001970 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 TAG, "New client " + client.asBinder()
1972 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001973
1974 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1975 reportNewConfig = true;
1976 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 }
1978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 if (reportNewConfig) {
1980 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07001982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 return res;
1986 }
Romain Guy06882f82009-06-10 13:36:04 -07001987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 public void removeWindow(Session session, IWindow client) {
1989 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001990 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001991 if (win == null) {
1992 return;
1993 }
1994 removeWindowLocked(session, win);
1995 }
1996 }
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 public void removeWindowLocked(Session session, WindowState win) {
1999
Joe Onorato8a9b2202010-02-26 18:56:32 -08002000 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 TAG, "Remove " + win + " client="
2002 + Integer.toHexString(System.identityHashCode(
2003 win.mClient.asBinder()))
2004 + ", surface=" + win.mSurface);
2005
2006 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002007
2008 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002009
Joe Onorato8a9b2202010-02-26 18:56:32 -08002010 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2012 + " mExiting=" + win.mExiting
2013 + " isAnimating=" + win.isAnimating()
2014 + " app-animation="
2015 + (win.mAppToken != null ? win.mAppToken.animation : null)
2016 + " inPendingTransaction="
2017 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2018 + " mDisplayFrozen=" + mDisplayFrozen);
2019 // Visibility of the removed window. Will be used later to update orientation later on.
2020 boolean wasVisible = false;
2021 // First, see if we need to run an animation. If we do, we have
2022 // to hold off on removing the window until the animation is done.
2023 // If the display is frozen, just remove immediately, since the
2024 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002025 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 // If we are not currently running the exit animation, we
2027 // need to see about starting one.
2028 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2031 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2032 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2033 }
2034 // Try starting an animation.
2035 if (applyAnimationLocked(win, transit, false)) {
2036 win.mExiting = true;
2037 }
2038 }
2039 if (win.mExiting || win.isAnimating()) {
2040 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002041 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 win.mExiting = true;
2043 win.mRemoveOnExit = true;
2044 mLayoutNeeded = true;
2045 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2046 performLayoutAndPlaceSurfacesLocked();
2047 if (win.mAppToken != null) {
2048 win.mAppToken.updateReportedVisibilityLocked();
2049 }
2050 //dump();
2051 Binder.restoreCallingIdentity(origId);
2052 return;
2053 }
2054 }
2055
2056 removeWindowInnerLocked(session, win);
2057 // Removing a visible window will effect the computed orientation
2058 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002059 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002060 != mForcedAppOrientation
2061 && updateOrientationFromAppTokensLocked()) {
2062 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 }
2064 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2065 Binder.restoreCallingIdentity(origId);
2066 }
Romain Guy06882f82009-06-10 13:36:04 -07002067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 if (mInputMethodTarget == win) {
2072 moveInputMethodWindowsIfNeededLocked(false);
2073 }
Romain Guy06882f82009-06-10 13:36:04 -07002074
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002075 if (false) {
2076 RuntimeException e = new RuntimeException("here");
2077 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002078 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002079 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 mPolicy.removeWindowLw(win);
2082 win.removeLocked();
2083
2084 mWindowMap.remove(win.mClient.asBinder());
2085 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002086 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002087 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088
2089 if (mInputMethodWindow == win) {
2090 mInputMethodWindow = null;
2091 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2092 mInputMethodDialogs.remove(win);
2093 }
Romain Guy06882f82009-06-10 13:36:04 -07002094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 final WindowToken token = win.mToken;
2096 final AppWindowToken atoken = win.mAppToken;
2097 token.windows.remove(win);
2098 if (atoken != null) {
2099 atoken.allAppWindows.remove(win);
2100 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002101 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 TAG, "**** Removing window " + win + ": count="
2103 + token.windows.size());
2104 if (token.windows.size() == 0) {
2105 if (!token.explicit) {
2106 mTokenMap.remove(token.token);
2107 mTokenList.remove(token);
2108 } else if (atoken != null) {
2109 atoken.firstWindowDrawn = false;
2110 }
2111 }
2112
2113 if (atoken != null) {
2114 if (atoken.startingWindow == win) {
2115 atoken.startingWindow = null;
2116 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2117 // If this is the last window and we had requested a starting
2118 // transition window, well there is no point now.
2119 atoken.startingData = null;
2120 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2121 // If this is the last window except for a starting transition
2122 // window, we need to get rid of the starting transition.
2123 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002124 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 + ": no more real windows");
2126 }
2127 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2128 mH.sendMessage(m);
2129 }
2130 }
Romain Guy06882f82009-06-10 13:36:04 -07002131
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002132 if (win.mAttrs.type == TYPE_WALLPAPER) {
2133 mLastWallpaperTimeoutTime = 0;
2134 adjustWallpaperWindowsLocked();
2135 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002136 adjustWallpaperWindowsLocked();
2137 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 if (!mInLayout) {
2140 assignLayersLocked();
2141 mLayoutNeeded = true;
2142 performLayoutAndPlaceSurfacesLocked();
2143 if (win.mAppToken != null) {
2144 win.mAppToken.updateReportedVisibilityLocked();
2145 }
2146 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002147
2148 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 }
2150
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002151 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2152 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2153 + ": " + msg + " / " + w.mAttrs.getTitle();
2154 if (where != null) {
2155 Slog.i(TAG, str, where);
2156 } else {
2157 Slog.i(TAG, str);
2158 }
2159 }
2160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2162 long origId = Binder.clearCallingIdentity();
2163 try {
2164 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002165 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002167 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002168 Surface.openTransaction();
2169 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002170 if (SHOW_TRANSACTIONS) logSurface(w,
2171 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 w.mSurface.setTransparentRegionHint(region);
2173 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002174 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 Surface.closeTransaction();
2176 }
2177 }
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(origId);
2181 }
2182 }
2183
2184 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002185 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 Rect visibleInsets) {
2187 long origId = Binder.clearCallingIdentity();
2188 try {
2189 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002190 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 if (w != null) {
2192 w.mGivenInsetsPending = false;
2193 w.mGivenContentInsets.set(contentInsets);
2194 w.mGivenVisibleInsets.set(visibleInsets);
2195 w.mTouchableInsets = touchableInsets;
2196 mLayoutNeeded = true;
2197 performLayoutAndPlaceSurfacesLocked();
2198 }
2199 }
2200 } finally {
2201 Binder.restoreCallingIdentity(origId);
2202 }
2203 }
Romain Guy06882f82009-06-10 13:36:04 -07002204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 public void getWindowDisplayFrame(Session session, IWindow client,
2206 Rect outDisplayFrame) {
2207 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002208 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 if (win == null) {
2210 outDisplayFrame.setEmpty();
2211 return;
2212 }
2213 outDisplayFrame.set(win.mDisplayFrame);
2214 }
2215 }
2216
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002217 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2218 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002219 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2220 window.mWallpaperX = x;
2221 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002222 window.mWallpaperXStep = xStep;
2223 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002224 if (updateWallpaperOffsetLocked(window, true)) {
2225 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002226 }
2227 }
2228 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002229
Dianne Hackborn75804932009-10-20 20:15:20 -07002230 void wallpaperCommandComplete(IBinder window, Bundle result) {
2231 synchronized (mWindowMap) {
2232 if (mWaitingOnWallpaper != null &&
2233 mWaitingOnWallpaper.mClient.asBinder() == window) {
2234 mWaitingOnWallpaper = null;
2235 mWindowMap.notifyAll();
2236 }
2237 }
2238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002239
Dianne Hackborn75804932009-10-20 20:15:20 -07002240 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2241 String action, int x, int y, int z, Bundle extras, boolean sync) {
2242 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2243 || window == mUpperWallpaperTarget) {
2244 boolean doWait = sync;
2245 int curTokenIndex = mWallpaperTokens.size();
2246 while (curTokenIndex > 0) {
2247 curTokenIndex--;
2248 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2249 int curWallpaperIndex = token.windows.size();
2250 while (curWallpaperIndex > 0) {
2251 curWallpaperIndex--;
2252 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2253 try {
2254 wallpaper.mClient.dispatchWallpaperCommand(action,
2255 x, y, z, extras, sync);
2256 // We only want to be synchronous with one wallpaper.
2257 sync = false;
2258 } catch (RemoteException e) {
2259 }
2260 }
2261 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002262
Dianne Hackborn75804932009-10-20 20:15:20 -07002263 if (doWait) {
2264 // XXX Need to wait for result.
2265 }
2266 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002267
Dianne Hackborn75804932009-10-20 20:15:20 -07002268 return null;
2269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 public int relayoutWindow(Session session, IWindow client,
2272 WindowManager.LayoutParams attrs, int requestedWidth,
2273 int requestedHeight, int viewVisibility, boolean insetsPending,
2274 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002275 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 boolean displayed = false;
2277 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002278 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002282 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 if (win == null) {
2284 return 0;
2285 }
2286 win.mRequestedWidth = requestedWidth;
2287 win.mRequestedHeight = requestedHeight;
2288
2289 if (attrs != null) {
2290 mPolicy.adjustWindowParamsLw(attrs);
2291 }
Romain Guy06882f82009-06-10 13:36:04 -07002292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 int attrChanges = 0;
2294 int flagChanges = 0;
2295 if (attrs != null) {
2296 flagChanges = win.mAttrs.flags ^= attrs.flags;
2297 attrChanges = win.mAttrs.copyFrom(attrs);
2298 }
2299
Joe Onorato8a9b2202010-02-26 18:56:32 -08002300 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301
2302 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2303 win.mAlpha = attrs.alpha;
2304 }
2305
2306 final boolean scaledWindow =
2307 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2308
2309 if (scaledWindow) {
2310 // requested{Width|Height} Surface's physical size
2311 // attrs.{width|height} Size on screen
2312 win.mHScale = (attrs.width != requestedWidth) ?
2313 (attrs.width / (float)requestedWidth) : 1.0f;
2314 win.mVScale = (attrs.height != requestedHeight) ?
2315 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002316 } else {
2317 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 }
2319
2320 boolean imMayMove = (flagChanges&(
2321 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2322 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 boolean focusMayChange = win.mViewVisibility != viewVisibility
2325 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2326 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002327
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002328 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2329 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 win.mRelayoutCalled = true;
2332 final int oldVisibility = win.mViewVisibility;
2333 win.mViewVisibility = viewVisibility;
2334 if (viewVisibility == View.VISIBLE &&
2335 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2336 displayed = !win.isVisibleLw();
2337 if (win.mExiting) {
2338 win.mExiting = false;
2339 win.mAnimation = null;
2340 }
2341 if (win.mDestroying) {
2342 win.mDestroying = false;
2343 mDestroySurface.remove(win);
2344 }
2345 if (oldVisibility == View.GONE) {
2346 win.mEnterAnimationPending = true;
2347 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002348 if (displayed) {
2349 if (win.mSurface != null && !win.mDrawPending
2350 && !win.mCommitDrawPending && !mDisplayFrozen
2351 && mPolicy.isScreenOn()) {
2352 applyEnterAnimationLocked(win);
2353 }
2354 if ((win.mAttrs.flags
2355 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2356 if (DEBUG_VISIBILITY) Slog.v(TAG,
2357 "Relayout window turning screen on: " + win);
2358 win.mTurnOnScreen = true;
2359 }
2360 int diff = 0;
2361 if (win.mConfiguration != mCurConfiguration
2362 && (win.mConfiguration == null
2363 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2364 win.mConfiguration = mCurConfiguration;
2365 if (DEBUG_CONFIGURATION) {
2366 Slog.i(TAG, "Window " + win + " visible with new config: "
2367 + win.mConfiguration + " / 0x"
2368 + Integer.toHexString(diff));
2369 }
2370 outConfig.setTo(mCurConfiguration);
2371 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002372 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2374 // To change the format, we need to re-build the surface.
2375 win.destroySurfaceLocked();
2376 displayed = true;
2377 }
2378 try {
2379 Surface surface = win.createSurfaceLocked();
2380 if (surface != null) {
2381 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002382 win.mReportDestroySurface = false;
2383 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002384 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002385 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002387 // For some reason there isn't a surface. Clear the
2388 // caller's object so they see the same state.
2389 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 }
2391 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002392 mInputMonitor.updateInputWindowsLw();
2393
Joe Onorato8a9b2202010-02-26 18:56:32 -08002394 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002395 + client + " (" + win.mAttrs.getTitle() + ")",
2396 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 Binder.restoreCallingIdentity(origId);
2398 return 0;
2399 }
2400 if (displayed) {
2401 focusMayChange = true;
2402 }
2403 if (win.mAttrs.type == TYPE_INPUT_METHOD
2404 && mInputMethodWindow == null) {
2405 mInputMethodWindow = win;
2406 imMayMove = true;
2407 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002408 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2409 && win.mAppToken != null
2410 && win.mAppToken.startingWindow != null) {
2411 // Special handling of starting window over the base
2412 // window of the app: propagate lock screen flags to it,
2413 // to provide the correct semantics while starting.
2414 final int mask =
2415 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002416 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2417 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002418 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2419 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2420 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 } else {
2422 win.mEnterAnimationPending = false;
2423 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002424 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002425 + ": mExiting=" + win.mExiting
2426 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 // If we are not currently running the exit animation, we
2428 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002429 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 // Try starting an animation; if there isn't one, we
2431 // can destroy the surface right away.
2432 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2433 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2434 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2435 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002436 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002438 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 } else if (win.isAnimating()) {
2441 // Currently in a hide animation... turn this into
2442 // an exit.
2443 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002444 } else if (win == mWallpaperTarget) {
2445 // If the wallpaper is currently behind this
2446 // window, we need to change both of them inside
2447 // of a transaction to avoid artifacts.
2448 win.mExiting = true;
2449 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 } else {
2451 if (mInputMethodWindow == win) {
2452 mInputMethodWindow = null;
2453 }
2454 win.destroySurfaceLocked();
2455 }
2456 }
2457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002458
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002459 if (win.mSurface == null || (win.getAttrs().flags
2460 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2461 || win.mSurfacePendingDestroy) {
2462 // We are being called from a local process, which
2463 // means outSurface holds its current surface. Ensure the
2464 // surface object is cleared, but we don't want it actually
2465 // destroyed at this point.
2466 win.mSurfacePendingDestroy = false;
2467 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002468 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002469 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002470 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002471 "Keeping surface, will report destroy: " + win);
2472 win.mReportDestroySurface = true;
2473 outSurface.copyFrom(win.mSurface);
2474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 }
2476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 if (focusMayChange) {
2478 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2479 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 imMayMove = false;
2481 }
2482 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2483 }
Romain Guy06882f82009-06-10 13:36:04 -07002484
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002485 // updateFocusedWindowLocked() already assigned layers so we only need to
2486 // reassign them at this point if the IM window state gets shuffled
2487 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002490 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2491 // Little hack here -- we -should- be able to rely on the
2492 // function to return true if the IME has moved and needs
2493 // its layer recomputed. However, if the IME was hidden
2494 // and isn't actually moved in the list, its layer may be
2495 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 assignLayers = true;
2497 }
2498 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002499 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002500 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002501 assignLayers = true;
2502 }
2503 }
Romain Guy06882f82009-06-10 13:36:04 -07002504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 mLayoutNeeded = true;
2506 win.mGivenInsetsPending = insetsPending;
2507 if (assignLayers) {
2508 assignLayersLocked();
2509 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002510 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002512 if (displayed && win.mIsWallpaper) {
2513 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002514 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 if (win.mAppToken != null) {
2517 win.mAppToken.updateReportedVisibilityLocked();
2518 }
2519 outFrame.set(win.mFrame);
2520 outContentInsets.set(win.mContentInsets);
2521 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002522 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002524 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 + ", requestedHeight=" + requestedHeight
2526 + ", viewVisibility=" + viewVisibility
2527 + "\nRelayout returning frame=" + outFrame
2528 + ", surface=" + outSurface);
2529
Joe Onorato8a9b2202010-02-26 18:56:32 -08002530 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2532
2533 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002534
2535 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 }
2537
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002538 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 sendNewConfiguration();
2540 }
Romain Guy06882f82009-06-10 13:36:04 -07002541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2545 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2546 }
2547
2548 public void finishDrawingWindow(Session session, IWindow client) {
2549 final long origId = Binder.clearCallingIdentity();
2550 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002551 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002553 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2554 adjustWallpaperWindowsLocked();
2555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 mLayoutNeeded = true;
2557 performLayoutAndPlaceSurfacesLocked();
2558 }
2559 }
2560 Binder.restoreCallingIdentity(origId);
2561 }
2562
2563 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002564 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 + (lp != null ? lp.packageName : null)
2566 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2567 if (lp != null && lp.windowAnimations != 0) {
2568 // If this is a system resource, don't try to load it from the
2569 // application resources. It is nice to avoid loading application
2570 // resources if we can.
2571 String packageName = lp.packageName != null ? lp.packageName : "android";
2572 int resId = lp.windowAnimations;
2573 if ((resId&0xFF000000) == 0x01000000) {
2574 packageName = "android";
2575 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002576 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 + packageName);
2578 return AttributeCache.instance().get(packageName, resId,
2579 com.android.internal.R.styleable.WindowAnimation);
2580 }
2581 return null;
2582 }
Romain Guy06882f82009-06-10 13:36:04 -07002583
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002584 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002585 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002586 + packageName + " resId=0x" + Integer.toHexString(resId));
2587 if (packageName != null) {
2588 if ((resId&0xFF000000) == 0x01000000) {
2589 packageName = "android";
2590 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002591 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002592 + packageName);
2593 return AttributeCache.instance().get(packageName, resId,
2594 com.android.internal.R.styleable.WindowAnimation);
2595 }
2596 return null;
2597 }
2598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 private void applyEnterAnimationLocked(WindowState win) {
2600 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2601 if (win.mEnterAnimationPending) {
2602 win.mEnterAnimationPending = false;
2603 transit = WindowManagerPolicy.TRANSIT_ENTER;
2604 }
2605
2606 applyAnimationLocked(win, transit, true);
2607 }
2608
2609 private boolean applyAnimationLocked(WindowState win,
2610 int transit, boolean isEntrance) {
2611 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2612 // If we are trying to apply an animation, but already running
2613 // an animation of the same type, then just leave that one alone.
2614 return true;
2615 }
Romain Guy06882f82009-06-10 13:36:04 -07002616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 // Only apply an animation if the display isn't frozen. If it is
2618 // frozen, there is no reason to animate and it can cause strange
2619 // artifacts when we unfreeze the display if some different animation
2620 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002621 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 int anim = mPolicy.selectAnimationLw(win, transit);
2623 int attr = -1;
2624 Animation a = null;
2625 if (anim != 0) {
2626 a = AnimationUtils.loadAnimation(mContext, anim);
2627 } else {
2628 switch (transit) {
2629 case WindowManagerPolicy.TRANSIT_ENTER:
2630 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2631 break;
2632 case WindowManagerPolicy.TRANSIT_EXIT:
2633 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2634 break;
2635 case WindowManagerPolicy.TRANSIT_SHOW:
2636 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2637 break;
2638 case WindowManagerPolicy.TRANSIT_HIDE:
2639 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2640 break;
2641 }
2642 if (attr >= 0) {
2643 a = loadAnimation(win.mAttrs, attr);
2644 }
2645 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002646 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2648 + " mAnimation=" + win.mAnimation
2649 + " isEntrance=" + isEntrance);
2650 if (a != null) {
2651 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002652 RuntimeException e = null;
2653 if (!HIDE_STACK_CRAWLS) {
2654 e = new RuntimeException();
2655 e.fillInStackTrace();
2656 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002657 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 }
2659 win.setAnimation(a);
2660 win.mAnimationIsEntrance = isEntrance;
2661 }
2662 } else {
2663 win.clearAnimation();
2664 }
2665
2666 return win.mAnimation != null;
2667 }
2668
2669 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2670 int anim = 0;
2671 Context context = mContext;
2672 if (animAttr >= 0) {
2673 AttributeCache.Entry ent = getCachedAnimations(lp);
2674 if (ent != null) {
2675 context = ent.context;
2676 anim = ent.array.getResourceId(animAttr, 0);
2677 }
2678 }
2679 if (anim != 0) {
2680 return AnimationUtils.loadAnimation(context, anim);
2681 }
2682 return null;
2683 }
Romain Guy06882f82009-06-10 13:36:04 -07002684
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002685 private Animation loadAnimation(String packageName, int resId) {
2686 int anim = 0;
2687 Context context = mContext;
2688 if (resId >= 0) {
2689 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2690 if (ent != null) {
2691 context = ent.context;
2692 anim = resId;
2693 }
2694 }
2695 if (anim != 0) {
2696 return AnimationUtils.loadAnimation(context, anim);
2697 }
2698 return null;
2699 }
2700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 private boolean applyAnimationLocked(AppWindowToken wtoken,
2702 WindowManager.LayoutParams lp, int transit, boolean enter) {
2703 // Only apply an animation if the display isn't frozen. If it is
2704 // frozen, there is no reason to animate and it can cause strange
2705 // artifacts when we unfreeze the display if some different animation
2706 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002707 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002708 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002709 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002710 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002711 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002712 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002713 } else if (mNextAppTransitionPackage != null) {
2714 a = loadAnimation(mNextAppTransitionPackage, enter ?
2715 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002716 } else {
2717 int animAttr = 0;
2718 switch (transit) {
2719 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2720 animAttr = enter
2721 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2722 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2723 break;
2724 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2725 animAttr = enter
2726 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2727 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2728 break;
2729 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2730 animAttr = enter
2731 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2732 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2733 break;
2734 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2735 animAttr = enter
2736 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2737 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2738 break;
2739 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2740 animAttr = enter
2741 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2742 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2743 break;
2744 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2745 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002746 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002747 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2748 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002749 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002750 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002751 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2752 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002753 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002754 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002755 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002756 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2757 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2758 break;
2759 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2760 animAttr = enter
2761 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2762 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2763 break;
2764 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2765 animAttr = enter
2766 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2767 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002768 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002769 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002770 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002771 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002772 + " anim=" + a
2773 + " animAttr=0x" + Integer.toHexString(animAttr)
2774 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 if (a != null) {
2777 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002778 RuntimeException e = null;
2779 if (!HIDE_STACK_CRAWLS) {
2780 e = new RuntimeException();
2781 e.fillInStackTrace();
2782 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002783 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 }
2785 wtoken.setAnimation(a);
2786 }
2787 } else {
2788 wtoken.clearAnimation();
2789 }
2790
2791 return wtoken.animation != null;
2792 }
2793
2794 // -------------------------------------------------------------
2795 // Application Window Tokens
2796 // -------------------------------------------------------------
2797
2798 public void validateAppTokens(List tokens) {
2799 int v = tokens.size()-1;
2800 int m = mAppTokens.size()-1;
2801 while (v >= 0 && m >= 0) {
2802 AppWindowToken wtoken = mAppTokens.get(m);
2803 if (wtoken.removed) {
2804 m--;
2805 continue;
2806 }
2807 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002808 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2810 }
2811 v--;
2812 m--;
2813 }
2814 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002815 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 v--;
2817 }
2818 while (m >= 0) {
2819 AppWindowToken wtoken = mAppTokens.get(m);
2820 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002821 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 }
2823 m--;
2824 }
2825 }
2826
2827 boolean checkCallingPermission(String permission, String func) {
2828 // Quick check: if the calling permission is me, it's all okay.
2829 if (Binder.getCallingPid() == Process.myPid()) {
2830 return true;
2831 }
Romain Guy06882f82009-06-10 13:36:04 -07002832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 if (mContext.checkCallingPermission(permission)
2834 == PackageManager.PERMISSION_GRANTED) {
2835 return true;
2836 }
2837 String msg = "Permission Denial: " + func + " from pid="
2838 + Binder.getCallingPid()
2839 + ", uid=" + Binder.getCallingUid()
2840 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002841 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 return false;
2843 }
Romain Guy06882f82009-06-10 13:36:04 -07002844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 AppWindowToken findAppWindowToken(IBinder token) {
2846 WindowToken wtoken = mTokenMap.get(token);
2847 if (wtoken == null) {
2848 return null;
2849 }
2850 return wtoken.appWindowToken;
2851 }
Romain Guy06882f82009-06-10 13:36:04 -07002852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 public void addWindowToken(IBinder token, int type) {
2854 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2855 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002856 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 }
Romain Guy06882f82009-06-10 13:36:04 -07002858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 synchronized(mWindowMap) {
2860 WindowToken wtoken = mTokenMap.get(token);
2861 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002862 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 return;
2864 }
2865 wtoken = new WindowToken(token, type, true);
2866 mTokenMap.put(token, wtoken);
2867 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002868 if (type == TYPE_WALLPAPER) {
2869 mWallpaperTokens.add(wtoken);
2870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 }
2872 }
Romain Guy06882f82009-06-10 13:36:04 -07002873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 public void removeWindowToken(IBinder token) {
2875 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2876 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002877 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 }
2879
2880 final long origId = Binder.clearCallingIdentity();
2881 synchronized(mWindowMap) {
2882 WindowToken wtoken = mTokenMap.remove(token);
2883 mTokenList.remove(wtoken);
2884 if (wtoken != null) {
2885 boolean delayed = false;
2886 if (!wtoken.hidden) {
2887 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 final int N = wtoken.windows.size();
2890 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 for (int i=0; i<N; i++) {
2893 WindowState win = wtoken.windows.get(i);
2894
2895 if (win.isAnimating()) {
2896 delayed = true;
2897 }
Romain Guy06882f82009-06-10 13:36:04 -07002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 if (win.isVisibleNow()) {
2900 applyAnimationLocked(win,
2901 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 changed = true;
2903 }
2904 }
2905
2906 if (changed) {
2907 mLayoutNeeded = true;
2908 performLayoutAndPlaceSurfacesLocked();
2909 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2910 }
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 if (delayed) {
2913 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002914 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2915 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 }
2917 }
Romain Guy06882f82009-06-10 13:36:04 -07002918
Jeff Brownc5ed5912010-07-14 18:48:53 -07002919 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002921 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 }
2923 }
2924 Binder.restoreCallingIdentity(origId);
2925 }
2926
2927 public void addAppToken(int addPos, IApplicationToken token,
2928 int groupId, int requestedOrientation, boolean fullscreen) {
2929 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2930 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002931 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
Jeff Brown349703e2010-06-22 01:27:15 -07002933
2934 // Get the dispatching timeout here while we are not holding any locks so that it
2935 // can be cached by the AppWindowToken. The timeout value is used later by the
2936 // input dispatcher in code that does hold locks. If we did not cache the value
2937 // here we would run the chance of introducing a deadlock between the window manager
2938 // (which holds locks while updating the input dispatcher state) and the activity manager
2939 // (which holds locks while querying the application token).
2940 long inputDispatchingTimeoutNanos;
2941 try {
2942 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2943 } catch (RemoteException ex) {
2944 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2945 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2946 }
Romain Guy06882f82009-06-10 13:36:04 -07002947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 synchronized(mWindowMap) {
2949 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2950 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002951 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 return;
2953 }
2954 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002955 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 wtoken.groupId = groupId;
2957 wtoken.appFullscreen = fullscreen;
2958 wtoken.requestedOrientation = requestedOrientation;
2959 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002960 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 mTokenMap.put(token.asBinder(), wtoken);
2962 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 // Application tokens start out hidden.
2965 wtoken.hidden = true;
2966 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 //dump();
2969 }
2970 }
Romain Guy06882f82009-06-10 13:36:04 -07002971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 public void setAppGroupId(IBinder token, int groupId) {
2973 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2974 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002975 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 }
2977
2978 synchronized(mWindowMap) {
2979 AppWindowToken wtoken = findAppWindowToken(token);
2980 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002981 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 return;
2983 }
2984 wtoken.groupId = groupId;
2985 }
2986 }
Romain Guy06882f82009-06-10 13:36:04 -07002987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 public int getOrientationFromWindowsLocked() {
2989 int pos = mWindows.size() - 1;
2990 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07002991 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 pos--;
2993 if (wtoken.mAppToken != null) {
2994 // We hit an application window. so the orientation will be determined by the
2995 // app window. No point in continuing further.
2996 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2997 }
Christopher Tateb696aee2010-04-02 19:08:30 -07002998 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 continue;
3000 }
3001 int req = wtoken.mAttrs.screenOrientation;
3002 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3003 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3004 continue;
3005 } else {
3006 return req;
3007 }
3008 }
3009 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3010 }
Romain Guy06882f82009-06-10 13:36:04 -07003011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003013 int pos = mAppTokens.size() - 1;
3014 int curGroup = 0;
3015 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3016 boolean findingBehind = false;
3017 boolean haveGroup = false;
3018 boolean lastFullscreen = false;
3019 while (pos >= 0) {
3020 AppWindowToken wtoken = mAppTokens.get(pos);
3021 pos--;
3022 // if we're about to tear down this window and not seek for
3023 // the behind activity, don't use it for orientation
3024 if (!findingBehind
3025 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3026 continue;
3027 }
3028
3029 if (!haveGroup) {
3030 // We ignore any hidden applications on the top.
3031 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003032 continue;
3033 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003034 haveGroup = true;
3035 curGroup = wtoken.groupId;
3036 lastOrientation = wtoken.requestedOrientation;
3037 } else if (curGroup != wtoken.groupId) {
3038 // If we have hit a new application group, and the bottom
3039 // of the previous group didn't explicitly say to use
3040 // the orientation behind it, and the last app was
3041 // full screen, then we'll stick with the
3042 // user's orientation.
3043 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3044 && lastFullscreen) {
3045 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003048 int or = wtoken.requestedOrientation;
3049 // If this application is fullscreen, and didn't explicitly say
3050 // to use the orientation behind it, then just take whatever
3051 // orientation it has and ignores whatever is under it.
3052 lastFullscreen = wtoken.appFullscreen;
3053 if (lastFullscreen
3054 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3055 return or;
3056 }
3057 // If this application has requested an explicit orientation,
3058 // then use it.
3059 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3060 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3061 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3062 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3063 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3064 return or;
3065 }
3066 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3067 }
3068 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069 }
Romain Guy06882f82009-06-10 13:36:04 -07003070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003071 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003072 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003073 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3074 "updateOrientationFromAppTokens()")) {
3075 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3076 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003077
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003078 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003080
3081 synchronized(mWindowMap) {
3082 if (updateOrientationFromAppTokensLocked()) {
3083 if (freezeThisOneIfNeeded != null) {
3084 AppWindowToken wtoken = findAppWindowToken(
3085 freezeThisOneIfNeeded);
3086 if (wtoken != null) {
3087 startAppFreezingScreenLocked(wtoken,
3088 ActivityInfo.CONFIG_ORIENTATION);
3089 }
3090 }
3091 config = computeNewConfigurationLocked();
3092
3093 } else if (currentConfig != null) {
3094 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003095 // state mismatches the activity manager's, update it,
3096 // disregarding font scale, which should remain set to
3097 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003098 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003099 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003100 if (computeNewConfigurationLocked(mTempConfiguration)) {
3101 if (currentConfig.diff(mTempConfiguration) != 0) {
3102 mWaitingForConfig = true;
3103 mLayoutNeeded = true;
3104 startFreezingDisplayLocked();
3105 config = new Configuration(mTempConfiguration);
3106 }
3107 }
3108 }
3109 }
3110
Dianne Hackborncfaef692009-06-15 14:24:44 -07003111 Binder.restoreCallingIdentity(ident);
3112 return config;
3113 }
3114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003116 * Determine the new desired orientation of the display, returning
3117 * a non-null new Configuration if it has changed from the current
3118 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3119 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3120 * SCREEN. This will typically be done for you if you call
3121 * sendNewConfiguration().
3122 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 * The orientation is computed from non-application windows first. If none of
3124 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003125 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3127 * android.os.IBinder)
3128 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003129 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003130 if (mDisplayFrozen) {
3131 // If the display is frozen, some activities may be in the middle
3132 // of restarting, and thus have removed their old window. If the
3133 // window has the flag to hide the lock screen, then the lock screen
3134 // can re-appear and inflict its own orientation on us. Keep the
3135 // orientation stable until this all settles down.
3136 return false;
3137 }
3138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 long ident = Binder.clearCallingIdentity();
3141 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003142 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 mForcedAppOrientation = req;
3146 //send a message to Policy indicating orientation change to take
3147 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003148 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003149 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3150 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3151 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 }
3153 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003154
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003155 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 } finally {
3157 Binder.restoreCallingIdentity(ident);
3158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 }
Romain Guy06882f82009-06-10 13:36:04 -07003160
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003161 int computeForcedAppOrientationLocked() {
3162 int req = getOrientationFromWindowsLocked();
3163 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3164 req = getOrientationFromAppTokensLocked();
3165 }
3166 return req;
3167 }
Romain Guy06882f82009-06-10 13:36:04 -07003168
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003169 public void setNewConfiguration(Configuration config) {
3170 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3171 "setNewConfiguration()")) {
3172 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3173 }
3174
3175 synchronized(mWindowMap) {
3176 mCurConfiguration = new Configuration(config);
3177 mWaitingForConfig = false;
3178 performLayoutAndPlaceSurfacesLocked();
3179 }
3180 }
3181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3183 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3184 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003185 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 }
Romain Guy06882f82009-06-10 13:36:04 -07003187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 synchronized(mWindowMap) {
3189 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3190 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003191 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 return;
3193 }
Romain Guy06882f82009-06-10 13:36:04 -07003194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 wtoken.requestedOrientation = requestedOrientation;
3196 }
3197 }
Romain Guy06882f82009-06-10 13:36:04 -07003198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 public int getAppOrientation(IApplicationToken token) {
3200 synchronized(mWindowMap) {
3201 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3202 if (wtoken == null) {
3203 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3204 }
Romain Guy06882f82009-06-10 13:36:04 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 return wtoken.requestedOrientation;
3207 }
3208 }
Romain Guy06882f82009-06-10 13:36:04 -07003209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3211 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3212 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003213 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 }
3215
3216 synchronized(mWindowMap) {
3217 boolean changed = false;
3218 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003219 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 changed = mFocusedApp != null;
3221 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003222 if (changed) {
3223 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 } else {
3226 AppWindowToken newFocus = findAppWindowToken(token);
3227 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003228 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 return;
3230 }
3231 changed = mFocusedApp != newFocus;
3232 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003233 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003234 if (changed) {
3235 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 }
3238
3239 if (moveFocusNow && changed) {
3240 final long origId = Binder.clearCallingIdentity();
3241 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3242 Binder.restoreCallingIdentity(origId);
3243 }
3244 }
3245 }
3246
3247 public void prepareAppTransition(int transit) {
3248 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3249 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003250 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 }
Romain Guy06882f82009-06-10 13:36:04 -07003252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003254 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 TAG, "Prepare app transition: transit=" + transit
3256 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003257 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003258 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3259 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003261 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3262 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3263 // Opening a new task always supersedes a close for the anim.
3264 mNextAppTransition = transit;
3265 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3266 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3267 // Opening a new activity always supersedes a close for the anim.
3268 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003269 }
3270 mAppTransitionReady = false;
3271 mAppTransitionTimeout = false;
3272 mStartingIconInTransition = false;
3273 mSkipAppTransitionAnimation = false;
3274 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3275 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3276 5000);
3277 }
3278 }
3279 }
3280
3281 public int getPendingAppTransition() {
3282 return mNextAppTransition;
3283 }
Romain Guy06882f82009-06-10 13:36:04 -07003284
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003285 public void overridePendingAppTransition(String packageName,
3286 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003287 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003288 mNextAppTransitionPackage = packageName;
3289 mNextAppTransitionEnter = enterAnim;
3290 mNextAppTransitionExit = exitAnim;
3291 }
3292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 public void executeAppTransition() {
3295 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3296 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003297 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 }
Romain Guy06882f82009-06-10 13:36:04 -07003299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003301 if (DEBUG_APP_TRANSITIONS) {
3302 RuntimeException e = new RuntimeException("here");
3303 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003305 + mNextAppTransition, e);
3306 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003307 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 mAppTransitionReady = true;
3309 final long origId = Binder.clearCallingIdentity();
3310 performLayoutAndPlaceSurfacesLocked();
3311 Binder.restoreCallingIdentity(origId);
3312 }
3313 }
3314 }
3315
3316 public void setAppStartingWindow(IBinder token, String pkg,
3317 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3318 IBinder transferFrom, boolean createIfNeeded) {
3319 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3320 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003321 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 }
3323
3324 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003325 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3327 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 AppWindowToken wtoken = findAppWindowToken(token);
3330 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003331 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 return;
3333 }
3334
3335 // If the display is frozen, we won't do anything until the
3336 // actual window is displayed so there is no reason to put in
3337 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003338 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 return;
3340 }
Romain Guy06882f82009-06-10 13:36:04 -07003341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 if (wtoken.startingData != null) {
3343 return;
3344 }
Romain Guy06882f82009-06-10 13:36:04 -07003345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 if (transferFrom != null) {
3347 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3348 if (ttoken != null) {
3349 WindowState startingWindow = ttoken.startingWindow;
3350 if (startingWindow != null) {
3351 if (mStartingIconInTransition) {
3352 // In this case, the starting icon has already
3353 // been displayed, so start letting windows get
3354 // shown immediately without any more transitions.
3355 mSkipAppTransitionAnimation = true;
3356 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003357 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 "Moving existing starting from " + ttoken
3359 + " to " + wtoken);
3360 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 // Transfer the starting window over to the new
3363 // token.
3364 wtoken.startingData = ttoken.startingData;
3365 wtoken.startingView = ttoken.startingView;
3366 wtoken.startingWindow = startingWindow;
3367 ttoken.startingData = null;
3368 ttoken.startingView = null;
3369 ttoken.startingWindow = null;
3370 ttoken.startingMoved = true;
3371 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003372 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003374 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003375 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003377 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 ttoken.windows.remove(startingWindow);
3379 ttoken.allAppWindows.remove(startingWindow);
3380 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 // Propagate other interesting state between the
3383 // tokens. If the old token is displayed, we should
3384 // immediately force the new one to be displayed. If
3385 // it is animating, we need to move that animation to
3386 // the new one.
3387 if (ttoken.allDrawn) {
3388 wtoken.allDrawn = true;
3389 }
3390 if (ttoken.firstWindowDrawn) {
3391 wtoken.firstWindowDrawn = true;
3392 }
3393 if (!ttoken.hidden) {
3394 wtoken.hidden = false;
3395 wtoken.hiddenRequested = false;
3396 wtoken.willBeHidden = false;
3397 }
3398 if (wtoken.clientHidden != ttoken.clientHidden) {
3399 wtoken.clientHidden = ttoken.clientHidden;
3400 wtoken.sendAppVisibilityToClients();
3401 }
3402 if (ttoken.animation != null) {
3403 wtoken.animation = ttoken.animation;
3404 wtoken.animating = ttoken.animating;
3405 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3406 ttoken.animation = null;
3407 ttoken.animLayerAdjustment = 0;
3408 wtoken.updateLayers();
3409 ttoken.updateLayers();
3410 }
Romain Guy06882f82009-06-10 13:36:04 -07003411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 mLayoutNeeded = true;
3414 performLayoutAndPlaceSurfacesLocked();
3415 Binder.restoreCallingIdentity(origId);
3416 return;
3417 } else if (ttoken.startingData != null) {
3418 // The previous app was getting ready to show a
3419 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003420 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 "Moving pending starting from " + ttoken
3422 + " to " + wtoken);
3423 wtoken.startingData = ttoken.startingData;
3424 ttoken.startingData = null;
3425 ttoken.startingMoved = true;
3426 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3427 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3428 // want to process the message ASAP, before any other queued
3429 // messages.
3430 mH.sendMessageAtFrontOfQueue(m);
3431 return;
3432 }
3433 }
3434 }
3435
3436 // There is no existing starting window, and the caller doesn't
3437 // want us to create one, so that's it!
3438 if (!createIfNeeded) {
3439 return;
3440 }
Romain Guy06882f82009-06-10 13:36:04 -07003441
Dianne Hackborn284ac932009-08-28 10:34:25 -07003442 // If this is a translucent or wallpaper window, then don't
3443 // show a starting window -- the current effect (a full-screen
3444 // opaque starting window that fades away to the real contents
3445 // when it is ready) does not work for this.
3446 if (theme != 0) {
3447 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3448 com.android.internal.R.styleable.Window);
3449 if (ent.array.getBoolean(
3450 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3451 return;
3452 }
3453 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003454 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3455 return;
3456 }
3457 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003458 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3459 return;
3460 }
3461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 mStartingIconInTransition = true;
3464 wtoken.startingData = new StartingData(
3465 pkg, theme, nonLocalizedLabel,
3466 labelRes, icon);
3467 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3468 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3469 // want to process the message ASAP, before any other queued
3470 // messages.
3471 mH.sendMessageAtFrontOfQueue(m);
3472 }
3473 }
3474
3475 public void setAppWillBeHidden(IBinder token) {
3476 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3477 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003478 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 }
3480
3481 AppWindowToken wtoken;
3482
3483 synchronized(mWindowMap) {
3484 wtoken = findAppWindowToken(token);
3485 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003486 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 -08003487 return;
3488 }
3489 wtoken.willBeHidden = true;
3490 }
3491 }
Romain Guy06882f82009-06-10 13:36:04 -07003492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3494 boolean visible, int transit, boolean performLayout) {
3495 boolean delayed = false;
3496
3497 if (wtoken.clientHidden == visible) {
3498 wtoken.clientHidden = !visible;
3499 wtoken.sendAppVisibilityToClients();
3500 }
Romain Guy06882f82009-06-10 13:36:04 -07003501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 wtoken.willBeHidden = false;
3503 if (wtoken.hidden == visible) {
3504 final int N = wtoken.allAppWindows.size();
3505 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003506 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3508 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003511
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003512 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 if (wtoken.animation == sDummyAnimation) {
3514 wtoken.animation = null;
3515 }
3516 applyAnimationLocked(wtoken, lp, transit, visible);
3517 changed = true;
3518 if (wtoken.animation != null) {
3519 delayed = runningAppAnimation = true;
3520 }
3521 }
Romain Guy06882f82009-06-10 13:36:04 -07003522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 for (int i=0; i<N; i++) {
3524 WindowState win = wtoken.allAppWindows.get(i);
3525 if (win == wtoken.startingWindow) {
3526 continue;
3527 }
3528
3529 if (win.isAnimating()) {
3530 delayed = true;
3531 }
Romain Guy06882f82009-06-10 13:36:04 -07003532
Joe Onorato8a9b2202010-02-26 18:56:32 -08003533 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 //win.dump(" ");
3535 if (visible) {
3536 if (!win.isVisibleNow()) {
3537 if (!runningAppAnimation) {
3538 applyAnimationLocked(win,
3539 WindowManagerPolicy.TRANSIT_ENTER, true);
3540 }
3541 changed = true;
3542 }
3543 } else if (win.isVisibleNow()) {
3544 if (!runningAppAnimation) {
3545 applyAnimationLocked(win,
3546 WindowManagerPolicy.TRANSIT_EXIT, false);
3547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 changed = true;
3549 }
3550 }
3551
3552 wtoken.hidden = wtoken.hiddenRequested = !visible;
3553 if (!visible) {
3554 unsetAppFreezingScreenLocked(wtoken, true, true);
3555 } else {
3556 // If we are being set visible, and the starting window is
3557 // not yet displayed, then make sure it doesn't get displayed.
3558 WindowState swin = wtoken.startingWindow;
3559 if (swin != null && (swin.mDrawPending
3560 || swin.mCommitDrawPending)) {
3561 swin.mPolicyVisibility = false;
3562 swin.mPolicyVisibilityAfterAnim = false;
3563 }
3564 }
Romain Guy06882f82009-06-10 13:36:04 -07003565
Joe Onorato8a9b2202010-02-26 18:56:32 -08003566 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3568 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003569
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003570 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003572 if (performLayout) {
3573 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3574 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003575 } else {
3576 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 }
3579 }
3580
3581 if (wtoken.animation != null) {
3582 delayed = true;
3583 }
Romain Guy06882f82009-06-10 13:36:04 -07003584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 return delayed;
3586 }
3587
3588 public void setAppVisibility(IBinder token, boolean visible) {
3589 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3590 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003591 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 }
3593
3594 AppWindowToken wtoken;
3595
3596 synchronized(mWindowMap) {
3597 wtoken = findAppWindowToken(token);
3598 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003599 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 return;
3601 }
3602
3603 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003604 RuntimeException e = null;
3605 if (!HIDE_STACK_CRAWLS) {
3606 e = new RuntimeException();
3607 e.fillInStackTrace();
3608 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003609 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 + "): mNextAppTransition=" + mNextAppTransition
3611 + " hidden=" + wtoken.hidden
3612 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3613 }
Romain Guy06882f82009-06-10 13:36:04 -07003614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 // If we are preparing an app transition, then delay changing
3616 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003617 if (!mDisplayFrozen && mPolicy.isScreenOn()
3618 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 // Already in requested state, don't do anything more.
3620 if (wtoken.hiddenRequested != visible) {
3621 return;
3622 }
3623 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003624
Joe Onorato8a9b2202010-02-26 18:56:32 -08003625 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 TAG, "Setting dummy animation on: " + wtoken);
3627 wtoken.setDummyAnimation();
3628 mOpeningApps.remove(wtoken);
3629 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003630 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 wtoken.inPendingTransaction = true;
3632 if (visible) {
3633 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 wtoken.startingDisplayed = false;
3635 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003636
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003637 // If the token is currently hidden (should be the
3638 // common case), then we need to set up to wait for
3639 // its windows to be ready.
3640 if (wtoken.hidden) {
3641 wtoken.allDrawn = false;
3642 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003643
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003644 if (wtoken.clientHidden) {
3645 // In the case where we are making an app visible
3646 // but holding off for a transition, we still need
3647 // to tell the client to make its windows visible so
3648 // they get drawn. Otherwise, we will wait on
3649 // performing the transition until all windows have
3650 // been drawn, they never will be, and we are sad.
3651 wtoken.clientHidden = false;
3652 wtoken.sendAppVisibilityToClients();
3653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 }
3655 } else {
3656 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003657
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003658 // If the token is currently visible (should be the
3659 // common case), then set up to wait for it to be hidden.
3660 if (!wtoken.hidden) {
3661 wtoken.waitingToHide = true;
3662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 }
3664 return;
3665 }
Romain Guy06882f82009-06-10 13:36:04 -07003666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003668 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 wtoken.updateReportedVisibilityLocked();
3670 Binder.restoreCallingIdentity(origId);
3671 }
3672 }
3673
3674 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3675 boolean unfreezeSurfaceNow, boolean force) {
3676 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003677 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 + " force=" + force);
3679 final int N = wtoken.allAppWindows.size();
3680 boolean unfrozeWindows = false;
3681 for (int i=0; i<N; i++) {
3682 WindowState w = wtoken.allAppWindows.get(i);
3683 if (w.mAppFreezing) {
3684 w.mAppFreezing = false;
3685 if (w.mSurface != null && !w.mOrientationChanging) {
3686 w.mOrientationChanging = true;
3687 }
3688 unfrozeWindows = true;
3689 }
3690 }
3691 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003692 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 wtoken.freezingScreen = false;
3694 mAppsFreezingScreen--;
3695 }
3696 if (unfreezeSurfaceNow) {
3697 if (unfrozeWindows) {
3698 mLayoutNeeded = true;
3699 performLayoutAndPlaceSurfacesLocked();
3700 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003701 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 }
3703 }
3704 }
Romain Guy06882f82009-06-10 13:36:04 -07003705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3707 int configChanges) {
3708 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003709 RuntimeException e = null;
3710 if (!HIDE_STACK_CRAWLS) {
3711 e = new RuntimeException();
3712 e.fillInStackTrace();
3713 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003714 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 + ": hidden=" + wtoken.hidden + " freezing="
3716 + wtoken.freezingScreen, e);
3717 }
3718 if (!wtoken.hiddenRequested) {
3719 if (!wtoken.freezingScreen) {
3720 wtoken.freezingScreen = true;
3721 mAppsFreezingScreen++;
3722 if (mAppsFreezingScreen == 1) {
3723 startFreezingDisplayLocked();
3724 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3725 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3726 5000);
3727 }
3728 }
3729 final int N = wtoken.allAppWindows.size();
3730 for (int i=0; i<N; i++) {
3731 WindowState w = wtoken.allAppWindows.get(i);
3732 w.mAppFreezing = true;
3733 }
3734 }
3735 }
Romain Guy06882f82009-06-10 13:36:04 -07003736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 public void startAppFreezingScreen(IBinder token, int configChanges) {
3738 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3739 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003740 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 }
3742
3743 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003744 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003745 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 return;
3747 }
Romain Guy06882f82009-06-10 13:36:04 -07003748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 AppWindowToken wtoken = findAppWindowToken(token);
3750 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003751 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 return;
3753 }
3754 final long origId = Binder.clearCallingIdentity();
3755 startAppFreezingScreenLocked(wtoken, configChanges);
3756 Binder.restoreCallingIdentity(origId);
3757 }
3758 }
Romain Guy06882f82009-06-10 13:36:04 -07003759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 public void stopAppFreezingScreen(IBinder token, boolean force) {
3761 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3762 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003763 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 }
3765
3766 synchronized(mWindowMap) {
3767 AppWindowToken wtoken = findAppWindowToken(token);
3768 if (wtoken == null || wtoken.appToken == null) {
3769 return;
3770 }
3771 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003772 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3774 unsetAppFreezingScreenLocked(wtoken, true, force);
3775 Binder.restoreCallingIdentity(origId);
3776 }
3777 }
Romain Guy06882f82009-06-10 13:36:04 -07003778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 public void removeAppToken(IBinder token) {
3780 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3781 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003782 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 }
3784
3785 AppWindowToken wtoken = null;
3786 AppWindowToken startingToken = null;
3787 boolean delayed = false;
3788
3789 final long origId = Binder.clearCallingIdentity();
3790 synchronized(mWindowMap) {
3791 WindowToken basewtoken = mTokenMap.remove(token);
3792 mTokenList.remove(basewtoken);
3793 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003794 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003795 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 wtoken.inPendingTransaction = false;
3797 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003798 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 if (mClosingApps.contains(wtoken)) {
3800 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003801 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003803 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 delayed = true;
3805 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003806 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 TAG, "Removing app " + wtoken + " delayed=" + delayed
3808 + " animation=" + wtoken.animation
3809 + " animating=" + wtoken.animating);
3810 if (delayed) {
3811 // set the token aside because it has an active animation to be finished
3812 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003813 } else {
3814 // Make sure there is no animation running on this token,
3815 // so any windows associated with it will be removed as
3816 // soon as their animations are complete
3817 wtoken.animation = null;
3818 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 }
3820 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003821 if (mLastEnterAnimToken == wtoken) {
3822 mLastEnterAnimToken = null;
3823 mLastEnterAnimParams = null;
3824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 wtoken.removed = true;
3826 if (wtoken.startingData != null) {
3827 startingToken = wtoken;
3828 }
3829 unsetAppFreezingScreenLocked(wtoken, true, true);
3830 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003831 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 mFocusedApp = null;
3833 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003834 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 }
3836 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003837 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 }
Romain Guy06882f82009-06-10 13:36:04 -07003839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 if (!delayed && wtoken != null) {
3841 wtoken.updateReportedVisibilityLocked();
3842 }
3843 }
3844 Binder.restoreCallingIdentity(origId);
3845
3846 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003847 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 + startingToken + ": app token removed");
3849 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3850 mH.sendMessage(m);
3851 }
3852 }
3853
3854 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3855 final int NW = token.windows.size();
3856 for (int i=0; i<NW; i++) {
3857 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003858 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003860 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 int j = win.mChildWindows.size();
3862 while (j > 0) {
3863 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003864 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003865 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003866 "Tmp removing child window " + cwin);
3867 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 }
3869 }
3870 return NW > 0;
3871 }
3872
3873 void dumpAppTokensLocked() {
3874 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003875 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 }
3877 }
Romain Guy06882f82009-06-10 13:36:04 -07003878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 void dumpWindowsLocked() {
3880 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003881 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 }
3883 }
Romain Guy06882f82009-06-10 13:36:04 -07003884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 private int findWindowOffsetLocked(int tokenPos) {
3886 final int NW = mWindows.size();
3887
3888 if (tokenPos >= mAppTokens.size()) {
3889 int i = NW;
3890 while (i > 0) {
3891 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003892 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 if (win.getAppToken() != null) {
3894 return i+1;
3895 }
3896 }
3897 }
3898
3899 while (tokenPos > 0) {
3900 // Find the first app token below the new position that has
3901 // a window displayed.
3902 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003903 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003905 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003907 "Skipping token -- currently sending to bottom");
3908 tokenPos--;
3909 continue;
3910 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 int i = wtoken.windows.size();
3912 while (i > 0) {
3913 i--;
3914 WindowState win = wtoken.windows.get(i);
3915 int j = win.mChildWindows.size();
3916 while (j > 0) {
3917 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003918 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003919 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 for (int pos=NW-1; pos>=0; pos--) {
3921 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003922 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003923 "Found child win @" + (pos+1));
3924 return pos+1;
3925 }
3926 }
3927 }
3928 }
3929 for (int pos=NW-1; pos>=0; pos--) {
3930 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003931 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 return pos+1;
3933 }
3934 }
3935 }
3936 tokenPos--;
3937 }
3938
3939 return 0;
3940 }
3941
3942 private final int reAddWindowLocked(int index, WindowState win) {
3943 final int NCW = win.mChildWindows.size();
3944 boolean added = false;
3945 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003946 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003947 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003948 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003949 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 mWindows.add(index, win);
3951 index++;
3952 added = true;
3953 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003954 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003955 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 mWindows.add(index, cwin);
3957 index++;
3958 }
3959 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003960 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003961 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 mWindows.add(index, win);
3963 index++;
3964 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003965 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 return index;
3967 }
Romain Guy06882f82009-06-10 13:36:04 -07003968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3970 final int NW = token.windows.size();
3971 for (int i=0; i<NW; i++) {
3972 index = reAddWindowLocked(index, token.windows.get(i));
3973 }
3974 return index;
3975 }
3976
3977 public void moveAppToken(int index, IBinder token) {
3978 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3979 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003980 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 }
3982
3983 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003984 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 if (DEBUG_REORDER) dumpAppTokensLocked();
3986 final AppWindowToken wtoken = findAppWindowToken(token);
3987 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003988 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 + token + " (" + wtoken + ")");
3990 return;
3991 }
3992 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003993 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003997 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 if (DEBUG_REORDER) dumpWindowsLocked();
3999 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004000 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 if (DEBUG_REORDER) dumpWindowsLocked();
4002 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 if (DEBUG_REORDER) dumpWindowsLocked();
4005 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 mLayoutNeeded = true;
4007 performLayoutAndPlaceSurfacesLocked();
4008 }
4009 Binder.restoreCallingIdentity(origId);
4010 }
4011 }
4012
4013 private void removeAppTokensLocked(List<IBinder> tokens) {
4014 // XXX This should be done more efficiently!
4015 // (take advantage of the fact that both lists should be
4016 // ordered in the same way.)
4017 int N = tokens.size();
4018 for (int i=0; i<N; i++) {
4019 IBinder token = tokens.get(i);
4020 final AppWindowToken wtoken = findAppWindowToken(token);
4021 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004022 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 + token + " (" + wtoken + ")");
4024 i--;
4025 N--;
4026 }
4027 }
4028 }
4029
Dianne Hackborna8f60182009-09-01 19:01:50 -07004030 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4031 boolean updateFocusAndLayout) {
4032 // First remove all of the windows from the list.
4033 tmpRemoveAppWindowsLocked(wtoken);
4034
4035 // Where to start adding?
4036 int pos = findWindowOffsetLocked(tokenPos);
4037
4038 // And now add them back at the correct place.
4039 pos = reAddAppWindowsLocked(pos, wtoken);
4040
4041 if (updateFocusAndLayout) {
4042 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4043 assignLayersLocked();
4044 }
4045 mLayoutNeeded = true;
4046 performLayoutAndPlaceSurfacesLocked();
4047 }
4048 }
4049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4051 // First remove all of the windows from the list.
4052 final int N = tokens.size();
4053 int i;
4054 for (i=0; i<N; i++) {
4055 WindowToken token = mTokenMap.get(tokens.get(i));
4056 if (token != null) {
4057 tmpRemoveAppWindowsLocked(token);
4058 }
4059 }
4060
4061 // Where to start adding?
4062 int pos = findWindowOffsetLocked(tokenPos);
4063
4064 // And now add them back at the correct place.
4065 for (i=0; i<N; i++) {
4066 WindowToken token = mTokenMap.get(tokens.get(i));
4067 if (token != null) {
4068 pos = reAddAppWindowsLocked(pos, token);
4069 }
4070 }
4071
Dianne Hackborna8f60182009-09-01 19:01:50 -07004072 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4073 assignLayersLocked();
4074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 mLayoutNeeded = true;
4076 performLayoutAndPlaceSurfacesLocked();
4077
4078 //dump();
4079 }
4080
4081 public void moveAppTokensToTop(List<IBinder> tokens) {
4082 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4083 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004084 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 }
4086
4087 final long origId = Binder.clearCallingIdentity();
4088 synchronized(mWindowMap) {
4089 removeAppTokensLocked(tokens);
4090 final int N = tokens.size();
4091 for (int i=0; i<N; i++) {
4092 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4093 if (wt != null) {
4094 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004095 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004096 mToTopApps.remove(wt);
4097 mToBottomApps.remove(wt);
4098 mToTopApps.add(wt);
4099 wt.sendingToBottom = false;
4100 wt.sendingToTop = true;
4101 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 }
4103 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004104
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004105 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004106 moveAppWindowsLocked(tokens, mAppTokens.size());
4107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 }
4109 Binder.restoreCallingIdentity(origId);
4110 }
4111
4112 public void moveAppTokensToBottom(List<IBinder> tokens) {
4113 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4114 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004115 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117
4118 final long origId = Binder.clearCallingIdentity();
4119 synchronized(mWindowMap) {
4120 removeAppTokensLocked(tokens);
4121 final int N = tokens.size();
4122 int pos = 0;
4123 for (int i=0; i<N; i++) {
4124 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4125 if (wt != null) {
4126 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004127 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004128 mToTopApps.remove(wt);
4129 mToBottomApps.remove(wt);
4130 mToBottomApps.add(i, wt);
4131 wt.sendingToTop = false;
4132 wt.sendingToBottom = true;
4133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004134 pos++;
4135 }
4136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004137
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004138 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004139 moveAppWindowsLocked(tokens, 0);
4140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 }
4142 Binder.restoreCallingIdentity(origId);
4143 }
4144
4145 // -------------------------------------------------------------
4146 // Misc IWindowSession methods
4147 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004148
Jim Miller284b62e2010-06-08 14:27:42 -07004149 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004150 {
Jim Miller284b62e2010-06-08 14:27:42 -07004151 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4152 // called before DevicePolicyManagerService has started.
4153 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4154 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4155 Context.DEVICE_POLICY_SERVICE);
4156 if (dpm != null) {
4157 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4158 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4159 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4160 }
Jim Millerd6b57052010-06-07 17:52:42 -07004161 }
Jim Miller284b62e2010-06-08 14:27:42 -07004162 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004163 }
4164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004166 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004167 != PackageManager.PERMISSION_GRANTED) {
4168 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4169 }
Jim Millerd6b57052010-06-07 17:52:42 -07004170
Jim Miller284b62e2010-06-08 14:27:42 -07004171 synchronized (mKeyguardTokenWatcher) {
4172 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 }
4175
4176 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004177 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004178 != PackageManager.PERMISSION_GRANTED) {
4179 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181
Jim Miller284b62e2010-06-08 14:27:42 -07004182 synchronized (mKeyguardTokenWatcher) {
4183 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004184
Jim Miller284b62e2010-06-08 14:27:42 -07004185 if (!mKeyguardTokenWatcher.isAcquired()) {
4186 // If we are the last one to reenable the keyguard wait until
4187 // we have actually finished reenabling until returning.
4188 // It is possible that reenableKeyguard() can be called before
4189 // the previous disableKeyguard() is handled, in which case
4190 // neither mKeyguardTokenWatcher.acquired() or released() would
4191 // be called. In that case mKeyguardDisabled will be false here
4192 // and we have nothing to wait for.
4193 while (mKeyguardDisabled) {
4194 try {
4195 mKeyguardTokenWatcher.wait();
4196 } catch (InterruptedException e) {
4197 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004198 }
4199 }
4200 }
4201 }
4202 }
4203
4204 /**
4205 * @see android.app.KeyguardManager#exitKeyguardSecurely
4206 */
4207 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004208 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 != PackageManager.PERMISSION_GRANTED) {
4210 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4211 }
4212 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4213 public void onKeyguardExitResult(boolean success) {
4214 try {
4215 callback.onKeyguardExitResult(success);
4216 } catch (RemoteException e) {
4217 // Client has died, we don't care.
4218 }
4219 }
4220 });
4221 }
4222
4223 public boolean inKeyguardRestrictedInputMode() {
4224 return mPolicy.inKeyguardRestrictedKeyInputMode();
4225 }
Romain Guy06882f82009-06-10 13:36:04 -07004226
Dianne Hackbornffa42482009-09-23 22:20:11 -07004227 public void closeSystemDialogs(String reason) {
4228 synchronized(mWindowMap) {
4229 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004230 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004231 if (w.mSurface != null) {
4232 try {
4233 w.mClient.closeSystemDialogs(reason);
4234 } catch (RemoteException e) {
4235 }
4236 }
4237 }
4238 }
4239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004241 static float fixScale(float scale) {
4242 if (scale < 0) scale = 0;
4243 else if (scale > 20) scale = 20;
4244 return Math.abs(scale);
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 public void setAnimationScale(int which, float scale) {
4248 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4249 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004250 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 }
4252
4253 if (scale < 0) scale = 0;
4254 else if (scale > 20) scale = 20;
4255 scale = Math.abs(scale);
4256 switch (which) {
4257 case 0: mWindowAnimationScale = fixScale(scale); break;
4258 case 1: mTransitionAnimationScale = fixScale(scale); break;
4259 }
Romain Guy06882f82009-06-10 13:36:04 -07004260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 // Persist setting
4262 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4263 }
Romain Guy06882f82009-06-10 13:36:04 -07004264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 public void setAnimationScales(float[] scales) {
4266 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4267 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004268 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 }
4270
4271 if (scales != null) {
4272 if (scales.length >= 1) {
4273 mWindowAnimationScale = fixScale(scales[0]);
4274 }
4275 if (scales.length >= 2) {
4276 mTransitionAnimationScale = fixScale(scales[1]);
4277 }
4278 }
Romain Guy06882f82009-06-10 13:36:04 -07004279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 // Persist setting
4281 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4282 }
Romain Guy06882f82009-06-10 13:36:04 -07004283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 public float getAnimationScale(int which) {
4285 switch (which) {
4286 case 0: return mWindowAnimationScale;
4287 case 1: return mTransitionAnimationScale;
4288 }
4289 return 0;
4290 }
Romain Guy06882f82009-06-10 13:36:04 -07004291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 public float[] getAnimationScales() {
4293 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4294 }
Romain Guy06882f82009-06-10 13:36:04 -07004295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 public int getSwitchState(int sw) {
4297 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4298 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004299 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004301 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 }
Romain Guy06882f82009-06-10 13:36:04 -07004303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 public int getSwitchStateForDevice(int devid, int sw) {
4305 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4306 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004307 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004309 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
Romain Guy06882f82009-06-10 13:36:04 -07004311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 public int getScancodeState(int sw) {
4313 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4314 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004315 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004317 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Romain Guy06882f82009-06-10 13:36:04 -07004319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 public int getScancodeStateForDevice(int devid, int sw) {
4321 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4322 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004323 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004325 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 }
Romain Guy06882f82009-06-10 13:36:04 -07004327
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004328 public int getTrackballScancodeState(int sw) {
4329 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4330 "getTrackballScancodeState()")) {
4331 throw new SecurityException("Requires READ_INPUT_STATE permission");
4332 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004333 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004334 }
4335
4336 public int getDPadScancodeState(int sw) {
4337 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4338 "getDPadScancodeState()")) {
4339 throw new SecurityException("Requires READ_INPUT_STATE permission");
4340 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004341 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004342 }
4343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 public int getKeycodeState(int sw) {
4345 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4346 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004347 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004349 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 }
Romain Guy06882f82009-06-10 13:36:04 -07004351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 public int getKeycodeStateForDevice(int devid, int sw) {
4353 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4354 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004355 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004357 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 }
Romain Guy06882f82009-06-10 13:36:04 -07004359
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004360 public int getTrackballKeycodeState(int sw) {
4361 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4362 "getTrackballKeycodeState()")) {
4363 throw new SecurityException("Requires READ_INPUT_STATE permission");
4364 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004365 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004366 }
4367
4368 public int getDPadKeycodeState(int sw) {
4369 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4370 "getDPadKeycodeState()")) {
4371 throw new SecurityException("Requires READ_INPUT_STATE permission");
4372 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004373 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004374 }
Jeff Browna41ca772010-08-11 14:46:32 -07004375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004377 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 }
Romain Guy06882f82009-06-10 13:36:04 -07004379
Jeff Browna41ca772010-08-11 14:46:32 -07004380 public InputChannel monitorInput(String inputChannelName) {
4381 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4382 "monitorInput()")) {
4383 throw new SecurityException("Requires READ_INPUT_STATE permission");
4384 }
4385 return mInputManager.monitorInput(inputChannelName);
4386 }
4387
Jeff Brown8d608662010-08-30 03:02:23 -07004388 public InputDevice getInputDevice(int deviceId) {
4389 return mInputManager.getInputDevice(deviceId);
4390 }
4391
4392 public int[] getInputDeviceIds() {
4393 return mInputManager.getInputDeviceIds();
4394 }
4395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 public void enableScreenAfterBoot() {
4397 synchronized(mWindowMap) {
4398 if (mSystemBooted) {
4399 return;
4400 }
4401 mSystemBooted = true;
4402 }
Romain Guy06882f82009-06-10 13:36:04 -07004403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 performEnableScreen();
4405 }
Romain Guy06882f82009-06-10 13:36:04 -07004406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 public void enableScreenIfNeededLocked() {
4408 if (mDisplayEnabled) {
4409 return;
4410 }
4411 if (!mSystemBooted) {
4412 return;
4413 }
4414 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4415 }
Romain Guy06882f82009-06-10 13:36:04 -07004416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 public void performEnableScreen() {
4418 synchronized(mWindowMap) {
4419 if (mDisplayEnabled) {
4420 return;
4421 }
4422 if (!mSystemBooted) {
4423 return;
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 // Don't enable the screen until all existing windows
4427 // have been drawn.
4428 final int N = mWindows.size();
4429 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004430 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004431 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 return;
4433 }
4434 }
Romain Guy06882f82009-06-10 13:36:04 -07004435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 mDisplayEnabled = true;
4437 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004438 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 StringWriter sw = new StringWriter();
4440 PrintWriter pw = new PrintWriter(sw);
4441 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 }
4444 try {
4445 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4446 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 Parcel data = Parcel.obtain();
4449 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4450 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4451 data, null, 0);
4452 data.recycle();
4453 }
4454 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004455 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
4457 }
Romain Guy06882f82009-06-10 13:36:04 -07004458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004462 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4463 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 }
Romain Guy06882f82009-06-10 13:36:04 -07004465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 public void setInTouchMode(boolean mode) {
4467 synchronized(mWindowMap) {
4468 mInTouchMode = mode;
4469 }
4470 }
4471
Romain Guy06882f82009-06-10 13:36:04 -07004472 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004473 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004475 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004476 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 }
4478
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004479 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 }
Romain Guy06882f82009-06-10 13:36:04 -07004481
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 public void setRotationUnchecked(int rotation,
4483 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004484 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 long origId = Binder.clearCallingIdentity();
4488 boolean changed;
4489 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004490 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004491 }
Romain Guy06882f82009-06-10 13:36:04 -07004492
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004493 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 sendNewConfiguration();
4495 }
Romain Guy06882f82009-06-10 13:36:04 -07004496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 Binder.restoreCallingIdentity(origId);
4498 }
Romain Guy06882f82009-06-10 13:36:04 -07004499
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004500 /**
4501 * Apply a new rotation to the screen, respecting the requests of
4502 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4503 * re-evaluate the desired rotation.
4504 *
4505 * Returns null if the rotation has been changed. In this case YOU
4506 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4507 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004508 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 boolean changed;
4510 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4511 rotation = mRequestedRotation;
4512 } else {
4513 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004514 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004516 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004517 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004518 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004519 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004523 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004524 "Rotation changed to " + rotation
4525 + " from " + mRotation
4526 + " (forceApp=" + mForcedAppOrientation
4527 + ", req=" + mRequestedRotation + ")");
4528 mRotation = rotation;
4529 mWindowsFreezingScreen = true;
4530 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4531 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4532 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004533 mWaitingForConfig = true;
4534 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004536 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004537 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004539 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 }
4541 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004542 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 if (w.mSurface != null) {
4544 w.mOrientationChanging = true;
4545 }
4546 }
4547 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4548 try {
4549 mRotationWatchers.get(i).onRotationChanged(rotation);
4550 } catch (RemoteException e) {
4551 }
4552 }
4553 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 return changed;
4556 }
Romain Guy06882f82009-06-10 13:36:04 -07004557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004558 public int getRotation() {
4559 return mRotation;
4560 }
4561
4562 public int watchRotation(IRotationWatcher watcher) {
4563 final IBinder watcherBinder = watcher.asBinder();
4564 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4565 public void binderDied() {
4566 synchronized (mWindowMap) {
4567 for (int i=0; i<mRotationWatchers.size(); i++) {
4568 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004569 IRotationWatcher removed = mRotationWatchers.remove(i);
4570 if (removed != null) {
4571 removed.asBinder().unlinkToDeath(this, 0);
4572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 i--;
4574 }
4575 }
4576 }
4577 }
4578 };
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 synchronized (mWindowMap) {
4581 try {
4582 watcher.asBinder().linkToDeath(dr, 0);
4583 mRotationWatchers.add(watcher);
4584 } catch (RemoteException e) {
4585 // Client died, no cleanup needed.
4586 }
Romain Guy06882f82009-06-10 13:36:04 -07004587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 return mRotation;
4589 }
4590 }
4591
4592 /**
4593 * Starts the view server on the specified port.
4594 *
4595 * @param port The port to listener to.
4596 *
4597 * @return True if the server was successfully started, false otherwise.
4598 *
4599 * @see com.android.server.ViewServer
4600 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4601 */
4602 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004603 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004604 return false;
4605 }
4606
4607 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4608 return false;
4609 }
4610
4611 if (port < 1024) {
4612 return false;
4613 }
4614
4615 if (mViewServer != null) {
4616 if (!mViewServer.isRunning()) {
4617 try {
4618 return mViewServer.start();
4619 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004620 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 }
4622 }
4623 return false;
4624 }
4625
4626 try {
4627 mViewServer = new ViewServer(this, port);
4628 return mViewServer.start();
4629 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004630 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 }
4632 return false;
4633 }
4634
Romain Guy06882f82009-06-10 13:36:04 -07004635 private boolean isSystemSecure() {
4636 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4637 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4638 }
4639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 /**
4641 * Stops the view server if it exists.
4642 *
4643 * @return True if the server stopped, false if it wasn't started or
4644 * couldn't be stopped.
4645 *
4646 * @see com.android.server.ViewServer
4647 */
4648 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004649 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004650 return false;
4651 }
4652
4653 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4654 return false;
4655 }
4656
4657 if (mViewServer != null) {
4658 return mViewServer.stop();
4659 }
4660 return false;
4661 }
4662
4663 /**
4664 * Indicates whether the view server is running.
4665 *
4666 * @return True if the server is running, false otherwise.
4667 *
4668 * @see com.android.server.ViewServer
4669 */
4670 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004671 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 return false;
4673 }
4674
4675 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4676 return false;
4677 }
4678
4679 return mViewServer != null && mViewServer.isRunning();
4680 }
4681
4682 /**
4683 * Lists all availble windows in the system. The listing is written in the
4684 * specified Socket's output stream with the following syntax:
4685 * windowHashCodeInHexadecimal windowName
4686 * Each line of the ouput represents a different window.
4687 *
4688 * @param client The remote client to send the listing to.
4689 * @return False if an error occured, true otherwise.
4690 */
4691 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004692 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 return false;
4694 }
4695
4696 boolean result = true;
4697
Jeff Browne33348b2010-07-15 23:54:05 -07004698 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004701 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702 }
4703
4704 BufferedWriter out = null;
4705
4706 // Any uncaught exception will crash the system process
4707 try {
4708 OutputStream clientStream = client.getOutputStream();
4709 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4710
4711 final int count = windows.length;
4712 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004713 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 out.write(Integer.toHexString(System.identityHashCode(w)));
4715 out.write(' ');
4716 out.append(w.mAttrs.getTitle());
4717 out.write('\n');
4718 }
4719
4720 out.write("DONE.\n");
4721 out.flush();
4722 } catch (Exception e) {
4723 result = false;
4724 } finally {
4725 if (out != null) {
4726 try {
4727 out.close();
4728 } catch (IOException e) {
4729 result = false;
4730 }
4731 }
4732 }
4733
4734 return result;
4735 }
4736
4737 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004738 * Returns the focused window in the following format:
4739 * windowHashCodeInHexadecimal windowName
4740 *
4741 * @param client The remote client to send the listing to.
4742 * @return False if an error occurred, true otherwise.
4743 */
4744 boolean viewServerGetFocusedWindow(Socket client) {
4745 if (isSystemSecure()) {
4746 return false;
4747 }
4748
4749 boolean result = true;
4750
4751 WindowState focusedWindow = getFocusedWindow();
4752
4753 BufferedWriter out = null;
4754
4755 // Any uncaught exception will crash the system process
4756 try {
4757 OutputStream clientStream = client.getOutputStream();
4758 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4759
4760 if(focusedWindow != null) {
4761 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4762 out.write(' ');
4763 out.append(focusedWindow.mAttrs.getTitle());
4764 }
4765 out.write('\n');
4766 out.flush();
4767 } catch (Exception e) {
4768 result = false;
4769 } finally {
4770 if (out != null) {
4771 try {
4772 out.close();
4773 } catch (IOException e) {
4774 result = false;
4775 }
4776 }
4777 }
4778
4779 return result;
4780 }
4781
4782 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 * Sends a command to a target window. The result of the command, if any, will be
4784 * written in the output stream of the specified socket.
4785 *
4786 * The parameters must follow this syntax:
4787 * windowHashcode extra
4788 *
4789 * Where XX is the length in characeters of the windowTitle.
4790 *
4791 * The first parameter is the target window. The window with the specified hashcode
4792 * will be the target. If no target can be found, nothing happens. The extra parameters
4793 * will be delivered to the target window and as parameters to the command itself.
4794 *
4795 * @param client The remote client to sent the result, if any, to.
4796 * @param command The command to execute.
4797 * @param parameters The command parameters.
4798 *
4799 * @return True if the command was successfully delivered, false otherwise. This does
4800 * not indicate whether the command itself was successful.
4801 */
4802 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004803 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 return false;
4805 }
4806
4807 boolean success = true;
4808 Parcel data = null;
4809 Parcel reply = null;
4810
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004811 BufferedWriter out = null;
4812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 // Any uncaught exception will crash the system process
4814 try {
4815 // Find the hashcode of the window
4816 int index = parameters.indexOf(' ');
4817 if (index == -1) {
4818 index = parameters.length();
4819 }
4820 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004821 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822
4823 // Extract the command's parameter after the window description
4824 if (index < parameters.length()) {
4825 parameters = parameters.substring(index + 1);
4826 } else {
4827 parameters = "";
4828 }
4829
4830 final WindowManagerService.WindowState window = findWindow(hashCode);
4831 if (window == null) {
4832 return false;
4833 }
4834
4835 data = Parcel.obtain();
4836 data.writeInterfaceToken("android.view.IWindow");
4837 data.writeString(command);
4838 data.writeString(parameters);
4839 data.writeInt(1);
4840 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4841
4842 reply = Parcel.obtain();
4843
4844 final IBinder binder = window.mClient.asBinder();
4845 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4846 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4847
4848 reply.readException();
4849
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004850 if (!client.isOutputShutdown()) {
4851 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
4852 out.write("DONE\n");
4853 out.flush();
4854 }
4855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004857 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004858 success = false;
4859 } finally {
4860 if (data != null) {
4861 data.recycle();
4862 }
4863 if (reply != null) {
4864 reply.recycle();
4865 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004866 if (out != null) {
4867 try {
4868 out.close();
4869 } catch (IOException e) {
4870
4871 }
4872 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
4874
4875 return success;
4876 }
4877
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004878 public void addWindowChangeListener(WindowChangeListener listener) {
4879 synchronized(mWindowMap) {
4880 mWindowChangeListeners.add(listener);
4881 }
4882 }
4883
4884 public void removeWindowChangeListener(WindowChangeListener listener) {
4885 synchronized(mWindowMap) {
4886 mWindowChangeListeners.remove(listener);
4887 }
4888 }
4889
4890 private void notifyWindowsChanged() {
4891 WindowChangeListener[] windowChangeListeners;
4892 synchronized(mWindowMap) {
4893 if(mWindowChangeListeners.isEmpty()) {
4894 return;
4895 }
4896 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4897 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4898 }
4899 int N = windowChangeListeners.length;
4900 for(int i = 0; i < N; i++) {
4901 windowChangeListeners[i].windowsChanged();
4902 }
4903 }
4904
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004905 private void notifyFocusChanged() {
4906 WindowChangeListener[] windowChangeListeners;
4907 synchronized(mWindowMap) {
4908 if(mWindowChangeListeners.isEmpty()) {
4909 return;
4910 }
4911 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4912 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4913 }
4914 int N = windowChangeListeners.length;
4915 for(int i = 0; i < N; i++) {
4916 windowChangeListeners[i].focusChanged();
4917 }
4918 }
4919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 private WindowState findWindow(int hashCode) {
4921 if (hashCode == -1) {
4922 return getFocusedWindow();
4923 }
4924
4925 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004926 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004927 final int count = windows.size();
4928
4929 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004930 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 if (System.identityHashCode(w) == hashCode) {
4932 return w;
4933 }
4934 }
4935 }
4936
4937 return null;
4938 }
4939
4940 /*
4941 * Instruct the Activity Manager to fetch the current configuration and broadcast
4942 * that to config-changed listeners if appropriate.
4943 */
4944 void sendNewConfiguration() {
4945 try {
4946 mActivityManager.updateConfiguration(null);
4947 } catch (RemoteException e) {
4948 }
4949 }
Romain Guy06882f82009-06-10 13:36:04 -07004950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 public Configuration computeNewConfiguration() {
4952 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004953 return computeNewConfigurationLocked();
4954 }
4955 }
Romain Guy06882f82009-06-10 13:36:04 -07004956
Dianne Hackbornc485a602009-03-24 22:39:49 -07004957 Configuration computeNewConfigurationLocked() {
4958 Configuration config = new Configuration();
4959 if (!computeNewConfigurationLocked(config)) {
4960 return null;
4961 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004962 return config;
4963 }
Romain Guy06882f82009-06-10 13:36:04 -07004964
Dianne Hackbornc485a602009-03-24 22:39:49 -07004965 boolean computeNewConfigurationLocked(Configuration config) {
4966 if (mDisplay == null) {
4967 return false;
4968 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004969
4970 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004971
4972 // Use the effective "visual" dimensions based on current rotation
4973 final boolean rotated = (mRotation == Surface.ROTATION_90
4974 || mRotation == Surface.ROTATION_270);
4975 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4976 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4977
Dianne Hackbornc485a602009-03-24 22:39:49 -07004978 int orientation = Configuration.ORIENTATION_SQUARE;
4979 if (dw < dh) {
4980 orientation = Configuration.ORIENTATION_PORTRAIT;
4981 } else if (dw > dh) {
4982 orientation = Configuration.ORIENTATION_LANDSCAPE;
4983 }
4984 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004985
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004986 DisplayMetrics dm = new DisplayMetrics();
4987 mDisplay.getMetrics(dm);
4988 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4989
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004990 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004991 // Note we only do this once because at this point we don't
4992 // expect the screen to change in this way at runtime, and want
4993 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004994 int longSize = dw;
4995 int shortSize = dh;
4996 if (longSize < shortSize) {
4997 int tmp = longSize;
4998 longSize = shortSize;
4999 shortSize = tmp;
5000 }
5001 longSize = (int)(longSize/dm.density);
5002 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005003
Dianne Hackborn723738c2009-06-25 19:48:04 -07005004 // These semi-magic numbers define our compatibility modes for
5005 // applications with different screens. Don't change unless you
5006 // make sure to test lots and lots of apps!
5007 if (longSize < 470) {
5008 // This is shorter than an HVGA normal density screen (which
5009 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005010 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5011 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005012 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005013 // What size is this screen screen?
5014 if (longSize >= 800 && shortSize >= 600) {
5015 // SVGA or larger screens at medium density are the point
5016 // at which we consider it to be an extra large screen.
5017 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5018 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005019 // VGA or larger screens at medium density are the point
5020 // at which we consider it to be a large screen.
5021 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5022 } else {
5023 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005024
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005025 // If this screen is wider than normal HVGA, or taller
5026 // than FWVGA, then for old apps we want to run in size
5027 // compatibility mode.
5028 if (shortSize > 321 || longSize > 570) {
5029 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5030 }
5031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005032
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005033 // Is this a long screen?
5034 if (((longSize*3)/5) >= (shortSize-1)) {
5035 // Anything wider than WVGA (5:3) is considering to be long.
5036 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5037 } else {
5038 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5039 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005040 }
5041 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005042 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005043
Dianne Hackbornc485a602009-03-24 22:39:49 -07005044 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5045 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5046 mPolicy.adjustConfigurationLw(config);
5047 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005048 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005050 // -------------------------------------------------------------
5051 // Input Events and Focus Management
5052 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005053
Jeff Brown349703e2010-06-22 01:27:15 -07005054 InputMonitor mInputMonitor = new InputMonitor();
5055
5056 /* Tracks the progress of input dispatch and ensures that input dispatch state
5057 * is kept in sync with changes in window focus, visibility, registration, and
5058 * other relevant Window Manager state transitions. */
5059 final class InputMonitor {
5060 // Current window with input focus for keys and other non-touch events. May be null.
5061 private WindowState mInputFocus;
5062
5063 // When true, prevents input dispatch from proceeding until set to false again.
5064 private boolean mInputDispatchFrozen;
5065
5066 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5067 private boolean mInputDispatchEnabled = true;
5068
5069 // Temporary list of windows information to provide to the input dispatcher.
5070 private InputWindowList mTempInputWindows = new InputWindowList();
5071
5072 // Temporary input application object to provide to the input dispatcher.
5073 private InputApplication mTempInputApplication = new InputApplication();
5074
5075 /* Notifies the window manager about a broken input channel.
5076 *
5077 * Called by the InputManager.
5078 */
5079 public void notifyInputChannelBroken(InputChannel inputChannel) {
5080 synchronized (mWindowMap) {
5081 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5082 if (windowState == null) {
5083 return; // irrelevant
5084 }
5085
5086 Slog.i(TAG, "WINDOW DIED " + windowState);
5087 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005088 }
5089 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005090
Jeff Brown349703e2010-06-22 01:27:15 -07005091 /* Notifies the window manager about an input channel that is not responding.
5092 * The method can either cause dispatching to be aborted by returning -2 or
5093 * return a new timeout in nanoseconds.
5094 *
5095 * Called by the InputManager.
5096 */
5097 public long notifyInputChannelANR(InputChannel inputChannel) {
5098 AppWindowToken token;
5099 synchronized (mWindowMap) {
5100 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5101 if (windowState == null) {
5102 return -2; // irrelevant, abort dispatching (-2)
5103 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005104
Jeff Brown349703e2010-06-22 01:27:15 -07005105 Slog.i(TAG, "Input event dispatching timed out sending to "
5106 + windowState.mAttrs.getTitle());
5107 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005108 }
5109
Jeff Brown349703e2010-06-22 01:27:15 -07005110 return notifyANRInternal(token);
5111 }
5112
5113 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5114 * by successfully delivering the event that originally timed out.
5115 *
5116 * Called by the InputManager.
5117 */
5118 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5119 // Nothing to do just now.
5120 // Just wait for the user to dismiss the ANR dialog.
5121 }
5122
5123 /* Notifies the window manager about an application that is not responding
5124 * in general rather than with respect to a particular input channel.
5125 * The method can either cause dispatching to be aborted by returning -2 or
5126 * return a new timeout in nanoseconds.
5127 *
5128 * Called by the InputManager.
5129 */
5130 public long notifyANR(Object token) {
5131 AppWindowToken appWindowToken = (AppWindowToken) token;
5132
5133 Slog.i(TAG, "Input event dispatching timed out sending to application "
5134 + appWindowToken.stringName);
5135 return notifyANRInternal(appWindowToken);
5136 }
5137
5138 private long notifyANRInternal(AppWindowToken token) {
5139 if (token != null && token.appToken != null) {
5140 try {
5141 // Notify the activity manager about the timeout and let it decide whether
5142 // to abort dispatching or keep waiting.
5143 boolean abort = token.appToken.keyDispatchingTimedOut();
5144 if (! abort) {
5145 // The activity manager declined to abort dispatching.
5146 // Wait a bit longer and timeout again later.
5147 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005148 }
Jeff Brown349703e2010-06-22 01:27:15 -07005149 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005150 }
5151 }
Jeff Brown349703e2010-06-22 01:27:15 -07005152 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005153 }
5154
Jeff Brown349703e2010-06-22 01:27:15 -07005155 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5156 synchronized (mWindowMap) {
5157 return getWindowStateForInputChannelLocked(inputChannel);
5158 }
5159 }
5160
5161 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5162 int windowCount = mWindows.size();
5163 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005164 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005165 if (windowState.mInputChannel == inputChannel) {
5166 return windowState;
5167 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005168 }
5169
Jeff Brown349703e2010-06-22 01:27:15 -07005170 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005171 }
5172
Jeff Brown349703e2010-06-22 01:27:15 -07005173 /* Updates the cached window information provided to the input dispatcher. */
5174 public void updateInputWindowsLw() {
5175 // Populate the input window list with information about all of the windows that
5176 // could potentially receive input.
5177 // As an optimization, we could try to prune the list of windows but this turns
5178 // out to be difficult because only the native code knows for sure which window
5179 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005180 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005181 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005182 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005183 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005184 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005185 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005186 continue;
5187 }
5188
Jeff Brown349703e2010-06-22 01:27:15 -07005189 final int flags = child.mAttrs.flags;
5190 final int type = child.mAttrs.type;
5191
5192 final boolean hasFocus = (child == mInputFocus);
5193 final boolean isVisible = child.isVisibleLw();
5194 final boolean hasWallpaper = (child == mWallpaperTarget)
5195 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5196
5197 // Add a window to our list of input windows.
5198 final InputWindow inputWindow = mTempInputWindows.add();
5199 inputWindow.inputChannel = child.mInputChannel;
5200 inputWindow.layoutParamsFlags = flags;
5201 inputWindow.layoutParamsType = type;
5202 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5203 inputWindow.visible = isVisible;
5204 inputWindow.hasFocus = hasFocus;
5205 inputWindow.hasWallpaper = hasWallpaper;
5206 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5207 inputWindow.ownerPid = child.mSession.mPid;
5208 inputWindow.ownerUid = child.mSession.mUid;
5209
5210 final Rect frame = child.mFrame;
5211 inputWindow.frameLeft = frame.left;
5212 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005213 inputWindow.frameRight = frame.right;
5214 inputWindow.frameBottom = frame.bottom;
5215
5216 final Rect visibleFrame = child.mVisibleFrame;
5217 inputWindow.visibleFrameLeft = visibleFrame.left;
5218 inputWindow.visibleFrameTop = visibleFrame.top;
5219 inputWindow.visibleFrameRight = visibleFrame.right;
5220 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005221
5222 switch (child.mTouchableInsets) {
5223 default:
5224 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5225 inputWindow.touchableAreaLeft = frame.left;
5226 inputWindow.touchableAreaTop = frame.top;
5227 inputWindow.touchableAreaRight = frame.right;
5228 inputWindow.touchableAreaBottom = frame.bottom;
5229 break;
5230
5231 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5232 Rect inset = child.mGivenContentInsets;
5233 inputWindow.touchableAreaLeft = frame.left + inset.left;
5234 inputWindow.touchableAreaTop = frame.top + inset.top;
5235 inputWindow.touchableAreaRight = frame.right - inset.right;
5236 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5237 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005238 }
Jeff Brown349703e2010-06-22 01:27:15 -07005239
5240 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5241 Rect inset = child.mGivenVisibleInsets;
5242 inputWindow.touchableAreaLeft = frame.left + inset.left;
5243 inputWindow.touchableAreaTop = frame.top + inset.top;
5244 inputWindow.touchableAreaRight = frame.right - inset.right;
5245 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005246 break;
5247 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005248 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005249 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005250
Jeff Brown349703e2010-06-22 01:27:15 -07005251 // Send windows to native code.
5252 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005253
Jeff Brown349703e2010-06-22 01:27:15 -07005254 // Clear the list in preparation for the next round.
5255 // Also avoids keeping InputChannel objects referenced unnecessarily.
5256 mTempInputWindows.clear();
5257 }
5258
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005259 /* Provides feedback for a virtual key down. */
5260 public void virtualKeyDownFeedback() {
5261 synchronized (mWindowMap) {
5262 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5263 }
5264 }
5265
Jeff Brown349703e2010-06-22 01:27:15 -07005266 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5267 * This essentially starts a .5 second timeout for the application to process
5268 * subsequent input events while waiting for the app switch to occur. If it takes longer
5269 * than this, the pending events will be dropped.
5270 */
5271 public void notifyAppSwitchComing() {
5272 // TODO Not implemented yet. Should go in the native side.
5273 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005274
5275 /* Notifies that the lid switch changed state. */
5276 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5277 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5278 }
5279
Jeff Brown349703e2010-06-22 01:27:15 -07005280 /* Provides an opportunity for the window manager policy to intercept early key
5281 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005282 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5283 int policyFlags, boolean isScreenOn) {
5284 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5285 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005286 }
5287
5288 /* Provides an opportunity for the window manager policy to process a key before
5289 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005290 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5291 int action, int flags, int keyCode, int metaState, int repeatCount,
5292 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005293 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005294 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5295 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005296 }
5297
5298 /* Called when the current input focus changes.
5299 * Layer assignment is assumed to be complete by the time this is called.
5300 */
5301 public void setInputFocusLw(WindowState newWindow) {
5302 if (DEBUG_INPUT) {
5303 Slog.d(TAG, "Input focus has changed to " + newWindow);
5304 }
5305
5306 if (newWindow != mInputFocus) {
5307 if (newWindow != null && newWindow.canReceiveKeys()) {
5308 // If the new input focus is an error window or appears above the current
5309 // input focus, preempt any pending synchronous dispatch so that we can
5310 // start delivering events to the new input focus as soon as possible.
5311 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5312 if (DEBUG_INPUT) {
5313 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005314 }
Jeff Brown349703e2010-06-22 01:27:15 -07005315 preemptInputDispatchLw();
5316 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5317 if (DEBUG_INPUT) {
5318 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5319 + "old win layer=" + mInputFocus.mLayer
5320 + ", new win layer=" + newWindow.mLayer);
5321 }
5322 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005323 }
Jeff Brown349703e2010-06-22 01:27:15 -07005324
5325 // Displaying a window implicitly causes dispatching to be unpaused.
5326 // This is to protect against bugs if someone pauses dispatching but
5327 // forgets to resume.
5328 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005329 }
Jeff Brown349703e2010-06-22 01:27:15 -07005330
5331 mInputFocus = newWindow;
5332 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005333 }
5334 }
5335
Jeff Brown349703e2010-06-22 01:27:15 -07005336 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5337 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5338 * can begin.
5339 */
5340 private void preemptInputDispatchLw() {
5341 mInputManager.preemptInputDispatch();
5342 }
5343
5344 public void setFocusedAppLw(AppWindowToken newApp) {
5345 // Focused app has changed.
5346 if (newApp == null) {
5347 mInputManager.setFocusedApplication(null);
5348 } else {
5349 mTempInputApplication.name = newApp.toString();
5350 mTempInputApplication.dispatchingTimeoutNanos =
5351 newApp.inputDispatchingTimeoutNanos;
5352 mTempInputApplication.token = newApp;
5353
5354 mInputManager.setFocusedApplication(mTempInputApplication);
5355 }
5356 }
5357
Jeff Brown349703e2010-06-22 01:27:15 -07005358 public void pauseDispatchingLw(WindowToken window) {
5359 if (! window.paused) {
5360 if (DEBUG_INPUT) {
5361 Slog.v(TAG, "Pausing WindowToken " + window);
5362 }
5363
5364 window.paused = true;
5365 updateInputWindowsLw();
5366 }
5367 }
5368
5369 public void resumeDispatchingLw(WindowToken window) {
5370 if (window.paused) {
5371 if (DEBUG_INPUT) {
5372 Slog.v(TAG, "Resuming WindowToken " + window);
5373 }
5374
5375 window.paused = false;
5376 updateInputWindowsLw();
5377 }
5378 }
5379
5380 public void freezeInputDispatchingLw() {
5381 if (! mInputDispatchFrozen) {
5382 if (DEBUG_INPUT) {
5383 Slog.v(TAG, "Freezing input dispatching");
5384 }
5385
5386 mInputDispatchFrozen = true;
5387 updateInputDispatchModeLw();
5388 }
5389 }
5390
5391 public void thawInputDispatchingLw() {
5392 if (mInputDispatchFrozen) {
5393 if (DEBUG_INPUT) {
5394 Slog.v(TAG, "Thawing input dispatching");
5395 }
5396
5397 mInputDispatchFrozen = false;
5398 updateInputDispatchModeLw();
5399 }
5400 }
5401
5402 public void setEventDispatchingLw(boolean enabled) {
5403 if (mInputDispatchEnabled != enabled) {
5404 if (DEBUG_INPUT) {
5405 Slog.v(TAG, "Setting event dispatching to " + enabled);
5406 }
5407
5408 mInputDispatchEnabled = enabled;
5409 updateInputDispatchModeLw();
5410 }
5411 }
5412
5413 private void updateInputDispatchModeLw() {
5414 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5415 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005418 public void pauseKeyDispatching(IBinder _token) {
5419 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5420 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005421 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422 }
5423
5424 synchronized (mWindowMap) {
5425 WindowToken token = mTokenMap.get(_token);
5426 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005427 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005428 }
5429 }
5430 }
5431
5432 public void resumeKeyDispatching(IBinder _token) {
5433 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5434 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005435 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 }
5437
5438 synchronized (mWindowMap) {
5439 WindowToken token = mTokenMap.get(_token);
5440 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005441 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 }
5443 }
5444 }
5445
5446 public void setEventDispatching(boolean enabled) {
5447 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5448 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005449 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005450 }
5451
5452 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005453 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005454 }
5455 }
Romain Guy06882f82009-06-10 13:36:04 -07005456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 /**
5458 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005459 * Even when sync is false, this method may block while waiting for current
5460 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005461 *
5462 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005463 * {@link SystemClock#uptimeMillis()} as the timebase.)
5464 * @param sync If true, wait for the event to be completed before returning to the caller.
5465 * @return Returns true if event was dispatched, false if it was dropped for any reason
5466 */
5467 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5468 long downTime = ev.getDownTime();
5469 long eventTime = ev.getEventTime();
5470
5471 int action = ev.getAction();
5472 int code = ev.getKeyCode();
5473 int repeatCount = ev.getRepeatCount();
5474 int metaState = ev.getMetaState();
5475 int deviceId = ev.getDeviceId();
5476 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005477 int source = ev.getSource();
5478
5479 if (source == InputDevice.SOURCE_UNKNOWN) {
5480 source = InputDevice.SOURCE_KEYBOARD;
5481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482
5483 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5484 if (downTime == 0) downTime = eventTime;
5485
5486 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005487 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005488
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005489 final int pid = Binder.getCallingPid();
5490 final int uid = Binder.getCallingUid();
5491 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005492
Jeff Brownbbda99d2010-07-28 15:48:59 -07005493 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5494 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5495 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5496 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005497
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005498 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005499 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005500 }
5501
5502 /**
5503 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005504 * Even when sync is false, this method may block while waiting for current
5505 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005506 *
5507 * @param ev A motion event describing the pointer (touch) action. (As noted in
5508 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005509 * {@link SystemClock#uptimeMillis()} as the timebase.)
5510 * @param sync If true, wait for the event to be completed before returning to the caller.
5511 * @return Returns true if event was dispatched, false if it was dropped for any reason
5512 */
5513 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005514 final int pid = Binder.getCallingPid();
5515 final int uid = Binder.getCallingUid();
5516 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005517
Jeff Brownc5ed5912010-07-14 18:48:53 -07005518 MotionEvent newEvent = MotionEvent.obtain(ev);
5519 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5520 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5521 }
5522
Jeff Brownbbda99d2010-07-28 15:48:59 -07005523 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5524 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5525 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5526 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005527
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005528 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005529 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530 }
Romain Guy06882f82009-06-10 13:36:04 -07005531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005532 /**
5533 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005534 * Even when sync is false, this method may block while waiting for current
5535 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005536 *
5537 * @param ev A motion event describing the trackball action. (As noted in
5538 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 * {@link SystemClock#uptimeMillis()} as the timebase.)
5540 * @param sync If true, wait for the event to be completed before returning to the caller.
5541 * @return Returns true if event was dispatched, false if it was dropped for any reason
5542 */
5543 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005544 final int pid = Binder.getCallingPid();
5545 final int uid = Binder.getCallingUid();
5546 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005547
Jeff Brownc5ed5912010-07-14 18:48:53 -07005548 MotionEvent newEvent = MotionEvent.obtain(ev);
5549 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5550 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5551 }
5552
Jeff Brownbbda99d2010-07-28 15:48:59 -07005553 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5554 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5555 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5556 INJECTION_TIMEOUT_MILLIS);
5557
5558 Binder.restoreCallingIdentity(ident);
5559 return reportInjectionResult(result);
5560 }
5561
5562 /**
5563 * Inject an input event into the UI without waiting for dispatch to commence.
5564 * This variant is useful for fire-and-forget input event injection. It does not
5565 * block any longer than it takes to enqueue the input event.
5566 *
5567 * @param ev An input event. (Be sure to set the input source correctly.)
5568 * @return Returns true if event was dispatched, false if it was dropped for any reason
5569 */
5570 public boolean injectInputEventNoWait(InputEvent ev) {
5571 final int pid = Binder.getCallingPid();
5572 final int uid = Binder.getCallingUid();
5573 final long ident = Binder.clearCallingIdentity();
5574
5575 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5576 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5577 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005578
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005579 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005580 return reportInjectionResult(result);
5581 }
5582
5583 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005584 switch (result) {
5585 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5586 Slog.w(TAG, "Input event injection permission denied.");
5587 throw new SecurityException(
5588 "Injecting to another application requires INJECT_EVENTS permission");
5589 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005590 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005591 return true;
5592 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5593 Slog.w(TAG, "Input event injection timed out.");
5594 return false;
5595 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5596 default:
5597 Slog.w(TAG, "Input event injection failed.");
5598 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005600 }
Romain Guy06882f82009-06-10 13:36:04 -07005601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005602 private WindowState getFocusedWindow() {
5603 synchronized (mWindowMap) {
5604 return getFocusedWindowLocked();
5605 }
5606 }
5607
5608 private WindowState getFocusedWindowLocked() {
5609 return mCurrentFocus;
5610 }
Romain Guy06882f82009-06-10 13:36:04 -07005611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005612 public boolean detectSafeMode() {
5613 mSafeMode = mPolicy.detectSafeMode();
5614 return mSafeMode;
5615 }
Romain Guy06882f82009-06-10 13:36:04 -07005616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005617 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005618 synchronized(mWindowMap) {
5619 if (mDisplay != null) {
5620 throw new IllegalStateException("Display already initialized");
5621 }
5622 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5623 mDisplay = wm.getDefaultDisplay();
5624 mInitialDisplayWidth = mDisplay.getWidth();
5625 mInitialDisplayHeight = mDisplay.getHeight();
5626 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
5627 }
5628
5629 try {
5630 mActivityManager.updateConfiguration(null);
5631 } catch (RemoteException e) {
5632 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005633
5634 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005635 }
5636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005637 // -------------------------------------------------------------
5638 // Client Session State
5639 // -------------------------------------------------------------
5640
5641 private final class Session extends IWindowSession.Stub
5642 implements IBinder.DeathRecipient {
5643 final IInputMethodClient mClient;
5644 final IInputContext mInputContext;
5645 final int mUid;
5646 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005647 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005648 SurfaceSession mSurfaceSession;
5649 int mNumWindow = 0;
5650 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005652 public Session(IInputMethodClient client, IInputContext inputContext) {
5653 mClient = client;
5654 mInputContext = inputContext;
5655 mUid = Binder.getCallingUid();
5656 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005657 StringBuilder sb = new StringBuilder();
5658 sb.append("Session{");
5659 sb.append(Integer.toHexString(System.identityHashCode(this)));
5660 sb.append(" uid ");
5661 sb.append(mUid);
5662 sb.append("}");
5663 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005665 synchronized (mWindowMap) {
5666 if (mInputMethodManager == null && mHaveInputMethods) {
5667 IBinder b = ServiceManager.getService(
5668 Context.INPUT_METHOD_SERVICE);
5669 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5670 }
5671 }
5672 long ident = Binder.clearCallingIdentity();
5673 try {
5674 // Note: it is safe to call in to the input method manager
5675 // here because we are not holding our lock.
5676 if (mInputMethodManager != null) {
5677 mInputMethodManager.addClient(client, inputContext,
5678 mUid, mPid);
5679 } else {
5680 client.setUsingInputMethod(false);
5681 }
5682 client.asBinder().linkToDeath(this, 0);
5683 } catch (RemoteException e) {
5684 // The caller has died, so we can just forget about this.
5685 try {
5686 if (mInputMethodManager != null) {
5687 mInputMethodManager.removeClient(client);
5688 }
5689 } catch (RemoteException ee) {
5690 }
5691 } finally {
5692 Binder.restoreCallingIdentity(ident);
5693 }
5694 }
Romain Guy06882f82009-06-10 13:36:04 -07005695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005696 @Override
5697 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5698 throws RemoteException {
5699 try {
5700 return super.onTransact(code, data, reply, flags);
5701 } catch (RuntimeException e) {
5702 // Log all 'real' exceptions thrown to the caller
5703 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005704 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 }
5706 throw e;
5707 }
5708 }
5709
5710 public void binderDied() {
5711 // Note: it is safe to call in to the input method manager
5712 // here because we are not holding our lock.
5713 try {
5714 if (mInputMethodManager != null) {
5715 mInputMethodManager.removeClient(mClient);
5716 }
5717 } catch (RemoteException e) {
5718 }
5719 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005720 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005721 mClientDead = true;
5722 killSessionLocked();
5723 }
5724 }
5725
5726 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005727 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5728 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5729 outInputChannel);
5730 }
5731
5732 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005734 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005735 }
Romain Guy06882f82009-06-10 13:36:04 -07005736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 public void remove(IWindow window) {
5738 removeWindow(this, window);
5739 }
Romain Guy06882f82009-06-10 13:36:04 -07005740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005741 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5742 int requestedWidth, int requestedHeight, int viewFlags,
5743 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005744 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005745 return relayoutWindow(this, window, attrs,
5746 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005747 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005748 }
Romain Guy06882f82009-06-10 13:36:04 -07005749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005750 public void setTransparentRegion(IWindow window, Region region) {
5751 setTransparentRegionWindow(this, window, region);
5752 }
Romain Guy06882f82009-06-10 13:36:04 -07005753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005754 public void setInsets(IWindow window, int touchableInsets,
5755 Rect contentInsets, Rect visibleInsets) {
5756 setInsetsWindow(this, window, touchableInsets, contentInsets,
5757 visibleInsets);
5758 }
Romain Guy06882f82009-06-10 13:36:04 -07005759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005760 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5761 getWindowDisplayFrame(this, window, outDisplayFrame);
5762 }
Romain Guy06882f82009-06-10 13:36:04 -07005763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005764 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005765 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005766 TAG, "IWindow finishDrawing called for " + window);
5767 finishDrawingWindow(this, window);
5768 }
5769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005770 public void setInTouchMode(boolean mode) {
5771 synchronized(mWindowMap) {
5772 mInTouchMode = mode;
5773 }
5774 }
5775
5776 public boolean getInTouchMode() {
5777 synchronized(mWindowMap) {
5778 return mInTouchMode;
5779 }
5780 }
5781
5782 public boolean performHapticFeedback(IWindow window, int effectId,
5783 boolean always) {
5784 synchronized(mWindowMap) {
5785 long ident = Binder.clearCallingIdentity();
5786 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005787 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005788 windowForClientLocked(this, window, true),
5789 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005790 } finally {
5791 Binder.restoreCallingIdentity(ident);
5792 }
5793 }
5794 }
Romain Guy06882f82009-06-10 13:36:04 -07005795
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005796 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005797 synchronized(mWindowMap) {
5798 long ident = Binder.clearCallingIdentity();
5799 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005800 setWindowWallpaperPositionLocked(
5801 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005802 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005803 } finally {
5804 Binder.restoreCallingIdentity(ident);
5805 }
5806 }
5807 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005808
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005809 public void wallpaperOffsetsComplete(IBinder window) {
5810 WindowManagerService.this.wallpaperOffsetsComplete(window);
5811 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005812
Dianne Hackborn75804932009-10-20 20:15:20 -07005813 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5814 int z, Bundle extras, boolean sync) {
5815 synchronized(mWindowMap) {
5816 long ident = Binder.clearCallingIdentity();
5817 try {
5818 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005819 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005820 action, x, y, z, extras, sync);
5821 } finally {
5822 Binder.restoreCallingIdentity(ident);
5823 }
5824 }
5825 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005826
Dianne Hackborn75804932009-10-20 20:15:20 -07005827 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5828 WindowManagerService.this.wallpaperCommandComplete(window, result);
5829 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 void windowAddedLocked() {
5832 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005833 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 TAG, "First window added to " + this + ", creating SurfaceSession");
5835 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005836 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005837 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 mSessions.add(this);
5839 }
5840 mNumWindow++;
5841 }
5842
5843 void windowRemovedLocked() {
5844 mNumWindow--;
5845 killSessionLocked();
5846 }
Romain Guy06882f82009-06-10 13:36:04 -07005847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005848 void killSessionLocked() {
5849 if (mNumWindow <= 0 && mClientDead) {
5850 mSessions.remove(this);
5851 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005852 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005853 TAG, "Last window removed from " + this
5854 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005855 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005856 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005857 try {
5858 mSurfaceSession.kill();
5859 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005860 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005861 + mSurfaceSession + " in session " + this
5862 + ": " + e.toString());
5863 }
5864 mSurfaceSession = null;
5865 }
5866 }
5867 }
Romain Guy06882f82009-06-10 13:36:04 -07005868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005869 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005870 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5871 pw.print(" mClientDead="); pw.print(mClientDead);
5872 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005873 }
5874
5875 @Override
5876 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005877 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005878 }
5879 }
5880
5881 // -------------------------------------------------------------
5882 // Client Window State
5883 // -------------------------------------------------------------
5884
5885 private final class WindowState implements WindowManagerPolicy.WindowState {
5886 final Session mSession;
5887 final IWindow mClient;
5888 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005889 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005890 AppWindowToken mAppToken;
5891 AppWindowToken mTargetAppToken;
5892 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5893 final DeathRecipient mDeathRecipient;
5894 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005895 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005896 final int mBaseLayer;
5897 final int mSubLayer;
5898 final boolean mLayoutAttached;
5899 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005900 final boolean mIsWallpaper;
5901 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 int mViewVisibility;
5903 boolean mPolicyVisibility = true;
5904 boolean mPolicyVisibilityAfterAnim = true;
5905 boolean mAppFreezing;
5906 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005907 boolean mReportDestroySurface;
5908 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005909 boolean mAttachedHidden; // is our parent window hidden?
5910 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005911 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005912 int mRequestedWidth;
5913 int mRequestedHeight;
5914 int mLastRequestedWidth;
5915 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005916 int mLayer;
5917 int mAnimLayer;
5918 int mLastLayer;
5919 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005920 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005921 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005922
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005923 int mLayoutSeq = -1;
5924
5925 Configuration mConfiguration = null;
5926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 // Actual frame shown on-screen (may be modified by animation)
5928 final Rect mShownFrame = new Rect();
5929 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005931 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005932 * Set when we have changed the size of the surface, to know that
5933 * we must tell them application to resize (and thus redraw itself).
5934 */
5935 boolean mSurfaceResized;
5936
5937 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005938 * Insets that determine the actually visible area
5939 */
5940 final Rect mVisibleInsets = new Rect();
5941 final Rect mLastVisibleInsets = new Rect();
5942 boolean mVisibleInsetsChanged;
5943
5944 /**
5945 * Insets that are covered by system windows
5946 */
5947 final Rect mContentInsets = new Rect();
5948 final Rect mLastContentInsets = new Rect();
5949 boolean mContentInsetsChanged;
5950
5951 /**
5952 * Set to true if we are waiting for this window to receive its
5953 * given internal insets before laying out other windows based on it.
5954 */
5955 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005957 /**
5958 * These are the content insets that were given during layout for
5959 * this window, to be applied to windows behind it.
5960 */
5961 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 /**
5964 * These are the visible insets that were given during layout for
5965 * this window, to be applied to windows behind it.
5966 */
5967 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005969 /**
5970 * Flag indicating whether the touchable region should be adjusted by
5971 * the visible insets; if false the area outside the visible insets is
5972 * NOT touchable, so we must use those to adjust the frame during hit
5973 * tests.
5974 */
5975 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005977 // Current transformation being applied.
5978 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5979 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5980 float mHScale=1, mVScale=1;
5981 float mLastHScale=1, mLastVScale=1;
5982 final Matrix mTmpMatrix = new Matrix();
5983
5984 // "Real" frame that the application sees.
5985 final Rect mFrame = new Rect();
5986 final Rect mLastFrame = new Rect();
5987
5988 final Rect mContainingFrame = new Rect();
5989 final Rect mDisplayFrame = new Rect();
5990 final Rect mContentFrame = new Rect();
5991 final Rect mVisibleFrame = new Rect();
5992
5993 float mShownAlpha = 1;
5994 float mAlpha = 1;
5995 float mLastAlpha = 1;
5996
5997 // Set to true if, when the window gets displayed, it should perform
5998 // an enter animation.
5999 boolean mEnterAnimationPending;
6000
6001 // Currently running animation.
6002 boolean mAnimating;
6003 boolean mLocalAnimating;
6004 Animation mAnimation;
6005 boolean mAnimationIsEntrance;
6006 boolean mHasTransformation;
6007 boolean mHasLocalTransformation;
6008 final Transformation mTransformation = new Transformation();
6009
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006010 // If a window showing a wallpaper: the requested offset for the
6011 // wallpaper; if a wallpaper window: the currently applied offset.
6012 float mWallpaperX = -1;
6013 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006014
6015 // If a window showing a wallpaper: what fraction of the offset
6016 // range corresponds to a full virtual screen.
6017 float mWallpaperXStep = -1;
6018 float mWallpaperYStep = -1;
6019
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006020 // Wallpaper windows: pixels offset based on above variables.
6021 int mXOffset;
6022 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006024 // This is set after IWindowSession.relayout() has been called at
6025 // least once for the window. It allows us to detect the situation
6026 // where we don't yet have a surface, but should have one soon, so
6027 // we can give the window focus before waiting for the relayout.
6028 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006030 // This is set after the Surface has been created but before the
6031 // window has been drawn. During this time the surface is hidden.
6032 boolean mDrawPending;
6033
6034 // This is set after the window has finished drawing for the first
6035 // time but before its surface is shown. The surface will be
6036 // displayed when the next layout is run.
6037 boolean mCommitDrawPending;
6038
6039 // This is set during the time after the window's drawing has been
6040 // committed, and before its surface is actually shown. It is used
6041 // to delay showing the surface until all windows in a token are ready
6042 // to be shown.
6043 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 // Set when the window has been shown in the screen the first time.
6046 boolean mHasDrawn;
6047
6048 // Currently running an exit animation?
6049 boolean mExiting;
6050
6051 // Currently on the mDestroySurface list?
6052 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006054 // Completely remove from window manager after exit animation?
6055 boolean mRemoveOnExit;
6056
6057 // Set when the orientation is changing and this window has not yet
6058 // been updated for the new orientation.
6059 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006061 // Is this window now (or just being) removed?
6062 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006063
Dianne Hackborn16064f92010-03-25 00:47:24 -07006064 // For debugging, this is the last information given to the surface flinger.
6065 boolean mSurfaceShown;
6066 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6067 int mSurfaceLayer;
6068 float mSurfaceAlpha;
6069
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006070 // Input channel
6071 InputChannel mInputChannel;
6072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 WindowState(Session s, IWindow c, WindowToken token,
6074 WindowState attachedWindow, WindowManager.LayoutParams a,
6075 int viewVisibility) {
6076 mSession = s;
6077 mClient = c;
6078 mToken = token;
6079 mAttrs.copyFrom(a);
6080 mViewVisibility = viewVisibility;
6081 DeathRecipient deathRecipient = new DeathRecipient();
6082 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006083 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 TAG, "Window " + this + " client=" + c.asBinder()
6085 + " token=" + token + " (" + mAttrs.token + ")");
6086 try {
6087 c.asBinder().linkToDeath(deathRecipient, 0);
6088 } catch (RemoteException e) {
6089 mDeathRecipient = null;
6090 mAttachedWindow = null;
6091 mLayoutAttached = false;
6092 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006093 mIsWallpaper = false;
6094 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095 mBaseLayer = 0;
6096 mSubLayer = 0;
6097 return;
6098 }
6099 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6102 mAttrs.type <= LAST_SUB_WINDOW)) {
6103 // The multiplier here is to reserve space for multiple
6104 // windows in the same type layer.
6105 mBaseLayer = mPolicy.windowTypeToLayerLw(
6106 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6107 + TYPE_LAYER_OFFSET;
6108 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6109 mAttachedWindow = attachedWindow;
6110 mAttachedWindow.mChildWindows.add(this);
6111 mLayoutAttached = mAttrs.type !=
6112 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6113 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6114 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006115 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6116 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 } else {
6118 // The multiplier here is to reserve space for multiple
6119 // windows in the same type layer.
6120 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6121 * TYPE_LAYER_MULTIPLIER
6122 + TYPE_LAYER_OFFSET;
6123 mSubLayer = 0;
6124 mAttachedWindow = null;
6125 mLayoutAttached = false;
6126 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6127 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006128 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6129 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006130 }
6131
6132 WindowState appWin = this;
6133 while (appWin.mAttachedWindow != null) {
6134 appWin = mAttachedWindow;
6135 }
6136 WindowToken appToken = appWin.mToken;
6137 while (appToken.appWindowToken == null) {
6138 WindowToken parent = mTokenMap.get(appToken.token);
6139 if (parent == null || appToken == parent) {
6140 break;
6141 }
6142 appToken = parent;
6143 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006144 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006145 mAppToken = appToken.appWindowToken;
6146
6147 mSurface = null;
6148 mRequestedWidth = 0;
6149 mRequestedHeight = 0;
6150 mLastRequestedWidth = 0;
6151 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006152 mXOffset = 0;
6153 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 mLayer = 0;
6155 mAnimLayer = 0;
6156 mLastLayer = 0;
6157 }
6158
6159 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006160 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006161 TAG, "Attaching " + this + " token=" + mToken
6162 + ", list=" + mToken.windows);
6163 mSession.windowAddedLocked();
6164 }
6165
6166 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6167 mHaveFrame = true;
6168
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006169 final Rect container = mContainingFrame;
6170 container.set(pf);
6171
6172 final Rect display = mDisplayFrame;
6173 display.set(df);
6174
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006175 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006176 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006177 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6178 display.intersect(mCompatibleScreenFrame);
6179 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006180 }
6181
6182 final int pw = container.right - container.left;
6183 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006184
6185 int w,h;
6186 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6187 w = mAttrs.width < 0 ? pw : mAttrs.width;
6188 h = mAttrs.height< 0 ? ph : mAttrs.height;
6189 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006190 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6191 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006192 }
Romain Guy06882f82009-06-10 13:36:04 -07006193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 final Rect content = mContentFrame;
6195 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006197 final Rect visible = mVisibleFrame;
6198 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006201 final int fw = frame.width();
6202 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6205 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6206
6207 Gravity.apply(mAttrs.gravity, w, h, container,
6208 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6209 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6210
6211 //System.out.println("Out: " + mFrame);
6212
6213 // Now make sure the window fits in the overall display.
6214 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 // Make sure the content and visible frames are inside of the
6217 // final window frame.
6218 if (content.left < frame.left) content.left = frame.left;
6219 if (content.top < frame.top) content.top = frame.top;
6220 if (content.right > frame.right) content.right = frame.right;
6221 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6222 if (visible.left < frame.left) visible.left = frame.left;
6223 if (visible.top < frame.top) visible.top = frame.top;
6224 if (visible.right > frame.right) visible.right = frame.right;
6225 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006227 final Rect contentInsets = mContentInsets;
6228 contentInsets.left = content.left-frame.left;
6229 contentInsets.top = content.top-frame.top;
6230 contentInsets.right = frame.right-content.right;
6231 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 final Rect visibleInsets = mVisibleInsets;
6234 visibleInsets.left = visible.left-frame.left;
6235 visibleInsets.top = visible.top-frame.top;
6236 visibleInsets.right = frame.right-visible.right;
6237 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006238
Dianne Hackborn284ac932009-08-28 10:34:25 -07006239 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6240 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006241 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006242 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006244 if (localLOGV) {
6245 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6246 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006247 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006248 + mRequestedWidth + ", mRequestedheight="
6249 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6250 + "): frame=" + mFrame.toShortString()
6251 + " ci=" + contentInsets.toShortString()
6252 + " vi=" + visibleInsets.toShortString());
6253 //}
6254 }
6255 }
Romain Guy06882f82009-06-10 13:36:04 -07006256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006257 public Rect getFrameLw() {
6258 return mFrame;
6259 }
6260
6261 public Rect getShownFrameLw() {
6262 return mShownFrame;
6263 }
6264
6265 public Rect getDisplayFrameLw() {
6266 return mDisplayFrame;
6267 }
6268
6269 public Rect getContentFrameLw() {
6270 return mContentFrame;
6271 }
6272
6273 public Rect getVisibleFrameLw() {
6274 return mVisibleFrame;
6275 }
6276
6277 public boolean getGivenInsetsPendingLw() {
6278 return mGivenInsetsPending;
6279 }
6280
6281 public Rect getGivenContentInsetsLw() {
6282 return mGivenContentInsets;
6283 }
Romain Guy06882f82009-06-10 13:36:04 -07006284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 public Rect getGivenVisibleInsetsLw() {
6286 return mGivenVisibleInsets;
6287 }
Romain Guy06882f82009-06-10 13:36:04 -07006288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 public WindowManager.LayoutParams getAttrs() {
6290 return mAttrs;
6291 }
6292
6293 public int getSurfaceLayer() {
6294 return mLayer;
6295 }
Romain Guy06882f82009-06-10 13:36:04 -07006296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 public IApplicationToken getAppToken() {
6298 return mAppToken != null ? mAppToken.appToken : null;
6299 }
Jeff Brown349703e2010-06-22 01:27:15 -07006300
6301 public long getInputDispatchingTimeoutNanos() {
6302 return mAppToken != null
6303 ? mAppToken.inputDispatchingTimeoutNanos
6304 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6305 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306
6307 public boolean hasAppShownWindows() {
6308 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6309 }
6310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006312 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 TAG, "Setting animation in " + this + ": " + anim);
6314 mAnimating = false;
6315 mLocalAnimating = false;
6316 mAnimation = anim;
6317 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6318 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6319 }
6320
6321 public void clearAnimation() {
6322 if (mAnimation != null) {
6323 mAnimating = true;
6324 mLocalAnimating = false;
6325 mAnimation = null;
6326 }
6327 }
Romain Guy06882f82009-06-10 13:36:04 -07006328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 Surface createSurfaceLocked() {
6330 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006331 mReportDestroySurface = false;
6332 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333 mDrawPending = true;
6334 mCommitDrawPending = false;
6335 mReadyToShow = false;
6336 if (mAppToken != null) {
6337 mAppToken.allDrawn = false;
6338 }
6339
6340 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006341 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 flags |= Surface.PUSH_BUFFERS;
6343 }
6344
6345 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6346 flags |= Surface.SECURE;
6347 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006348 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 TAG, "Creating surface in session "
6350 + mSession.mSurfaceSession + " window " + this
6351 + " w=" + mFrame.width()
6352 + " h=" + mFrame.height() + " format="
6353 + mAttrs.format + " flags=" + flags);
6354
6355 int w = mFrame.width();
6356 int h = mFrame.height();
6357 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6358 // for a scaled surface, we always want the requested
6359 // size.
6360 w = mRequestedWidth;
6361 h = mRequestedHeight;
6362 }
6363
Romain Guy9825ec62009-10-01 00:58:09 -07006364 // Something is wrong and SurfaceFlinger will not like this,
6365 // try to revert to sane values
6366 if (w <= 0) w = 1;
6367 if (h <= 0) h = 1;
6368
Dianne Hackborn16064f92010-03-25 00:47:24 -07006369 mSurfaceShown = false;
6370 mSurfaceLayer = 0;
6371 mSurfaceAlpha = 1;
6372 mSurfaceX = 0;
6373 mSurfaceY = 0;
6374 mSurfaceW = w;
6375 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 try {
6377 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006378 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006379 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006381 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006382 + mSurface + " IN SESSION "
6383 + mSession.mSurfaceSession
6384 + ": pid=" + mSession.mPid + " format="
6385 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006386 + Integer.toHexString(flags)
6387 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006388 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006389 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006390 reclaimSomeSurfaceMemoryLocked(this, "create");
6391 return null;
6392 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006393 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 return null;
6395 }
Romain Guy06882f82009-06-10 13:36:04 -07006396
Joe Onorato8a9b2202010-02-26 18:56:32 -08006397 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 TAG, "Got surface: " + mSurface
6399 + ", set left=" + mFrame.left + " top=" + mFrame.top
6400 + ", animLayer=" + mAnimLayer);
6401 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006402 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006403 if (SHOW_TRANSACTIONS) logSurface(this,
6404 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6405 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6406 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006407 }
6408 Surface.openTransaction();
6409 try {
6410 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006411 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006412 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006413 mSurface.setPosition(mSurfaceX, mSurfaceY);
6414 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006416 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006417 mSurface.hide();
6418 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006419 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 mSurface.setFlags(Surface.SURFACE_DITHER,
6421 Surface.SURFACE_DITHER);
6422 }
6423 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006424 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006425 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6426 }
6427 mLastHidden = true;
6428 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006429 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006430 Surface.closeTransaction();
6431 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006432 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 TAG, "Created surface " + this);
6434 }
6435 return mSurface;
6436 }
Romain Guy06882f82009-06-10 13:36:04 -07006437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 if (mAppToken != null && this == mAppToken.startingWindow) {
6440 mAppToken.startingDisplayed = false;
6441 }
Romain Guy06882f82009-06-10 13:36:04 -07006442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006444 mDrawPending = false;
6445 mCommitDrawPending = false;
6446 mReadyToShow = false;
6447
6448 int i = mChildWindows.size();
6449 while (i > 0) {
6450 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006451 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006452 c.mAttachedHidden = true;
6453 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006454
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006455 if (mReportDestroySurface) {
6456 mReportDestroySurface = false;
6457 mSurfacePendingDestroy = true;
6458 try {
6459 mClient.dispatchGetNewSurface();
6460 // We'll really destroy on the next time around.
6461 return;
6462 } catch (RemoteException e) {
6463 }
6464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006467 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006468 RuntimeException e = null;
6469 if (!HIDE_STACK_CRAWLS) {
6470 e = new RuntimeException();
6471 e.fillInStackTrace();
6472 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006473 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006474 + mSurface + ", session " + mSession, e);
6475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006477 RuntimeException e = null;
6478 if (!HIDE_STACK_CRAWLS) {
6479 e = new RuntimeException();
6480 e.fillInStackTrace();
6481 }
6482 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006484 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006485 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006486 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 + " surface " + mSurface + " session " + mSession
6488 + ": " + e.toString());
6489 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006490
Dianne Hackborn16064f92010-03-25 00:47:24 -07006491 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 }
6494 }
6495
6496 boolean finishDrawingLocked() {
6497 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006498 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 TAG, "finishDrawingLocked: " + mSurface);
6500 mCommitDrawPending = true;
6501 mDrawPending = false;
6502 return true;
6503 }
6504 return false;
6505 }
6506
6507 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006508 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006509 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006511 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 }
6513 mCommitDrawPending = false;
6514 mReadyToShow = true;
6515 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6516 final AppWindowToken atoken = mAppToken;
6517 if (atoken == null || atoken.allDrawn || starting) {
6518 performShowLocked();
6519 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006520 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 }
6522
6523 // This must be called while inside a transaction.
6524 boolean performShowLocked() {
6525 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006526 RuntimeException e = null;
6527 if (!HIDE_STACK_CRAWLS) {
6528 e = new RuntimeException();
6529 e.fillInStackTrace();
6530 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006531 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006532 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6533 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6534 }
6535 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006536 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6537 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006538 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006539 + " during animation: policyVis=" + mPolicyVisibility
6540 + " attHidden=" + mAttachedHidden
6541 + " tok.hiddenRequested="
6542 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006543 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006544 + (mAppToken != null ? mAppToken.hidden : false)
6545 + " animating=" + mAnimating
6546 + " tok animating="
6547 + (mAppToken != null ? mAppToken.animating : false));
6548 if (!showSurfaceRobustlyLocked(this)) {
6549 return false;
6550 }
6551 mLastAlpha = -1;
6552 mHasDrawn = true;
6553 mLastHidden = false;
6554 mReadyToShow = false;
6555 enableScreenIfNeededLocked();
6556
6557 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 int i = mChildWindows.size();
6560 while (i > 0) {
6561 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006562 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006563 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006564 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006565 if (c.mSurface != null) {
6566 c.performShowLocked();
6567 // It hadn't been shown, which means layout not
6568 // performed on it, so now we want to make sure to
6569 // do a layout. If called from within the transaction
6570 // loop, this will cause it to restart with a new
6571 // layout.
6572 mLayoutNeeded = true;
6573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 }
6575 }
Romain Guy06882f82009-06-10 13:36:04 -07006576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577 if (mAttrs.type != TYPE_APPLICATION_STARTING
6578 && mAppToken != null) {
6579 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006580
Dianne Hackborn248b1882009-09-16 16:46:44 -07006581 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006582 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006583 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006584 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006585 // If this initial window is animating, stop it -- we
6586 // will do an animation to reveal it from behind the
6587 // starting window, so there is no need for it to also
6588 // be doing its own stuff.
6589 if (mAnimation != null) {
6590 mAnimation = null;
6591 // Make sure we clean up the animation.
6592 mAnimating = true;
6593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 mFinishedStarting.add(mAppToken);
6595 mH.sendEmptyMessage(H.FINISHED_STARTING);
6596 }
6597 mAppToken.updateReportedVisibilityLocked();
6598 }
6599 }
6600 return true;
6601 }
Romain Guy06882f82009-06-10 13:36:04 -07006602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 // This must be called while inside a transaction. Returns true if
6604 // there is more animation to run.
6605 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006606 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006607 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6610 mHasTransformation = true;
6611 mHasLocalTransformation = true;
6612 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006613 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006614 TAG, "Starting animation in " + this +
6615 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6616 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6617 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6618 mAnimation.setStartTime(currentTime);
6619 mLocalAnimating = true;
6620 mAnimating = true;
6621 }
6622 mTransformation.clear();
6623 final boolean more = mAnimation.getTransformation(
6624 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006625 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 TAG, "Stepped animation in " + this +
6627 ": more=" + more + ", xform=" + mTransformation);
6628 if (more) {
6629 // we're not done!
6630 return true;
6631 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006632 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006633 TAG, "Finished animation in " + this +
6634 " @ " + currentTime);
6635 mAnimation = null;
6636 //WindowManagerService.this.dump();
6637 }
6638 mHasLocalTransformation = false;
6639 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006640 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006641 // When our app token is animating, we kind-of pretend like
6642 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6643 // part of this check means that we will only do this if
6644 // our window is not currently exiting, or it is not
6645 // locally animating itself. The idea being that one that
6646 // is exiting and doing a local animation should be removed
6647 // once that animation is done.
6648 mAnimating = true;
6649 mHasTransformation = true;
6650 mTransformation.clear();
6651 return false;
6652 } else if (mHasTransformation) {
6653 // Little trick to get through the path below to act like
6654 // we have finished an animation.
6655 mAnimating = true;
6656 } else if (isAnimating()) {
6657 mAnimating = true;
6658 }
6659 } else if (mAnimation != null) {
6660 // If the display is frozen, and there is a pending animation,
6661 // clear it and make sure we run the cleanup code.
6662 mAnimating = true;
6663 mLocalAnimating = true;
6664 mAnimation = null;
6665 }
Romain Guy06882f82009-06-10 13:36:04 -07006666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 if (!mAnimating && !mLocalAnimating) {
6668 return false;
6669 }
6670
Joe Onorato8a9b2202010-02-26 18:56:32 -08006671 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006672 TAG, "Animation done in " + this + ": exiting=" + mExiting
6673 + ", reportedVisible="
6674 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 mAnimating = false;
6677 mLocalAnimating = false;
6678 mAnimation = null;
6679 mAnimLayer = mLayer;
6680 if (mIsImWindow) {
6681 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006682 } else if (mIsWallpaper) {
6683 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006684 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006685 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 + " anim layer: " + mAnimLayer);
6687 mHasTransformation = false;
6688 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006689 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6690 if (DEBUG_VISIBILITY) {
6691 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6692 + mPolicyVisibilityAfterAnim);
6693 }
6694 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6695 if (!mPolicyVisibility) {
6696 if (mCurrentFocus == this) {
6697 mFocusMayChange = true;
6698 }
6699 // Window is no longer visible -- make sure if we were waiting
6700 // for it to be displayed before enabling the display, that
6701 // we allow the display to be enabled now.
6702 enableScreenIfNeededLocked();
6703 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006704 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006705 mTransformation.clear();
6706 if (mHasDrawn
6707 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6708 && mAppToken != null
6709 && mAppToken.firstWindowDrawn
6710 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006711 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 + mToken + ": first real window done animating");
6713 mFinishedStarting.add(mAppToken);
6714 mH.sendEmptyMessage(H.FINISHED_STARTING);
6715 }
Romain Guy06882f82009-06-10 13:36:04 -07006716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 finishExit();
6718
6719 if (mAppToken != null) {
6720 mAppToken.updateReportedVisibilityLocked();
6721 }
6722
6723 return false;
6724 }
6725
6726 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006727 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 TAG, "finishExit in " + this
6729 + ": exiting=" + mExiting
6730 + " remove=" + mRemoveOnExit
6731 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006733 final int N = mChildWindows.size();
6734 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006735 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006736 }
Romain Guy06882f82009-06-10 13:36:04 -07006737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 if (!mExiting) {
6739 return;
6740 }
Romain Guy06882f82009-06-10 13:36:04 -07006741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 if (isWindowAnimating()) {
6743 return;
6744 }
6745
Joe Onorato8a9b2202010-02-26 18:56:32 -08006746 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 TAG, "Exit animation finished in " + this
6748 + ": remove=" + mRemoveOnExit);
6749 if (mSurface != null) {
6750 mDestroySurface.add(this);
6751 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006752 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006753 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006754 try {
6755 mSurface.hide();
6756 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006757 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 }
6759 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 }
6761 mExiting = false;
6762 if (mRemoveOnExit) {
6763 mPendingRemove.add(this);
6764 mRemoveOnExit = false;
6765 }
6766 }
Romain Guy06882f82009-06-10 13:36:04 -07006767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006768 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6769 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6770 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6771 if (dtdx < -.000001f || dtdx > .000001f) return false;
6772 if (dsdy < -.000001f || dsdy > .000001f) return false;
6773 return true;
6774 }
Romain Guy06882f82009-06-10 13:36:04 -07006775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 void computeShownFrameLocked() {
6777 final boolean selfTransformation = mHasLocalTransformation;
6778 Transformation attachedTransformation =
6779 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6780 ? mAttachedWindow.mTransformation : null;
6781 Transformation appTransformation =
6782 (mAppToken != null && mAppToken.hasTransformation)
6783 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006784
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006785 // Wallpapers are animated based on the "real" window they
6786 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006787 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006788 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006789 if (mWallpaperTarget.mHasLocalTransformation &&
6790 mWallpaperTarget.mAnimation != null &&
6791 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006792 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006793 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006794 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006795 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006796 }
6797 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006798 mWallpaperTarget.mAppToken.hasTransformation &&
6799 mWallpaperTarget.mAppToken.animation != null &&
6800 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006801 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006802 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006803 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006804 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006805 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006806 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 if (selfTransformation || attachedTransformation != null
6809 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006810 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006811 final Rect frame = mFrame;
6812 final float tmpFloats[] = mTmpFloats;
6813 final Matrix tmpMatrix = mTmpMatrix;
6814
6815 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006816 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006817 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006818 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006819 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006820 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006821 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006822 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 }
6824 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006825 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006826 }
6827
6828 // "convert" it into SurfaceFlinger's format
6829 // (a 2x2 matrix + an offset)
6830 // Here we must not transform the position of the surface
6831 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006832 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 tmpMatrix.getValues(tmpFloats);
6835 mDsDx = tmpFloats[Matrix.MSCALE_X];
6836 mDtDx = tmpFloats[Matrix.MSKEW_X];
6837 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6838 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006839 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6840 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 int w = frame.width();
6842 int h = frame.height();
6843 mShownFrame.set(x, y, x+w, y+h);
6844
6845 // Now set the alpha... but because our current hardware
6846 // can't do alpha transformation on a non-opaque surface,
6847 // turn it off if we are running an animation that is also
6848 // transforming since it is more important to have that
6849 // animation be smooth.
6850 mShownAlpha = mAlpha;
6851 if (!mLimitedAlphaCompositing
6852 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6853 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6854 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006855 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 if (selfTransformation) {
6857 mShownAlpha *= mTransformation.getAlpha();
6858 }
6859 if (attachedTransformation != null) {
6860 mShownAlpha *= attachedTransformation.getAlpha();
6861 }
6862 if (appTransformation != null) {
6863 mShownAlpha *= appTransformation.getAlpha();
6864 }
6865 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006866 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 }
Romain Guy06882f82009-06-10 13:36:04 -07006868
Joe Onorato8a9b2202010-02-26 18:56:32 -08006869 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 TAG, "Continuing animation in " + this +
6871 ": " + mShownFrame +
6872 ", alpha=" + mTransformation.getAlpha());
6873 return;
6874 }
Romain Guy06882f82009-06-10 13:36:04 -07006875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006876 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006877 if (mXOffset != 0 || mYOffset != 0) {
6878 mShownFrame.offset(mXOffset, mYOffset);
6879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006880 mShownAlpha = mAlpha;
6881 mDsDx = 1;
6882 mDtDx = 0;
6883 mDsDy = 0;
6884 mDtDy = 1;
6885 }
Romain Guy06882f82009-06-10 13:36:04 -07006886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 /**
6888 * Is this window visible? It is not visible if there is no
6889 * surface, or we are in the process of running an exit animation
6890 * that will remove the surface, or its app token has been hidden.
6891 */
6892 public boolean isVisibleLw() {
6893 final AppWindowToken atoken = mAppToken;
6894 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6895 && (atoken == null || !atoken.hiddenRequested)
6896 && !mExiting && !mDestroying;
6897 }
6898
6899 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006900 * Like {@link #isVisibleLw}, but also counts a window that is currently
6901 * "hidden" behind the keyguard as visible. This allows us to apply
6902 * things like window flags that impact the keyguard.
6903 * XXX I am starting to think we need to have ANOTHER visibility flag
6904 * for this "hidden behind keyguard" state rather than overloading
6905 * mPolicyVisibility. Ungh.
6906 */
6907 public boolean isVisibleOrBehindKeyguardLw() {
6908 final AppWindowToken atoken = mAppToken;
6909 return mSurface != null && !mAttachedHidden
6910 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006911 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006912 && !mExiting && !mDestroying;
6913 }
6914
6915 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006916 * Is this window visible, ignoring its app token? It is not visible
6917 * if there is no surface, or we are in the process of running an exit animation
6918 * that will remove the surface.
6919 */
6920 public boolean isWinVisibleLw() {
6921 final AppWindowToken atoken = mAppToken;
6922 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6923 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6924 && !mExiting && !mDestroying;
6925 }
6926
6927 /**
6928 * The same as isVisible(), but follows the current hidden state of
6929 * the associated app token, not the pending requested hidden state.
6930 */
6931 boolean isVisibleNow() {
6932 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006933 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 }
6935
6936 /**
6937 * Same as isVisible(), but we also count it as visible between the
6938 * call to IWindowSession.add() and the first relayout().
6939 */
6940 boolean isVisibleOrAdding() {
6941 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006942 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006943 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6944 && mPolicyVisibility && !mAttachedHidden
6945 && (atoken == null || !atoken.hiddenRequested)
6946 && !mExiting && !mDestroying;
6947 }
6948
6949 /**
6950 * Is this window currently on-screen? It is on-screen either if it
6951 * is visible or it is currently running an animation before no longer
6952 * being visible.
6953 */
6954 boolean isOnScreen() {
6955 final AppWindowToken atoken = mAppToken;
6956 if (atoken != null) {
6957 return mSurface != null && mPolicyVisibility && !mDestroying
6958 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006959 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006960 } else {
6961 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006962 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 }
6964 }
Romain Guy06882f82009-06-10 13:36:04 -07006965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006966 /**
6967 * Like isOnScreen(), but we don't return true if the window is part
6968 * of a transition that has not yet been started.
6969 */
6970 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006971 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006972 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006973 return false;
6974 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006976 final boolean animating = atoken != null
6977 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006979 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6980 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006981 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006982 }
6983
6984 /** Is the window or its container currently animating? */
6985 boolean isAnimating() {
6986 final WindowState attached = mAttachedWindow;
6987 final AppWindowToken atoken = mAppToken;
6988 return mAnimation != null
6989 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006990 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006991 (atoken.animation != null
6992 || atoken.inPendingTransaction));
6993 }
6994
6995 /** Is this window currently animating? */
6996 boolean isWindowAnimating() {
6997 return mAnimation != null;
6998 }
6999
7000 /**
7001 * Like isOnScreen, but returns false if the surface hasn't yet
7002 * been drawn.
7003 */
7004 public boolean isDisplayedLw() {
7005 final AppWindowToken atoken = mAppToken;
7006 return mSurface != null && mPolicyVisibility && !mDestroying
7007 && !mDrawPending && !mCommitDrawPending
7008 && ((!mAttachedHidden &&
7009 (atoken == null || !atoken.hiddenRequested))
7010 || mAnimating);
7011 }
7012
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007013 /**
7014 * Returns true if the window has a surface that it has drawn a
7015 * complete UI in to.
7016 */
7017 public boolean isDrawnLw() {
7018 final AppWindowToken atoken = mAppToken;
7019 return mSurface != null && !mDestroying
7020 && !mDrawPending && !mCommitDrawPending;
7021 }
7022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007023 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7024 boolean shownFrame, boolean onlyOpaque) {
7025 if (mSurface == null) {
7026 return false;
7027 }
7028 if (mAppToken != null && !mAppToken.appFullscreen) {
7029 return false;
7030 }
7031 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7032 return false;
7033 }
7034 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007035
7036 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7037 return frame.left <= mCompatibleScreenFrame.left &&
7038 frame.top <= mCompatibleScreenFrame.top &&
7039 frame.right >= mCompatibleScreenFrame.right &&
7040 frame.bottom >= mCompatibleScreenFrame.bottom;
7041 } else {
Joe Onorato93056472010-09-10 10:30:46 -04007042 if ((mAttrs.flags & FLAG_FULLSCREEN) != 0) {
7043 return true;
7044 }
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007045 return frame.left <= 0 && frame.top <= 0
7046 && frame.right >= screenWidth
7047 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 }
Romain Guy06882f82009-06-10 13:36:04 -07007050
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007051 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007052 * Return true if the window is opaque and fully drawn. This indicates
7053 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007054 */
7055 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007056 return (mAttrs.format == PixelFormat.OPAQUE
7057 || mAttrs.type == TYPE_WALLPAPER)
7058 && mSurface != null && mAnimation == null
7059 && (mAppToken == null || mAppToken.animation == null)
7060 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007061 }
7062
7063 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7064 return
7065 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007066 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7067 // only if it's visible
7068 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007069 // and only if the application fills the compatible screen
7070 mFrame.left <= mCompatibleScreenFrame.left &&
7071 mFrame.top <= mCompatibleScreenFrame.top &&
7072 mFrame.right >= mCompatibleScreenFrame.right &&
7073 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007074 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007075 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007076 }
7077
7078 boolean isFullscreen(int screenWidth, int screenHeight) {
7079 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007080 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 }
7082
7083 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007084 disposeInputChannel();
7085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 if (mAttachedWindow != null) {
7087 mAttachedWindow.mChildWindows.remove(this);
7088 }
7089 destroySurfaceLocked();
7090 mSession.windowRemovedLocked();
7091 try {
7092 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7093 } catch (RuntimeException e) {
7094 // Ignore if it has already been removed (usually because
7095 // we are doing this as part of processing a death note.)
7096 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007097 }
7098
7099 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007100 if (mInputChannel != null) {
7101 mInputManager.unregisterInputChannel(mInputChannel);
7102
7103 mInputChannel.dispose();
7104 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 }
7107
7108 private class DeathRecipient implements IBinder.DeathRecipient {
7109 public void binderDied() {
7110 try {
7111 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007112 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007113 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007114 if (win != null) {
7115 removeWindowLocked(mSession, win);
7116 }
7117 }
7118 } catch (IllegalArgumentException ex) {
7119 // This will happen if the window has already been
7120 // removed.
7121 }
7122 }
7123 }
7124
7125 /** Returns true if this window desires key events. */
7126 public final boolean canReceiveKeys() {
7127 return isVisibleOrAdding()
7128 && (mViewVisibility == View.VISIBLE)
7129 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7130 }
7131
7132 public boolean hasDrawnLw() {
7133 return mHasDrawn;
7134 }
7135
7136 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007137 return showLw(doAnimation, true);
7138 }
7139
7140 boolean showLw(boolean doAnimation, boolean requestAnim) {
7141 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7142 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007143 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007144 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007145 if (doAnimation) {
7146 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7147 + mPolicyVisibility + " mAnimation=" + mAnimation);
7148 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7149 doAnimation = false;
7150 } else if (mPolicyVisibility && mAnimation == null) {
7151 // Check for the case where we are currently visible and
7152 // not animating; we do not want to do animation at such a
7153 // point to become visible when we already are.
7154 doAnimation = false;
7155 }
7156 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007157 mPolicyVisibility = true;
7158 mPolicyVisibilityAfterAnim = true;
7159 if (doAnimation) {
7160 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7161 }
7162 if (requestAnim) {
7163 requestAnimationLocked(0);
7164 }
7165 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007166 }
7167
7168 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007169 return hideLw(doAnimation, true);
7170 }
7171
7172 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007173 if (doAnimation) {
7174 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7175 doAnimation = false;
7176 }
7177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007178 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7179 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007180 if (!current) {
7181 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007183 if (doAnimation) {
7184 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7185 if (mAnimation == null) {
7186 doAnimation = false;
7187 }
7188 }
7189 if (doAnimation) {
7190 mPolicyVisibilityAfterAnim = false;
7191 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007192 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007193 mPolicyVisibilityAfterAnim = false;
7194 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007195 // Window is no longer visible -- make sure if we were waiting
7196 // for it to be displayed before enabling the display, that
7197 // we allow the display to be enabled now.
7198 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007199 if (mCurrentFocus == this) {
7200 mFocusMayChange = true;
7201 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007202 }
7203 if (requestAnim) {
7204 requestAnimationLocked(0);
7205 }
7206 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007207 }
7208
7209 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007210 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7211 pw.print(" mClient="); pw.println(mClient.asBinder());
7212 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7213 if (mAttachedWindow != null || mLayoutAttached) {
7214 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7215 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7216 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007217 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7218 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7219 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007220 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7221 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007222 }
7223 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7224 pw.print(" mSubLayer="); pw.print(mSubLayer);
7225 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7226 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7227 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7228 pw.print("="); pw.print(mAnimLayer);
7229 pw.print(" mLastLayer="); pw.println(mLastLayer);
7230 if (mSurface != null) {
7231 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007232 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7233 pw.print(" layer="); pw.print(mSurfaceLayer);
7234 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7235 pw.print(" rect=("); pw.print(mSurfaceX);
7236 pw.print(","); pw.print(mSurfaceY);
7237 pw.print(") "); pw.print(mSurfaceW);
7238 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007239 }
7240 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7241 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7242 if (mAppToken != null) {
7243 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7244 }
7245 if (mTargetAppToken != null) {
7246 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7247 }
7248 pw.print(prefix); pw.print("mViewVisibility=0x");
7249 pw.print(Integer.toHexString(mViewVisibility));
7250 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007251 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7252 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007253 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7254 pw.print(prefix); pw.print("mPolicyVisibility=");
7255 pw.print(mPolicyVisibility);
7256 pw.print(" mPolicyVisibilityAfterAnim=");
7257 pw.print(mPolicyVisibilityAfterAnim);
7258 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7259 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007260 if (!mRelayoutCalled) {
7261 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7262 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007263 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007264 pw.print(" h="); pw.print(mRequestedHeight);
7265 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007266 if (mXOffset != 0 || mYOffset != 0) {
7267 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7268 pw.print(" y="); pw.println(mYOffset);
7269 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007270 pw.print(prefix); pw.print("mGivenContentInsets=");
7271 mGivenContentInsets.printShortString(pw);
7272 pw.print(" mGivenVisibleInsets=");
7273 mGivenVisibleInsets.printShortString(pw);
7274 pw.println();
7275 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7276 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7277 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7278 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007279 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007280 pw.print(prefix); pw.print("mShownFrame=");
7281 mShownFrame.printShortString(pw);
7282 pw.print(" last="); mLastShownFrame.printShortString(pw);
7283 pw.println();
7284 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7285 pw.print(" last="); mLastFrame.printShortString(pw);
7286 pw.println();
7287 pw.print(prefix); pw.print("mContainingFrame=");
7288 mContainingFrame.printShortString(pw);
7289 pw.print(" mDisplayFrame=");
7290 mDisplayFrame.printShortString(pw);
7291 pw.println();
7292 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7293 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7294 pw.println();
7295 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7296 pw.print(" last="); mLastContentInsets.printShortString(pw);
7297 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7298 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7299 pw.println();
7300 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7301 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7302 pw.print(" mAlpha="); pw.print(mAlpha);
7303 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7304 }
7305 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7306 || mAnimation != null) {
7307 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7308 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7309 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7310 pw.print(" mAnimation="); pw.println(mAnimation);
7311 }
7312 if (mHasTransformation || mHasLocalTransformation) {
7313 pw.print(prefix); pw.print("XForm: has=");
7314 pw.print(mHasTransformation);
7315 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7316 pw.print(" "); mTransformation.printShortString(pw);
7317 pw.println();
7318 }
7319 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7320 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7321 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7322 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7323 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7324 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7325 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7326 pw.print(" mDestroying="); pw.print(mDestroying);
7327 pw.print(" mRemoved="); pw.println(mRemoved);
7328 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007329 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007330 pw.print(prefix); pw.print("mOrientationChanging=");
7331 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007332 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7333 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007334 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007335 if (mHScale != 1 || mVScale != 1) {
7336 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7337 pw.print(" mVScale="); pw.println(mVScale);
7338 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007339 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007340 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7341 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7342 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007343 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7344 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7345 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7346 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007348
7349 String makeInputChannelName() {
7350 return Integer.toHexString(System.identityHashCode(this))
7351 + " " + mAttrs.getTitle();
7352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353
7354 @Override
7355 public String toString() {
7356 return "Window{"
7357 + Integer.toHexString(System.identityHashCode(this))
7358 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7359 }
7360 }
Romain Guy06882f82009-06-10 13:36:04 -07007361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 // -------------------------------------------------------------
7363 // Window Token State
7364 // -------------------------------------------------------------
7365
7366 class WindowToken {
7367 // The actual token.
7368 final IBinder token;
7369
7370 // The type of window this token is for, as per WindowManager.LayoutParams.
7371 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007373 // Set if this token was explicitly added by a client, so should
7374 // not be removed when all windows are removed.
7375 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007376
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007377 // For printing.
7378 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 // If this is an AppWindowToken, this is non-null.
7381 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 // All of the windows associated with this token.
7384 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7385
7386 // Is key dispatching paused for this token?
7387 boolean paused = false;
7388
7389 // Should this token's windows be hidden?
7390 boolean hidden;
7391
7392 // Temporary for finding which tokens no longer have visible windows.
7393 boolean hasVisible;
7394
Dianne Hackborna8f60182009-09-01 19:01:50 -07007395 // Set to true when this token is in a pending transaction where it
7396 // will be shown.
7397 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007398
Dianne Hackborna8f60182009-09-01 19:01:50 -07007399 // Set to true when this token is in a pending transaction where it
7400 // will be hidden.
7401 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007402
Dianne Hackborna8f60182009-09-01 19:01:50 -07007403 // Set to true when this token is in a pending transaction where its
7404 // windows will be put to the bottom of the list.
7405 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007406
Dianne Hackborna8f60182009-09-01 19:01:50 -07007407 // Set to true when this token is in a pending transaction where its
7408 // windows will be put to the top of the list.
7409 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007411 WindowToken(IBinder _token, int type, boolean _explicit) {
7412 token = _token;
7413 windowType = type;
7414 explicit = _explicit;
7415 }
7416
7417 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007418 pw.print(prefix); pw.print("token="); pw.println(token);
7419 pw.print(prefix); pw.print("windows="); pw.println(windows);
7420 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7421 pw.print(" hidden="); pw.print(hidden);
7422 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007423 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7424 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7425 pw.print(" waitingToHide="); pw.print(waitingToHide);
7426 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7427 pw.print(" sendingToTop="); pw.println(sendingToTop);
7428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 }
7430
7431 @Override
7432 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007433 if (stringName == null) {
7434 StringBuilder sb = new StringBuilder();
7435 sb.append("WindowToken{");
7436 sb.append(Integer.toHexString(System.identityHashCode(this)));
7437 sb.append(" token="); sb.append(token); sb.append('}');
7438 stringName = sb.toString();
7439 }
7440 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 }
7442 };
7443
7444 class AppWindowToken extends WindowToken {
7445 // Non-null only for application tokens.
7446 final IApplicationToken appToken;
7447
7448 // All of the windows and child windows that are included in this
7449 // application token. Note this list is NOT sorted!
7450 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7451
7452 int groupId = -1;
7453 boolean appFullscreen;
7454 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007455
7456 // The input dispatching timeout for this application token in nanoseconds.
7457 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007459 // These are used for determining when all windows associated with
7460 // an activity have been drawn, so they can be made visible together
7461 // at the same time.
7462 int lastTransactionSequence = mTransactionSequence-1;
7463 int numInterestingWindows;
7464 int numDrawnWindows;
7465 boolean inPendingTransaction;
7466 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007468 // Is this token going to be hidden in a little while? If so, it
7469 // won't be taken into account for setting the screen orientation.
7470 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007472 // Is this window's surface needed? This is almost like hidden, except
7473 // it will sometimes be true a little earlier: when the token has
7474 // been shown, but is still waiting for its app transition to execute
7475 // before making its windows shown.
7476 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 // Have we told the window clients to hide themselves?
7479 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 // Last visibility state we reported to the app token.
7482 boolean reportedVisible;
7483
7484 // Set to true when the token has been removed from the window mgr.
7485 boolean removed;
7486
7487 // Have we been asked to have this token keep the screen frozen?
7488 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 boolean animating;
7491 Animation animation;
7492 boolean hasTransformation;
7493 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 // Offset to the window of all layers in the token, for use by
7496 // AppWindowToken animations.
7497 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 // Information about an application starting window if displayed.
7500 StartingData startingData;
7501 WindowState startingWindow;
7502 View startingView;
7503 boolean startingDisplayed;
7504 boolean startingMoved;
7505 boolean firstWindowDrawn;
7506
7507 AppWindowToken(IApplicationToken _token) {
7508 super(_token.asBinder(),
7509 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7510 appWindowToken = this;
7511 appToken = _token;
7512 }
Romain Guy06882f82009-06-10 13:36:04 -07007513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007514 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007515 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 TAG, "Setting animation in " + this + ": " + anim);
7517 animation = anim;
7518 animating = false;
7519 anim.restrictDuration(MAX_ANIMATION_DURATION);
7520 anim.scaleCurrentDuration(mTransitionAnimationScale);
7521 int zorder = anim.getZAdjustment();
7522 int adj = 0;
7523 if (zorder == Animation.ZORDER_TOP) {
7524 adj = TYPE_LAYER_OFFSET;
7525 } else if (zorder == Animation.ZORDER_BOTTOM) {
7526 adj = -TYPE_LAYER_OFFSET;
7527 }
Romain Guy06882f82009-06-10 13:36:04 -07007528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 if (animLayerAdjustment != adj) {
7530 animLayerAdjustment = adj;
7531 updateLayers();
7532 }
7533 }
Romain Guy06882f82009-06-10 13:36:04 -07007534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 public void setDummyAnimation() {
7536 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007537 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007538 TAG, "Setting dummy animation in " + this);
7539 animation = sDummyAnimation;
7540 }
7541 }
7542
7543 public void clearAnimation() {
7544 if (animation != null) {
7545 animation = null;
7546 animating = true;
7547 }
7548 }
Romain Guy06882f82009-06-10 13:36:04 -07007549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 void updateLayers() {
7551 final int N = allAppWindows.size();
7552 final int adj = animLayerAdjustment;
7553 for (int i=0; i<N; i++) {
7554 WindowState w = allAppWindows.get(i);
7555 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007556 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 + w.mAnimLayer);
7558 if (w == mInputMethodTarget) {
7559 setInputMethodAnimLayerAdjustment(adj);
7560 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007561 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007562 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007564 }
7565 }
Romain Guy06882f82009-06-10 13:36:04 -07007566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 void sendAppVisibilityToClients() {
7568 final int N = allAppWindows.size();
7569 for (int i=0; i<N; i++) {
7570 WindowState win = allAppWindows.get(i);
7571 if (win == startingWindow && clientHidden) {
7572 // Don't hide the starting window.
7573 continue;
7574 }
7575 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007576 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007577 "Setting visibility of " + win + ": " + (!clientHidden));
7578 win.mClient.dispatchAppVisibility(!clientHidden);
7579 } catch (RemoteException e) {
7580 }
7581 }
7582 }
Romain Guy06882f82009-06-10 13:36:04 -07007583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 void showAllWindowsLocked() {
7585 final int NW = allAppWindows.size();
7586 for (int i=0; i<NW; i++) {
7587 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007588 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 "performing show on: " + w);
7590 w.performShowLocked();
7591 }
7592 }
Romain Guy06882f82009-06-10 13:36:04 -07007593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 // This must be called while inside a transaction.
7595 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007596 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 if (animation == sDummyAnimation) {
7600 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007601 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 // when it is really time to animate, this will be set to
7603 // a real animation and the next call will execute normally.
7604 return false;
7605 }
Romain Guy06882f82009-06-10 13:36:04 -07007606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7608 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007609 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007610 TAG, "Starting animation in " + this +
7611 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7612 + " scale=" + mTransitionAnimationScale
7613 + " allDrawn=" + allDrawn + " animating=" + animating);
7614 animation.initialize(dw, dh, dw, dh);
7615 animation.setStartTime(currentTime);
7616 animating = true;
7617 }
7618 transformation.clear();
7619 final boolean more = animation.getTransformation(
7620 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007621 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 TAG, "Stepped animation in " + this +
7623 ": more=" + more + ", xform=" + transformation);
7624 if (more) {
7625 // we're done!
7626 hasTransformation = true;
7627 return true;
7628 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007629 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007630 TAG, "Finished animation in " + this +
7631 " @ " + currentTime);
7632 animation = null;
7633 }
7634 } else if (animation != null) {
7635 // If the display is frozen, and there is a pending animation,
7636 // clear it and make sure we run the cleanup code.
7637 animating = true;
7638 animation = null;
7639 }
7640
7641 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 if (!animating) {
7644 return false;
7645 }
7646
7647 clearAnimation();
7648 animating = false;
7649 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7650 moveInputMethodWindowsIfNeededLocked(true);
7651 }
Romain Guy06882f82009-06-10 13:36:04 -07007652
Joe Onorato8a9b2202010-02-26 18:56:32 -08007653 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007654 TAG, "Animation done in " + this
7655 + ": reportedVisible=" + reportedVisible);
7656
7657 transformation.clear();
7658 if (animLayerAdjustment != 0) {
7659 animLayerAdjustment = 0;
7660 updateLayers();
7661 }
Romain Guy06882f82009-06-10 13:36:04 -07007662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 final int N = windows.size();
7664 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007665 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007666 }
7667 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007669 return false;
7670 }
7671
7672 void updateReportedVisibilityLocked() {
7673 if (appToken == null) {
7674 return;
7675 }
Romain Guy06882f82009-06-10 13:36:04 -07007676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 int numInteresting = 0;
7678 int numVisible = 0;
7679 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007680
Joe Onorato8a9b2202010-02-26 18:56:32 -08007681 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007682 final int N = allAppWindows.size();
7683 for (int i=0; i<N; i++) {
7684 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007685 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007686 || win.mViewVisibility != View.VISIBLE
7687 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007688 continue;
7689 }
7690 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007691 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007692 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007693 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007694 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007695 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 + " pv=" + win.mPolicyVisibility
7697 + " dp=" + win.mDrawPending
7698 + " cdp=" + win.mCommitDrawPending
7699 + " ah=" + win.mAttachedHidden
7700 + " th="
7701 + (win.mAppToken != null
7702 ? win.mAppToken.hiddenRequested : false)
7703 + " a=" + win.mAnimating);
7704 }
7705 }
7706 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007707 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 if (!win.isAnimating()) {
7709 numVisible++;
7710 }
7711 nowGone = false;
7712 } else if (win.isAnimating()) {
7713 nowGone = false;
7714 }
7715 }
Romain Guy06882f82009-06-10 13:36:04 -07007716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007717 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007718 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 + numInteresting + " visible=" + numVisible);
7720 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007721 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007722 TAG, "Visibility changed in " + this
7723 + ": vis=" + nowVisible);
7724 reportedVisible = nowVisible;
7725 Message m = mH.obtainMessage(
7726 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7727 nowVisible ? 1 : 0,
7728 nowGone ? 1 : 0,
7729 this);
7730 mH.sendMessage(m);
7731 }
7732 }
Romain Guy06882f82009-06-10 13:36:04 -07007733
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007734 WindowState findMainWindow() {
7735 int j = windows.size();
7736 while (j > 0) {
7737 j--;
7738 WindowState win = windows.get(j);
7739 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7740 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7741 return win;
7742 }
7743 }
7744 return null;
7745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007747 void dump(PrintWriter pw, String prefix) {
7748 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007749 if (appToken != null) {
7750 pw.print(prefix); pw.println("app=true");
7751 }
7752 if (allAppWindows.size() > 0) {
7753 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7754 }
7755 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007756 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007757 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7758 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7759 pw.print(" clientHidden="); pw.print(clientHidden);
7760 pw.print(" willBeHidden="); pw.print(willBeHidden);
7761 pw.print(" reportedVisible="); pw.println(reportedVisible);
7762 if (paused || freezingScreen) {
7763 pw.print(prefix); pw.print("paused="); pw.print(paused);
7764 pw.print(" freezingScreen="); pw.println(freezingScreen);
7765 }
7766 if (numInterestingWindows != 0 || numDrawnWindows != 0
7767 || inPendingTransaction || allDrawn) {
7768 pw.print(prefix); pw.print("numInterestingWindows=");
7769 pw.print(numInterestingWindows);
7770 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7771 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7772 pw.print(" allDrawn="); pw.println(allDrawn);
7773 }
7774 if (animating || animation != null) {
7775 pw.print(prefix); pw.print("animating="); pw.print(animating);
7776 pw.print(" animation="); pw.println(animation);
7777 }
7778 if (animLayerAdjustment != 0) {
7779 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7780 }
7781 if (hasTransformation) {
7782 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7783 pw.print(" transformation="); transformation.printShortString(pw);
7784 pw.println();
7785 }
7786 if (startingData != null || removed || firstWindowDrawn) {
7787 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7788 pw.print(" removed="); pw.print(removed);
7789 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7790 }
7791 if (startingWindow != null || startingView != null
7792 || startingDisplayed || startingMoved) {
7793 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7794 pw.print(" startingView="); pw.print(startingView);
7795 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7796 pw.print(" startingMoved"); pw.println(startingMoved);
7797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798 }
7799
7800 @Override
7801 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007802 if (stringName == null) {
7803 StringBuilder sb = new StringBuilder();
7804 sb.append("AppWindowToken{");
7805 sb.append(Integer.toHexString(System.identityHashCode(this)));
7806 sb.append(" token="); sb.append(token); sb.append('}');
7807 stringName = sb.toString();
7808 }
7809 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007810 }
7811 }
Romain Guy06882f82009-06-10 13:36:04 -07007812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007813 // -------------------------------------------------------------
7814 // DummyAnimation
7815 // -------------------------------------------------------------
7816
7817 // This is an animation that does nothing: it just immediately finishes
7818 // itself every time it is called. It is used as a stub animation in cases
7819 // where we want to synchronize multiple things that may be animating.
7820 static final class DummyAnimation extends Animation {
7821 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7822 return false;
7823 }
7824 }
7825 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007827 // -------------------------------------------------------------
7828 // Async Handler
7829 // -------------------------------------------------------------
7830
7831 static final class StartingData {
7832 final String pkg;
7833 final int theme;
7834 final CharSequence nonLocalizedLabel;
7835 final int labelRes;
7836 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7839 int _labelRes, int _icon) {
7840 pkg = _pkg;
7841 theme = _theme;
7842 nonLocalizedLabel = _nonLocalizedLabel;
7843 labelRes = _labelRes;
7844 icon = _icon;
7845 }
7846 }
7847
7848 private final class H extends Handler {
7849 public static final int REPORT_FOCUS_CHANGE = 2;
7850 public static final int REPORT_LOSING_FOCUS = 3;
7851 public static final int ANIMATE = 4;
7852 public static final int ADD_STARTING = 5;
7853 public static final int REMOVE_STARTING = 6;
7854 public static final int FINISHED_STARTING = 7;
7855 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007856 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7857 public static final int HOLD_SCREEN_CHANGED = 12;
7858 public static final int APP_TRANSITION_TIMEOUT = 13;
7859 public static final int PERSIST_ANIMATION_SCALE = 14;
7860 public static final int FORCE_GC = 15;
7861 public static final int ENABLE_SCREEN = 16;
7862 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007863 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007864 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 public H() {
7869 }
Romain Guy06882f82009-06-10 13:36:04 -07007870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 @Override
7872 public void handleMessage(Message msg) {
7873 switch (msg.what) {
7874 case REPORT_FOCUS_CHANGE: {
7875 WindowState lastFocus;
7876 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007878 synchronized(mWindowMap) {
7879 lastFocus = mLastFocus;
7880 newFocus = mCurrentFocus;
7881 if (lastFocus == newFocus) {
7882 // Focus is not changing, so nothing to do.
7883 return;
7884 }
7885 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007886 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007887 // + " to " + newFocus);
7888 if (newFocus != null && lastFocus != null
7889 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007890 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 mLosingFocus.add(lastFocus);
7892 lastFocus = null;
7893 }
7894 }
7895
7896 if (lastFocus != newFocus) {
7897 //System.out.println("Changing focus from " + lastFocus
7898 // + " to " + newFocus);
7899 if (newFocus != null) {
7900 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007901 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007902 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7903 } catch (RemoteException e) {
7904 // Ignore if process has died.
7905 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007906 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 }
7908
7909 if (lastFocus != null) {
7910 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007911 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7913 } catch (RemoteException e) {
7914 // Ignore if process has died.
7915 }
7916 }
7917 }
7918 } break;
7919
7920 case REPORT_LOSING_FOCUS: {
7921 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007923 synchronized(mWindowMap) {
7924 losers = mLosingFocus;
7925 mLosingFocus = new ArrayList<WindowState>();
7926 }
7927
7928 final int N = losers.size();
7929 for (int i=0; i<N; i++) {
7930 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007931 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7933 } catch (RemoteException e) {
7934 // Ignore if process has died.
7935 }
7936 }
7937 } break;
7938
7939 case ANIMATE: {
7940 synchronized(mWindowMap) {
7941 mAnimationPending = false;
7942 performLayoutAndPlaceSurfacesLocked();
7943 }
7944 } break;
7945
7946 case ADD_STARTING: {
7947 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7948 final StartingData sd = wtoken.startingData;
7949
7950 if (sd == null) {
7951 // Animation has been canceled... do nothing.
7952 return;
7953 }
Romain Guy06882f82009-06-10 13:36:04 -07007954
Joe Onorato8a9b2202010-02-26 18:56:32 -08007955 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007956 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007958 View view = null;
7959 try {
7960 view = mPolicy.addStartingWindow(
7961 wtoken.token, sd.pkg,
7962 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7963 sd.icon);
7964 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007965 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007966 }
7967
7968 if (view != null) {
7969 boolean abort = false;
7970
7971 synchronized(mWindowMap) {
7972 if (wtoken.removed || wtoken.startingData == null) {
7973 // If the window was successfully added, then
7974 // we need to remove it.
7975 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007976 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 "Aborted starting " + wtoken
7978 + ": removed=" + wtoken.removed
7979 + " startingData=" + wtoken.startingData);
7980 wtoken.startingWindow = null;
7981 wtoken.startingData = null;
7982 abort = true;
7983 }
7984 } else {
7985 wtoken.startingView = view;
7986 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007987 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 "Added starting " + wtoken
7989 + ": startingWindow="
7990 + wtoken.startingWindow + " startingView="
7991 + wtoken.startingView);
7992 }
7993
7994 if (abort) {
7995 try {
7996 mPolicy.removeStartingWindow(wtoken.token, view);
7997 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007998 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007999 }
8000 }
8001 }
8002 } break;
8003
8004 case REMOVE_STARTING: {
8005 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8006 IBinder token = null;
8007 View view = null;
8008 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008009 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008010 + wtoken + ": startingWindow="
8011 + wtoken.startingWindow + " startingView="
8012 + wtoken.startingView);
8013 if (wtoken.startingWindow != null) {
8014 view = wtoken.startingView;
8015 token = wtoken.token;
8016 wtoken.startingData = null;
8017 wtoken.startingView = null;
8018 wtoken.startingWindow = null;
8019 }
8020 }
8021 if (view != null) {
8022 try {
8023 mPolicy.removeStartingWindow(token, view);
8024 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008025 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008026 }
8027 }
8028 } break;
8029
8030 case FINISHED_STARTING: {
8031 IBinder token = null;
8032 View view = null;
8033 while (true) {
8034 synchronized (mWindowMap) {
8035 final int N = mFinishedStarting.size();
8036 if (N <= 0) {
8037 break;
8038 }
8039 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8040
Joe Onorato8a9b2202010-02-26 18:56:32 -08008041 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008042 "Finished starting " + wtoken
8043 + ": startingWindow=" + wtoken.startingWindow
8044 + " startingView=" + wtoken.startingView);
8045
8046 if (wtoken.startingWindow == null) {
8047 continue;
8048 }
8049
8050 view = wtoken.startingView;
8051 token = wtoken.token;
8052 wtoken.startingData = null;
8053 wtoken.startingView = null;
8054 wtoken.startingWindow = null;
8055 }
8056
8057 try {
8058 mPolicy.removeStartingWindow(token, view);
8059 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008060 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008061 }
8062 }
8063 } break;
8064
8065 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8066 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8067
8068 boolean nowVisible = msg.arg1 != 0;
8069 boolean nowGone = msg.arg2 != 0;
8070
8071 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008072 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008073 TAG, "Reporting visible in " + wtoken
8074 + " visible=" + nowVisible
8075 + " gone=" + nowGone);
8076 if (nowVisible) {
8077 wtoken.appToken.windowsVisible();
8078 } else {
8079 wtoken.appToken.windowsGone();
8080 }
8081 } catch (RemoteException ex) {
8082 }
8083 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 case WINDOW_FREEZE_TIMEOUT: {
8086 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008087 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008088 int i = mWindows.size();
8089 while (i > 0) {
8090 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008091 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008092 if (w.mOrientationChanging) {
8093 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008094 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 }
8096 }
8097 performLayoutAndPlaceSurfacesLocked();
8098 }
8099 break;
8100 }
Romain Guy06882f82009-06-10 13:36:04 -07008101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008102 case HOLD_SCREEN_CHANGED: {
8103 Session oldHold;
8104 Session newHold;
8105 synchronized (mWindowMap) {
8106 oldHold = mLastReportedHold;
8107 newHold = (Session)msg.obj;
8108 mLastReportedHold = newHold;
8109 }
Romain Guy06882f82009-06-10 13:36:04 -07008110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 if (oldHold != newHold) {
8112 try {
8113 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008114 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008115 "window",
8116 BatteryStats.WAKE_TYPE_WINDOW);
8117 }
8118 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008119 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 "window",
8121 BatteryStats.WAKE_TYPE_WINDOW);
8122 }
8123 } catch (RemoteException e) {
8124 }
8125 }
8126 break;
8127 }
Romain Guy06882f82009-06-10 13:36:04 -07008128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008129 case APP_TRANSITION_TIMEOUT: {
8130 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008131 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008132 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 "*** APP TRANSITION TIMEOUT");
8134 mAppTransitionReady = true;
8135 mAppTransitionTimeout = true;
8136 performLayoutAndPlaceSurfacesLocked();
8137 }
8138 }
8139 break;
8140 }
Romain Guy06882f82009-06-10 13:36:04 -07008141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008142 case PERSIST_ANIMATION_SCALE: {
8143 Settings.System.putFloat(mContext.getContentResolver(),
8144 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8145 Settings.System.putFloat(mContext.getContentResolver(),
8146 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8147 break;
8148 }
Romain Guy06882f82009-06-10 13:36:04 -07008149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008150 case FORCE_GC: {
8151 synchronized(mWindowMap) {
8152 if (mAnimationPending) {
8153 // If we are animating, don't do the gc now but
8154 // delay a bit so we don't interrupt the animation.
8155 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8156 2000);
8157 return;
8158 }
8159 // If we are currently rotating the display, it will
8160 // schedule a new message when done.
8161 if (mDisplayFrozen) {
8162 return;
8163 }
8164 mFreezeGcPending = 0;
8165 }
8166 Runtime.getRuntime().gc();
8167 break;
8168 }
Romain Guy06882f82009-06-10 13:36:04 -07008169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008170 case ENABLE_SCREEN: {
8171 performEnableScreen();
8172 break;
8173 }
Romain Guy06882f82009-06-10 13:36:04 -07008174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 case APP_FREEZE_TIMEOUT: {
8176 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008177 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008178 int i = mAppTokens.size();
8179 while (i > 0) {
8180 i--;
8181 AppWindowToken tok = mAppTokens.get(i);
8182 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008183 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008184 unsetAppFreezingScreenLocked(tok, true, true);
8185 }
8186 }
8187 }
8188 break;
8189 }
Romain Guy06882f82009-06-10 13:36:04 -07008190
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008191 case SEND_NEW_CONFIGURATION: {
8192 removeMessages(SEND_NEW_CONFIGURATION);
8193 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008194 break;
8195 }
Romain Guy06882f82009-06-10 13:36:04 -07008196
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008197 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008198 if (mWindowsChanged) {
8199 synchronized (mWindowMap) {
8200 mWindowsChanged = false;
8201 }
8202 notifyWindowsChanged();
8203 }
8204 break;
8205 }
8206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008207 }
8208 }
8209 }
8210
8211 // -------------------------------------------------------------
8212 // IWindowManager API
8213 // -------------------------------------------------------------
8214
8215 public IWindowSession openSession(IInputMethodClient client,
8216 IInputContext inputContext) {
8217 if (client == null) throw new IllegalArgumentException("null client");
8218 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008219 Session session = new Session(client, inputContext);
8220 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008221 }
8222
8223 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8224 synchronized (mWindowMap) {
8225 // The focus for the client is the window immediately below
8226 // where we would place the input method window.
8227 int idx = findDesiredInputMethodWindowIndexLocked(false);
8228 WindowState imFocus;
8229 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008230 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008231 if (imFocus != null) {
8232 if (imFocus.mSession.mClient != null &&
8233 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8234 return true;
8235 }
8236 }
8237 }
8238 }
8239 return false;
8240 }
Romain Guy06882f82009-06-10 13:36:04 -07008241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008242 // -------------------------------------------------------------
8243 // Internals
8244 // -------------------------------------------------------------
8245
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008246 final WindowState windowForClientLocked(Session session, IWindow client,
8247 boolean throwOnError) {
8248 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008249 }
Romain Guy06882f82009-06-10 13:36:04 -07008250
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008251 final WindowState windowForClientLocked(Session session, IBinder client,
8252 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008253 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008254 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008255 TAG, "Looking up client " + client + ": " + win);
8256 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008257 RuntimeException ex = new IllegalArgumentException(
8258 "Requested window " + client + " does not exist");
8259 if (throwOnError) {
8260 throw ex;
8261 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008262 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008263 return null;
8264 }
8265 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008266 RuntimeException ex = new IllegalArgumentException(
8267 "Requested window " + client + " is in session " +
8268 win.mSession + ", not " + session);
8269 if (throwOnError) {
8270 throw ex;
8271 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008272 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008273 return null;
8274 }
8275
8276 return win;
8277 }
8278
Dianne Hackborna8f60182009-09-01 19:01:50 -07008279 final void rebuildAppWindowListLocked() {
8280 int NW = mWindows.size();
8281 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008282 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008283 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008284
Dianne Hackborna8f60182009-09-01 19:01:50 -07008285 // First remove all existing app windows.
8286 i=0;
8287 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008288 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008289 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008290 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008291 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008292 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008293 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008294 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008295 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008296 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008297 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8298 && lastWallpaper == i-1) {
8299 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008300 }
8301 i++;
8302 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008303
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008304 // The wallpaper window(s) typically live at the bottom of the stack,
8305 // so skip them before adding app tokens.
8306 lastWallpaper++;
8307 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008308
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008309 // First add all of the exiting app tokens... these are no longer
8310 // in the main app list, but still have windows shown. We put them
8311 // in the back because now that the animation is over we no longer
8312 // will care about them.
8313 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008314 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008315 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8316 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008317
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008318 // And add in the still active app tokens in Z order.
8319 NT = mAppTokens.size();
8320 for (int j=0; j<NT; j++) {
8321 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008322 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008323
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008324 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008325 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008326 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008327 + " windows but added " + i);
8328 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008329 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008331 private final void assignLayersLocked() {
8332 int N = mWindows.size();
8333 int curBaseLayer = 0;
8334 int curLayer = 0;
8335 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008337 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008338 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008339 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8340 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008341 curLayer += WINDOW_LAYER_MULTIPLIER;
8342 w.mLayer = curLayer;
8343 } else {
8344 curBaseLayer = curLayer = w.mBaseLayer;
8345 w.mLayer = curLayer;
8346 }
8347 if (w.mTargetAppToken != null) {
8348 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8349 } else if (w.mAppToken != null) {
8350 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8351 } else {
8352 w.mAnimLayer = w.mLayer;
8353 }
8354 if (w.mIsImWindow) {
8355 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008356 } else if (w.mIsWallpaper) {
8357 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008358 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008359 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 + w.mAnimLayer);
8361 //System.out.println(
8362 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8363 }
8364 }
8365
8366 private boolean mInLayout = false;
8367 private final void performLayoutAndPlaceSurfacesLocked() {
8368 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008369 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370 throw new RuntimeException("Recursive call!");
8371 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008372 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008373 return;
8374 }
8375
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008376 if (mWaitingForConfig) {
8377 // Our configuration has changed (most likely rotation), but we
8378 // don't yet have the complete configuration to report to
8379 // applications. Don't do any window layout until we have it.
8380 return;
8381 }
8382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008383 boolean recoveringMemory = false;
8384 if (mForceRemoves != null) {
8385 recoveringMemory = true;
8386 // Wait a little it for things to settle down, and off we go.
8387 for (int i=0; i<mForceRemoves.size(); i++) {
8388 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008389 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008390 removeWindowInnerLocked(ws.mSession, ws);
8391 }
8392 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008393 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008394 Object tmp = new Object();
8395 synchronized (tmp) {
8396 try {
8397 tmp.wait(250);
8398 } catch (InterruptedException e) {
8399 }
8400 }
8401 }
Romain Guy06882f82009-06-10 13:36:04 -07008402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 mInLayout = true;
8404 try {
8405 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008407 int i = mPendingRemove.size()-1;
8408 if (i >= 0) {
8409 while (i >= 0) {
8410 WindowState w = mPendingRemove.get(i);
8411 removeWindowInnerLocked(w.mSession, w);
8412 i--;
8413 }
8414 mPendingRemove.clear();
8415
8416 mInLayout = false;
8417 assignLayersLocked();
8418 mLayoutNeeded = true;
8419 performLayoutAndPlaceSurfacesLocked();
8420
8421 } else {
8422 mInLayout = false;
8423 if (mLayoutNeeded) {
8424 requestAnimationLocked(0);
8425 }
8426 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008427 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008428 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8429 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008431 } catch (RuntimeException e) {
8432 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008433 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008434 }
8435 }
8436
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008437 private final int performLayoutLockedInner() {
8438 if (!mLayoutNeeded) {
8439 return 0;
8440 }
8441
8442 mLayoutNeeded = false;
8443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008444 final int dw = mDisplay.getWidth();
8445 final int dh = mDisplay.getHeight();
8446
8447 final int N = mWindows.size();
8448 int i;
8449
Joe Onorato8a9b2202010-02-26 18:56:32 -08008450 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008451 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8452
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008453 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008454
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008455 int seq = mLayoutSeq+1;
8456 if (seq < 0) seq = 0;
8457 mLayoutSeq = seq;
8458
8459 // First perform layout of any root windows (not attached
8460 // to another window).
8461 int topAttached = -1;
8462 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008463 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008465 // Don't do layout of a window if it is not visible, or
8466 // soon won't be visible, to avoid wasting time and funky
8467 // changes while a window is animating away.
8468 final AppWindowToken atoken = win.mAppToken;
8469 final boolean gone = win.mViewVisibility == View.GONE
8470 || !win.mRelayoutCalled
8471 || win.mRootToken.hidden
8472 || (atoken != null && atoken.hiddenRequested)
8473 || win.mAttachedHidden
8474 || win.mExiting || win.mDestroying;
8475
8476 if (!win.mLayoutAttached) {
8477 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8478 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8479 + " mLayoutAttached=" + win.mLayoutAttached);
8480 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8481 + win.mViewVisibility + " mRelayoutCalled="
8482 + win.mRelayoutCalled + " hidden="
8483 + win.mRootToken.hidden + " hiddenRequested="
8484 + (atoken != null && atoken.hiddenRequested)
8485 + " mAttachedHidden=" + win.mAttachedHidden);
8486 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008487
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008488 // If this view is GONE, then skip it -- keep the current
8489 // frame, and let the caller know so they can ignore it
8490 // if they want. (We do the normal layout for INVISIBLE
8491 // windows, since that means "perform layout as normal,
8492 // just don't display").
8493 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008494 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008495 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8496 win.mLayoutSeq = seq;
8497 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8498 + win.mFrame + " mContainingFrame="
8499 + win.mContainingFrame + " mDisplayFrame="
8500 + win.mDisplayFrame);
8501 } else {
8502 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008503 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008505 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008506
8507 // Now perform layout of attached windows, which usually
8508 // depend on the position of the window they are attached to.
8509 // XXX does not deal with windows that are attached to windows
8510 // that are themselves attached.
8511 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008512 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008513
8514 // If this view is GONE, then skip it -- keep the current
8515 // frame, and let the caller know so they can ignore it
8516 // if they want. (We do the normal layout for INVISIBLE
8517 // windows, since that means "perform layout as normal,
8518 // just don't display").
8519 if (win.mLayoutAttached) {
8520 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8521 + " mHaveFrame=" + win.mHaveFrame
8522 + " mViewVisibility=" + win.mViewVisibility
8523 + " mRelayoutCalled=" + win.mRelayoutCalled);
8524 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8525 || !win.mHaveFrame) {
8526 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8527 win.mLayoutSeq = seq;
8528 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8529 + win.mFrame + " mContainingFrame="
8530 + win.mContainingFrame + " mDisplayFrame="
8531 + win.mDisplayFrame);
8532 }
8533 }
8534 }
Jeff Brown349703e2010-06-22 01:27:15 -07008535
8536 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008537 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008538
8539 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 }
Romain Guy06882f82009-06-10 13:36:04 -07008541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008542 private final void performLayoutAndPlaceSurfacesLockedInner(
8543 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008544 if (mDisplay == null) {
8545 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8546 return;
8547 }
8548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 final long currentTime = SystemClock.uptimeMillis();
8550 final int dw = mDisplay.getWidth();
8551 final int dh = mDisplay.getHeight();
8552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008553 int i;
8554
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008555 if (mFocusMayChange) {
8556 mFocusMayChange = false;
8557 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8558 }
8559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008560 // Initialize state of exiting tokens.
8561 for (i=mExitingTokens.size()-1; i>=0; i--) {
8562 mExitingTokens.get(i).hasVisible = false;
8563 }
8564
8565 // Initialize state of exiting applications.
8566 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8567 mExitingAppTokens.get(i).hasVisible = false;
8568 }
8569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 boolean orientationChangeComplete = true;
8571 Session holdScreen = null;
8572 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008573 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 boolean focusDisplayed = false;
8575 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008576 boolean createWatermark = false;
8577
8578 if (mFxSession == null) {
8579 mFxSession = new SurfaceSession();
8580 createWatermark = true;
8581 }
8582
8583 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008584
8585 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008586
8587 if (createWatermark) {
8588 createWatermark();
8589 }
8590 if (mWatermark != null) {
8591 mWatermark.positionSurface(dw, dh);
8592 }
8593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008594 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008595 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008596 int repeats = 0;
8597 int changes = 0;
8598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008600 repeats++;
8601 if (repeats > 6) {
8602 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8603 mLayoutNeeded = false;
8604 break;
8605 }
8606
8607 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8608 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8609 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8610 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8611 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8612 assignLayersLocked();
8613 mLayoutNeeded = true;
8614 }
8615 }
8616 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8617 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8618 if (updateOrientationFromAppTokensLocked()) {
8619 mLayoutNeeded = true;
8620 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8621 }
8622 }
8623 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8624 mLayoutNeeded = true;
8625 }
8626 }
8627
8628 // FIRST LOOP: Perform a layout, if needed.
8629 if (repeats < 4) {
8630 changes = performLayoutLockedInner();
8631 if (changes != 0) {
8632 continue;
8633 }
8634 } else {
8635 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8636 changes = 0;
8637 }
8638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008639 final int transactionSequence = ++mTransactionSequence;
8640
8641 // Update animations of all applications, including those
8642 // associated with exiting/removed apps
8643 boolean tokensAnimating = false;
8644 final int NAT = mAppTokens.size();
8645 for (i=0; i<NAT; i++) {
8646 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8647 tokensAnimating = true;
8648 }
8649 }
8650 final int NEAT = mExitingAppTokens.size();
8651 for (i=0; i<NEAT; i++) {
8652 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8653 tokensAnimating = true;
8654 }
8655 }
8656
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008657 // SECOND LOOP: Execute animations and update visibility of windows.
8658
Joe Onorato8a9b2202010-02-26 18:56:32 -08008659 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008660 + transactionSequence + " tokensAnimating="
8661 + tokensAnimating);
8662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664
8665 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008666 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008667 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668
8669 mPolicy.beginAnimationLw(dw, dh);
8670
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008671 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008674 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008675
8676 final WindowManager.LayoutParams attrs = w.mAttrs;
8677
8678 if (w.mSurface != null) {
8679 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008680 if (w.commitFinishDrawingLocked(currentTime)) {
8681 if ((w.mAttrs.flags
8682 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008683 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008684 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008685 wallpaperMayChange = true;
8686 }
8687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008688
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008689 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008690 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8691 animating = true;
8692 //w.dump(" ");
8693 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008694 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8695 wallpaperMayChange = true;
8696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008697
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008698 if (mPolicy.doesForceHide(w, attrs)) {
8699 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008700 if (DEBUG_VISIBILITY) Slog.v(TAG,
8701 "Animation done that could impact force hide: "
8702 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008703 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008704 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008705 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8706 forceHiding = true;
8707 }
8708 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8709 boolean changed;
8710 if (forceHiding) {
8711 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008712 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8713 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008714 } else {
8715 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008716 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8717 "Now policy shown: " + w);
8718 if (changed) {
8719 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008720 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008721 // Assume we will need to animate. If
8722 // we don't (because the wallpaper will
8723 // stay with the lock screen), then we will
8724 // clean up later.
8725 Animation a = mPolicy.createForceHideEnterAnimation();
8726 if (a != null) {
8727 w.setAnimation(a);
8728 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008729 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008730 if (mCurrentFocus == null ||
8731 mCurrentFocus.mLayer < w.mLayer) {
8732 // We are showing on to of the current
8733 // focus, so re-evaluate focus to make
8734 // sure it is correct.
8735 mFocusMayChange = true;
8736 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008737 }
8738 }
8739 if (changed && (attrs.flags
8740 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8741 wallpaperMayChange = true;
8742 }
8743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008745 mPolicy.animatingWindowLw(w, attrs);
8746 }
8747
8748 final AppWindowToken atoken = w.mAppToken;
8749 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8750 if (atoken.lastTransactionSequence != transactionSequence) {
8751 atoken.lastTransactionSequence = transactionSequence;
8752 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8753 atoken.startingDisplayed = false;
8754 }
8755 if ((w.isOnScreen() || w.mAttrs.type
8756 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8757 && !w.mExiting && !w.mDestroying) {
8758 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008759 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008760 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008762 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008763 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008764 + " pv=" + w.mPolicyVisibility
8765 + " dp=" + w.mDrawPending
8766 + " cdp=" + w.mCommitDrawPending
8767 + " ah=" + w.mAttachedHidden
8768 + " th=" + atoken.hiddenRequested
8769 + " a=" + w.mAnimating);
8770 }
8771 }
8772 if (w != atoken.startingWindow) {
8773 if (!atoken.freezingScreen || !w.mAppFreezing) {
8774 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008775 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008776 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008777 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008778 "tokenMayBeDrawn: " + atoken
8779 + " freezingScreen=" + atoken.freezingScreen
8780 + " mAppFreezing=" + w.mAppFreezing);
8781 tokenMayBeDrawn = true;
8782 }
8783 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008784 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008785 atoken.startingDisplayed = true;
8786 }
8787 }
8788 } else if (w.mReadyToShow) {
8789 w.performShowLocked();
8790 }
8791 }
8792
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008793 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008794
8795 if (tokenMayBeDrawn) {
8796 // See if any windows have been drawn, so they (and others
8797 // associated with them) can now be shown.
8798 final int NT = mTokenList.size();
8799 for (i=0; i<NT; i++) {
8800 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8801 if (wtoken == null) {
8802 continue;
8803 }
8804 if (wtoken.freezingScreen) {
8805 int numInteresting = wtoken.numInterestingWindows;
8806 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008807 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008808 "allDrawn: " + wtoken
8809 + " interesting=" + numInteresting
8810 + " drawn=" + wtoken.numDrawnWindows);
8811 wtoken.showAllWindowsLocked();
8812 unsetAppFreezingScreenLocked(wtoken, false, true);
8813 orientationChangeComplete = true;
8814 }
8815 } else if (!wtoken.allDrawn) {
8816 int numInteresting = wtoken.numInterestingWindows;
8817 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008818 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008819 "allDrawn: " + wtoken
8820 + " interesting=" + numInteresting
8821 + " drawn=" + wtoken.numDrawnWindows);
8822 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008823 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008824
8825 // We can now show all of the drawn windows!
8826 if (!mOpeningApps.contains(wtoken)) {
8827 wtoken.showAllWindowsLocked();
8828 }
8829 }
8830 }
8831 }
8832 }
8833
8834 // If we are ready to perform an app transition, check through
8835 // all of the app tokens to be shown and see if they are ready
8836 // to go.
8837 if (mAppTransitionReady) {
8838 int NN = mOpeningApps.size();
8839 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008840 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008841 "Checking " + NN + " opening apps (frozen="
8842 + mDisplayFrozen + " timeout="
8843 + mAppTransitionTimeout + ")...");
8844 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8845 // If the display isn't frozen, wait to do anything until
8846 // all of the apps are ready. Otherwise just go because
8847 // we'll unfreeze the display when everyone is ready.
8848 for (i=0; i<NN && goodToGo; i++) {
8849 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008850 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008851 "Check opening app" + wtoken + ": allDrawn="
8852 + wtoken.allDrawn + " startingDisplayed="
8853 + wtoken.startingDisplayed);
8854 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8855 && !wtoken.startingMoved) {
8856 goodToGo = false;
8857 }
8858 }
8859 }
8860 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008861 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008862 int transit = mNextAppTransition;
8863 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008864 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008865 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008866 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008867 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008868 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008869 mAppTransitionTimeout = false;
8870 mStartingIconInTransition = false;
8871 mSkipAppTransitionAnimation = false;
8872
8873 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8874
Dianne Hackborna8f60182009-09-01 19:01:50 -07008875 // If there are applications waiting to come to the
8876 // top of the stack, now is the time to move their windows.
8877 // (Note that we don't do apps going to the bottom
8878 // here -- we want to keep their windows in the old
8879 // Z-order until the animation completes.)
8880 if (mToTopApps.size() > 0) {
8881 NN = mAppTokens.size();
8882 for (i=0; i<NN; i++) {
8883 AppWindowToken wtoken = mAppTokens.get(i);
8884 if (wtoken.sendingToTop) {
8885 wtoken.sendingToTop = false;
8886 moveAppWindowsLocked(wtoken, NN, false);
8887 }
8888 }
8889 mToTopApps.clear();
8890 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008891
Dianne Hackborn25994b42009-09-04 14:21:19 -07008892 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008893
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008894 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008895 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008896
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008897 // The top-most window will supply the layout params,
8898 // and we will determine it below.
8899 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008900 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008901 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008902
Joe Onorato8a9b2202010-02-26 18:56:32 -08008903 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008904 "New wallpaper target=" + mWallpaperTarget
8905 + ", lower target=" + mLowerWallpaperTarget
8906 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008907 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008908 // Do a first pass through the tokens for two
8909 // things:
8910 // (1) Determine if both the closing and opening
8911 // app token sets are wallpaper targets, in which
8912 // case special animations are needed
8913 // (since the wallpaper needs to stay static
8914 // behind them).
8915 // (2) Find the layout params of the top-most
8916 // application window in the tokens, which is
8917 // what will control the animation theme.
8918 final int NC = mClosingApps.size();
8919 NN = NC + mOpeningApps.size();
8920 for (i=0; i<NN; i++) {
8921 AppWindowToken wtoken;
8922 int mode;
8923 if (i < NC) {
8924 wtoken = mClosingApps.get(i);
8925 mode = 1;
8926 } else {
8927 wtoken = mOpeningApps.get(i-NC);
8928 mode = 2;
8929 }
8930 if (mLowerWallpaperTarget != null) {
8931 if (mLowerWallpaperTarget.mAppToken == wtoken
8932 || mUpperWallpaperTarget.mAppToken == wtoken) {
8933 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008934 }
8935 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008936 if (wtoken.appFullscreen) {
8937 WindowState ws = wtoken.findMainWindow();
8938 if (ws != null) {
8939 // If this is a compatibility mode
8940 // window, we will always use its anim.
8941 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8942 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008943 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008944 bestAnimLayer = Integer.MAX_VALUE;
8945 } else if (ws.mLayer > bestAnimLayer) {
8946 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008947 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008948 bestAnimLayer = ws.mLayer;
8949 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008950 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008951 }
8952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008953
Dianne Hackborn25994b42009-09-04 14:21:19 -07008954 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008955 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008956 "Wallpaper animation!");
8957 switch (transit) {
8958 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8959 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8960 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8961 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8962 break;
8963 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8964 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8965 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8966 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8967 break;
8968 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008969 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008970 "New transit: " + transit);
8971 } else if (oldWallpaper != null) {
8972 // We are transitioning from an activity with
8973 // a wallpaper to one without.
8974 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008975 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008976 "New transit away from wallpaper: " + transit);
8977 } else if (mWallpaperTarget != null) {
8978 // We are transitioning from an activity without
8979 // a wallpaper to now showing the wallpaper
8980 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008981 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008982 "New transit into wallpaper: " + transit);
8983 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008984
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008985 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8986 mLastEnterAnimToken = animToken;
8987 mLastEnterAnimParams = animLp;
8988 } else if (mLastEnterAnimParams != null) {
8989 animLp = mLastEnterAnimParams;
8990 mLastEnterAnimToken = null;
8991 mLastEnterAnimParams = null;
8992 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008993
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008994 // If all closing windows are obscured, then there is
8995 // no need to do an animation. This is the case, for
8996 // example, when this transition is being done behind
8997 // the lock screen.
8998 if (!mPolicy.allowAppAnimationsLw()) {
8999 animLp = null;
9000 }
9001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 NN = mOpeningApps.size();
9003 for (i=0; i<NN; i++) {
9004 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009005 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009006 "Now opening app" + wtoken);
9007 wtoken.reportedVisible = false;
9008 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009009 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009010 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009011 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009012 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009013 wtoken.showAllWindowsLocked();
9014 }
9015 NN = mClosingApps.size();
9016 for (i=0; i<NN; i++) {
9017 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009018 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 "Now closing app" + wtoken);
9020 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009021 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009022 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009023 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009024 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009025 // Force the allDrawn flag, because we want to start
9026 // this guy's animations regardless of whether it's
9027 // gotten drawn.
9028 wtoken.allDrawn = true;
9029 }
9030
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009031 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009033 mOpeningApps.clear();
9034 mClosingApps.clear();
9035
9036 // This has changed the visibility of windows, so perform
9037 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009038 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009039 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009040 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9041 assignLayersLocked();
9042 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009044 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009045 }
9046 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009047
Dianne Hackborn16064f92010-03-25 00:47:24 -07009048 int adjResult = 0;
9049
Dianne Hackborna8f60182009-09-01 19:01:50 -07009050 if (!animating && mAppTransitionRunning) {
9051 // We have finished the animation of an app transition. To do
9052 // this, we have delayed a lot of operations like showing and
9053 // hiding apps, moving apps in Z-order, etc. The app token list
9054 // reflects the correct Z-order, but the window list may now
9055 // be out of sync with it. So here we will just rebuild the
9056 // entire app window list. Fun!
9057 mAppTransitionRunning = false;
9058 // Clear information about apps that were moving.
9059 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009060
Dianne Hackborna8f60182009-09-01 19:01:50 -07009061 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009062 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009063 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009064 moveInputMethodWindowsIfNeededLocked(false);
9065 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009066 // Since the window list has been rebuilt, focus might
9067 // have to be recomputed since the actual order of windows
9068 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009069 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009070 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009071
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009072 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009073 // At this point, there was a window with a wallpaper that
9074 // was force hiding other windows behind it, but now it
9075 // is going away. This may be simple -- just animate
9076 // away the wallpaper and its window -- or it may be
9077 // hard -- the wallpaper now needs to be shown behind
9078 // something that was hidden.
9079 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009080 if (mLowerWallpaperTarget != null
9081 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009082 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009083 "wallpaperForceHiding changed with lower="
9084 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009085 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009086 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9087 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9088 if (mLowerWallpaperTarget.mAppToken.hidden) {
9089 // The lower target has become hidden before we
9090 // actually started the animation... let's completely
9091 // re-evaluate everything.
9092 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009093 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009094 }
9095 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009096 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009097 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009098 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009099 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009100 + " NEW: " + mWallpaperTarget
9101 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009102 if (mLowerWallpaperTarget == null) {
9103 // Whoops, we don't need a special wallpaper animation.
9104 // Clear them out.
9105 forceHiding = false;
9106 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009107 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009108 if (w.mSurface != null) {
9109 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009110 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009111 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009112 forceHiding = true;
9113 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9114 if (!w.mAnimating) {
9115 // We set the animation above so it
9116 // is not yet running.
9117 w.clearAnimation();
9118 }
9119 }
9120 }
9121 }
9122 }
9123 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009124
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009125 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009126 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009127 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009128 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009130
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009131 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009132 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009133 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009134 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009135 assignLayersLocked();
9136 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009137 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009138 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009139 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009140 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009141
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009142 if (mFocusMayChange) {
9143 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009144 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009145 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009146 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009147 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009148 }
9149
9150 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009151 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009152 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009153
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009154 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9155 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009156
Jeff Browne33348b2010-07-15 23:54:05 -07009157 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009158 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009159
9160 // THIRD LOOP: Update the surfaces of all windows.
9161
9162 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9163
9164 boolean obscured = false;
9165 boolean blurring = false;
9166 boolean dimming = false;
9167 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009168 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009169 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009170
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009171 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009173 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009174 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009175
9176 boolean displayed = false;
9177 final WindowManager.LayoutParams attrs = w.mAttrs;
9178 final int attrFlags = attrs.flags;
9179
9180 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009181 // XXX NOTE: The logic here could be improved. We have
9182 // the decision about whether to resize a window separated
9183 // from whether to hide the surface. This can cause us to
9184 // resize a surface even if we are going to hide it. You
9185 // can see this by (1) holding device in landscape mode on
9186 // home screen; (2) tapping browser icon (device will rotate
9187 // to landscape; (3) tap home. The wallpaper will be resized
9188 // in step 2 but then immediately hidden, causing us to
9189 // have to resize and then redraw it again in step 3. It
9190 // would be nice to figure out how to avoid this, but it is
9191 // difficult because we do need to resize surfaces in some
9192 // cases while they are hidden such as when first showing a
9193 // window.
9194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009195 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009196 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009197 TAG, "Placing surface #" + i + " " + w.mSurface
9198 + ": new=" + w.mShownFrame + ", old="
9199 + w.mLastShownFrame);
9200
9201 boolean resize;
9202 int width, height;
9203 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9204 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9205 w.mLastRequestedHeight != w.mRequestedHeight;
9206 // for a scaled surface, we just want to use
9207 // the requested size.
9208 width = w.mRequestedWidth;
9209 height = w.mRequestedHeight;
9210 w.mLastRequestedWidth = width;
9211 w.mLastRequestedHeight = height;
9212 w.mLastShownFrame.set(w.mShownFrame);
9213 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009214 if (SHOW_TRANSACTIONS) logSurface(w,
9215 "POS " + w.mShownFrame.left
9216 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009217 w.mSurfaceX = w.mShownFrame.left;
9218 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9220 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009221 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 if (!recoveringMemory) {
9223 reclaimSomeSurfaceMemoryLocked(w, "position");
9224 }
9225 }
9226 } else {
9227 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9228 width = w.mShownFrame.width();
9229 height = w.mShownFrame.height();
9230 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009231 }
9232
9233 if (resize) {
9234 if (width < 1) width = 1;
9235 if (height < 1) height = 1;
9236 if (w.mSurface != null) {
9237 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009238 if (SHOW_TRANSACTIONS) logSurface(w,
9239 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009240 + w.mShownFrame.top + " SIZE "
9241 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009242 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009243 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009244 w.mSurfaceW = width;
9245 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009246 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009247 w.mSurfaceX = w.mShownFrame.left;
9248 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 w.mSurface.setPosition(w.mShownFrame.left,
9250 w.mShownFrame.top);
9251 } catch (RuntimeException e) {
9252 // If something goes wrong with the surface (such
9253 // as running out of memory), don't take down the
9254 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009255 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009256 + "size=(" + width + "x" + height
9257 + "), pos=(" + w.mShownFrame.left
9258 + "," + w.mShownFrame.top + ")", e);
9259 if (!recoveringMemory) {
9260 reclaimSomeSurfaceMemoryLocked(w, "size");
9261 }
9262 }
9263 }
9264 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009265 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009266 w.mContentInsetsChanged =
9267 !w.mLastContentInsets.equals(w.mContentInsets);
9268 w.mVisibleInsetsChanged =
9269 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009270 boolean configChanged =
9271 w.mConfiguration != mCurConfiguration
9272 && (w.mConfiguration == null
9273 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009274 if (DEBUG_CONFIGURATION && configChanged) {
9275 Slog.v(TAG, "Win " + w + " config changed: "
9276 + mCurConfiguration);
9277 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009278 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009279 + ": configChanged=" + configChanged
9280 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009281 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009282 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009283 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009284 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009285 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009286 w.mLastFrame.set(w.mFrame);
9287 w.mLastContentInsets.set(w.mContentInsets);
9288 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009289 // If the screen is currently frozen, then keep
9290 // it frozen until this window draws at its new
9291 // orientation.
9292 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009293 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009294 "Resizing while display frozen: " + w);
9295 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009296 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009297 mWindowsFreezingScreen = true;
9298 // XXX should probably keep timeout from
9299 // when we first froze the display.
9300 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9301 mH.sendMessageDelayed(mH.obtainMessage(
9302 H.WINDOW_FREEZE_TIMEOUT), 2000);
9303 }
9304 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009305 // If the orientation is changing, then we need to
9306 // hold off on unfreezing the display until this
9307 // window has been redrawn; to do that, we need
9308 // to go through the process of getting informed
9309 // by the application when it has finished drawing.
9310 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009311 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 "Orientation start waiting for draw in "
9313 + w + ", surface " + w.mSurface);
9314 w.mDrawPending = true;
9315 w.mCommitDrawPending = false;
9316 w.mReadyToShow = false;
9317 if (w.mAppToken != null) {
9318 w.mAppToken.allDrawn = false;
9319 }
9320 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009321 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 "Resizing window " + w + " to " + w.mFrame);
9323 mResizingWindows.add(w);
9324 } else if (w.mOrientationChanging) {
9325 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009326 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 "Orientation not waiting for draw in "
9328 + w + ", surface " + w.mSurface);
9329 w.mOrientationChanging = false;
9330 }
9331 }
9332 }
9333
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009334 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 if (!w.mLastHidden) {
9336 //dump();
9337 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009338 if (SHOW_TRANSACTIONS) logSurface(w,
9339 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009341 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 try {
9343 w.mSurface.hide();
9344 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009345 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009346 }
9347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009348 }
9349 // If we are waiting for this window to handle an
9350 // orientation change, well, it is hidden, so
9351 // doesn't really matter. Note that this does
9352 // introduce a potential glitch if the window
9353 // becomes unhidden before it has drawn for the
9354 // new orientation.
9355 if (w.mOrientationChanging) {
9356 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009357 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 "Orientation change skips hidden " + w);
9359 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009360 } else if (w.mLastLayer != w.mAnimLayer
9361 || w.mLastAlpha != w.mShownAlpha
9362 || w.mLastDsDx != w.mDsDx
9363 || w.mLastDtDx != w.mDtDx
9364 || w.mLastDsDy != w.mDsDy
9365 || w.mLastDtDy != w.mDtDy
9366 || w.mLastHScale != w.mHScale
9367 || w.mLastVScale != w.mVScale
9368 || w.mLastHidden) {
9369 displayed = true;
9370 w.mLastAlpha = w.mShownAlpha;
9371 w.mLastLayer = w.mAnimLayer;
9372 w.mLastDsDx = w.mDsDx;
9373 w.mLastDtDx = w.mDtDx;
9374 w.mLastDsDy = w.mDsDy;
9375 w.mLastDtDy = w.mDtDy;
9376 w.mLastHScale = w.mHScale;
9377 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009378 if (SHOW_TRANSACTIONS) logSurface(w,
9379 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009380 + " matrix=[" + (w.mDsDx*w.mHScale)
9381 + "," + (w.mDtDx*w.mVScale)
9382 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009383 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 if (w.mSurface != null) {
9385 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009386 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009387 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009388 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009389 w.mSurface.setLayer(w.mAnimLayer);
9390 w.mSurface.setMatrix(
9391 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9392 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9393 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009394 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009395 if (!recoveringMemory) {
9396 reclaimSomeSurfaceMemoryLocked(w, "update");
9397 }
9398 }
9399 }
9400
9401 if (w.mLastHidden && !w.mDrawPending
9402 && !w.mCommitDrawPending
9403 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009404 if (SHOW_TRANSACTIONS) logSurface(w,
9405 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009406 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 + " during relayout");
9408 if (showSurfaceRobustlyLocked(w)) {
9409 w.mHasDrawn = true;
9410 w.mLastHidden = false;
9411 } else {
9412 w.mOrientationChanging = false;
9413 }
9414 }
9415 if (w.mSurface != null) {
9416 w.mToken.hasVisible = true;
9417 }
9418 } else {
9419 displayed = true;
9420 }
9421
9422 if (displayed) {
9423 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009424 if (attrs.width == LayoutParams.MATCH_PARENT
9425 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 covered = true;
9427 }
9428 }
9429 if (w.mOrientationChanging) {
9430 if (w.mDrawPending || w.mCommitDrawPending) {
9431 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009432 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009433 "Orientation continue waiting for draw in " + w);
9434 } else {
9435 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009436 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009437 "Orientation change complete in " + w);
9438 }
9439 }
9440 w.mToken.hasVisible = true;
9441 }
9442 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009443 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009444 "Orientation change skips hidden " + w);
9445 w.mOrientationChanging = false;
9446 }
9447
9448 final boolean canBeSeen = w.isDisplayedLw();
9449
9450 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9451 focusDisplayed = true;
9452 }
9453
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009454 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009456 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009457 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009458 if (w.mSurface != null) {
9459 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9460 holdScreen = w.mSession;
9461 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009462 if (!syswin && w.mAttrs.screenBrightness >= 0
9463 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009464 screenBrightness = w.mAttrs.screenBrightness;
9465 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009466 if (!syswin && w.mAttrs.buttonBrightness >= 0
9467 && buttonBrightness < 0) {
9468 buttonBrightness = w.mAttrs.buttonBrightness;
9469 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009470 if (canBeSeen
9471 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9472 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9473 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009474 syswin = true;
9475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009477
Dianne Hackborn25994b42009-09-04 14:21:19 -07009478 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9479 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 // This window completely covers everything behind it,
9481 // so we want to leave all of them as unblurred (for
9482 // performance reasons).
9483 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009484 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009485 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009486 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009487 obscured = true;
9488 if (mBackgroundFillerSurface == null) {
9489 try {
9490 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009491 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009492 0, dw, dh,
9493 PixelFormat.OPAQUE,
9494 Surface.FX_SURFACE_NORMAL);
9495 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009496 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009497 }
9498 }
9499 try {
9500 mBackgroundFillerSurface.setPosition(0, 0);
9501 mBackgroundFillerSurface.setSize(dw, dh);
9502 // Using the same layer as Dim because they will never be shown at the
9503 // same time.
9504 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9505 mBackgroundFillerSurface.show();
9506 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009507 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009508 }
9509 backgroundFillerShown = true;
9510 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009511 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009512 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009513 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514 + ": blurring=" + blurring
9515 + " obscured=" + obscured
9516 + " displayed=" + displayed);
9517 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9518 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009519 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009520 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009521 if (mDimAnimator == null) {
9522 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009524 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009525 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 }
9528 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9529 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009530 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009531 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009532 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009533 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 + mBlurSurface + ": CREATE");
9535 try {
Romain Guy06882f82009-06-10 13:36:04 -07009536 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009537 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009538 -1, 16, 16,
9539 PixelFormat.OPAQUE,
9540 Surface.FX_SURFACE_BLUR);
9541 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009542 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009543 }
9544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009546 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9547 + mBlurSurface + ": pos=(0,0) (" +
9548 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009549 mBlurSurface.setPosition(0, 0);
9550 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009551 mBlurSurface.setLayer(w.mAnimLayer-2);
9552 if (!mBlurShown) {
9553 try {
9554 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9555 + mBlurSurface + ": SHOW");
9556 mBlurSurface.show();
9557 } catch (RuntimeException e) {
9558 Slog.w(TAG, "Failure showing blur surface", e);
9559 }
9560 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009561 }
9562 }
9563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009564 }
9565 }
9566 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009567
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009568 if (obscuredChanged && mWallpaperTarget == w) {
9569 // This is the wallpaper target and its obscured state
9570 // changed... make sure the current wallaper's visibility
9571 // has been updated accordingly.
9572 updateWallpaperVisibilityLocked();
9573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009574 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009575
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009576 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9577 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009578 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009579 try {
9580 mBackgroundFillerSurface.hide();
9581 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009582 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009583 }
9584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009585
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009586 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009587 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9588 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 }
Romain Guy06882f82009-06-10 13:36:04 -07009590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009591 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009592 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 + ": HIDE");
9594 try {
9595 mBlurSurface.hide();
9596 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009597 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009598 }
9599 mBlurShown = false;
9600 }
9601
Joe Onorato8a9b2202010-02-26 18:56:32 -08009602 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009604 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 }
9606
Jeff Browne33348b2010-07-15 23:54:05 -07009607 mInputMonitor.updateInputWindowsLw();
9608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009609 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009610
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07009611 if (mWatermark != null) {
9612 mWatermark.drawIfNeeded();
9613 }
9614
Joe Onorato8a9b2202010-02-26 18:56:32 -08009615 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009616 "With display frozen, orientationChangeComplete="
9617 + orientationChangeComplete);
9618 if (orientationChangeComplete) {
9619 if (mWindowsFreezingScreen) {
9620 mWindowsFreezingScreen = false;
9621 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9622 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009623 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009624 }
Romain Guy06882f82009-06-10 13:36:04 -07009625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009626 i = mResizingWindows.size();
9627 if (i > 0) {
9628 do {
9629 i--;
9630 WindowState win = mResizingWindows.get(i);
9631 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009632 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9633 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009634 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009635 boolean configChanged =
9636 win.mConfiguration != mCurConfiguration
9637 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009638 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9639 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9640 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009641 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009642 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009643 + " / " + mCurConfiguration + " / 0x"
9644 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009645 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009646 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009647 win.mClient.resized(win.mFrame.width(),
9648 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009649 win.mLastVisibleInsets, win.mDrawPending,
9650 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 win.mContentInsetsChanged = false;
9652 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009653 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009654 } catch (RemoteException e) {
9655 win.mOrientationChanging = false;
9656 }
9657 } while (i > 0);
9658 mResizingWindows.clear();
9659 }
Romain Guy06882f82009-06-10 13:36:04 -07009660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009662 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009663 i = mDestroySurface.size();
9664 if (i > 0) {
9665 do {
9666 i--;
9667 WindowState win = mDestroySurface.get(i);
9668 win.mDestroying = false;
9669 if (mInputMethodWindow == win) {
9670 mInputMethodWindow = null;
9671 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009672 if (win == mWallpaperTarget) {
9673 wallpaperDestroyed = true;
9674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009675 win.destroySurfaceLocked();
9676 } while (i > 0);
9677 mDestroySurface.clear();
9678 }
9679
9680 // Time to remove any exiting tokens?
9681 for (i=mExitingTokens.size()-1; i>=0; i--) {
9682 WindowToken token = mExitingTokens.get(i);
9683 if (!token.hasVisible) {
9684 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009685 if (token.windowType == TYPE_WALLPAPER) {
9686 mWallpaperTokens.remove(token);
9687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009688 }
9689 }
9690
9691 // Time to remove any exiting applications?
9692 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9693 AppWindowToken token = mExitingAppTokens.get(i);
9694 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009695 // Make sure there is no animation running on this token,
9696 // so any windows associated with it will be removed as
9697 // soon as their animations are complete
9698 token.animation = null;
9699 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009700 mAppTokens.remove(token);
9701 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009702 if (mLastEnterAnimToken == token) {
9703 mLastEnterAnimToken = null;
9704 mLastEnterAnimParams = null;
9705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009706 }
9707 }
9708
Dianne Hackborna8f60182009-09-01 19:01:50 -07009709 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009710
Dianne Hackborna8f60182009-09-01 19:01:50 -07009711 if (!animating && mAppTransitionRunning) {
9712 // We have finished the animation of an app transition. To do
9713 // this, we have delayed a lot of operations like showing and
9714 // hiding apps, moving apps in Z-order, etc. The app token list
9715 // reflects the correct Z-order, but the window list may now
9716 // be out of sync with it. So here we will just rebuild the
9717 // entire app window list. Fun!
9718 mAppTransitionRunning = false;
9719 needRelayout = true;
9720 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009721 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009722 // Clear information about apps that were moving.
9723 mToBottomApps.clear();
9724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009726 if (focusDisplayed) {
9727 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9728 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009729 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009730 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009731 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009732 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009733 requestAnimationLocked(0);
9734 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009735 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9736 }
Jeff Browneb857f12010-07-16 10:06:33 -07009737
Jeff Browne33348b2010-07-15 23:54:05 -07009738 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009739
Jeff Brown8e03b752010-06-13 19:16:55 -07009740 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9742 mPowerManager.setScreenBrightnessOverride(-1);
9743 } else {
9744 mPowerManager.setScreenBrightnessOverride((int)
9745 (screenBrightness * Power.BRIGHTNESS_ON));
9746 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009747 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9748 mPowerManager.setButtonBrightnessOverride(-1);
9749 } else {
9750 mPowerManager.setButtonBrightnessOverride((int)
9751 (buttonBrightness * Power.BRIGHTNESS_ON));
9752 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 if (holdScreen != mHoldingScreenOn) {
9754 mHoldingScreenOn = holdScreen;
9755 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9756 mH.sendMessage(m);
9757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009758
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009759 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009760 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009761 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9762 LocalPowerManager.BUTTON_EVENT, true);
9763 mTurnOnScreen = false;
9764 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009765
9766 // Check to see if we are now in a state where the screen should
9767 // be enabled, because the window obscured flags have changed.
9768 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009770
9771 /**
9772 * Must be called with the main window manager lock held.
9773 */
9774 void setHoldScreenLocked(boolean holding) {
9775 boolean state = mHoldingScreenWakeLock.isHeld();
9776 if (holding != state) {
9777 if (holding) {
9778 mHoldingScreenWakeLock.acquire();
9779 } else {
9780 mPolicy.screenOnStoppedLw();
9781 mHoldingScreenWakeLock.release();
9782 }
9783 }
9784 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009785
9786 void requestAnimationLocked(long delay) {
9787 if (!mAnimationPending) {
9788 mAnimationPending = true;
9789 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9790 }
9791 }
Romain Guy06882f82009-06-10 13:36:04 -07009792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009793 /**
9794 * Have the surface flinger show a surface, robustly dealing with
9795 * error conditions. In particular, if there is not enough memory
9796 * to show the surface, then we will try to get rid of other surfaces
9797 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009798 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009799 * @return Returns true if the surface was successfully shown.
9800 */
9801 boolean showSurfaceRobustlyLocked(WindowState win) {
9802 try {
9803 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009804 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009806 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009807 if (DEBUG_VISIBILITY) Slog.v(TAG,
9808 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009809 win.mTurnOnScreen = false;
9810 mTurnOnScreen = true;
9811 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 }
9813 return true;
9814 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009815 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 }
Romain Guy06882f82009-06-10 13:36:04 -07009817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009820 return false;
9821 }
Romain Guy06882f82009-06-10 13:36:04 -07009822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009823 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9824 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009825
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009826 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 if (mForceRemoves == null) {
9830 mForceRemoves = new ArrayList<WindowState>();
9831 }
Romain Guy06882f82009-06-10 13:36:04 -07009832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009833 long callingIdentity = Binder.clearCallingIdentity();
9834 try {
9835 // There was some problem... first, do a sanity check of the
9836 // window list to make sure we haven't left any dangling surfaces
9837 // around.
9838 int N = mWindows.size();
9839 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009840 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009841 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009842 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009843 if (ws.mSurface != null) {
9844 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009845 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 + ws + " surface=" + ws.mSurface
9847 + " token=" + win.mToken
9848 + " pid=" + ws.mSession.mPid
9849 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009850 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009851 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009852 ws.mSurface = null;
9853 mForceRemoves.add(ws);
9854 i--;
9855 N--;
9856 leakedSurface = true;
9857 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009858 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 + ws + " surface=" + ws.mSurface
9860 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009861 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009862 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009863 ws.mSurface = null;
9864 leakedSurface = true;
9865 }
9866 }
9867 }
Romain Guy06882f82009-06-10 13:36:04 -07009868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009869 boolean killedApps = false;
9870 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009871 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 SparseIntArray pidCandidates = new SparseIntArray();
9873 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009874 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009875 if (ws.mSurface != null) {
9876 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9877 }
9878 }
9879 if (pidCandidates.size() > 0) {
9880 int[] pids = new int[pidCandidates.size()];
9881 for (int i=0; i<pids.length; i++) {
9882 pids[i] = pidCandidates.keyAt(i);
9883 }
9884 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009885 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009886 killedApps = true;
9887 }
9888 } catch (RemoteException e) {
9889 }
9890 }
9891 }
Romain Guy06882f82009-06-10 13:36:04 -07009892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 if (leakedSurface || killedApps) {
9894 // We managed to reclaim some memory, so get rid of the trouble
9895 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009896 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009897 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009898 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009899 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 win.mSurface = null;
9901 }
Romain Guy06882f82009-06-10 13:36:04 -07009902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 try {
9904 win.mClient.dispatchGetNewSurface();
9905 } catch (RemoteException e) {
9906 }
9907 }
9908 } finally {
9909 Binder.restoreCallingIdentity(callingIdentity);
9910 }
9911 }
Romain Guy06882f82009-06-10 13:36:04 -07009912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913 private boolean updateFocusedWindowLocked(int mode) {
9914 WindowState newFocus = computeFocusedWindowLocked();
9915 if (mCurrentFocus != newFocus) {
9916 // This check makes sure that we don't already have the focus
9917 // change message pending.
9918 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9919 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009920 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009921 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9922 final WindowState oldFocus = mCurrentFocus;
9923 mCurrentFocus = newFocus;
9924 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926 final WindowState imWindow = mInputMethodWindow;
9927 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009928 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009930 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9931 mLayoutNeeded = true;
9932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9934 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009935 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9936 // Client will do the layout, but we need to assign layers
9937 // for handleNewWindowLocked() below.
9938 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 }
9940 }
Jeff Brown349703e2010-06-22 01:27:15 -07009941
9942 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9943 // If we defer assigning layers, then the caller is responsible for
9944 // doing this part.
9945 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009947 return true;
9948 }
9949 return false;
9950 }
Jeff Brown349703e2010-06-22 01:27:15 -07009951
9952 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009953 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955
9956 private WindowState computeFocusedWindowLocked() {
9957 WindowState result = null;
9958 WindowState win;
9959
9960 int i = mWindows.size() - 1;
9961 int nextAppIndex = mAppTokens.size()-1;
9962 WindowToken nextApp = nextAppIndex >= 0
9963 ? mAppTokens.get(nextAppIndex) : null;
9964
9965 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009966 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009967
Joe Onorato8a9b2202010-02-26 18:56:32 -08009968 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009969 TAG, "Looking for focus: " + i
9970 + " = " + win
9971 + ", flags=" + win.mAttrs.flags
9972 + ", canReceive=" + win.canReceiveKeys());
9973
9974 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 // If this window's application has been removed, just skip it.
9977 if (thisApp != null && thisApp.removed) {
9978 i--;
9979 continue;
9980 }
Romain Guy06882f82009-06-10 13:36:04 -07009981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009982 // If there is a focused app, don't allow focus to go to any
9983 // windows below it. If this is an application window, step
9984 // through the app tokens until we find its app.
9985 if (thisApp != null && nextApp != null && thisApp != nextApp
9986 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9987 int origAppIndex = nextAppIndex;
9988 while (nextAppIndex > 0) {
9989 if (nextApp == mFocusedApp) {
9990 // Whoops, we are below the focused app... no focus
9991 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009992 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 TAG, "Reached focused app: " + mFocusedApp);
9994 return null;
9995 }
9996 nextAppIndex--;
9997 nextApp = mAppTokens.get(nextAppIndex);
9998 if (nextApp == thisApp) {
9999 break;
10000 }
10001 }
10002 if (thisApp != nextApp) {
10003 // Uh oh, the app token doesn't exist! This shouldn't
10004 // happen, but if it does we can get totally hosed...
10005 // so restart at the original app.
10006 nextAppIndex = origAppIndex;
10007 nextApp = mAppTokens.get(nextAppIndex);
10008 }
10009 }
10010
10011 // Dispatch to this window if it is wants key events.
10012 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010013 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010014 TAG, "Found focus @ " + i + " = " + win);
10015 result = win;
10016 break;
10017 }
10018
10019 i--;
10020 }
10021
10022 return result;
10023 }
10024
10025 private void startFreezingDisplayLocked() {
10026 if (mDisplayFrozen) {
10027 return;
10028 }
Romain Guy06882f82009-06-10 13:36:04 -070010029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010032 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010033 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010034 if (mFreezeGcPending != 0) {
10035 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010036 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010037 mH.removeMessages(H.FORCE_GC);
10038 Runtime.getRuntime().gc();
10039 mFreezeGcPending = now;
10040 }
10041 } else {
10042 mFreezeGcPending = now;
10043 }
Romain Guy06882f82009-06-10 13:36:04 -070010044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010045 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010046
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010047 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010048
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010049 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10050 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010051 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010052 mAppTransitionReady = true;
10053 }
Romain Guy06882f82009-06-10 13:36:04 -070010054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 if (PROFILE_ORIENTATION) {
10056 File file = new File("/data/system/frozen");
10057 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10058 }
10059 Surface.freezeDisplay(0);
10060 }
Romain Guy06882f82009-06-10 13:36:04 -070010061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010062 private void stopFreezingDisplayLocked() {
10063 if (!mDisplayFrozen) {
10064 return;
10065 }
Romain Guy06882f82009-06-10 13:36:04 -070010066
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010067 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10068 return;
10069 }
10070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 mDisplayFrozen = false;
10072 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10073 if (PROFILE_ORIENTATION) {
10074 Debug.stopMethodTracing();
10075 }
10076 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010077
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010078 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010079
Christopher Tateb696aee2010-04-02 19:08:30 -070010080 // While the display is frozen we don't re-compute the orientation
10081 // to avoid inconsistent states. However, something interesting
10082 // could have actually changed during that time so re-evaluate it
10083 // now to catch that.
10084 if (updateOrientationFromAppTokensLocked()) {
10085 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10086 }
10087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010088 // A little kludge: a lot could have happened while the
10089 // display was frozen, so now that we are coming back we
10090 // do a gc so that any remote references the system
10091 // processes holds on others can be released if they are
10092 // no longer needed.
10093 mH.removeMessages(H.FORCE_GC);
10094 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10095 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010097 mScreenFrozenLock.release();
10098 }
Romain Guy06882f82009-06-10 13:36:04 -070010099
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010100 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10101 DisplayMetrics dm) {
10102 if (index < tokens.length) {
10103 String str = tokens[index];
10104 if (str != null && str.length() > 0) {
10105 try {
10106 int val = Integer.parseInt(str);
10107 return val;
10108 } catch (Exception e) {
10109 }
10110 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010111 }
10112 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10113 return defDps;
10114 }
10115 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10116 return val;
10117 }
10118
10119 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010120 final String[] mTokens;
10121 final String mText;
10122 final Paint mTextPaint;
10123 final int mTextWidth;
10124 final int mTextHeight;
10125 final int mTextAscent;
10126 final int mTextDescent;
10127 final int mDeltaX;
10128 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010129
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010130 Surface mSurface;
10131 int mLastDW;
10132 int mLastDH;
10133 boolean mDrawNeeded;
10134
10135 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010136 final DisplayMetrics dm = new DisplayMetrics();
10137 mDisplay.getMetrics(dm);
10138
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010139 if (false) {
10140 Log.i(TAG, "*********************** WATERMARK");
10141 for (int i=0; i<tokens.length; i++) {
10142 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10143 }
10144 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010145
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010146 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010147
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010148 StringBuilder builder = new StringBuilder(32);
10149 int len = mTokens[0].length();
10150 len = len & ~1;
10151 for (int i=0; i<len; i+=2) {
10152 int c1 = mTokens[0].charAt(i);
10153 int c2 = mTokens[0].charAt(i+1);
10154 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10155 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10156 else c1 -= '0';
10157 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10158 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10159 else c2 -= '0';
10160 builder.append((char)(255-((c1*16)+c2)));
10161 }
10162 mText = builder.toString();
10163 if (false) {
10164 Log.i(TAG, "Final text: " + mText);
10165 }
10166
10167 int fontSize = getPropertyInt(tokens, 1,
10168 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10169
10170 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10171 mTextPaint.setTextSize(fontSize);
10172 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10173
10174 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10175 mTextWidth = (int)mTextPaint.measureText(mText);
10176 mTextAscent = fm.ascent;
10177 mTextDescent = fm.descent;
10178 mTextHeight = fm.descent - fm.ascent;
10179
10180 mDeltaX = getPropertyInt(tokens, 2,
10181 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10182 mDeltaY = getPropertyInt(tokens, 3,
10183 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10184 int shadowColor = getPropertyInt(tokens, 4,
10185 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10186 int color = getPropertyInt(tokens, 5,
10187 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10188 int shadowRadius = getPropertyInt(tokens, 6,
10189 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10190 int shadowDx = getPropertyInt(tokens, 8,
10191 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10192 int shadowDy = getPropertyInt(tokens, 9,
10193 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10194
10195 mTextPaint.setColor(color);
10196 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010197
10198 try {
10199 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010200 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010201 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010202 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010203 mSurface.show();
10204 } catch (OutOfResourcesException e) {
10205 }
10206 }
10207
10208 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010209 if (mLastDW != dw || mLastDH != dh) {
10210 mLastDW = dw;
10211 mLastDH = dh;
10212 mSurface.setSize(dw, dh);
10213 mDrawNeeded = true;
10214 }
10215 }
10216
10217 void drawIfNeeded() {
10218 if (mDrawNeeded) {
10219 final int dw = mLastDW;
10220 final int dh = mLastDH;
10221
10222 mDrawNeeded = false;
10223 Rect dirty = new Rect(0, 0, dw, dh);
10224 Canvas c = null;
10225 try {
10226 c = mSurface.lockCanvas(dirty);
10227 } catch (IllegalArgumentException e) {
10228 } catch (OutOfResourcesException e) {
10229 }
10230 if (c != null) {
10231 int deltaX = mDeltaX;
10232 int deltaY = mDeltaY;
10233
10234 // deltaX shouldn't be close to a round fraction of our
10235 // x step, or else things will line up too much.
10236 int div = (dw+mTextWidth)/deltaX;
10237 int rem = (dw+mTextWidth) - (div*deltaX);
10238 int qdelta = deltaX/4;
10239 if (rem < qdelta || rem > (deltaX-qdelta)) {
10240 deltaX += deltaX/3;
10241 }
10242
10243 int y = -mTextHeight;
10244 int x = -mTextWidth;
10245 while (y < (dh+mTextHeight)) {
10246 c.drawText(mText, x, y, mTextPaint);
10247 x += deltaX;
10248 if (x >= dw) {
10249 x -= (dw+mTextWidth);
10250 y += deltaY;
10251 }
10252 }
10253 mSurface.unlockCanvasAndPost(c);
10254 }
10255 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010256 }
10257 }
10258
10259 void createWatermark() {
10260 if (mWatermark != null) {
10261 return;
10262 }
10263
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010264 File file = new File("/system/etc/setup.conf");
10265 FileInputStream in = null;
10266 try {
10267 in = new FileInputStream(file);
10268 DataInputStream ind = new DataInputStream(in);
10269 String line = ind.readLine();
10270 if (line != null) {
10271 String[] toks = line.split("%");
10272 if (toks != null && toks.length > 0) {
10273 mWatermark = new Watermark(mFxSession, toks);
10274 }
10275 }
10276 } catch (FileNotFoundException e) {
10277 } catch (IOException e) {
10278 } finally {
10279 if (in != null) {
10280 try {
10281 in.close();
10282 } catch (IOException e) {
10283 }
10284 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010285 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010286 }
10287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 @Override
10289 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10290 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10291 != PackageManager.PERMISSION_GRANTED) {
10292 pw.println("Permission Denial: can't dump WindowManager from from pid="
10293 + Binder.getCallingPid()
10294 + ", uid=" + Binder.getCallingUid());
10295 return;
10296 }
Romain Guy06882f82009-06-10 13:36:04 -070010297
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010298 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010299 pw.println(" ");
10300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010301 synchronized(mWindowMap) {
10302 pw.println("Current Window Manager state:");
10303 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010304 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010305 pw.print(" Window #"); pw.print(i); pw.print(' ');
10306 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 w.dump(pw, " ");
10308 }
10309 if (mInputMethodDialogs.size() > 0) {
10310 pw.println(" ");
10311 pw.println(" Input method dialogs:");
10312 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10313 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010314 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010315 }
10316 }
10317 if (mPendingRemove.size() > 0) {
10318 pw.println(" ");
10319 pw.println(" Remove pending for:");
10320 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10321 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010322 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10323 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 w.dump(pw, " ");
10325 }
10326 }
10327 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10328 pw.println(" ");
10329 pw.println(" Windows force removing:");
10330 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10331 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010332 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10333 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010334 w.dump(pw, " ");
10335 }
10336 }
10337 if (mDestroySurface.size() > 0) {
10338 pw.println(" ");
10339 pw.println(" Windows waiting to destroy their surface:");
10340 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10341 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010342 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10343 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010344 w.dump(pw, " ");
10345 }
10346 }
10347 if (mLosingFocus.size() > 0) {
10348 pw.println(" ");
10349 pw.println(" Windows losing focus:");
10350 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10351 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010352 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10353 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354 w.dump(pw, " ");
10355 }
10356 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010357 if (mResizingWindows.size() > 0) {
10358 pw.println(" ");
10359 pw.println(" Windows waiting to resize:");
10360 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10361 WindowState w = mResizingWindows.get(i);
10362 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10363 pw.print(w); pw.println(":");
10364 w.dump(pw, " ");
10365 }
10366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 if (mSessions.size() > 0) {
10368 pw.println(" ");
10369 pw.println(" All active sessions:");
10370 Iterator<Session> it = mSessions.iterator();
10371 while (it.hasNext()) {
10372 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010373 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010374 s.dump(pw, " ");
10375 }
10376 }
10377 if (mTokenMap.size() > 0) {
10378 pw.println(" ");
10379 pw.println(" All tokens:");
10380 Iterator<WindowToken> it = mTokenMap.values().iterator();
10381 while (it.hasNext()) {
10382 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010383 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010384 token.dump(pw, " ");
10385 }
10386 }
10387 if (mTokenList.size() > 0) {
10388 pw.println(" ");
10389 pw.println(" Window token list:");
10390 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010391 pw.print(" #"); pw.print(i); pw.print(": ");
10392 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 }
10394 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010395 if (mWallpaperTokens.size() > 0) {
10396 pw.println(" ");
10397 pw.println(" Wallpaper tokens:");
10398 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10399 WindowToken token = mWallpaperTokens.get(i);
10400 pw.print(" Wallpaper #"); pw.print(i);
10401 pw.print(' '); pw.print(token); pw.println(':');
10402 token.dump(pw, " ");
10403 }
10404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010405 if (mAppTokens.size() > 0) {
10406 pw.println(" ");
10407 pw.println(" Application tokens in Z order:");
10408 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010409 pw.print(" App #"); pw.print(i); pw.print(": ");
10410 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 }
10412 }
10413 if (mFinishedStarting.size() > 0) {
10414 pw.println(" ");
10415 pw.println(" Finishing start of application tokens:");
10416 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10417 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010418 pw.print(" Finished Starting #"); pw.print(i);
10419 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010420 token.dump(pw, " ");
10421 }
10422 }
10423 if (mExitingTokens.size() > 0) {
10424 pw.println(" ");
10425 pw.println(" Exiting tokens:");
10426 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10427 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010428 pw.print(" Exiting #"); pw.print(i);
10429 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010430 token.dump(pw, " ");
10431 }
10432 }
10433 if (mExitingAppTokens.size() > 0) {
10434 pw.println(" ");
10435 pw.println(" Exiting application tokens:");
10436 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10437 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010438 pw.print(" Exiting App #"); pw.print(i);
10439 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010440 token.dump(pw, " ");
10441 }
10442 }
10443 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010444 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10445 pw.print(" mLastFocus="); pw.println(mLastFocus);
10446 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10447 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10448 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010449 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010450 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10451 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10452 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10453 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010454 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10455 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10456 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010457 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10458 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10459 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10460 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010461 if (mDimAnimator != null) {
10462 mDimAnimator.printTo(pw);
10463 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010464 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010465 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010466 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010467 pw.print(mInputMethodAnimLayerAdjustment);
10468 pw.print(" mWallpaperAnimLayerAdjustment=");
10469 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010470 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10471 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010472 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10473 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010474 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10475 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010476 pw.print(" mRotation="); pw.print(mRotation);
10477 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10478 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10479 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10480 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10481 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10482 pw.print(" mNextAppTransition=0x");
10483 pw.print(Integer.toHexString(mNextAppTransition));
10484 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010485 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010486 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010487 if (mNextAppTransitionPackage != null) {
10488 pw.print(" mNextAppTransitionPackage=");
10489 pw.print(mNextAppTransitionPackage);
10490 pw.print(", mNextAppTransitionEnter=0x");
10491 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10492 pw.print(", mNextAppTransitionExit=0x");
10493 pw.print(Integer.toHexString(mNextAppTransitionExit));
10494 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010495 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10496 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010497 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10498 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10499 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10500 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010501 if (mOpeningApps.size() > 0) {
10502 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10503 }
10504 if (mClosingApps.size() > 0) {
10505 pw.print(" mClosingApps="); pw.println(mClosingApps);
10506 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010507 if (mToTopApps.size() > 0) {
10508 pw.print(" mToTopApps="); pw.println(mToTopApps);
10509 }
10510 if (mToBottomApps.size() > 0) {
10511 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10512 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010513 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10514 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 }
10516 }
10517
Jeff Brown349703e2010-06-22 01:27:15 -070010518 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 public void monitor() {
10520 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010521 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010523
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010524 /**
10525 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010526 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010527 */
10528 private static class DimAnimator {
10529 Surface mDimSurface;
10530 boolean mDimShown = false;
10531 float mDimCurrentAlpha;
10532 float mDimTargetAlpha;
10533 float mDimDeltaPerMs;
10534 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010535
10536 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010537
10538 DimAnimator (SurfaceSession session) {
10539 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010540 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010541 + mDimSurface + ": CREATE");
10542 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010543 mDimSurface = new Surface(session, 0,
10544 "DimSurface",
10545 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010546 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010547 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010548 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010549 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010550 }
10551 }
10552 }
10553
10554 /**
10555 * Show the dim surface.
10556 */
10557 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010558 if (!mDimShown) {
10559 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10560 dw + "x" + dh + ")");
10561 mDimShown = true;
10562 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010563 mLastDimWidth = dw;
10564 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010565 mDimSurface.setPosition(0, 0);
10566 mDimSurface.setSize(dw, dh);
10567 mDimSurface.show();
10568 } catch (RuntimeException e) {
10569 Slog.w(TAG, "Failure showing dim surface", e);
10570 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010571 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10572 mLastDimWidth = dw;
10573 mLastDimHeight = dh;
10574 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010575 }
10576 }
10577
10578 /**
10579 * Set's the dim surface's layer and update dim parameters that will be used in
10580 * {@link updateSurface} after all windows are examined.
10581 */
10582 void updateParameters(WindowState w, long currentTime) {
10583 mDimSurface.setLayer(w.mAnimLayer-1);
10584
10585 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010586 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010587 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010588 if (mDimTargetAlpha != target) {
10589 // If the desired dim level has changed, then
10590 // start an animation to it.
10591 mLastDimAnimTime = currentTime;
10592 long duration = (w.mAnimating && w.mAnimation != null)
10593 ? w.mAnimation.computeDurationHint()
10594 : DEFAULT_DIM_DURATION;
10595 if (target > mDimTargetAlpha) {
10596 // This is happening behind the activity UI,
10597 // so we can make it run a little longer to
10598 // give a stronger impression without disrupting
10599 // the user.
10600 duration *= DIM_DURATION_MULTIPLIER;
10601 }
10602 if (duration < 1) {
10603 // Don't divide by zero
10604 duration = 1;
10605 }
10606 mDimTargetAlpha = target;
10607 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10608 }
10609 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010610
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010611 /**
10612 * Updating the surface's alpha. Returns true if the animation continues, or returns
10613 * false when the animation is finished and the dim surface is hidden.
10614 */
10615 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10616 if (!dimming) {
10617 if (mDimTargetAlpha != 0) {
10618 mLastDimAnimTime = currentTime;
10619 mDimTargetAlpha = 0;
10620 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10621 }
10622 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010623
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010624 boolean animating = false;
10625 if (mLastDimAnimTime != 0) {
10626 mDimCurrentAlpha += mDimDeltaPerMs
10627 * (currentTime-mLastDimAnimTime);
10628 boolean more = true;
10629 if (displayFrozen) {
10630 // If the display is frozen, there is no reason to animate.
10631 more = false;
10632 } else if (mDimDeltaPerMs > 0) {
10633 if (mDimCurrentAlpha > mDimTargetAlpha) {
10634 more = false;
10635 }
10636 } else if (mDimDeltaPerMs < 0) {
10637 if (mDimCurrentAlpha < mDimTargetAlpha) {
10638 more = false;
10639 }
10640 } else {
10641 more = false;
10642 }
10643
10644 // Do we need to continue animating?
10645 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010646 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010647 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10648 mLastDimAnimTime = currentTime;
10649 mDimSurface.setAlpha(mDimCurrentAlpha);
10650 animating = true;
10651 } else {
10652 mDimCurrentAlpha = mDimTargetAlpha;
10653 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010654 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010655 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10656 mDimSurface.setAlpha(mDimCurrentAlpha);
10657 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010658 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010659 + ": HIDE");
10660 try {
10661 mDimSurface.hide();
10662 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010663 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010664 }
10665 mDimShown = false;
10666 }
10667 }
10668 }
10669 return animating;
10670 }
10671
10672 public void printTo(PrintWriter pw) {
10673 pw.print(" mDimShown="); pw.print(mDimShown);
10674 pw.print(" current="); pw.print(mDimCurrentAlpha);
10675 pw.print(" target="); pw.print(mDimTargetAlpha);
10676 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10677 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10678 }
10679 }
10680
10681 /**
10682 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10683 * This is used for opening/closing transition for apps in compatible mode.
10684 */
10685 private static class FadeInOutAnimation extends Animation {
10686 int mWidth;
10687 boolean mFadeIn;
10688
10689 public FadeInOutAnimation(boolean fadeIn) {
10690 setInterpolator(new AccelerateInterpolator());
10691 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10692 mFadeIn = fadeIn;
10693 }
10694
10695 @Override
10696 protected void applyTransformation(float interpolatedTime, Transformation t) {
10697 float x = interpolatedTime;
10698 if (!mFadeIn) {
10699 x = 1.0f - x; // reverse the interpolation for fade out
10700 }
10701 if (x < 0.5) {
10702 // move the window out of the screen.
10703 t.getMatrix().setTranslate(mWidth, 0);
10704 } else {
10705 t.getMatrix().setTranslate(0, 0);// show
10706 t.setAlpha((x - 0.5f) * 2);
10707 }
10708 }
10709
10710 @Override
10711 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10712 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10713 mWidth = width;
10714 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010715
10716 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010717 public int getZAdjustment() {
10718 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010719 }
10720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010721}