blob: dacdd7dea3bb1a9e808e049ed82e304d1cd83f0e [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.
Jeff Brownb88102f2010-09-08 11:49:43 -07005092 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005093 *
5094 * Called by the InputManager.
5095 */
5096 public long notifyInputChannelANR(InputChannel inputChannel) {
5097 AppWindowToken token;
5098 synchronized (mWindowMap) {
5099 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5100 if (windowState == null) {
Jeff Brownb88102f2010-09-08 11:49:43 -07005101 return 0; // window is unknown, abort dispatching
Jeff Brown349703e2010-06-22 01:27:15 -07005102 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005103
Jeff Brown349703e2010-06-22 01:27:15 -07005104 Slog.i(TAG, "Input event dispatching timed out sending to "
5105 + windowState.mAttrs.getTitle());
5106 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005107 }
5108
Jeff Brown349703e2010-06-22 01:27:15 -07005109 return notifyANRInternal(token);
5110 }
5111
5112 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5113 * by successfully delivering the event that originally timed out.
5114 *
5115 * Called by the InputManager.
5116 */
5117 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5118 // Nothing to do just now.
5119 // Just wait for the user to dismiss the ANR dialog.
5120 }
5121
5122 /* Notifies the window manager about an application that is not responding
5123 * in general rather than with respect to a particular input channel.
Jeff Brownb88102f2010-09-08 11:49:43 -07005124 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005125 *
5126 * Called by the InputManager.
5127 */
5128 public long notifyANR(Object token) {
5129 AppWindowToken appWindowToken = (AppWindowToken) token;
5130
5131 Slog.i(TAG, "Input event dispatching timed out sending to application "
5132 + appWindowToken.stringName);
5133 return notifyANRInternal(appWindowToken);
5134 }
5135
5136 private long notifyANRInternal(AppWindowToken token) {
5137 if (token != null && token.appToken != null) {
5138 try {
5139 // Notify the activity manager about the timeout and let it decide whether
5140 // to abort dispatching or keep waiting.
5141 boolean abort = token.appToken.keyDispatchingTimedOut();
5142 if (! abort) {
5143 // The activity manager declined to abort dispatching.
5144 // Wait a bit longer and timeout again later.
5145 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005146 }
Jeff Brown349703e2010-06-22 01:27:15 -07005147 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005148 }
5149 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005150 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005151 }
5152
Jeff Brown349703e2010-06-22 01:27:15 -07005153 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5154 synchronized (mWindowMap) {
5155 return getWindowStateForInputChannelLocked(inputChannel);
5156 }
5157 }
5158
5159 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5160 int windowCount = mWindows.size();
5161 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005162 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005163 if (windowState.mInputChannel == inputChannel) {
5164 return windowState;
5165 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005166 }
5167
Jeff Brown349703e2010-06-22 01:27:15 -07005168 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005169 }
5170
Jeff Brown349703e2010-06-22 01:27:15 -07005171 /* Updates the cached window information provided to the input dispatcher. */
5172 public void updateInputWindowsLw() {
5173 // Populate the input window list with information about all of the windows that
5174 // could potentially receive input.
5175 // As an optimization, we could try to prune the list of windows but this turns
5176 // out to be difficult because only the native code knows for sure which window
5177 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005178 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005179 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005180 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005181 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005182 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005183 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005184 continue;
5185 }
5186
Jeff Brown349703e2010-06-22 01:27:15 -07005187 final int flags = child.mAttrs.flags;
5188 final int type = child.mAttrs.type;
5189
5190 final boolean hasFocus = (child == mInputFocus);
5191 final boolean isVisible = child.isVisibleLw();
5192 final boolean hasWallpaper = (child == mWallpaperTarget)
5193 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5194
5195 // Add a window to our list of input windows.
5196 final InputWindow inputWindow = mTempInputWindows.add();
5197 inputWindow.inputChannel = child.mInputChannel;
5198 inputWindow.layoutParamsFlags = flags;
5199 inputWindow.layoutParamsType = type;
5200 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5201 inputWindow.visible = isVisible;
5202 inputWindow.hasFocus = hasFocus;
5203 inputWindow.hasWallpaper = hasWallpaper;
5204 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5205 inputWindow.ownerPid = child.mSession.mPid;
5206 inputWindow.ownerUid = child.mSession.mUid;
5207
5208 final Rect frame = child.mFrame;
5209 inputWindow.frameLeft = frame.left;
5210 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005211 inputWindow.frameRight = frame.right;
5212 inputWindow.frameBottom = frame.bottom;
5213
5214 final Rect visibleFrame = child.mVisibleFrame;
5215 inputWindow.visibleFrameLeft = visibleFrame.left;
5216 inputWindow.visibleFrameTop = visibleFrame.top;
5217 inputWindow.visibleFrameRight = visibleFrame.right;
5218 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005219
5220 switch (child.mTouchableInsets) {
5221 default:
5222 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5223 inputWindow.touchableAreaLeft = frame.left;
5224 inputWindow.touchableAreaTop = frame.top;
5225 inputWindow.touchableAreaRight = frame.right;
5226 inputWindow.touchableAreaBottom = frame.bottom;
5227 break;
5228
5229 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5230 Rect inset = child.mGivenContentInsets;
5231 inputWindow.touchableAreaLeft = frame.left + inset.left;
5232 inputWindow.touchableAreaTop = frame.top + inset.top;
5233 inputWindow.touchableAreaRight = frame.right - inset.right;
5234 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5235 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005236 }
Jeff Brown349703e2010-06-22 01:27:15 -07005237
5238 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5239 Rect inset = child.mGivenVisibleInsets;
5240 inputWindow.touchableAreaLeft = frame.left + inset.left;
5241 inputWindow.touchableAreaTop = frame.top + inset.top;
5242 inputWindow.touchableAreaRight = frame.right - inset.right;
5243 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005244 break;
5245 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005246 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005247 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005248
Jeff Brown349703e2010-06-22 01:27:15 -07005249 // Send windows to native code.
5250 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005251
Jeff Brown349703e2010-06-22 01:27:15 -07005252 // Clear the list in preparation for the next round.
5253 // Also avoids keeping InputChannel objects referenced unnecessarily.
5254 mTempInputWindows.clear();
5255 }
5256
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005257 /* Provides feedback for a virtual key down. */
5258 public void virtualKeyDownFeedback() {
5259 synchronized (mWindowMap) {
5260 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5261 }
5262 }
5263
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005264 /* Notifies that the lid switch changed state. */
5265 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5266 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5267 }
5268
Jeff Brown349703e2010-06-22 01:27:15 -07005269 /* Provides an opportunity for the window manager policy to intercept early key
5270 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005271 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5272 int policyFlags, boolean isScreenOn) {
5273 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5274 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005275 }
5276
5277 /* Provides an opportunity for the window manager policy to process a key before
5278 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005279 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5280 int action, int flags, int keyCode, int metaState, int repeatCount,
5281 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005282 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005283 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5284 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005285 }
5286
5287 /* Called when the current input focus changes.
5288 * Layer assignment is assumed to be complete by the time this is called.
5289 */
5290 public void setInputFocusLw(WindowState newWindow) {
5291 if (DEBUG_INPUT) {
5292 Slog.d(TAG, "Input focus has changed to " + newWindow);
5293 }
5294
5295 if (newWindow != mInputFocus) {
5296 if (newWindow != null && newWindow.canReceiveKeys()) {
5297 // If the new input focus is an error window or appears above the current
5298 // input focus, preempt any pending synchronous dispatch so that we can
5299 // start delivering events to the new input focus as soon as possible.
5300 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5301 if (DEBUG_INPUT) {
5302 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005303 }
Jeff Brown349703e2010-06-22 01:27:15 -07005304 preemptInputDispatchLw();
5305 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5306 if (DEBUG_INPUT) {
5307 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5308 + "old win layer=" + mInputFocus.mLayer
5309 + ", new win layer=" + newWindow.mLayer);
5310 }
5311 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005312 }
Jeff Brown349703e2010-06-22 01:27:15 -07005313
5314 // Displaying a window implicitly causes dispatching to be unpaused.
5315 // This is to protect against bugs if someone pauses dispatching but
5316 // forgets to resume.
5317 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005318 }
Jeff Brown349703e2010-06-22 01:27:15 -07005319
5320 mInputFocus = newWindow;
5321 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005322 }
5323 }
5324
Jeff Brown349703e2010-06-22 01:27:15 -07005325 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5326 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5327 * can begin.
5328 */
5329 private void preemptInputDispatchLw() {
5330 mInputManager.preemptInputDispatch();
5331 }
5332
5333 public void setFocusedAppLw(AppWindowToken newApp) {
5334 // Focused app has changed.
5335 if (newApp == null) {
5336 mInputManager.setFocusedApplication(null);
5337 } else {
5338 mTempInputApplication.name = newApp.toString();
5339 mTempInputApplication.dispatchingTimeoutNanos =
5340 newApp.inputDispatchingTimeoutNanos;
5341 mTempInputApplication.token = newApp;
5342
5343 mInputManager.setFocusedApplication(mTempInputApplication);
5344 }
5345 }
5346
Jeff Brown349703e2010-06-22 01:27:15 -07005347 public void pauseDispatchingLw(WindowToken window) {
5348 if (! window.paused) {
5349 if (DEBUG_INPUT) {
5350 Slog.v(TAG, "Pausing WindowToken " + window);
5351 }
5352
5353 window.paused = true;
5354 updateInputWindowsLw();
5355 }
5356 }
5357
5358 public void resumeDispatchingLw(WindowToken window) {
5359 if (window.paused) {
5360 if (DEBUG_INPUT) {
5361 Slog.v(TAG, "Resuming WindowToken " + window);
5362 }
5363
5364 window.paused = false;
5365 updateInputWindowsLw();
5366 }
5367 }
5368
5369 public void freezeInputDispatchingLw() {
5370 if (! mInputDispatchFrozen) {
5371 if (DEBUG_INPUT) {
5372 Slog.v(TAG, "Freezing input dispatching");
5373 }
5374
5375 mInputDispatchFrozen = true;
5376 updateInputDispatchModeLw();
5377 }
5378 }
5379
5380 public void thawInputDispatchingLw() {
5381 if (mInputDispatchFrozen) {
5382 if (DEBUG_INPUT) {
5383 Slog.v(TAG, "Thawing input dispatching");
5384 }
5385
5386 mInputDispatchFrozen = false;
5387 updateInputDispatchModeLw();
5388 }
5389 }
5390
5391 public void setEventDispatchingLw(boolean enabled) {
5392 if (mInputDispatchEnabled != enabled) {
5393 if (DEBUG_INPUT) {
5394 Slog.v(TAG, "Setting event dispatching to " + enabled);
5395 }
5396
5397 mInputDispatchEnabled = enabled;
5398 updateInputDispatchModeLw();
5399 }
5400 }
5401
5402 private void updateInputDispatchModeLw() {
5403 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5404 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005407 public void pauseKeyDispatching(IBinder _token) {
5408 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5409 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005410 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005411 }
5412
5413 synchronized (mWindowMap) {
5414 WindowToken token = mTokenMap.get(_token);
5415 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005416 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005417 }
5418 }
5419 }
5420
5421 public void resumeKeyDispatching(IBinder _token) {
5422 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5423 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005424 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425 }
5426
5427 synchronized (mWindowMap) {
5428 WindowToken token = mTokenMap.get(_token);
5429 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005430 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005431 }
5432 }
5433 }
5434
5435 public void setEventDispatching(boolean enabled) {
5436 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5437 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005438 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005439 }
5440
5441 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005442 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005443 }
5444 }
Romain Guy06882f82009-06-10 13:36:04 -07005445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005446 /**
5447 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005448 * Even when sync is false, this method may block while waiting for current
5449 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005450 *
5451 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452 * {@link SystemClock#uptimeMillis()} as the timebase.)
5453 * @param sync If true, wait for the event to be completed before returning to the caller.
5454 * @return Returns true if event was dispatched, false if it was dropped for any reason
5455 */
5456 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5457 long downTime = ev.getDownTime();
5458 long eventTime = ev.getEventTime();
5459
5460 int action = ev.getAction();
5461 int code = ev.getKeyCode();
5462 int repeatCount = ev.getRepeatCount();
5463 int metaState = ev.getMetaState();
5464 int deviceId = ev.getDeviceId();
5465 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005466 int source = ev.getSource();
5467
5468 if (source == InputDevice.SOURCE_UNKNOWN) {
5469 source = InputDevice.SOURCE_KEYBOARD;
5470 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005471
5472 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5473 if (downTime == 0) downTime = eventTime;
5474
5475 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005476 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005477
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005478 final int pid = Binder.getCallingPid();
5479 final int uid = Binder.getCallingUid();
5480 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005481
Jeff Brownbbda99d2010-07-28 15:48:59 -07005482 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5483 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5484 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5485 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005486
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005487 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005488 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005489 }
5490
5491 /**
5492 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005493 * Even when sync is false, this method may block while waiting for current
5494 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005495 *
5496 * @param ev A motion event describing the pointer (touch) action. (As noted in
5497 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005498 * {@link SystemClock#uptimeMillis()} as the timebase.)
5499 * @param sync If true, wait for the event to be completed before returning to the caller.
5500 * @return Returns true if event was dispatched, false if it was dropped for any reason
5501 */
5502 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005503 final int pid = Binder.getCallingPid();
5504 final int uid = Binder.getCallingUid();
5505 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005506
Jeff Brownc5ed5912010-07-14 18:48:53 -07005507 MotionEvent newEvent = MotionEvent.obtain(ev);
5508 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5509 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5510 }
5511
Jeff Brownbbda99d2010-07-28 15:48:59 -07005512 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5513 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5514 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5515 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005516
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005517 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005518 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005519 }
Romain Guy06882f82009-06-10 13:36:04 -07005520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005521 /**
5522 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005523 * Even when sync is false, this method may block while waiting for current
5524 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005525 *
5526 * @param ev A motion event describing the trackball action. (As noted in
5527 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005528 * {@link SystemClock#uptimeMillis()} as the timebase.)
5529 * @param sync If true, wait for the event to be completed before returning to the caller.
5530 * @return Returns true if event was dispatched, false if it was dropped for any reason
5531 */
5532 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005533 final int pid = Binder.getCallingPid();
5534 final int uid = Binder.getCallingUid();
5535 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005536
Jeff Brownc5ed5912010-07-14 18:48:53 -07005537 MotionEvent newEvent = MotionEvent.obtain(ev);
5538 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5539 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5540 }
5541
Jeff Brownbbda99d2010-07-28 15:48:59 -07005542 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5543 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5544 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5545 INJECTION_TIMEOUT_MILLIS);
5546
5547 Binder.restoreCallingIdentity(ident);
5548 return reportInjectionResult(result);
5549 }
5550
5551 /**
5552 * Inject an input event into the UI without waiting for dispatch to commence.
5553 * This variant is useful for fire-and-forget input event injection. It does not
5554 * block any longer than it takes to enqueue the input event.
5555 *
5556 * @param ev An input event. (Be sure to set the input source correctly.)
5557 * @return Returns true if event was dispatched, false if it was dropped for any reason
5558 */
5559 public boolean injectInputEventNoWait(InputEvent ev) {
5560 final int pid = Binder.getCallingPid();
5561 final int uid = Binder.getCallingUid();
5562 final long ident = Binder.clearCallingIdentity();
5563
5564 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5565 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5566 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005567
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005568 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005569 return reportInjectionResult(result);
5570 }
5571
5572 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005573 switch (result) {
5574 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5575 Slog.w(TAG, "Input event injection permission denied.");
5576 throw new SecurityException(
5577 "Injecting to another application requires INJECT_EVENTS permission");
5578 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005579 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005580 return true;
5581 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5582 Slog.w(TAG, "Input event injection timed out.");
5583 return false;
5584 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5585 default:
5586 Slog.w(TAG, "Input event injection failed.");
5587 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005589 }
Romain Guy06882f82009-06-10 13:36:04 -07005590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005591 private WindowState getFocusedWindow() {
5592 synchronized (mWindowMap) {
5593 return getFocusedWindowLocked();
5594 }
5595 }
5596
5597 private WindowState getFocusedWindowLocked() {
5598 return mCurrentFocus;
5599 }
Romain Guy06882f82009-06-10 13:36:04 -07005600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005601 public boolean detectSafeMode() {
5602 mSafeMode = mPolicy.detectSafeMode();
5603 return mSafeMode;
5604 }
Romain Guy06882f82009-06-10 13:36:04 -07005605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005607 synchronized(mWindowMap) {
5608 if (mDisplay != null) {
5609 throw new IllegalStateException("Display already initialized");
5610 }
5611 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5612 mDisplay = wm.getDefaultDisplay();
5613 mInitialDisplayWidth = mDisplay.getWidth();
5614 mInitialDisplayHeight = mDisplay.getHeight();
5615 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
5616 }
5617
5618 try {
5619 mActivityManager.updateConfiguration(null);
5620 } catch (RemoteException e) {
5621 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005622
5623 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005624 }
5625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005626 // -------------------------------------------------------------
5627 // Client Session State
5628 // -------------------------------------------------------------
5629
5630 private final class Session extends IWindowSession.Stub
5631 implements IBinder.DeathRecipient {
5632 final IInputMethodClient mClient;
5633 final IInputContext mInputContext;
5634 final int mUid;
5635 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005636 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005637 SurfaceSession mSurfaceSession;
5638 int mNumWindow = 0;
5639 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005641 public Session(IInputMethodClient client, IInputContext inputContext) {
5642 mClient = client;
5643 mInputContext = inputContext;
5644 mUid = Binder.getCallingUid();
5645 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005646 StringBuilder sb = new StringBuilder();
5647 sb.append("Session{");
5648 sb.append(Integer.toHexString(System.identityHashCode(this)));
5649 sb.append(" uid ");
5650 sb.append(mUid);
5651 sb.append("}");
5652 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005654 synchronized (mWindowMap) {
5655 if (mInputMethodManager == null && mHaveInputMethods) {
5656 IBinder b = ServiceManager.getService(
5657 Context.INPUT_METHOD_SERVICE);
5658 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5659 }
5660 }
5661 long ident = Binder.clearCallingIdentity();
5662 try {
5663 // Note: it is safe to call in to the input method manager
5664 // here because we are not holding our lock.
5665 if (mInputMethodManager != null) {
5666 mInputMethodManager.addClient(client, inputContext,
5667 mUid, mPid);
5668 } else {
5669 client.setUsingInputMethod(false);
5670 }
5671 client.asBinder().linkToDeath(this, 0);
5672 } catch (RemoteException e) {
5673 // The caller has died, so we can just forget about this.
5674 try {
5675 if (mInputMethodManager != null) {
5676 mInputMethodManager.removeClient(client);
5677 }
5678 } catch (RemoteException ee) {
5679 }
5680 } finally {
5681 Binder.restoreCallingIdentity(ident);
5682 }
5683 }
Romain Guy06882f82009-06-10 13:36:04 -07005684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005685 @Override
5686 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5687 throws RemoteException {
5688 try {
5689 return super.onTransact(code, data, reply, flags);
5690 } catch (RuntimeException e) {
5691 // Log all 'real' exceptions thrown to the caller
5692 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005693 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005694 }
5695 throw e;
5696 }
5697 }
5698
5699 public void binderDied() {
5700 // Note: it is safe to call in to the input method manager
5701 // here because we are not holding our lock.
5702 try {
5703 if (mInputMethodManager != null) {
5704 mInputMethodManager.removeClient(mClient);
5705 }
5706 } catch (RemoteException e) {
5707 }
5708 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005709 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005710 mClientDead = true;
5711 killSessionLocked();
5712 }
5713 }
5714
5715 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005716 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5717 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5718 outInputChannel);
5719 }
5720
5721 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005723 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005724 }
Romain Guy06882f82009-06-10 13:36:04 -07005725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005726 public void remove(IWindow window) {
5727 removeWindow(this, window);
5728 }
Romain Guy06882f82009-06-10 13:36:04 -07005729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005730 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5731 int requestedWidth, int requestedHeight, int viewFlags,
5732 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005733 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005734 return relayoutWindow(this, window, attrs,
5735 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005736 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 }
Romain Guy06882f82009-06-10 13:36:04 -07005738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005739 public void setTransparentRegion(IWindow window, Region region) {
5740 setTransparentRegionWindow(this, window, region);
5741 }
Romain Guy06882f82009-06-10 13:36:04 -07005742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005743 public void setInsets(IWindow window, int touchableInsets,
5744 Rect contentInsets, Rect visibleInsets) {
5745 setInsetsWindow(this, window, touchableInsets, contentInsets,
5746 visibleInsets);
5747 }
Romain Guy06882f82009-06-10 13:36:04 -07005748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005749 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5750 getWindowDisplayFrame(this, window, outDisplayFrame);
5751 }
Romain Guy06882f82009-06-10 13:36:04 -07005752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005753 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005754 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005755 TAG, "IWindow finishDrawing called for " + window);
5756 finishDrawingWindow(this, window);
5757 }
5758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005759 public void setInTouchMode(boolean mode) {
5760 synchronized(mWindowMap) {
5761 mInTouchMode = mode;
5762 }
5763 }
5764
5765 public boolean getInTouchMode() {
5766 synchronized(mWindowMap) {
5767 return mInTouchMode;
5768 }
5769 }
5770
5771 public boolean performHapticFeedback(IWindow window, int effectId,
5772 boolean always) {
5773 synchronized(mWindowMap) {
5774 long ident = Binder.clearCallingIdentity();
5775 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005776 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005777 windowForClientLocked(this, window, true),
5778 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005779 } finally {
5780 Binder.restoreCallingIdentity(ident);
5781 }
5782 }
5783 }
Romain Guy06882f82009-06-10 13:36:04 -07005784
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005785 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005786 synchronized(mWindowMap) {
5787 long ident = Binder.clearCallingIdentity();
5788 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005789 setWindowWallpaperPositionLocked(
5790 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005791 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005792 } finally {
5793 Binder.restoreCallingIdentity(ident);
5794 }
5795 }
5796 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005797
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005798 public void wallpaperOffsetsComplete(IBinder window) {
5799 WindowManagerService.this.wallpaperOffsetsComplete(window);
5800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005801
Dianne Hackborn75804932009-10-20 20:15:20 -07005802 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5803 int z, Bundle extras, boolean sync) {
5804 synchronized(mWindowMap) {
5805 long ident = Binder.clearCallingIdentity();
5806 try {
5807 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005808 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005809 action, x, y, z, extras, sync);
5810 } finally {
5811 Binder.restoreCallingIdentity(ident);
5812 }
5813 }
5814 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005815
Dianne Hackborn75804932009-10-20 20:15:20 -07005816 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5817 WindowManagerService.this.wallpaperCommandComplete(window, result);
5818 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005820 void windowAddedLocked() {
5821 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005822 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 TAG, "First window added to " + this + ", creating SurfaceSession");
5824 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005825 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005826 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005827 mSessions.add(this);
5828 }
5829 mNumWindow++;
5830 }
5831
5832 void windowRemovedLocked() {
5833 mNumWindow--;
5834 killSessionLocked();
5835 }
Romain Guy06882f82009-06-10 13:36:04 -07005836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 void killSessionLocked() {
5838 if (mNumWindow <= 0 && mClientDead) {
5839 mSessions.remove(this);
5840 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005841 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005842 TAG, "Last window removed from " + this
5843 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005844 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005845 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005846 try {
5847 mSurfaceSession.kill();
5848 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005849 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 + mSurfaceSession + " in session " + this
5851 + ": " + e.toString());
5852 }
5853 mSurfaceSession = null;
5854 }
5855 }
5856 }
Romain Guy06882f82009-06-10 13:36:04 -07005857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005858 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005859 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5860 pw.print(" mClientDead="); pw.print(mClientDead);
5861 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862 }
5863
5864 @Override
5865 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005866 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005867 }
5868 }
5869
5870 // -------------------------------------------------------------
5871 // Client Window State
5872 // -------------------------------------------------------------
5873
5874 private final class WindowState implements WindowManagerPolicy.WindowState {
5875 final Session mSession;
5876 final IWindow mClient;
5877 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005878 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 AppWindowToken mAppToken;
5880 AppWindowToken mTargetAppToken;
5881 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5882 final DeathRecipient mDeathRecipient;
5883 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005884 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005885 final int mBaseLayer;
5886 final int mSubLayer;
5887 final boolean mLayoutAttached;
5888 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005889 final boolean mIsWallpaper;
5890 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005891 int mViewVisibility;
5892 boolean mPolicyVisibility = true;
5893 boolean mPolicyVisibilityAfterAnim = true;
5894 boolean mAppFreezing;
5895 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005896 boolean mReportDestroySurface;
5897 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005898 boolean mAttachedHidden; // is our parent window hidden?
5899 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005900 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901 int mRequestedWidth;
5902 int mRequestedHeight;
5903 int mLastRequestedWidth;
5904 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005905 int mLayer;
5906 int mAnimLayer;
5907 int mLastLayer;
5908 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005909 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005910 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005912 int mLayoutSeq = -1;
5913
5914 Configuration mConfiguration = null;
5915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005916 // Actual frame shown on-screen (may be modified by animation)
5917 final Rect mShownFrame = new Rect();
5918 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005920 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005921 * Set when we have changed the size of the surface, to know that
5922 * we must tell them application to resize (and thus redraw itself).
5923 */
5924 boolean mSurfaceResized;
5925
5926 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 * Insets that determine the actually visible area
5928 */
5929 final Rect mVisibleInsets = new Rect();
5930 final Rect mLastVisibleInsets = new Rect();
5931 boolean mVisibleInsetsChanged;
5932
5933 /**
5934 * Insets that are covered by system windows
5935 */
5936 final Rect mContentInsets = new Rect();
5937 final Rect mLastContentInsets = new Rect();
5938 boolean mContentInsetsChanged;
5939
5940 /**
5941 * Set to true if we are waiting for this window to receive its
5942 * given internal insets before laying out other windows based on it.
5943 */
5944 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005946 /**
5947 * These are the content insets that were given during layout for
5948 * this window, to be applied to windows behind it.
5949 */
5950 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005952 /**
5953 * These are the visible insets that were given during layout for
5954 * this window, to be applied to windows behind it.
5955 */
5956 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005958 /**
5959 * Flag indicating whether the touchable region should be adjusted by
5960 * the visible insets; if false the area outside the visible insets is
5961 * NOT touchable, so we must use those to adjust the frame during hit
5962 * tests.
5963 */
5964 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005966 // Current transformation being applied.
5967 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5968 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5969 float mHScale=1, mVScale=1;
5970 float mLastHScale=1, mLastVScale=1;
5971 final Matrix mTmpMatrix = new Matrix();
5972
5973 // "Real" frame that the application sees.
5974 final Rect mFrame = new Rect();
5975 final Rect mLastFrame = new Rect();
5976
5977 final Rect mContainingFrame = new Rect();
5978 final Rect mDisplayFrame = new Rect();
5979 final Rect mContentFrame = new Rect();
5980 final Rect mVisibleFrame = new Rect();
5981
5982 float mShownAlpha = 1;
5983 float mAlpha = 1;
5984 float mLastAlpha = 1;
5985
5986 // Set to true if, when the window gets displayed, it should perform
5987 // an enter animation.
5988 boolean mEnterAnimationPending;
5989
5990 // Currently running animation.
5991 boolean mAnimating;
5992 boolean mLocalAnimating;
5993 Animation mAnimation;
5994 boolean mAnimationIsEntrance;
5995 boolean mHasTransformation;
5996 boolean mHasLocalTransformation;
5997 final Transformation mTransformation = new Transformation();
5998
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005999 // If a window showing a wallpaper: the requested offset for the
6000 // wallpaper; if a wallpaper window: the currently applied offset.
6001 float mWallpaperX = -1;
6002 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006003
6004 // If a window showing a wallpaper: what fraction of the offset
6005 // range corresponds to a full virtual screen.
6006 float mWallpaperXStep = -1;
6007 float mWallpaperYStep = -1;
6008
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006009 // Wallpaper windows: pixels offset based on above variables.
6010 int mXOffset;
6011 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006013 // This is set after IWindowSession.relayout() has been called at
6014 // least once for the window. It allows us to detect the situation
6015 // where we don't yet have a surface, but should have one soon, so
6016 // we can give the window focus before waiting for the relayout.
6017 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006019 // This is set after the Surface has been created but before the
6020 // window has been drawn. During this time the surface is hidden.
6021 boolean mDrawPending;
6022
6023 // This is set after the window has finished drawing for the first
6024 // time but before its surface is shown. The surface will be
6025 // displayed when the next layout is run.
6026 boolean mCommitDrawPending;
6027
6028 // This is set during the time after the window's drawing has been
6029 // committed, and before its surface is actually shown. It is used
6030 // to delay showing the surface until all windows in a token are ready
6031 // to be shown.
6032 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006034 // Set when the window has been shown in the screen the first time.
6035 boolean mHasDrawn;
6036
6037 // Currently running an exit animation?
6038 boolean mExiting;
6039
6040 // Currently on the mDestroySurface list?
6041 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006043 // Completely remove from window manager after exit animation?
6044 boolean mRemoveOnExit;
6045
6046 // Set when the orientation is changing and this window has not yet
6047 // been updated for the new orientation.
6048 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006050 // Is this window now (or just being) removed?
6051 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006052
Dianne Hackborn16064f92010-03-25 00:47:24 -07006053 // For debugging, this is the last information given to the surface flinger.
6054 boolean mSurfaceShown;
6055 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6056 int mSurfaceLayer;
6057 float mSurfaceAlpha;
6058
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006059 // Input channel
6060 InputChannel mInputChannel;
6061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006062 WindowState(Session s, IWindow c, WindowToken token,
6063 WindowState attachedWindow, WindowManager.LayoutParams a,
6064 int viewVisibility) {
6065 mSession = s;
6066 mClient = c;
6067 mToken = token;
6068 mAttrs.copyFrom(a);
6069 mViewVisibility = viewVisibility;
6070 DeathRecipient deathRecipient = new DeathRecipient();
6071 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006072 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 TAG, "Window " + this + " client=" + c.asBinder()
6074 + " token=" + token + " (" + mAttrs.token + ")");
6075 try {
6076 c.asBinder().linkToDeath(deathRecipient, 0);
6077 } catch (RemoteException e) {
6078 mDeathRecipient = null;
6079 mAttachedWindow = null;
6080 mLayoutAttached = false;
6081 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006082 mIsWallpaper = false;
6083 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 mBaseLayer = 0;
6085 mSubLayer = 0;
6086 return;
6087 }
6088 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006090 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6091 mAttrs.type <= LAST_SUB_WINDOW)) {
6092 // The multiplier here is to reserve space for multiple
6093 // windows in the same type layer.
6094 mBaseLayer = mPolicy.windowTypeToLayerLw(
6095 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6096 + TYPE_LAYER_OFFSET;
6097 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6098 mAttachedWindow = attachedWindow;
6099 mAttachedWindow.mChildWindows.add(this);
6100 mLayoutAttached = mAttrs.type !=
6101 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6102 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6103 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006104 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6105 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006106 } else {
6107 // The multiplier here is to reserve space for multiple
6108 // windows in the same type layer.
6109 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6110 * TYPE_LAYER_MULTIPLIER
6111 + TYPE_LAYER_OFFSET;
6112 mSubLayer = 0;
6113 mAttachedWindow = null;
6114 mLayoutAttached = false;
6115 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6116 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006117 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6118 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006119 }
6120
6121 WindowState appWin = this;
6122 while (appWin.mAttachedWindow != null) {
6123 appWin = mAttachedWindow;
6124 }
6125 WindowToken appToken = appWin.mToken;
6126 while (appToken.appWindowToken == null) {
6127 WindowToken parent = mTokenMap.get(appToken.token);
6128 if (parent == null || appToken == parent) {
6129 break;
6130 }
6131 appToken = parent;
6132 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006133 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006134 mAppToken = appToken.appWindowToken;
6135
6136 mSurface = null;
6137 mRequestedWidth = 0;
6138 mRequestedHeight = 0;
6139 mLastRequestedWidth = 0;
6140 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006141 mXOffset = 0;
6142 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 mLayer = 0;
6144 mAnimLayer = 0;
6145 mLastLayer = 0;
6146 }
6147
6148 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006149 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 TAG, "Attaching " + this + " token=" + mToken
6151 + ", list=" + mToken.windows);
6152 mSession.windowAddedLocked();
6153 }
6154
6155 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6156 mHaveFrame = true;
6157
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006158 final Rect container = mContainingFrame;
6159 container.set(pf);
6160
6161 final Rect display = mDisplayFrame;
6162 display.set(df);
6163
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006164 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006165 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006166 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6167 display.intersect(mCompatibleScreenFrame);
6168 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006169 }
6170
6171 final int pw = container.right - container.left;
6172 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006173
6174 int w,h;
6175 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6176 w = mAttrs.width < 0 ? pw : mAttrs.width;
6177 h = mAttrs.height< 0 ? ph : mAttrs.height;
6178 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006179 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6180 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181 }
Romain Guy06882f82009-06-10 13:36:04 -07006182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006183 final Rect content = mContentFrame;
6184 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 final Rect visible = mVisibleFrame;
6187 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006189 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006190 final int fw = frame.width();
6191 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6194 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6195
6196 Gravity.apply(mAttrs.gravity, w, h, container,
6197 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6198 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6199
6200 //System.out.println("Out: " + mFrame);
6201
6202 // Now make sure the window fits in the overall display.
6203 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006205 // Make sure the content and visible frames are inside of the
6206 // final window frame.
6207 if (content.left < frame.left) content.left = frame.left;
6208 if (content.top < frame.top) content.top = frame.top;
6209 if (content.right > frame.right) content.right = frame.right;
6210 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6211 if (visible.left < frame.left) visible.left = frame.left;
6212 if (visible.top < frame.top) visible.top = frame.top;
6213 if (visible.right > frame.right) visible.right = frame.right;
6214 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 final Rect contentInsets = mContentInsets;
6217 contentInsets.left = content.left-frame.left;
6218 contentInsets.top = content.top-frame.top;
6219 contentInsets.right = frame.right-content.right;
6220 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 final Rect visibleInsets = mVisibleInsets;
6223 visibleInsets.left = visible.left-frame.left;
6224 visibleInsets.top = visible.top-frame.top;
6225 visibleInsets.right = frame.right-visible.right;
6226 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006227
Dianne Hackborn284ac932009-08-28 10:34:25 -07006228 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6229 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006230 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006231 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 if (localLOGV) {
6234 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6235 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006236 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006237 + mRequestedWidth + ", mRequestedheight="
6238 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6239 + "): frame=" + mFrame.toShortString()
6240 + " ci=" + contentInsets.toShortString()
6241 + " vi=" + visibleInsets.toShortString());
6242 //}
6243 }
6244 }
Romain Guy06882f82009-06-10 13:36:04 -07006245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006246 public Rect getFrameLw() {
6247 return mFrame;
6248 }
6249
6250 public Rect getShownFrameLw() {
6251 return mShownFrame;
6252 }
6253
6254 public Rect getDisplayFrameLw() {
6255 return mDisplayFrame;
6256 }
6257
6258 public Rect getContentFrameLw() {
6259 return mContentFrame;
6260 }
6261
6262 public Rect getVisibleFrameLw() {
6263 return mVisibleFrame;
6264 }
6265
6266 public boolean getGivenInsetsPendingLw() {
6267 return mGivenInsetsPending;
6268 }
6269
6270 public Rect getGivenContentInsetsLw() {
6271 return mGivenContentInsets;
6272 }
Romain Guy06882f82009-06-10 13:36:04 -07006273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006274 public Rect getGivenVisibleInsetsLw() {
6275 return mGivenVisibleInsets;
6276 }
Romain Guy06882f82009-06-10 13:36:04 -07006277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 public WindowManager.LayoutParams getAttrs() {
6279 return mAttrs;
6280 }
6281
6282 public int getSurfaceLayer() {
6283 return mLayer;
6284 }
Romain Guy06882f82009-06-10 13:36:04 -07006285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006286 public IApplicationToken getAppToken() {
6287 return mAppToken != null ? mAppToken.appToken : null;
6288 }
Jeff Brown349703e2010-06-22 01:27:15 -07006289
6290 public long getInputDispatchingTimeoutNanos() {
6291 return mAppToken != null
6292 ? mAppToken.inputDispatchingTimeoutNanos
6293 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295
6296 public boolean hasAppShownWindows() {
6297 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6298 }
6299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006300 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006301 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006302 TAG, "Setting animation in " + this + ": " + anim);
6303 mAnimating = false;
6304 mLocalAnimating = false;
6305 mAnimation = anim;
6306 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6307 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6308 }
6309
6310 public void clearAnimation() {
6311 if (mAnimation != null) {
6312 mAnimating = true;
6313 mLocalAnimating = false;
6314 mAnimation = null;
6315 }
6316 }
Romain Guy06882f82009-06-10 13:36:04 -07006317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006318 Surface createSurfaceLocked() {
6319 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006320 mReportDestroySurface = false;
6321 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006322 mDrawPending = true;
6323 mCommitDrawPending = false;
6324 mReadyToShow = false;
6325 if (mAppToken != null) {
6326 mAppToken.allDrawn = false;
6327 }
6328
6329 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006330 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 flags |= Surface.PUSH_BUFFERS;
6332 }
6333
6334 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6335 flags |= Surface.SECURE;
6336 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006337 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 TAG, "Creating surface in session "
6339 + mSession.mSurfaceSession + " window " + this
6340 + " w=" + mFrame.width()
6341 + " h=" + mFrame.height() + " format="
6342 + mAttrs.format + " flags=" + flags);
6343
6344 int w = mFrame.width();
6345 int h = mFrame.height();
6346 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6347 // for a scaled surface, we always want the requested
6348 // size.
6349 w = mRequestedWidth;
6350 h = mRequestedHeight;
6351 }
6352
Romain Guy9825ec62009-10-01 00:58:09 -07006353 // Something is wrong and SurfaceFlinger will not like this,
6354 // try to revert to sane values
6355 if (w <= 0) w = 1;
6356 if (h <= 0) h = 1;
6357
Dianne Hackborn16064f92010-03-25 00:47:24 -07006358 mSurfaceShown = false;
6359 mSurfaceLayer = 0;
6360 mSurfaceAlpha = 1;
6361 mSurfaceX = 0;
6362 mSurfaceY = 0;
6363 mSurfaceW = w;
6364 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 try {
6366 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006367 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006368 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006370 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006371 + mSurface + " IN SESSION "
6372 + mSession.mSurfaceSession
6373 + ": pid=" + mSession.mPid + " format="
6374 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006375 + Integer.toHexString(flags)
6376 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006378 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 reclaimSomeSurfaceMemoryLocked(this, "create");
6380 return null;
6381 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006382 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 return null;
6384 }
Romain Guy06882f82009-06-10 13:36:04 -07006385
Joe Onorato8a9b2202010-02-26 18:56:32 -08006386 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 TAG, "Got surface: " + mSurface
6388 + ", set left=" + mFrame.left + " top=" + mFrame.top
6389 + ", animLayer=" + mAnimLayer);
6390 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006391 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006392 if (SHOW_TRANSACTIONS) logSurface(this,
6393 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6394 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6395 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 }
6397 Surface.openTransaction();
6398 try {
6399 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006400 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006401 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006402 mSurface.setPosition(mSurfaceX, mSurfaceY);
6403 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006404 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006405 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406 mSurface.hide();
6407 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006408 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 mSurface.setFlags(Surface.SURFACE_DITHER,
6410 Surface.SURFACE_DITHER);
6411 }
6412 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006413 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6415 }
6416 mLastHidden = true;
6417 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006418 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 Surface.closeTransaction();
6420 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006421 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006422 TAG, "Created surface " + this);
6423 }
6424 return mSurface;
6425 }
Romain Guy06882f82009-06-10 13:36:04 -07006426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006428 if (mAppToken != null && this == mAppToken.startingWindow) {
6429 mAppToken.startingDisplayed = false;
6430 }
Romain Guy06882f82009-06-10 13:36:04 -07006431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006433 mDrawPending = false;
6434 mCommitDrawPending = false;
6435 mReadyToShow = false;
6436
6437 int i = mChildWindows.size();
6438 while (i > 0) {
6439 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006440 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006441 c.mAttachedHidden = true;
6442 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006443
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006444 if (mReportDestroySurface) {
6445 mReportDestroySurface = false;
6446 mSurfacePendingDestroy = true;
6447 try {
6448 mClient.dispatchGetNewSurface();
6449 // We'll really destroy on the next time around.
6450 return;
6451 } catch (RemoteException e) {
6452 }
6453 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006455 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006456 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006457 RuntimeException e = null;
6458 if (!HIDE_STACK_CRAWLS) {
6459 e = new RuntimeException();
6460 e.fillInStackTrace();
6461 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006462 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006463 + mSurface + ", session " + mSession, e);
6464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006466 RuntimeException e = null;
6467 if (!HIDE_STACK_CRAWLS) {
6468 e = new RuntimeException();
6469 e.fillInStackTrace();
6470 }
6471 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006473 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006475 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 + " surface " + mSurface + " session " + mSession
6477 + ": " + e.toString());
6478 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006479
Dianne Hackborn16064f92010-03-25 00:47:24 -07006480 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 }
6483 }
6484
6485 boolean finishDrawingLocked() {
6486 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006487 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 TAG, "finishDrawingLocked: " + mSurface);
6489 mCommitDrawPending = true;
6490 mDrawPending = false;
6491 return true;
6492 }
6493 return false;
6494 }
6495
6496 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006497 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006498 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006500 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006501 }
6502 mCommitDrawPending = false;
6503 mReadyToShow = true;
6504 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6505 final AppWindowToken atoken = mAppToken;
6506 if (atoken == null || atoken.allDrawn || starting) {
6507 performShowLocked();
6508 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006509 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 }
6511
6512 // This must be called while inside a transaction.
6513 boolean performShowLocked() {
6514 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006515 RuntimeException e = null;
6516 if (!HIDE_STACK_CRAWLS) {
6517 e = new RuntimeException();
6518 e.fillInStackTrace();
6519 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006520 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6522 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6523 }
6524 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006525 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6526 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006527 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006528 + " during animation: policyVis=" + mPolicyVisibility
6529 + " attHidden=" + mAttachedHidden
6530 + " tok.hiddenRequested="
6531 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006532 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 + (mAppToken != null ? mAppToken.hidden : false)
6534 + " animating=" + mAnimating
6535 + " tok animating="
6536 + (mAppToken != null ? mAppToken.animating : false));
6537 if (!showSurfaceRobustlyLocked(this)) {
6538 return false;
6539 }
6540 mLastAlpha = -1;
6541 mHasDrawn = true;
6542 mLastHidden = false;
6543 mReadyToShow = false;
6544 enableScreenIfNeededLocked();
6545
6546 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 int i = mChildWindows.size();
6549 while (i > 0) {
6550 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006551 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006552 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006554 if (c.mSurface != null) {
6555 c.performShowLocked();
6556 // It hadn't been shown, which means layout not
6557 // performed on it, so now we want to make sure to
6558 // do a layout. If called from within the transaction
6559 // loop, this will cause it to restart with a new
6560 // layout.
6561 mLayoutNeeded = true;
6562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 }
6564 }
Romain Guy06882f82009-06-10 13:36:04 -07006565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006566 if (mAttrs.type != TYPE_APPLICATION_STARTING
6567 && mAppToken != null) {
6568 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006569
Dianne Hackborn248b1882009-09-16 16:46:44 -07006570 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006571 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006572 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006574 // If this initial window is animating, stop it -- we
6575 // will do an animation to reveal it from behind the
6576 // starting window, so there is no need for it to also
6577 // be doing its own stuff.
6578 if (mAnimation != null) {
6579 mAnimation = null;
6580 // Make sure we clean up the animation.
6581 mAnimating = true;
6582 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 mFinishedStarting.add(mAppToken);
6584 mH.sendEmptyMessage(H.FINISHED_STARTING);
6585 }
6586 mAppToken.updateReportedVisibilityLocked();
6587 }
6588 }
6589 return true;
6590 }
Romain Guy06882f82009-06-10 13:36:04 -07006591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006592 // This must be called while inside a transaction. Returns true if
6593 // there is more animation to run.
6594 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006595 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006596 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006598 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6599 mHasTransformation = true;
6600 mHasLocalTransformation = true;
6601 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006602 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 TAG, "Starting animation in " + this +
6604 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6605 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6606 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6607 mAnimation.setStartTime(currentTime);
6608 mLocalAnimating = true;
6609 mAnimating = true;
6610 }
6611 mTransformation.clear();
6612 final boolean more = mAnimation.getTransformation(
6613 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006614 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 TAG, "Stepped animation in " + this +
6616 ": more=" + more + ", xform=" + mTransformation);
6617 if (more) {
6618 // we're not done!
6619 return true;
6620 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006621 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006622 TAG, "Finished animation in " + this +
6623 " @ " + currentTime);
6624 mAnimation = null;
6625 //WindowManagerService.this.dump();
6626 }
6627 mHasLocalTransformation = false;
6628 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006629 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006630 // When our app token is animating, we kind-of pretend like
6631 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6632 // part of this check means that we will only do this if
6633 // our window is not currently exiting, or it is not
6634 // locally animating itself. The idea being that one that
6635 // is exiting and doing a local animation should be removed
6636 // once that animation is done.
6637 mAnimating = true;
6638 mHasTransformation = true;
6639 mTransformation.clear();
6640 return false;
6641 } else if (mHasTransformation) {
6642 // Little trick to get through the path below to act like
6643 // we have finished an animation.
6644 mAnimating = true;
6645 } else if (isAnimating()) {
6646 mAnimating = true;
6647 }
6648 } else if (mAnimation != null) {
6649 // If the display is frozen, and there is a pending animation,
6650 // clear it and make sure we run the cleanup code.
6651 mAnimating = true;
6652 mLocalAnimating = true;
6653 mAnimation = null;
6654 }
Romain Guy06882f82009-06-10 13:36:04 -07006655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 if (!mAnimating && !mLocalAnimating) {
6657 return false;
6658 }
6659
Joe Onorato8a9b2202010-02-26 18:56:32 -08006660 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661 TAG, "Animation done in " + this + ": exiting=" + mExiting
6662 + ", reportedVisible="
6663 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006665 mAnimating = false;
6666 mLocalAnimating = false;
6667 mAnimation = null;
6668 mAnimLayer = mLayer;
6669 if (mIsImWindow) {
6670 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006671 } else if (mIsWallpaper) {
6672 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006673 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006674 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006675 + " anim layer: " + mAnimLayer);
6676 mHasTransformation = false;
6677 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006678 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6679 if (DEBUG_VISIBILITY) {
6680 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6681 + mPolicyVisibilityAfterAnim);
6682 }
6683 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6684 if (!mPolicyVisibility) {
6685 if (mCurrentFocus == this) {
6686 mFocusMayChange = true;
6687 }
6688 // Window is no longer visible -- make sure if we were waiting
6689 // for it to be displayed before enabling the display, that
6690 // we allow the display to be enabled now.
6691 enableScreenIfNeededLocked();
6692 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006694 mTransformation.clear();
6695 if (mHasDrawn
6696 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6697 && mAppToken != null
6698 && mAppToken.firstWindowDrawn
6699 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006700 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 + mToken + ": first real window done animating");
6702 mFinishedStarting.add(mAppToken);
6703 mH.sendEmptyMessage(H.FINISHED_STARTING);
6704 }
Romain Guy06882f82009-06-10 13:36:04 -07006705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 finishExit();
6707
6708 if (mAppToken != null) {
6709 mAppToken.updateReportedVisibilityLocked();
6710 }
6711
6712 return false;
6713 }
6714
6715 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006716 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 TAG, "finishExit in " + this
6718 + ": exiting=" + mExiting
6719 + " remove=" + mRemoveOnExit
6720 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 final int N = mChildWindows.size();
6723 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006724 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 }
Romain Guy06882f82009-06-10 13:36:04 -07006726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 if (!mExiting) {
6728 return;
6729 }
Romain Guy06882f82009-06-10 13:36:04 -07006730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 if (isWindowAnimating()) {
6732 return;
6733 }
6734
Joe Onorato8a9b2202010-02-26 18:56:32 -08006735 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006736 TAG, "Exit animation finished in " + this
6737 + ": remove=" + mRemoveOnExit);
6738 if (mSurface != null) {
6739 mDestroySurface.add(this);
6740 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006741 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006742 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 try {
6744 mSurface.hide();
6745 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006746 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 }
6748 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 }
6750 mExiting = false;
6751 if (mRemoveOnExit) {
6752 mPendingRemove.add(this);
6753 mRemoveOnExit = false;
6754 }
6755 }
Romain Guy06882f82009-06-10 13:36:04 -07006756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006757 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6758 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6759 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6760 if (dtdx < -.000001f || dtdx > .000001f) return false;
6761 if (dsdy < -.000001f || dsdy > .000001f) return false;
6762 return true;
6763 }
Romain Guy06882f82009-06-10 13:36:04 -07006764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 void computeShownFrameLocked() {
6766 final boolean selfTransformation = mHasLocalTransformation;
6767 Transformation attachedTransformation =
6768 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6769 ? mAttachedWindow.mTransformation : null;
6770 Transformation appTransformation =
6771 (mAppToken != null && mAppToken.hasTransformation)
6772 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006773
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006774 // Wallpapers are animated based on the "real" window they
6775 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006776 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006777 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006778 if (mWallpaperTarget.mHasLocalTransformation &&
6779 mWallpaperTarget.mAnimation != null &&
6780 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006781 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006782 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006783 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006784 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006785 }
6786 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006787 mWallpaperTarget.mAppToken.hasTransformation &&
6788 mWallpaperTarget.mAppToken.animation != null &&
6789 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006790 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006791 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006792 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006793 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006794 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006795 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 if (selfTransformation || attachedTransformation != null
6798 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006799 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 final Rect frame = mFrame;
6801 final float tmpFloats[] = mTmpFloats;
6802 final Matrix tmpMatrix = mTmpMatrix;
6803
6804 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006805 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006807 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006809 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006811 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 }
6813 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006814 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 }
6816
6817 // "convert" it into SurfaceFlinger's format
6818 // (a 2x2 matrix + an offset)
6819 // Here we must not transform the position of the surface
6820 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006821 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 tmpMatrix.getValues(tmpFloats);
6824 mDsDx = tmpFloats[Matrix.MSCALE_X];
6825 mDtDx = tmpFloats[Matrix.MSKEW_X];
6826 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6827 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006828 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6829 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006830 int w = frame.width();
6831 int h = frame.height();
6832 mShownFrame.set(x, y, x+w, y+h);
6833
6834 // Now set the alpha... but because our current hardware
6835 // can't do alpha transformation on a non-opaque surface,
6836 // turn it off if we are running an animation that is also
6837 // transforming since it is more important to have that
6838 // animation be smooth.
6839 mShownAlpha = mAlpha;
6840 if (!mLimitedAlphaCompositing
6841 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6842 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6843 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006844 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845 if (selfTransformation) {
6846 mShownAlpha *= mTransformation.getAlpha();
6847 }
6848 if (attachedTransformation != null) {
6849 mShownAlpha *= attachedTransformation.getAlpha();
6850 }
6851 if (appTransformation != null) {
6852 mShownAlpha *= appTransformation.getAlpha();
6853 }
6854 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006855 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 }
Romain Guy06882f82009-06-10 13:36:04 -07006857
Joe Onorato8a9b2202010-02-26 18:56:32 -08006858 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 TAG, "Continuing animation in " + this +
6860 ": " + mShownFrame +
6861 ", alpha=" + mTransformation.getAlpha());
6862 return;
6863 }
Romain Guy06882f82009-06-10 13:36:04 -07006864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006865 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006866 if (mXOffset != 0 || mYOffset != 0) {
6867 mShownFrame.offset(mXOffset, mYOffset);
6868 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 mShownAlpha = mAlpha;
6870 mDsDx = 1;
6871 mDtDx = 0;
6872 mDsDy = 0;
6873 mDtDy = 1;
6874 }
Romain Guy06882f82009-06-10 13:36:04 -07006875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006876 /**
6877 * Is this window visible? It is not visible if there is no
6878 * surface, or we are in the process of running an exit animation
6879 * that will remove the surface, or its app token has been hidden.
6880 */
6881 public boolean isVisibleLw() {
6882 final AppWindowToken atoken = mAppToken;
6883 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6884 && (atoken == null || !atoken.hiddenRequested)
6885 && !mExiting && !mDestroying;
6886 }
6887
6888 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006889 * Like {@link #isVisibleLw}, but also counts a window that is currently
6890 * "hidden" behind the keyguard as visible. This allows us to apply
6891 * things like window flags that impact the keyguard.
6892 * XXX I am starting to think we need to have ANOTHER visibility flag
6893 * for this "hidden behind keyguard" state rather than overloading
6894 * mPolicyVisibility. Ungh.
6895 */
6896 public boolean isVisibleOrBehindKeyguardLw() {
6897 final AppWindowToken atoken = mAppToken;
6898 return mSurface != null && !mAttachedHidden
6899 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006900 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006901 && !mExiting && !mDestroying;
6902 }
6903
6904 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 * Is this window visible, ignoring its app token? It is not visible
6906 * if there is no surface, or we are in the process of running an exit animation
6907 * that will remove the surface.
6908 */
6909 public boolean isWinVisibleLw() {
6910 final AppWindowToken atoken = mAppToken;
6911 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6912 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6913 && !mExiting && !mDestroying;
6914 }
6915
6916 /**
6917 * The same as isVisible(), but follows the current hidden state of
6918 * the associated app token, not the pending requested hidden state.
6919 */
6920 boolean isVisibleNow() {
6921 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006922 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006923 }
6924
6925 /**
6926 * Same as isVisible(), but we also count it as visible between the
6927 * call to IWindowSession.add() and the first relayout().
6928 */
6929 boolean isVisibleOrAdding() {
6930 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006931 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6933 && mPolicyVisibility && !mAttachedHidden
6934 && (atoken == null || !atoken.hiddenRequested)
6935 && !mExiting && !mDestroying;
6936 }
6937
6938 /**
6939 * Is this window currently on-screen? It is on-screen either if it
6940 * is visible or it is currently running an animation before no longer
6941 * being visible.
6942 */
6943 boolean isOnScreen() {
6944 final AppWindowToken atoken = mAppToken;
6945 if (atoken != null) {
6946 return mSurface != null && mPolicyVisibility && !mDestroying
6947 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006948 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 } else {
6950 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006951 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 }
6953 }
Romain Guy06882f82009-06-10 13:36:04 -07006954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 /**
6956 * Like isOnScreen(), but we don't return true if the window is part
6957 * of a transition that has not yet been started.
6958 */
6959 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006960 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006961 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006962 return false;
6963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006965 final boolean animating = atoken != null
6966 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006967 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006968 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6969 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006970 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006971 }
6972
6973 /** Is the window or its container currently animating? */
6974 boolean isAnimating() {
6975 final WindowState attached = mAttachedWindow;
6976 final AppWindowToken atoken = mAppToken;
6977 return mAnimation != null
6978 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006979 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006980 (atoken.animation != null
6981 || atoken.inPendingTransaction));
6982 }
6983
6984 /** Is this window currently animating? */
6985 boolean isWindowAnimating() {
6986 return mAnimation != null;
6987 }
6988
6989 /**
6990 * Like isOnScreen, but returns false if the surface hasn't yet
6991 * been drawn.
6992 */
6993 public boolean isDisplayedLw() {
6994 final AppWindowToken atoken = mAppToken;
6995 return mSurface != null && mPolicyVisibility && !mDestroying
6996 && !mDrawPending && !mCommitDrawPending
6997 && ((!mAttachedHidden &&
6998 (atoken == null || !atoken.hiddenRequested))
6999 || mAnimating);
7000 }
7001
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007002 /**
7003 * Returns true if the window has a surface that it has drawn a
7004 * complete UI in to.
7005 */
7006 public boolean isDrawnLw() {
7007 final AppWindowToken atoken = mAppToken;
7008 return mSurface != null && !mDestroying
7009 && !mDrawPending && !mCommitDrawPending;
7010 }
7011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7013 boolean shownFrame, boolean onlyOpaque) {
7014 if (mSurface == null) {
7015 return false;
7016 }
7017 if (mAppToken != null && !mAppToken.appFullscreen) {
7018 return false;
7019 }
7020 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7021 return false;
7022 }
7023 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007024
7025 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7026 return frame.left <= mCompatibleScreenFrame.left &&
7027 frame.top <= mCompatibleScreenFrame.top &&
7028 frame.right >= mCompatibleScreenFrame.right &&
7029 frame.bottom >= mCompatibleScreenFrame.bottom;
7030 } else {
Joe Onorato93056472010-09-10 10:30:46 -04007031 if ((mAttrs.flags & FLAG_FULLSCREEN) != 0) {
7032 return true;
7033 }
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007034 return frame.left <= 0 && frame.top <= 0
7035 && frame.right >= screenWidth
7036 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 }
Romain Guy06882f82009-06-10 13:36:04 -07007039
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007040 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007041 * Return true if the window is opaque and fully drawn. This indicates
7042 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007043 */
7044 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007045 return (mAttrs.format == PixelFormat.OPAQUE
7046 || mAttrs.type == TYPE_WALLPAPER)
7047 && mSurface != null && mAnimation == null
7048 && (mAppToken == null || mAppToken.animation == null)
7049 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007050 }
7051
7052 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7053 return
7054 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007055 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7056 // only if it's visible
7057 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007058 // and only if the application fills the compatible screen
7059 mFrame.left <= mCompatibleScreenFrame.left &&
7060 mFrame.top <= mCompatibleScreenFrame.top &&
7061 mFrame.right >= mCompatibleScreenFrame.right &&
7062 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007063 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007064 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007065 }
7066
7067 boolean isFullscreen(int screenWidth, int screenHeight) {
7068 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007069 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 }
7071
7072 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007073 disposeInputChannel();
7074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007075 if (mAttachedWindow != null) {
7076 mAttachedWindow.mChildWindows.remove(this);
7077 }
7078 destroySurfaceLocked();
7079 mSession.windowRemovedLocked();
7080 try {
7081 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7082 } catch (RuntimeException e) {
7083 // Ignore if it has already been removed (usually because
7084 // we are doing this as part of processing a death note.)
7085 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007086 }
7087
7088 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007089 if (mInputChannel != null) {
7090 mInputManager.unregisterInputChannel(mInputChannel);
7091
7092 mInputChannel.dispose();
7093 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007094 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 }
7096
7097 private class DeathRecipient implements IBinder.DeathRecipient {
7098 public void binderDied() {
7099 try {
7100 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007101 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007102 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 if (win != null) {
7104 removeWindowLocked(mSession, win);
7105 }
7106 }
7107 } catch (IllegalArgumentException ex) {
7108 // This will happen if the window has already been
7109 // removed.
7110 }
7111 }
7112 }
7113
7114 /** Returns true if this window desires key events. */
7115 public final boolean canReceiveKeys() {
7116 return isVisibleOrAdding()
7117 && (mViewVisibility == View.VISIBLE)
7118 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7119 }
7120
7121 public boolean hasDrawnLw() {
7122 return mHasDrawn;
7123 }
7124
7125 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007126 return showLw(doAnimation, true);
7127 }
7128
7129 boolean showLw(boolean doAnimation, boolean requestAnim) {
7130 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7131 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007132 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007133 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007134 if (doAnimation) {
7135 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7136 + mPolicyVisibility + " mAnimation=" + mAnimation);
7137 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7138 doAnimation = false;
7139 } else if (mPolicyVisibility && mAnimation == null) {
7140 // Check for the case where we are currently visible and
7141 // not animating; we do not want to do animation at such a
7142 // point to become visible when we already are.
7143 doAnimation = false;
7144 }
7145 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007146 mPolicyVisibility = true;
7147 mPolicyVisibilityAfterAnim = true;
7148 if (doAnimation) {
7149 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7150 }
7151 if (requestAnim) {
7152 requestAnimationLocked(0);
7153 }
7154 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007155 }
7156
7157 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007158 return hideLw(doAnimation, true);
7159 }
7160
7161 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007162 if (doAnimation) {
7163 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7164 doAnimation = false;
7165 }
7166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007167 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7168 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007169 if (!current) {
7170 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007172 if (doAnimation) {
7173 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7174 if (mAnimation == null) {
7175 doAnimation = false;
7176 }
7177 }
7178 if (doAnimation) {
7179 mPolicyVisibilityAfterAnim = false;
7180 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007181 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007182 mPolicyVisibilityAfterAnim = false;
7183 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007184 // Window is no longer visible -- make sure if we were waiting
7185 // for it to be displayed before enabling the display, that
7186 // we allow the display to be enabled now.
7187 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007188 if (mCurrentFocus == this) {
7189 mFocusMayChange = true;
7190 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007191 }
7192 if (requestAnim) {
7193 requestAnimationLocked(0);
7194 }
7195 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 }
7197
7198 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007199 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7200 pw.print(" mClient="); pw.println(mClient.asBinder());
7201 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7202 if (mAttachedWindow != null || mLayoutAttached) {
7203 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7204 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7205 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007206 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7207 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7208 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007209 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7210 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007211 }
7212 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7213 pw.print(" mSubLayer="); pw.print(mSubLayer);
7214 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7215 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7216 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7217 pw.print("="); pw.print(mAnimLayer);
7218 pw.print(" mLastLayer="); pw.println(mLastLayer);
7219 if (mSurface != null) {
7220 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007221 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7222 pw.print(" layer="); pw.print(mSurfaceLayer);
7223 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7224 pw.print(" rect=("); pw.print(mSurfaceX);
7225 pw.print(","); pw.print(mSurfaceY);
7226 pw.print(") "); pw.print(mSurfaceW);
7227 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007228 }
7229 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7230 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7231 if (mAppToken != null) {
7232 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7233 }
7234 if (mTargetAppToken != null) {
7235 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7236 }
7237 pw.print(prefix); pw.print("mViewVisibility=0x");
7238 pw.print(Integer.toHexString(mViewVisibility));
7239 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007240 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7241 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007242 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7243 pw.print(prefix); pw.print("mPolicyVisibility=");
7244 pw.print(mPolicyVisibility);
7245 pw.print(" mPolicyVisibilityAfterAnim=");
7246 pw.print(mPolicyVisibilityAfterAnim);
7247 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7248 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007249 if (!mRelayoutCalled) {
7250 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7251 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007252 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007253 pw.print(" h="); pw.print(mRequestedHeight);
7254 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007255 if (mXOffset != 0 || mYOffset != 0) {
7256 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7257 pw.print(" y="); pw.println(mYOffset);
7258 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007259 pw.print(prefix); pw.print("mGivenContentInsets=");
7260 mGivenContentInsets.printShortString(pw);
7261 pw.print(" mGivenVisibleInsets=");
7262 mGivenVisibleInsets.printShortString(pw);
7263 pw.println();
7264 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7265 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7266 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7267 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007268 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007269 pw.print(prefix); pw.print("mShownFrame=");
7270 mShownFrame.printShortString(pw);
7271 pw.print(" last="); mLastShownFrame.printShortString(pw);
7272 pw.println();
7273 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7274 pw.print(" last="); mLastFrame.printShortString(pw);
7275 pw.println();
7276 pw.print(prefix); pw.print("mContainingFrame=");
7277 mContainingFrame.printShortString(pw);
7278 pw.print(" mDisplayFrame=");
7279 mDisplayFrame.printShortString(pw);
7280 pw.println();
7281 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7282 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7283 pw.println();
7284 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7285 pw.print(" last="); mLastContentInsets.printShortString(pw);
7286 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7287 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7288 pw.println();
7289 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7290 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7291 pw.print(" mAlpha="); pw.print(mAlpha);
7292 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7293 }
7294 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7295 || mAnimation != null) {
7296 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7297 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7298 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7299 pw.print(" mAnimation="); pw.println(mAnimation);
7300 }
7301 if (mHasTransformation || mHasLocalTransformation) {
7302 pw.print(prefix); pw.print("XForm: has=");
7303 pw.print(mHasTransformation);
7304 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7305 pw.print(" "); mTransformation.printShortString(pw);
7306 pw.println();
7307 }
7308 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7309 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7310 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7311 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7312 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7313 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7314 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7315 pw.print(" mDestroying="); pw.print(mDestroying);
7316 pw.print(" mRemoved="); pw.println(mRemoved);
7317 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007318 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007319 pw.print(prefix); pw.print("mOrientationChanging=");
7320 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007321 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7322 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007323 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007324 if (mHScale != 1 || mVScale != 1) {
7325 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7326 pw.print(" mVScale="); pw.println(mVScale);
7327 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007328 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007329 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7330 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7331 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007332 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7333 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7334 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007337
7338 String makeInputChannelName() {
7339 return Integer.toHexString(System.identityHashCode(this))
7340 + " " + mAttrs.getTitle();
7341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342
7343 @Override
7344 public String toString() {
7345 return "Window{"
7346 + Integer.toHexString(System.identityHashCode(this))
7347 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7348 }
7349 }
Romain Guy06882f82009-06-10 13:36:04 -07007350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 // -------------------------------------------------------------
7352 // Window Token State
7353 // -------------------------------------------------------------
7354
7355 class WindowToken {
7356 // The actual token.
7357 final IBinder token;
7358
7359 // The type of window this token is for, as per WindowManager.LayoutParams.
7360 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 // Set if this token was explicitly added by a client, so should
7363 // not be removed when all windows are removed.
7364 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007365
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007366 // For printing.
7367 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 // If this is an AppWindowToken, this is non-null.
7370 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 // All of the windows associated with this token.
7373 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7374
7375 // Is key dispatching paused for this token?
7376 boolean paused = false;
7377
7378 // Should this token's windows be hidden?
7379 boolean hidden;
7380
7381 // Temporary for finding which tokens no longer have visible windows.
7382 boolean hasVisible;
7383
Dianne Hackborna8f60182009-09-01 19:01:50 -07007384 // Set to true when this token is in a pending transaction where it
7385 // will be shown.
7386 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007387
Dianne Hackborna8f60182009-09-01 19:01:50 -07007388 // Set to true when this token is in a pending transaction where it
7389 // will be hidden.
7390 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007391
Dianne Hackborna8f60182009-09-01 19:01:50 -07007392 // Set to true when this token is in a pending transaction where its
7393 // windows will be put to the bottom of the list.
7394 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007395
Dianne Hackborna8f60182009-09-01 19:01:50 -07007396 // Set to true when this token is in a pending transaction where its
7397 // windows will be put to the top of the list.
7398 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 WindowToken(IBinder _token, int type, boolean _explicit) {
7401 token = _token;
7402 windowType = type;
7403 explicit = _explicit;
7404 }
7405
7406 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007407 pw.print(prefix); pw.print("token="); pw.println(token);
7408 pw.print(prefix); pw.print("windows="); pw.println(windows);
7409 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7410 pw.print(" hidden="); pw.print(hidden);
7411 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007412 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7413 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7414 pw.print(" waitingToHide="); pw.print(waitingToHide);
7415 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7416 pw.print(" sendingToTop="); pw.println(sendingToTop);
7417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 }
7419
7420 @Override
7421 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007422 if (stringName == null) {
7423 StringBuilder sb = new StringBuilder();
7424 sb.append("WindowToken{");
7425 sb.append(Integer.toHexString(System.identityHashCode(this)));
7426 sb.append(" token="); sb.append(token); sb.append('}');
7427 stringName = sb.toString();
7428 }
7429 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 }
7431 };
7432
7433 class AppWindowToken extends WindowToken {
7434 // Non-null only for application tokens.
7435 final IApplicationToken appToken;
7436
7437 // All of the windows and child windows that are included in this
7438 // application token. Note this list is NOT sorted!
7439 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7440
7441 int groupId = -1;
7442 boolean appFullscreen;
7443 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007444
7445 // The input dispatching timeout for this application token in nanoseconds.
7446 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 // These are used for determining when all windows associated with
7449 // an activity have been drawn, so they can be made visible together
7450 // at the same time.
7451 int lastTransactionSequence = mTransactionSequence-1;
7452 int numInterestingWindows;
7453 int numDrawnWindows;
7454 boolean inPendingTransaction;
7455 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 // Is this token going to be hidden in a little while? If so, it
7458 // won't be taken into account for setting the screen orientation.
7459 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 // Is this window's surface needed? This is almost like hidden, except
7462 // it will sometimes be true a little earlier: when the token has
7463 // been shown, but is still waiting for its app transition to execute
7464 // before making its windows shown.
7465 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 // Have we told the window clients to hide themselves?
7468 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 // Last visibility state we reported to the app token.
7471 boolean reportedVisible;
7472
7473 // Set to true when the token has been removed from the window mgr.
7474 boolean removed;
7475
7476 // Have we been asked to have this token keep the screen frozen?
7477 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 boolean animating;
7480 Animation animation;
7481 boolean hasTransformation;
7482 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 // Offset to the window of all layers in the token, for use by
7485 // AppWindowToken animations.
7486 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007488 // Information about an application starting window if displayed.
7489 StartingData startingData;
7490 WindowState startingWindow;
7491 View startingView;
7492 boolean startingDisplayed;
7493 boolean startingMoved;
7494 boolean firstWindowDrawn;
7495
7496 AppWindowToken(IApplicationToken _token) {
7497 super(_token.asBinder(),
7498 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7499 appWindowToken = this;
7500 appToken = _token;
7501 }
Romain Guy06882f82009-06-10 13:36:04 -07007502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007504 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 TAG, "Setting animation in " + this + ": " + anim);
7506 animation = anim;
7507 animating = false;
7508 anim.restrictDuration(MAX_ANIMATION_DURATION);
7509 anim.scaleCurrentDuration(mTransitionAnimationScale);
7510 int zorder = anim.getZAdjustment();
7511 int adj = 0;
7512 if (zorder == Animation.ZORDER_TOP) {
7513 adj = TYPE_LAYER_OFFSET;
7514 } else if (zorder == Animation.ZORDER_BOTTOM) {
7515 adj = -TYPE_LAYER_OFFSET;
7516 }
Romain Guy06882f82009-06-10 13:36:04 -07007517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 if (animLayerAdjustment != adj) {
7519 animLayerAdjustment = adj;
7520 updateLayers();
7521 }
7522 }
Romain Guy06882f82009-06-10 13:36:04 -07007523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 public void setDummyAnimation() {
7525 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007526 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 TAG, "Setting dummy animation in " + this);
7528 animation = sDummyAnimation;
7529 }
7530 }
7531
7532 public void clearAnimation() {
7533 if (animation != null) {
7534 animation = null;
7535 animating = true;
7536 }
7537 }
Romain Guy06882f82009-06-10 13:36:04 -07007538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 void updateLayers() {
7540 final int N = allAppWindows.size();
7541 final int adj = animLayerAdjustment;
7542 for (int i=0; i<N; i++) {
7543 WindowState w = allAppWindows.get(i);
7544 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007545 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 + w.mAnimLayer);
7547 if (w == mInputMethodTarget) {
7548 setInputMethodAnimLayerAdjustment(adj);
7549 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007550 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007551 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 }
7554 }
Romain Guy06882f82009-06-10 13:36:04 -07007555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007556 void sendAppVisibilityToClients() {
7557 final int N = allAppWindows.size();
7558 for (int i=0; i<N; i++) {
7559 WindowState win = allAppWindows.get(i);
7560 if (win == startingWindow && clientHidden) {
7561 // Don't hide the starting window.
7562 continue;
7563 }
7564 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007565 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007566 "Setting visibility of " + win + ": " + (!clientHidden));
7567 win.mClient.dispatchAppVisibility(!clientHidden);
7568 } catch (RemoteException e) {
7569 }
7570 }
7571 }
Romain Guy06882f82009-06-10 13:36:04 -07007572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 void showAllWindowsLocked() {
7574 final int NW = allAppWindows.size();
7575 for (int i=0; i<NW; i++) {
7576 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007577 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007578 "performing show on: " + w);
7579 w.performShowLocked();
7580 }
7581 }
Romain Guy06882f82009-06-10 13:36:04 -07007582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 // This must be called while inside a transaction.
7584 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007585 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007586 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 if (animation == sDummyAnimation) {
7589 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007590 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 // when it is really time to animate, this will be set to
7592 // a real animation and the next call will execute normally.
7593 return false;
7594 }
Romain Guy06882f82009-06-10 13:36:04 -07007595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7597 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007598 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 TAG, "Starting animation in " + this +
7600 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7601 + " scale=" + mTransitionAnimationScale
7602 + " allDrawn=" + allDrawn + " animating=" + animating);
7603 animation.initialize(dw, dh, dw, dh);
7604 animation.setStartTime(currentTime);
7605 animating = true;
7606 }
7607 transformation.clear();
7608 final boolean more = animation.getTransformation(
7609 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007610 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 TAG, "Stepped animation in " + this +
7612 ": more=" + more + ", xform=" + transformation);
7613 if (more) {
7614 // we're done!
7615 hasTransformation = true;
7616 return true;
7617 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007618 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007619 TAG, "Finished animation in " + this +
7620 " @ " + currentTime);
7621 animation = null;
7622 }
7623 } else if (animation != null) {
7624 // If the display is frozen, and there is a pending animation,
7625 // clear it and make sure we run the cleanup code.
7626 animating = true;
7627 animation = null;
7628 }
7629
7630 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 if (!animating) {
7633 return false;
7634 }
7635
7636 clearAnimation();
7637 animating = false;
7638 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7639 moveInputMethodWindowsIfNeededLocked(true);
7640 }
Romain Guy06882f82009-06-10 13:36:04 -07007641
Joe Onorato8a9b2202010-02-26 18:56:32 -08007642 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 TAG, "Animation done in " + this
7644 + ": reportedVisible=" + reportedVisible);
7645
7646 transformation.clear();
7647 if (animLayerAdjustment != 0) {
7648 animLayerAdjustment = 0;
7649 updateLayers();
7650 }
Romain Guy06882f82009-06-10 13:36:04 -07007651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007652 final int N = windows.size();
7653 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007654 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007655 }
7656 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007658 return false;
7659 }
7660
7661 void updateReportedVisibilityLocked() {
7662 if (appToken == null) {
7663 return;
7664 }
Romain Guy06882f82009-06-10 13:36:04 -07007665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007666 int numInteresting = 0;
7667 int numVisible = 0;
7668 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007669
Joe Onorato8a9b2202010-02-26 18:56:32 -08007670 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007671 final int N = allAppWindows.size();
7672 for (int i=0; i<N; i++) {
7673 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007674 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007675 || win.mViewVisibility != View.VISIBLE
7676 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 continue;
7678 }
7679 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007680 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007681 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007682 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007683 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007684 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 + " pv=" + win.mPolicyVisibility
7686 + " dp=" + win.mDrawPending
7687 + " cdp=" + win.mCommitDrawPending
7688 + " ah=" + win.mAttachedHidden
7689 + " th="
7690 + (win.mAppToken != null
7691 ? win.mAppToken.hiddenRequested : false)
7692 + " a=" + win.mAnimating);
7693 }
7694 }
7695 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007696 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007697 if (!win.isAnimating()) {
7698 numVisible++;
7699 }
7700 nowGone = false;
7701 } else if (win.isAnimating()) {
7702 nowGone = false;
7703 }
7704 }
Romain Guy06882f82009-06-10 13:36:04 -07007705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007707 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 + numInteresting + " visible=" + numVisible);
7709 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007710 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007711 TAG, "Visibility changed in " + this
7712 + ": vis=" + nowVisible);
7713 reportedVisible = nowVisible;
7714 Message m = mH.obtainMessage(
7715 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7716 nowVisible ? 1 : 0,
7717 nowGone ? 1 : 0,
7718 this);
7719 mH.sendMessage(m);
7720 }
7721 }
Romain Guy06882f82009-06-10 13:36:04 -07007722
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007723 WindowState findMainWindow() {
7724 int j = windows.size();
7725 while (j > 0) {
7726 j--;
7727 WindowState win = windows.get(j);
7728 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7729 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7730 return win;
7731 }
7732 }
7733 return null;
7734 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007736 void dump(PrintWriter pw, String prefix) {
7737 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007738 if (appToken != null) {
7739 pw.print(prefix); pw.println("app=true");
7740 }
7741 if (allAppWindows.size() > 0) {
7742 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7743 }
7744 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007745 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007746 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7747 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7748 pw.print(" clientHidden="); pw.print(clientHidden);
7749 pw.print(" willBeHidden="); pw.print(willBeHidden);
7750 pw.print(" reportedVisible="); pw.println(reportedVisible);
7751 if (paused || freezingScreen) {
7752 pw.print(prefix); pw.print("paused="); pw.print(paused);
7753 pw.print(" freezingScreen="); pw.println(freezingScreen);
7754 }
7755 if (numInterestingWindows != 0 || numDrawnWindows != 0
7756 || inPendingTransaction || allDrawn) {
7757 pw.print(prefix); pw.print("numInterestingWindows=");
7758 pw.print(numInterestingWindows);
7759 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7760 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7761 pw.print(" allDrawn="); pw.println(allDrawn);
7762 }
7763 if (animating || animation != null) {
7764 pw.print(prefix); pw.print("animating="); pw.print(animating);
7765 pw.print(" animation="); pw.println(animation);
7766 }
7767 if (animLayerAdjustment != 0) {
7768 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7769 }
7770 if (hasTransformation) {
7771 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7772 pw.print(" transformation="); transformation.printShortString(pw);
7773 pw.println();
7774 }
7775 if (startingData != null || removed || firstWindowDrawn) {
7776 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7777 pw.print(" removed="); pw.print(removed);
7778 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7779 }
7780 if (startingWindow != null || startingView != null
7781 || startingDisplayed || startingMoved) {
7782 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7783 pw.print(" startingView="); pw.print(startingView);
7784 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7785 pw.print(" startingMoved"); pw.println(startingMoved);
7786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 }
7788
7789 @Override
7790 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007791 if (stringName == null) {
7792 StringBuilder sb = new StringBuilder();
7793 sb.append("AppWindowToken{");
7794 sb.append(Integer.toHexString(System.identityHashCode(this)));
7795 sb.append(" token="); sb.append(token); sb.append('}');
7796 stringName = sb.toString();
7797 }
7798 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 }
7800 }
Romain Guy06882f82009-06-10 13:36:04 -07007801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007802 // -------------------------------------------------------------
7803 // DummyAnimation
7804 // -------------------------------------------------------------
7805
7806 // This is an animation that does nothing: it just immediately finishes
7807 // itself every time it is called. It is used as a stub animation in cases
7808 // where we want to synchronize multiple things that may be animating.
7809 static final class DummyAnimation extends Animation {
7810 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7811 return false;
7812 }
7813 }
7814 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007816 // -------------------------------------------------------------
7817 // Async Handler
7818 // -------------------------------------------------------------
7819
7820 static final class StartingData {
7821 final String pkg;
7822 final int theme;
7823 final CharSequence nonLocalizedLabel;
7824 final int labelRes;
7825 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007827 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7828 int _labelRes, int _icon) {
7829 pkg = _pkg;
7830 theme = _theme;
7831 nonLocalizedLabel = _nonLocalizedLabel;
7832 labelRes = _labelRes;
7833 icon = _icon;
7834 }
7835 }
7836
7837 private final class H extends Handler {
7838 public static final int REPORT_FOCUS_CHANGE = 2;
7839 public static final int REPORT_LOSING_FOCUS = 3;
7840 public static final int ANIMATE = 4;
7841 public static final int ADD_STARTING = 5;
7842 public static final int REMOVE_STARTING = 6;
7843 public static final int FINISHED_STARTING = 7;
7844 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7846 public static final int HOLD_SCREEN_CHANGED = 12;
7847 public static final int APP_TRANSITION_TIMEOUT = 13;
7848 public static final int PERSIST_ANIMATION_SCALE = 14;
7849 public static final int FORCE_GC = 15;
7850 public static final int ENABLE_SCREEN = 16;
7851 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007852 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007853 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007857 public H() {
7858 }
Romain Guy06882f82009-06-10 13:36:04 -07007859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007860 @Override
7861 public void handleMessage(Message msg) {
7862 switch (msg.what) {
7863 case REPORT_FOCUS_CHANGE: {
7864 WindowState lastFocus;
7865 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007867 synchronized(mWindowMap) {
7868 lastFocus = mLastFocus;
7869 newFocus = mCurrentFocus;
7870 if (lastFocus == newFocus) {
7871 // Focus is not changing, so nothing to do.
7872 return;
7873 }
7874 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007875 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 // + " to " + newFocus);
7877 if (newFocus != null && lastFocus != null
7878 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007879 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 mLosingFocus.add(lastFocus);
7881 lastFocus = null;
7882 }
7883 }
7884
7885 if (lastFocus != newFocus) {
7886 //System.out.println("Changing focus from " + lastFocus
7887 // + " to " + newFocus);
7888 if (newFocus != null) {
7889 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007890 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7892 } catch (RemoteException e) {
7893 // Ignore if process has died.
7894 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007895 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007896 }
7897
7898 if (lastFocus != null) {
7899 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007900 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7902 } catch (RemoteException e) {
7903 // Ignore if process has died.
7904 }
7905 }
7906 }
7907 } break;
7908
7909 case REPORT_LOSING_FOCUS: {
7910 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 synchronized(mWindowMap) {
7913 losers = mLosingFocus;
7914 mLosingFocus = new ArrayList<WindowState>();
7915 }
7916
7917 final int N = losers.size();
7918 for (int i=0; i<N; i++) {
7919 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007920 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7922 } catch (RemoteException e) {
7923 // Ignore if process has died.
7924 }
7925 }
7926 } break;
7927
7928 case ANIMATE: {
7929 synchronized(mWindowMap) {
7930 mAnimationPending = false;
7931 performLayoutAndPlaceSurfacesLocked();
7932 }
7933 } break;
7934
7935 case ADD_STARTING: {
7936 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7937 final StartingData sd = wtoken.startingData;
7938
7939 if (sd == null) {
7940 // Animation has been canceled... do nothing.
7941 return;
7942 }
Romain Guy06882f82009-06-10 13:36:04 -07007943
Joe Onorato8a9b2202010-02-26 18:56:32 -08007944 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007945 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007947 View view = null;
7948 try {
7949 view = mPolicy.addStartingWindow(
7950 wtoken.token, sd.pkg,
7951 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7952 sd.icon);
7953 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007954 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007955 }
7956
7957 if (view != null) {
7958 boolean abort = false;
7959
7960 synchronized(mWindowMap) {
7961 if (wtoken.removed || wtoken.startingData == null) {
7962 // If the window was successfully added, then
7963 // we need to remove it.
7964 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007965 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007966 "Aborted starting " + wtoken
7967 + ": removed=" + wtoken.removed
7968 + " startingData=" + wtoken.startingData);
7969 wtoken.startingWindow = null;
7970 wtoken.startingData = null;
7971 abort = true;
7972 }
7973 } else {
7974 wtoken.startingView = view;
7975 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007976 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 "Added starting " + wtoken
7978 + ": startingWindow="
7979 + wtoken.startingWindow + " startingView="
7980 + wtoken.startingView);
7981 }
7982
7983 if (abort) {
7984 try {
7985 mPolicy.removeStartingWindow(wtoken.token, view);
7986 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007987 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 }
7989 }
7990 }
7991 } break;
7992
7993 case REMOVE_STARTING: {
7994 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7995 IBinder token = null;
7996 View view = null;
7997 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007998 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007999 + wtoken + ": startingWindow="
8000 + wtoken.startingWindow + " startingView="
8001 + wtoken.startingView);
8002 if (wtoken.startingWindow != null) {
8003 view = wtoken.startingView;
8004 token = wtoken.token;
8005 wtoken.startingData = null;
8006 wtoken.startingView = null;
8007 wtoken.startingWindow = null;
8008 }
8009 }
8010 if (view != null) {
8011 try {
8012 mPolicy.removeStartingWindow(token, view);
8013 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008014 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008015 }
8016 }
8017 } break;
8018
8019 case FINISHED_STARTING: {
8020 IBinder token = null;
8021 View view = null;
8022 while (true) {
8023 synchronized (mWindowMap) {
8024 final int N = mFinishedStarting.size();
8025 if (N <= 0) {
8026 break;
8027 }
8028 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8029
Joe Onorato8a9b2202010-02-26 18:56:32 -08008030 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008031 "Finished starting " + wtoken
8032 + ": startingWindow=" + wtoken.startingWindow
8033 + " startingView=" + wtoken.startingView);
8034
8035 if (wtoken.startingWindow == null) {
8036 continue;
8037 }
8038
8039 view = wtoken.startingView;
8040 token = wtoken.token;
8041 wtoken.startingData = null;
8042 wtoken.startingView = null;
8043 wtoken.startingWindow = null;
8044 }
8045
8046 try {
8047 mPolicy.removeStartingWindow(token, view);
8048 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008049 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 }
8051 }
8052 } break;
8053
8054 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8055 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8056
8057 boolean nowVisible = msg.arg1 != 0;
8058 boolean nowGone = msg.arg2 != 0;
8059
8060 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008061 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 TAG, "Reporting visible in " + wtoken
8063 + " visible=" + nowVisible
8064 + " gone=" + nowGone);
8065 if (nowVisible) {
8066 wtoken.appToken.windowsVisible();
8067 } else {
8068 wtoken.appToken.windowsGone();
8069 }
8070 } catch (RemoteException ex) {
8071 }
8072 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008074 case WINDOW_FREEZE_TIMEOUT: {
8075 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008076 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008077 int i = mWindows.size();
8078 while (i > 0) {
8079 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008080 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008081 if (w.mOrientationChanging) {
8082 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008083 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008084 }
8085 }
8086 performLayoutAndPlaceSurfacesLocked();
8087 }
8088 break;
8089 }
Romain Guy06882f82009-06-10 13:36:04 -07008090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008091 case HOLD_SCREEN_CHANGED: {
8092 Session oldHold;
8093 Session newHold;
8094 synchronized (mWindowMap) {
8095 oldHold = mLastReportedHold;
8096 newHold = (Session)msg.obj;
8097 mLastReportedHold = newHold;
8098 }
Romain Guy06882f82009-06-10 13:36:04 -07008099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008100 if (oldHold != newHold) {
8101 try {
8102 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008103 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008104 "window",
8105 BatteryStats.WAKE_TYPE_WINDOW);
8106 }
8107 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008108 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008109 "window",
8110 BatteryStats.WAKE_TYPE_WINDOW);
8111 }
8112 } catch (RemoteException e) {
8113 }
8114 }
8115 break;
8116 }
Romain Guy06882f82009-06-10 13:36:04 -07008117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 case APP_TRANSITION_TIMEOUT: {
8119 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008120 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008121 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008122 "*** APP TRANSITION TIMEOUT");
8123 mAppTransitionReady = true;
8124 mAppTransitionTimeout = true;
8125 performLayoutAndPlaceSurfacesLocked();
8126 }
8127 }
8128 break;
8129 }
Romain Guy06882f82009-06-10 13:36:04 -07008130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008131 case PERSIST_ANIMATION_SCALE: {
8132 Settings.System.putFloat(mContext.getContentResolver(),
8133 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8134 Settings.System.putFloat(mContext.getContentResolver(),
8135 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8136 break;
8137 }
Romain Guy06882f82009-06-10 13:36:04 -07008138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008139 case FORCE_GC: {
8140 synchronized(mWindowMap) {
8141 if (mAnimationPending) {
8142 // If we are animating, don't do the gc now but
8143 // delay a bit so we don't interrupt the animation.
8144 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8145 2000);
8146 return;
8147 }
8148 // If we are currently rotating the display, it will
8149 // schedule a new message when done.
8150 if (mDisplayFrozen) {
8151 return;
8152 }
8153 mFreezeGcPending = 0;
8154 }
8155 Runtime.getRuntime().gc();
8156 break;
8157 }
Romain Guy06882f82009-06-10 13:36:04 -07008158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 case ENABLE_SCREEN: {
8160 performEnableScreen();
8161 break;
8162 }
Romain Guy06882f82009-06-10 13:36:04 -07008163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008164 case APP_FREEZE_TIMEOUT: {
8165 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008166 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 int i = mAppTokens.size();
8168 while (i > 0) {
8169 i--;
8170 AppWindowToken tok = mAppTokens.get(i);
8171 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008172 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008173 unsetAppFreezingScreenLocked(tok, true, true);
8174 }
8175 }
8176 }
8177 break;
8178 }
Romain Guy06882f82009-06-10 13:36:04 -07008179
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008180 case SEND_NEW_CONFIGURATION: {
8181 removeMessages(SEND_NEW_CONFIGURATION);
8182 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008183 break;
8184 }
Romain Guy06882f82009-06-10 13:36:04 -07008185
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008186 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008187 if (mWindowsChanged) {
8188 synchronized (mWindowMap) {
8189 mWindowsChanged = false;
8190 }
8191 notifyWindowsChanged();
8192 }
8193 break;
8194 }
8195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008196 }
8197 }
8198 }
8199
8200 // -------------------------------------------------------------
8201 // IWindowManager API
8202 // -------------------------------------------------------------
8203
8204 public IWindowSession openSession(IInputMethodClient client,
8205 IInputContext inputContext) {
8206 if (client == null) throw new IllegalArgumentException("null client");
8207 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008208 Session session = new Session(client, inputContext);
8209 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008210 }
8211
8212 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8213 synchronized (mWindowMap) {
8214 // The focus for the client is the window immediately below
8215 // where we would place the input method window.
8216 int idx = findDesiredInputMethodWindowIndexLocked(false);
8217 WindowState imFocus;
8218 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008219 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008220 if (imFocus != null) {
8221 if (imFocus.mSession.mClient != null &&
8222 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8223 return true;
8224 }
8225 }
8226 }
8227 }
8228 return false;
8229 }
Romain Guy06882f82009-06-10 13:36:04 -07008230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008231 // -------------------------------------------------------------
8232 // Internals
8233 // -------------------------------------------------------------
8234
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008235 final WindowState windowForClientLocked(Session session, IWindow client,
8236 boolean throwOnError) {
8237 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 }
Romain Guy06882f82009-06-10 13:36:04 -07008239
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008240 final WindowState windowForClientLocked(Session session, IBinder client,
8241 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008242 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008243 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008244 TAG, "Looking up client " + client + ": " + win);
8245 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008246 RuntimeException ex = new IllegalArgumentException(
8247 "Requested window " + client + " does not exist");
8248 if (throwOnError) {
8249 throw ex;
8250 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008251 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008252 return null;
8253 }
8254 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008255 RuntimeException ex = new IllegalArgumentException(
8256 "Requested window " + client + " is in session " +
8257 win.mSession + ", not " + session);
8258 if (throwOnError) {
8259 throw ex;
8260 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008261 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262 return null;
8263 }
8264
8265 return win;
8266 }
8267
Dianne Hackborna8f60182009-09-01 19:01:50 -07008268 final void rebuildAppWindowListLocked() {
8269 int NW = mWindows.size();
8270 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008271 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008272 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008273
Dianne Hackborna8f60182009-09-01 19:01:50 -07008274 // First remove all existing app windows.
8275 i=0;
8276 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008277 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008278 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008279 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008280 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008281 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008282 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008283 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008284 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008285 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008286 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8287 && lastWallpaper == i-1) {
8288 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008289 }
8290 i++;
8291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008292
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008293 // The wallpaper window(s) typically live at the bottom of the stack,
8294 // so skip them before adding app tokens.
8295 lastWallpaper++;
8296 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008297
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008298 // First add all of the exiting app tokens... these are no longer
8299 // in the main app list, but still have windows shown. We put them
8300 // in the back because now that the animation is over we no longer
8301 // will care about them.
8302 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008303 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008304 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8305 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008306
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008307 // And add in the still active app tokens in Z order.
8308 NT = mAppTokens.size();
8309 for (int j=0; j<NT; j++) {
8310 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008311 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008312
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008313 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008314 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008315 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008316 + " windows but added " + i);
8317 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008318 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008320 private final void assignLayersLocked() {
8321 int N = mWindows.size();
8322 int curBaseLayer = 0;
8323 int curLayer = 0;
8324 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008326 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008327 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008328 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8329 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008330 curLayer += WINDOW_LAYER_MULTIPLIER;
8331 w.mLayer = curLayer;
8332 } else {
8333 curBaseLayer = curLayer = w.mBaseLayer;
8334 w.mLayer = curLayer;
8335 }
8336 if (w.mTargetAppToken != null) {
8337 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8338 } else if (w.mAppToken != null) {
8339 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8340 } else {
8341 w.mAnimLayer = w.mLayer;
8342 }
8343 if (w.mIsImWindow) {
8344 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008345 } else if (w.mIsWallpaper) {
8346 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008347 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008348 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008349 + w.mAnimLayer);
8350 //System.out.println(
8351 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8352 }
8353 }
8354
8355 private boolean mInLayout = false;
8356 private final void performLayoutAndPlaceSurfacesLocked() {
8357 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008358 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008359 throw new RuntimeException("Recursive call!");
8360 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008361 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008362 return;
8363 }
8364
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008365 if (mWaitingForConfig) {
8366 // Our configuration has changed (most likely rotation), but we
8367 // don't yet have the complete configuration to report to
8368 // applications. Don't do any window layout until we have it.
8369 return;
8370 }
8371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008372 boolean recoveringMemory = false;
8373 if (mForceRemoves != null) {
8374 recoveringMemory = true;
8375 // Wait a little it for things to settle down, and off we go.
8376 for (int i=0; i<mForceRemoves.size(); i++) {
8377 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008378 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 removeWindowInnerLocked(ws.mSession, ws);
8380 }
8381 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008382 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008383 Object tmp = new Object();
8384 synchronized (tmp) {
8385 try {
8386 tmp.wait(250);
8387 } catch (InterruptedException e) {
8388 }
8389 }
8390 }
Romain Guy06882f82009-06-10 13:36:04 -07008391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008392 mInLayout = true;
8393 try {
8394 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008396 int i = mPendingRemove.size()-1;
8397 if (i >= 0) {
8398 while (i >= 0) {
8399 WindowState w = mPendingRemove.get(i);
8400 removeWindowInnerLocked(w.mSession, w);
8401 i--;
8402 }
8403 mPendingRemove.clear();
8404
8405 mInLayout = false;
8406 assignLayersLocked();
8407 mLayoutNeeded = true;
8408 performLayoutAndPlaceSurfacesLocked();
8409
8410 } else {
8411 mInLayout = false;
8412 if (mLayoutNeeded) {
8413 requestAnimationLocked(0);
8414 }
8415 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008416 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008417 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8418 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008420 } catch (RuntimeException e) {
8421 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008422 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008423 }
8424 }
8425
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008426 private final int performLayoutLockedInner() {
8427 if (!mLayoutNeeded) {
8428 return 0;
8429 }
8430
8431 mLayoutNeeded = false;
8432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 final int dw = mDisplay.getWidth();
8434 final int dh = mDisplay.getHeight();
8435
8436 final int N = mWindows.size();
8437 int i;
8438
Joe Onorato8a9b2202010-02-26 18:56:32 -08008439 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008440 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8441
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008442 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008443
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008444 int seq = mLayoutSeq+1;
8445 if (seq < 0) seq = 0;
8446 mLayoutSeq = seq;
8447
8448 // First perform layout of any root windows (not attached
8449 // to another window).
8450 int topAttached = -1;
8451 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008452 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008454 // Don't do layout of a window if it is not visible, or
8455 // soon won't be visible, to avoid wasting time and funky
8456 // changes while a window is animating away.
8457 final AppWindowToken atoken = win.mAppToken;
8458 final boolean gone = win.mViewVisibility == View.GONE
8459 || !win.mRelayoutCalled
8460 || win.mRootToken.hidden
8461 || (atoken != null && atoken.hiddenRequested)
8462 || win.mAttachedHidden
8463 || win.mExiting || win.mDestroying;
8464
8465 if (!win.mLayoutAttached) {
8466 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8467 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8468 + " mLayoutAttached=" + win.mLayoutAttached);
8469 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8470 + win.mViewVisibility + " mRelayoutCalled="
8471 + win.mRelayoutCalled + " hidden="
8472 + win.mRootToken.hidden + " hiddenRequested="
8473 + (atoken != null && atoken.hiddenRequested)
8474 + " mAttachedHidden=" + win.mAttachedHidden);
8475 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008476
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008477 // If this view is GONE, then skip it -- keep the current
8478 // frame, and let the caller know so they can ignore it
8479 // if they want. (We do the normal layout for INVISIBLE
8480 // windows, since that means "perform layout as normal,
8481 // just don't display").
8482 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008483 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008484 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8485 win.mLayoutSeq = seq;
8486 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8487 + win.mFrame + " mContainingFrame="
8488 + win.mContainingFrame + " mDisplayFrame="
8489 + win.mDisplayFrame);
8490 } else {
8491 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008492 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008495
8496 // Now perform layout of attached windows, which usually
8497 // depend on the position of the window they are attached to.
8498 // XXX does not deal with windows that are attached to windows
8499 // that are themselves attached.
8500 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008501 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008502
8503 // If this view is GONE, then skip it -- keep the current
8504 // frame, and let the caller know so they can ignore it
8505 // if they want. (We do the normal layout for INVISIBLE
8506 // windows, since that means "perform layout as normal,
8507 // just don't display").
8508 if (win.mLayoutAttached) {
8509 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8510 + " mHaveFrame=" + win.mHaveFrame
8511 + " mViewVisibility=" + win.mViewVisibility
8512 + " mRelayoutCalled=" + win.mRelayoutCalled);
8513 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8514 || !win.mHaveFrame) {
8515 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8516 win.mLayoutSeq = seq;
8517 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8518 + win.mFrame + " mContainingFrame="
8519 + win.mContainingFrame + " mDisplayFrame="
8520 + win.mDisplayFrame);
8521 }
8522 }
8523 }
Jeff Brown349703e2010-06-22 01:27:15 -07008524
8525 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008526 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008527
8528 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 }
Romain Guy06882f82009-06-10 13:36:04 -07008530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 private final void performLayoutAndPlaceSurfacesLockedInner(
8532 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008533 if (mDisplay == null) {
8534 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8535 return;
8536 }
8537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 final long currentTime = SystemClock.uptimeMillis();
8539 final int dw = mDisplay.getWidth();
8540 final int dh = mDisplay.getHeight();
8541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008542 int i;
8543
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008544 if (mFocusMayChange) {
8545 mFocusMayChange = false;
8546 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8547 }
8548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 // Initialize state of exiting tokens.
8550 for (i=mExitingTokens.size()-1; i>=0; i--) {
8551 mExitingTokens.get(i).hasVisible = false;
8552 }
8553
8554 // Initialize state of exiting applications.
8555 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8556 mExitingAppTokens.get(i).hasVisible = false;
8557 }
8558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 boolean orientationChangeComplete = true;
8560 Session holdScreen = null;
8561 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008562 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563 boolean focusDisplayed = false;
8564 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008565 boolean createWatermark = false;
8566
8567 if (mFxSession == null) {
8568 mFxSession = new SurfaceSession();
8569 createWatermark = true;
8570 }
8571
8572 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573
8574 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008575
8576 if (createWatermark) {
8577 createWatermark();
8578 }
8579 if (mWatermark != null) {
8580 mWatermark.positionSurface(dw, dh);
8581 }
8582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008584 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008585 int repeats = 0;
8586 int changes = 0;
8587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008589 repeats++;
8590 if (repeats > 6) {
8591 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8592 mLayoutNeeded = false;
8593 break;
8594 }
8595
8596 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8597 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8598 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8599 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8600 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8601 assignLayersLocked();
8602 mLayoutNeeded = true;
8603 }
8604 }
8605 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8606 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8607 if (updateOrientationFromAppTokensLocked()) {
8608 mLayoutNeeded = true;
8609 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8610 }
8611 }
8612 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8613 mLayoutNeeded = true;
8614 }
8615 }
8616
8617 // FIRST LOOP: Perform a layout, if needed.
8618 if (repeats < 4) {
8619 changes = performLayoutLockedInner();
8620 if (changes != 0) {
8621 continue;
8622 }
8623 } else {
8624 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8625 changes = 0;
8626 }
8627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 final int transactionSequence = ++mTransactionSequence;
8629
8630 // Update animations of all applications, including those
8631 // associated with exiting/removed apps
8632 boolean tokensAnimating = false;
8633 final int NAT = mAppTokens.size();
8634 for (i=0; i<NAT; i++) {
8635 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8636 tokensAnimating = true;
8637 }
8638 }
8639 final int NEAT = mExitingAppTokens.size();
8640 for (i=0; i<NEAT; i++) {
8641 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8642 tokensAnimating = true;
8643 }
8644 }
8645
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008646 // SECOND LOOP: Execute animations and update visibility of windows.
8647
Joe Onorato8a9b2202010-02-26 18:56:32 -08008648 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008649 + transactionSequence + " tokensAnimating="
8650 + tokensAnimating);
8651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008652 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653
8654 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008655 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008656 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008657
8658 mPolicy.beginAnimationLw(dw, dh);
8659
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008660 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008662 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008663 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664
8665 final WindowManager.LayoutParams attrs = w.mAttrs;
8666
8667 if (w.mSurface != null) {
8668 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008669 if (w.commitFinishDrawingLocked(currentTime)) {
8670 if ((w.mAttrs.flags
8671 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008672 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008673 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008674 wallpaperMayChange = true;
8675 }
8676 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008677
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008678 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8680 animating = true;
8681 //w.dump(" ");
8682 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008683 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8684 wallpaperMayChange = true;
8685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008686
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008687 if (mPolicy.doesForceHide(w, attrs)) {
8688 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008689 if (DEBUG_VISIBILITY) Slog.v(TAG,
8690 "Animation done that could impact force hide: "
8691 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008692 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008693 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008694 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8695 forceHiding = true;
8696 }
8697 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8698 boolean changed;
8699 if (forceHiding) {
8700 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008701 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8702 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008703 } else {
8704 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008705 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8706 "Now policy shown: " + w);
8707 if (changed) {
8708 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008709 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008710 // Assume we will need to animate. If
8711 // we don't (because the wallpaper will
8712 // stay with the lock screen), then we will
8713 // clean up later.
8714 Animation a = mPolicy.createForceHideEnterAnimation();
8715 if (a != null) {
8716 w.setAnimation(a);
8717 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008718 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008719 if (mCurrentFocus == null ||
8720 mCurrentFocus.mLayer < w.mLayer) {
8721 // We are showing on to of the current
8722 // focus, so re-evaluate focus to make
8723 // sure it is correct.
8724 mFocusMayChange = true;
8725 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008726 }
8727 }
8728 if (changed && (attrs.flags
8729 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8730 wallpaperMayChange = true;
8731 }
8732 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 mPolicy.animatingWindowLw(w, attrs);
8735 }
8736
8737 final AppWindowToken atoken = w.mAppToken;
8738 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8739 if (atoken.lastTransactionSequence != transactionSequence) {
8740 atoken.lastTransactionSequence = transactionSequence;
8741 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8742 atoken.startingDisplayed = false;
8743 }
8744 if ((w.isOnScreen() || w.mAttrs.type
8745 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8746 && !w.mExiting && !w.mDestroying) {
8747 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008748 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008749 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008750 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008751 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008752 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008753 + " pv=" + w.mPolicyVisibility
8754 + " dp=" + w.mDrawPending
8755 + " cdp=" + w.mCommitDrawPending
8756 + " ah=" + w.mAttachedHidden
8757 + " th=" + atoken.hiddenRequested
8758 + " a=" + w.mAnimating);
8759 }
8760 }
8761 if (w != atoken.startingWindow) {
8762 if (!atoken.freezingScreen || !w.mAppFreezing) {
8763 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008764 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008765 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008766 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008767 "tokenMayBeDrawn: " + atoken
8768 + " freezingScreen=" + atoken.freezingScreen
8769 + " mAppFreezing=" + w.mAppFreezing);
8770 tokenMayBeDrawn = true;
8771 }
8772 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008773 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008774 atoken.startingDisplayed = true;
8775 }
8776 }
8777 } else if (w.mReadyToShow) {
8778 w.performShowLocked();
8779 }
8780 }
8781
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008782 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783
8784 if (tokenMayBeDrawn) {
8785 // See if any windows have been drawn, so they (and others
8786 // associated with them) can now be shown.
8787 final int NT = mTokenList.size();
8788 for (i=0; i<NT; i++) {
8789 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8790 if (wtoken == null) {
8791 continue;
8792 }
8793 if (wtoken.freezingScreen) {
8794 int numInteresting = wtoken.numInterestingWindows;
8795 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008796 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 "allDrawn: " + wtoken
8798 + " interesting=" + numInteresting
8799 + " drawn=" + wtoken.numDrawnWindows);
8800 wtoken.showAllWindowsLocked();
8801 unsetAppFreezingScreenLocked(wtoken, false, true);
8802 orientationChangeComplete = true;
8803 }
8804 } else if (!wtoken.allDrawn) {
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.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008812 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813
8814 // We can now show all of the drawn windows!
8815 if (!mOpeningApps.contains(wtoken)) {
8816 wtoken.showAllWindowsLocked();
8817 }
8818 }
8819 }
8820 }
8821 }
8822
8823 // If we are ready to perform an app transition, check through
8824 // all of the app tokens to be shown and see if they are ready
8825 // to go.
8826 if (mAppTransitionReady) {
8827 int NN = mOpeningApps.size();
8828 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008829 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008830 "Checking " + NN + " opening apps (frozen="
8831 + mDisplayFrozen + " timeout="
8832 + mAppTransitionTimeout + ")...");
8833 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8834 // If the display isn't frozen, wait to do anything until
8835 // all of the apps are ready. Otherwise just go because
8836 // we'll unfreeze the display when everyone is ready.
8837 for (i=0; i<NN && goodToGo; i++) {
8838 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008839 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008840 "Check opening app" + wtoken + ": allDrawn="
8841 + wtoken.allDrawn + " startingDisplayed="
8842 + wtoken.startingDisplayed);
8843 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8844 && !wtoken.startingMoved) {
8845 goodToGo = false;
8846 }
8847 }
8848 }
8849 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008850 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008851 int transit = mNextAppTransition;
8852 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008853 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008854 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008855 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008856 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008857 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008858 mAppTransitionTimeout = false;
8859 mStartingIconInTransition = false;
8860 mSkipAppTransitionAnimation = false;
8861
8862 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8863
Dianne Hackborna8f60182009-09-01 19:01:50 -07008864 // If there are applications waiting to come to the
8865 // top of the stack, now is the time to move their windows.
8866 // (Note that we don't do apps going to the bottom
8867 // here -- we want to keep their windows in the old
8868 // Z-order until the animation completes.)
8869 if (mToTopApps.size() > 0) {
8870 NN = mAppTokens.size();
8871 for (i=0; i<NN; i++) {
8872 AppWindowToken wtoken = mAppTokens.get(i);
8873 if (wtoken.sendingToTop) {
8874 wtoken.sendingToTop = false;
8875 moveAppWindowsLocked(wtoken, NN, false);
8876 }
8877 }
8878 mToTopApps.clear();
8879 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008880
Dianne Hackborn25994b42009-09-04 14:21:19 -07008881 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008882
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008883 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008884 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008885
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008886 // The top-most window will supply the layout params,
8887 // and we will determine it below.
8888 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008889 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008890 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008891
Joe Onorato8a9b2202010-02-26 18:56:32 -08008892 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008893 "New wallpaper target=" + mWallpaperTarget
8894 + ", lower target=" + mLowerWallpaperTarget
8895 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008896 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008897 // Do a first pass through the tokens for two
8898 // things:
8899 // (1) Determine if both the closing and opening
8900 // app token sets are wallpaper targets, in which
8901 // case special animations are needed
8902 // (since the wallpaper needs to stay static
8903 // behind them).
8904 // (2) Find the layout params of the top-most
8905 // application window in the tokens, which is
8906 // what will control the animation theme.
8907 final int NC = mClosingApps.size();
8908 NN = NC + mOpeningApps.size();
8909 for (i=0; i<NN; i++) {
8910 AppWindowToken wtoken;
8911 int mode;
8912 if (i < NC) {
8913 wtoken = mClosingApps.get(i);
8914 mode = 1;
8915 } else {
8916 wtoken = mOpeningApps.get(i-NC);
8917 mode = 2;
8918 }
8919 if (mLowerWallpaperTarget != null) {
8920 if (mLowerWallpaperTarget.mAppToken == wtoken
8921 || mUpperWallpaperTarget.mAppToken == wtoken) {
8922 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008923 }
8924 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008925 if (wtoken.appFullscreen) {
8926 WindowState ws = wtoken.findMainWindow();
8927 if (ws != null) {
8928 // If this is a compatibility mode
8929 // window, we will always use its anim.
8930 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8931 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008932 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008933 bestAnimLayer = Integer.MAX_VALUE;
8934 } else if (ws.mLayer > bestAnimLayer) {
8935 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008936 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008937 bestAnimLayer = ws.mLayer;
8938 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008939 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008940 }
8941 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008942
Dianne Hackborn25994b42009-09-04 14:21:19 -07008943 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008944 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008945 "Wallpaper animation!");
8946 switch (transit) {
8947 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8948 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8949 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8950 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8951 break;
8952 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8953 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8954 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8955 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8956 break;
8957 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008958 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008959 "New transit: " + transit);
8960 } else if (oldWallpaper != null) {
8961 // We are transitioning from an activity with
8962 // a wallpaper to one without.
8963 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008964 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008965 "New transit away from wallpaper: " + transit);
8966 } else if (mWallpaperTarget != null) {
8967 // We are transitioning from an activity without
8968 // a wallpaper to now showing the wallpaper
8969 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008970 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008971 "New transit into wallpaper: " + transit);
8972 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008973
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008974 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8975 mLastEnterAnimToken = animToken;
8976 mLastEnterAnimParams = animLp;
8977 } else if (mLastEnterAnimParams != null) {
8978 animLp = mLastEnterAnimParams;
8979 mLastEnterAnimToken = null;
8980 mLastEnterAnimParams = null;
8981 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008982
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008983 // If all closing windows are obscured, then there is
8984 // no need to do an animation. This is the case, for
8985 // example, when this transition is being done behind
8986 // the lock screen.
8987 if (!mPolicy.allowAppAnimationsLw()) {
8988 animLp = null;
8989 }
8990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008991 NN = mOpeningApps.size();
8992 for (i=0; i<NN; i++) {
8993 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 "Now opening app" + wtoken);
8996 wtoken.reportedVisible = false;
8997 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008998 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008999 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009000 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009001 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 wtoken.showAllWindowsLocked();
9003 }
9004 NN = mClosingApps.size();
9005 for (i=0; i<NN; i++) {
9006 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009007 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 "Now closing app" + wtoken);
9009 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009010 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009011 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009012 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009013 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009014 // Force the allDrawn flag, because we want to start
9015 // this guy's animations regardless of whether it's
9016 // gotten drawn.
9017 wtoken.allDrawn = true;
9018 }
9019
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009020 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009022 mOpeningApps.clear();
9023 mClosingApps.clear();
9024
9025 // This has changed the visibility of windows, so perform
9026 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009027 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009028 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009029 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9030 assignLayersLocked();
9031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009032 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009033 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009034 }
9035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009036
Dianne Hackborn16064f92010-03-25 00:47:24 -07009037 int adjResult = 0;
9038
Dianne Hackborna8f60182009-09-01 19:01:50 -07009039 if (!animating && mAppTransitionRunning) {
9040 // We have finished the animation of an app transition. To do
9041 // this, we have delayed a lot of operations like showing and
9042 // hiding apps, moving apps in Z-order, etc. The app token list
9043 // reflects the correct Z-order, but the window list may now
9044 // be out of sync with it. So here we will just rebuild the
9045 // entire app window list. Fun!
9046 mAppTransitionRunning = false;
9047 // Clear information about apps that were moving.
9048 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009049
Dianne Hackborna8f60182009-09-01 19:01:50 -07009050 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009051 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009052 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009053 moveInputMethodWindowsIfNeededLocked(false);
9054 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009055 // Since the window list has been rebuilt, focus might
9056 // have to be recomputed since the actual order of windows
9057 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009058 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009059 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009060
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009061 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009062 // At this point, there was a window with a wallpaper that
9063 // was force hiding other windows behind it, but now it
9064 // is going away. This may be simple -- just animate
9065 // away the wallpaper and its window -- or it may be
9066 // hard -- the wallpaper now needs to be shown behind
9067 // something that was hidden.
9068 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009069 if (mLowerWallpaperTarget != null
9070 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009071 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009072 "wallpaperForceHiding changed with lower="
9073 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009074 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009075 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9076 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9077 if (mLowerWallpaperTarget.mAppToken.hidden) {
9078 // The lower target has become hidden before we
9079 // actually started the animation... let's completely
9080 // re-evaluate everything.
9081 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009082 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009083 }
9084 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009085 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009086 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009087 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009088 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009089 + " NEW: " + mWallpaperTarget
9090 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009091 if (mLowerWallpaperTarget == null) {
9092 // Whoops, we don't need a special wallpaper animation.
9093 // Clear them out.
9094 forceHiding = false;
9095 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009096 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009097 if (w.mSurface != null) {
9098 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009099 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009100 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009101 forceHiding = true;
9102 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9103 if (!w.mAnimating) {
9104 // We set the animation above so it
9105 // is not yet running.
9106 w.clearAnimation();
9107 }
9108 }
9109 }
9110 }
9111 }
9112 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009113
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009114 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009115 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009116 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009117 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009118 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009119
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009120 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009121 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009122 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009123 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009124 assignLayersLocked();
9125 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009126 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009127 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009128 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009130
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009131 if (mFocusMayChange) {
9132 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009133 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009134 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009135 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009136 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009137 }
9138
9139 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009140 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009142
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009143 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9144 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009145
Jeff Browne33348b2010-07-15 23:54:05 -07009146 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009147 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009148
9149 // THIRD LOOP: Update the surfaces of all windows.
9150
9151 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9152
9153 boolean obscured = false;
9154 boolean blurring = false;
9155 boolean dimming = false;
9156 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009157 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009158 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009159
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009160 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009163 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009164
9165 boolean displayed = false;
9166 final WindowManager.LayoutParams attrs = w.mAttrs;
9167 final int attrFlags = attrs.flags;
9168
9169 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009170 // XXX NOTE: The logic here could be improved. We have
9171 // the decision about whether to resize a window separated
9172 // from whether to hide the surface. This can cause us to
9173 // resize a surface even if we are going to hide it. You
9174 // can see this by (1) holding device in landscape mode on
9175 // home screen; (2) tapping browser icon (device will rotate
9176 // to landscape; (3) tap home. The wallpaper will be resized
9177 // in step 2 but then immediately hidden, causing us to
9178 // have to resize and then redraw it again in step 3. It
9179 // would be nice to figure out how to avoid this, but it is
9180 // difficult because we do need to resize surfaces in some
9181 // cases while they are hidden such as when first showing a
9182 // window.
9183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009185 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 TAG, "Placing surface #" + i + " " + w.mSurface
9187 + ": new=" + w.mShownFrame + ", old="
9188 + w.mLastShownFrame);
9189
9190 boolean resize;
9191 int width, height;
9192 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9193 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9194 w.mLastRequestedHeight != w.mRequestedHeight;
9195 // for a scaled surface, we just want to use
9196 // the requested size.
9197 width = w.mRequestedWidth;
9198 height = w.mRequestedHeight;
9199 w.mLastRequestedWidth = width;
9200 w.mLastRequestedHeight = height;
9201 w.mLastShownFrame.set(w.mShownFrame);
9202 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009203 if (SHOW_TRANSACTIONS) logSurface(w,
9204 "POS " + w.mShownFrame.left
9205 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009206 w.mSurfaceX = w.mShownFrame.left;
9207 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009208 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9209 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009210 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 if (!recoveringMemory) {
9212 reclaimSomeSurfaceMemoryLocked(w, "position");
9213 }
9214 }
9215 } else {
9216 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9217 width = w.mShownFrame.width();
9218 height = w.mShownFrame.height();
9219 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009220 }
9221
9222 if (resize) {
9223 if (width < 1) width = 1;
9224 if (height < 1) height = 1;
9225 if (w.mSurface != null) {
9226 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009227 if (SHOW_TRANSACTIONS) logSurface(w,
9228 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009229 + w.mShownFrame.top + " SIZE "
9230 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009231 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009232 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009233 w.mSurfaceW = width;
9234 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009235 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009236 w.mSurfaceX = w.mShownFrame.left;
9237 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009238 w.mSurface.setPosition(w.mShownFrame.left,
9239 w.mShownFrame.top);
9240 } catch (RuntimeException e) {
9241 // If something goes wrong with the surface (such
9242 // as running out of memory), don't take down the
9243 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009244 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009245 + "size=(" + width + "x" + height
9246 + "), pos=(" + w.mShownFrame.left
9247 + "," + w.mShownFrame.top + ")", e);
9248 if (!recoveringMemory) {
9249 reclaimSomeSurfaceMemoryLocked(w, "size");
9250 }
9251 }
9252 }
9253 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009254 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009255 w.mContentInsetsChanged =
9256 !w.mLastContentInsets.equals(w.mContentInsets);
9257 w.mVisibleInsetsChanged =
9258 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009259 boolean configChanged =
9260 w.mConfiguration != mCurConfiguration
9261 && (w.mConfiguration == null
9262 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009263 if (DEBUG_CONFIGURATION && configChanged) {
9264 Slog.v(TAG, "Win " + w + " config changed: "
9265 + mCurConfiguration);
9266 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009267 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009268 + ": configChanged=" + configChanged
9269 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009270 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009271 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009272 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009273 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009274 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009275 w.mLastFrame.set(w.mFrame);
9276 w.mLastContentInsets.set(w.mContentInsets);
9277 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009278 // If the screen is currently frozen, then keep
9279 // it frozen until this window draws at its new
9280 // orientation.
9281 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009282 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009283 "Resizing while display frozen: " + w);
9284 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009285 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009286 mWindowsFreezingScreen = true;
9287 // XXX should probably keep timeout from
9288 // when we first froze the display.
9289 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9290 mH.sendMessageDelayed(mH.obtainMessage(
9291 H.WINDOW_FREEZE_TIMEOUT), 2000);
9292 }
9293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009294 // If the orientation is changing, then we need to
9295 // hold off on unfreezing the display until this
9296 // window has been redrawn; to do that, we need
9297 // to go through the process of getting informed
9298 // by the application when it has finished drawing.
9299 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009300 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009301 "Orientation start waiting for draw in "
9302 + w + ", surface " + w.mSurface);
9303 w.mDrawPending = true;
9304 w.mCommitDrawPending = false;
9305 w.mReadyToShow = false;
9306 if (w.mAppToken != null) {
9307 w.mAppToken.allDrawn = false;
9308 }
9309 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009310 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 "Resizing window " + w + " to " + w.mFrame);
9312 mResizingWindows.add(w);
9313 } else if (w.mOrientationChanging) {
9314 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009315 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009316 "Orientation not waiting for draw in "
9317 + w + ", surface " + w.mSurface);
9318 w.mOrientationChanging = false;
9319 }
9320 }
9321 }
9322
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009323 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009324 if (!w.mLastHidden) {
9325 //dump();
9326 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009327 if (SHOW_TRANSACTIONS) logSurface(w,
9328 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009330 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009331 try {
9332 w.mSurface.hide();
9333 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009334 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 }
9336 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009337 }
9338 // If we are waiting for this window to handle an
9339 // orientation change, well, it is hidden, so
9340 // doesn't really matter. Note that this does
9341 // introduce a potential glitch if the window
9342 // becomes unhidden before it has drawn for the
9343 // new orientation.
9344 if (w.mOrientationChanging) {
9345 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009346 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 "Orientation change skips hidden " + w);
9348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009349 } else if (w.mLastLayer != w.mAnimLayer
9350 || w.mLastAlpha != w.mShownAlpha
9351 || w.mLastDsDx != w.mDsDx
9352 || w.mLastDtDx != w.mDtDx
9353 || w.mLastDsDy != w.mDsDy
9354 || w.mLastDtDy != w.mDtDy
9355 || w.mLastHScale != w.mHScale
9356 || w.mLastVScale != w.mVScale
9357 || w.mLastHidden) {
9358 displayed = true;
9359 w.mLastAlpha = w.mShownAlpha;
9360 w.mLastLayer = w.mAnimLayer;
9361 w.mLastDsDx = w.mDsDx;
9362 w.mLastDtDx = w.mDtDx;
9363 w.mLastDsDy = w.mDsDy;
9364 w.mLastDtDy = w.mDtDy;
9365 w.mLastHScale = w.mHScale;
9366 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009367 if (SHOW_TRANSACTIONS) logSurface(w,
9368 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009369 + " matrix=[" + (w.mDsDx*w.mHScale)
9370 + "," + (w.mDtDx*w.mVScale)
9371 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009372 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009373 if (w.mSurface != null) {
9374 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009375 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009376 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009377 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009378 w.mSurface.setLayer(w.mAnimLayer);
9379 w.mSurface.setMatrix(
9380 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9381 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9382 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009383 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 if (!recoveringMemory) {
9385 reclaimSomeSurfaceMemoryLocked(w, "update");
9386 }
9387 }
9388 }
9389
9390 if (w.mLastHidden && !w.mDrawPending
9391 && !w.mCommitDrawPending
9392 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009393 if (SHOW_TRANSACTIONS) logSurface(w,
9394 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009395 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009396 + " during relayout");
9397 if (showSurfaceRobustlyLocked(w)) {
9398 w.mHasDrawn = true;
9399 w.mLastHidden = false;
9400 } else {
9401 w.mOrientationChanging = false;
9402 }
9403 }
9404 if (w.mSurface != null) {
9405 w.mToken.hasVisible = true;
9406 }
9407 } else {
9408 displayed = true;
9409 }
9410
9411 if (displayed) {
9412 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009413 if (attrs.width == LayoutParams.MATCH_PARENT
9414 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 covered = true;
9416 }
9417 }
9418 if (w.mOrientationChanging) {
9419 if (w.mDrawPending || w.mCommitDrawPending) {
9420 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009421 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 "Orientation continue waiting for draw in " + w);
9423 } else {
9424 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009425 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 "Orientation change complete in " + w);
9427 }
9428 }
9429 w.mToken.hasVisible = true;
9430 }
9431 } else if (w.mOrientationChanging) {
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 change skips hidden " + w);
9434 w.mOrientationChanging = false;
9435 }
9436
9437 final boolean canBeSeen = w.isDisplayedLw();
9438
9439 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9440 focusDisplayed = true;
9441 }
9442
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009443 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009446 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447 if (w.mSurface != null) {
9448 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9449 holdScreen = w.mSession;
9450 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009451 if (!syswin && w.mAttrs.screenBrightness >= 0
9452 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009453 screenBrightness = w.mAttrs.screenBrightness;
9454 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009455 if (!syswin && w.mAttrs.buttonBrightness >= 0
9456 && buttonBrightness < 0) {
9457 buttonBrightness = w.mAttrs.buttonBrightness;
9458 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009459 if (canBeSeen
9460 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9461 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9462 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009463 syswin = true;
9464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009465 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009466
Dianne Hackborn25994b42009-09-04 14:21:19 -07009467 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9468 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 // This window completely covers everything behind it,
9470 // so we want to leave all of them as unblurred (for
9471 // performance reasons).
9472 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009473 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009474 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009475 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009476 obscured = true;
9477 if (mBackgroundFillerSurface == null) {
9478 try {
9479 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009480 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009481 0, dw, dh,
9482 PixelFormat.OPAQUE,
9483 Surface.FX_SURFACE_NORMAL);
9484 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009485 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009486 }
9487 }
9488 try {
9489 mBackgroundFillerSurface.setPosition(0, 0);
9490 mBackgroundFillerSurface.setSize(dw, dh);
9491 // Using the same layer as Dim because they will never be shown at the
9492 // same time.
9493 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9494 mBackgroundFillerSurface.show();
9495 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009496 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009497 }
9498 backgroundFillerShown = true;
9499 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009500 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009501 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009502 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 + ": blurring=" + blurring
9504 + " obscured=" + obscured
9505 + " displayed=" + displayed);
9506 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9507 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009508 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009510 if (mDimAnimator == null) {
9511 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009512 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009513 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009514 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 }
9517 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9518 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009519 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009520 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009522 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 + mBlurSurface + ": CREATE");
9524 try {
Romain Guy06882f82009-06-10 13:36:04 -07009525 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009526 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 -1, 16, 16,
9528 PixelFormat.OPAQUE,
9529 Surface.FX_SURFACE_BLUR);
9530 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009531 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009532 }
9533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009535 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9536 + mBlurSurface + ": pos=(0,0) (" +
9537 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009538 mBlurSurface.setPosition(0, 0);
9539 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009540 mBlurSurface.setLayer(w.mAnimLayer-2);
9541 if (!mBlurShown) {
9542 try {
9543 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9544 + mBlurSurface + ": SHOW");
9545 mBlurSurface.show();
9546 } catch (RuntimeException e) {
9547 Slog.w(TAG, "Failure showing blur surface", e);
9548 }
9549 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009550 }
9551 }
9552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009553 }
9554 }
9555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009556
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009557 if (obscuredChanged && mWallpaperTarget == w) {
9558 // This is the wallpaper target and its obscured state
9559 // changed... make sure the current wallaper's visibility
9560 // has been updated accordingly.
9561 updateWallpaperVisibilityLocked();
9562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009563 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009564
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009565 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9566 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009567 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009568 try {
9569 mBackgroundFillerSurface.hide();
9570 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009571 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009572 }
9573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009574
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009575 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009576 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9577 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009578 }
Romain Guy06882f82009-06-10 13:36:04 -07009579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009581 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009582 + ": HIDE");
9583 try {
9584 mBlurSurface.hide();
9585 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009586 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009587 }
9588 mBlurShown = false;
9589 }
9590
Joe Onorato8a9b2202010-02-26 18:56:32 -08009591 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009592 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009593 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594 }
9595
Jeff Browne33348b2010-07-15 23:54:05 -07009596 mInputMonitor.updateInputWindowsLw();
9597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009598 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009599
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07009600 if (mWatermark != null) {
9601 mWatermark.drawIfNeeded();
9602 }
9603
Joe Onorato8a9b2202010-02-26 18:56:32 -08009604 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 "With display frozen, orientationChangeComplete="
9606 + orientationChangeComplete);
9607 if (orientationChangeComplete) {
9608 if (mWindowsFreezingScreen) {
9609 mWindowsFreezingScreen = false;
9610 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9611 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009612 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 }
Romain Guy06882f82009-06-10 13:36:04 -07009614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009615 i = mResizingWindows.size();
9616 if (i > 0) {
9617 do {
9618 i--;
9619 WindowState win = mResizingWindows.get(i);
9620 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009621 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9622 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009623 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009624 boolean configChanged =
9625 win.mConfiguration != mCurConfiguration
9626 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009627 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9628 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9629 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009630 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009631 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009632 + " / " + mCurConfiguration + " / 0x"
9633 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009634 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009635 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009636 win.mClient.resized(win.mFrame.width(),
9637 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009638 win.mLastVisibleInsets, win.mDrawPending,
9639 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009640 win.mContentInsetsChanged = false;
9641 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009642 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009643 } catch (RemoteException e) {
9644 win.mOrientationChanging = false;
9645 }
9646 } while (i > 0);
9647 mResizingWindows.clear();
9648 }
Romain Guy06882f82009-06-10 13:36:04 -07009649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009651 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009652 i = mDestroySurface.size();
9653 if (i > 0) {
9654 do {
9655 i--;
9656 WindowState win = mDestroySurface.get(i);
9657 win.mDestroying = false;
9658 if (mInputMethodWindow == win) {
9659 mInputMethodWindow = null;
9660 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009661 if (win == mWallpaperTarget) {
9662 wallpaperDestroyed = true;
9663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009664 win.destroySurfaceLocked();
9665 } while (i > 0);
9666 mDestroySurface.clear();
9667 }
9668
9669 // Time to remove any exiting tokens?
9670 for (i=mExitingTokens.size()-1; i>=0; i--) {
9671 WindowToken token = mExitingTokens.get(i);
9672 if (!token.hasVisible) {
9673 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009674 if (token.windowType == TYPE_WALLPAPER) {
9675 mWallpaperTokens.remove(token);
9676 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009677 }
9678 }
9679
9680 // Time to remove any exiting applications?
9681 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9682 AppWindowToken token = mExitingAppTokens.get(i);
9683 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009684 // Make sure there is no animation running on this token,
9685 // so any windows associated with it will be removed as
9686 // soon as their animations are complete
9687 token.animation = null;
9688 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009689 mAppTokens.remove(token);
9690 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009691 if (mLastEnterAnimToken == token) {
9692 mLastEnterAnimToken = null;
9693 mLastEnterAnimParams = null;
9694 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009695 }
9696 }
9697
Dianne Hackborna8f60182009-09-01 19:01:50 -07009698 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009699
Dianne Hackborna8f60182009-09-01 19:01:50 -07009700 if (!animating && mAppTransitionRunning) {
9701 // We have finished the animation of an app transition. To do
9702 // this, we have delayed a lot of operations like showing and
9703 // hiding apps, moving apps in Z-order, etc. The app token list
9704 // reflects the correct Z-order, but the window list may now
9705 // be out of sync with it. So here we will just rebuild the
9706 // entire app window list. Fun!
9707 mAppTransitionRunning = false;
9708 needRelayout = true;
9709 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009710 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009711 // Clear information about apps that were moving.
9712 mToBottomApps.clear();
9713 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715 if (focusDisplayed) {
9716 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9717 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009718 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009719 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009720 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009721 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009722 requestAnimationLocked(0);
9723 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009724 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9725 }
Jeff Browneb857f12010-07-16 10:06:33 -07009726
Jeff Browne33348b2010-07-15 23:54:05 -07009727 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009728
Jeff Brown8e03b752010-06-13 19:16:55 -07009729 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009730 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9731 mPowerManager.setScreenBrightnessOverride(-1);
9732 } else {
9733 mPowerManager.setScreenBrightnessOverride((int)
9734 (screenBrightness * Power.BRIGHTNESS_ON));
9735 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009736 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9737 mPowerManager.setButtonBrightnessOverride(-1);
9738 } else {
9739 mPowerManager.setButtonBrightnessOverride((int)
9740 (buttonBrightness * Power.BRIGHTNESS_ON));
9741 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742 if (holdScreen != mHoldingScreenOn) {
9743 mHoldingScreenOn = holdScreen;
9744 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9745 mH.sendMessage(m);
9746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009747
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009748 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009749 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009750 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9751 LocalPowerManager.BUTTON_EVENT, true);
9752 mTurnOnScreen = false;
9753 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009754
9755 // Check to see if we are now in a state where the screen should
9756 // be enabled, because the window obscured flags have changed.
9757 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009759
9760 /**
9761 * Must be called with the main window manager lock held.
9762 */
9763 void setHoldScreenLocked(boolean holding) {
9764 boolean state = mHoldingScreenWakeLock.isHeld();
9765 if (holding != state) {
9766 if (holding) {
9767 mHoldingScreenWakeLock.acquire();
9768 } else {
9769 mPolicy.screenOnStoppedLw();
9770 mHoldingScreenWakeLock.release();
9771 }
9772 }
9773 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009774
9775 void requestAnimationLocked(long delay) {
9776 if (!mAnimationPending) {
9777 mAnimationPending = true;
9778 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9779 }
9780 }
Romain Guy06882f82009-06-10 13:36:04 -07009781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 /**
9783 * Have the surface flinger show a surface, robustly dealing with
9784 * error conditions. In particular, if there is not enough memory
9785 * to show the surface, then we will try to get rid of other surfaces
9786 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009787 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 * @return Returns true if the surface was successfully shown.
9789 */
9790 boolean showSurfaceRobustlyLocked(WindowState win) {
9791 try {
9792 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009793 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009795 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009796 if (DEBUG_VISIBILITY) Slog.v(TAG,
9797 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009798 win.mTurnOnScreen = false;
9799 mTurnOnScreen = true;
9800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 }
9802 return true;
9803 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009804 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 }
Romain Guy06882f82009-06-10 13:36:04 -07009806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009809 return false;
9810 }
Romain Guy06882f82009-06-10 13:36:04 -07009811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9813 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009814
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009815 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 if (mForceRemoves == null) {
9819 mForceRemoves = new ArrayList<WindowState>();
9820 }
Romain Guy06882f82009-06-10 13:36:04 -07009821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009822 long callingIdentity = Binder.clearCallingIdentity();
9823 try {
9824 // There was some problem... first, do a sanity check of the
9825 // window list to make sure we haven't left any dangling surfaces
9826 // around.
9827 int N = mWindows.size();
9828 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009829 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009830 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009831 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009832 if (ws.mSurface != null) {
9833 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009834 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009835 + ws + " surface=" + ws.mSurface
9836 + " token=" + win.mToken
9837 + " pid=" + ws.mSession.mPid
9838 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009839 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009840 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009841 ws.mSurface = null;
9842 mForceRemoves.add(ws);
9843 i--;
9844 N--;
9845 leakedSurface = true;
9846 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009847 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 + ws + " surface=" + ws.mSurface
9849 + " token=" + win.mAppToken);
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 leakedSurface = true;
9854 }
9855 }
9856 }
Romain Guy06882f82009-06-10 13:36:04 -07009857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009858 boolean killedApps = false;
9859 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009860 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861 SparseIntArray pidCandidates = new SparseIntArray();
9862 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009863 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864 if (ws.mSurface != null) {
9865 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9866 }
9867 }
9868 if (pidCandidates.size() > 0) {
9869 int[] pids = new int[pidCandidates.size()];
9870 for (int i=0; i<pids.length; i++) {
9871 pids[i] = pidCandidates.keyAt(i);
9872 }
9873 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009874 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009875 killedApps = true;
9876 }
9877 } catch (RemoteException e) {
9878 }
9879 }
9880 }
Romain Guy06882f82009-06-10 13:36:04 -07009881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 if (leakedSurface || killedApps) {
9883 // We managed to reclaim some memory, so get rid of the trouble
9884 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009885 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009886 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009887 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009888 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889 win.mSurface = null;
9890 }
Romain Guy06882f82009-06-10 13:36:04 -07009891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 try {
9893 win.mClient.dispatchGetNewSurface();
9894 } catch (RemoteException e) {
9895 }
9896 }
9897 } finally {
9898 Binder.restoreCallingIdentity(callingIdentity);
9899 }
9900 }
Romain Guy06882f82009-06-10 13:36:04 -07009901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 private boolean updateFocusedWindowLocked(int mode) {
9903 WindowState newFocus = computeFocusedWindowLocked();
9904 if (mCurrentFocus != newFocus) {
9905 // This check makes sure that we don't already have the focus
9906 // change message pending.
9907 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9908 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009909 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009910 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9911 final WindowState oldFocus = mCurrentFocus;
9912 mCurrentFocus = newFocus;
9913 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 final WindowState imWindow = mInputMethodWindow;
9916 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009917 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009918 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009919 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9920 mLayoutNeeded = true;
9921 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9923 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009924 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9925 // Client will do the layout, but we need to assign layers
9926 // for handleNewWindowLocked() below.
9927 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009928 }
9929 }
Jeff Brown349703e2010-06-22 01:27:15 -07009930
9931 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9932 // If we defer assigning layers, then the caller is responsible for
9933 // doing this part.
9934 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 return true;
9937 }
9938 return false;
9939 }
Jeff Brown349703e2010-06-22 01:27:15 -07009940
9941 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009942 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944
9945 private WindowState computeFocusedWindowLocked() {
9946 WindowState result = null;
9947 WindowState win;
9948
9949 int i = mWindows.size() - 1;
9950 int nextAppIndex = mAppTokens.size()-1;
9951 WindowToken nextApp = nextAppIndex >= 0
9952 ? mAppTokens.get(nextAppIndex) : null;
9953
9954 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009955 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009956
Joe Onorato8a9b2202010-02-26 18:56:32 -08009957 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009958 TAG, "Looking for focus: " + i
9959 + " = " + win
9960 + ", flags=" + win.mAttrs.flags
9961 + ", canReceive=" + win.canReceiveKeys());
9962
9963 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 // If this window's application has been removed, just skip it.
9966 if (thisApp != null && thisApp.removed) {
9967 i--;
9968 continue;
9969 }
Romain Guy06882f82009-06-10 13:36:04 -07009970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009971 // If there is a focused app, don't allow focus to go to any
9972 // windows below it. If this is an application window, step
9973 // through the app tokens until we find its app.
9974 if (thisApp != null && nextApp != null && thisApp != nextApp
9975 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9976 int origAppIndex = nextAppIndex;
9977 while (nextAppIndex > 0) {
9978 if (nextApp == mFocusedApp) {
9979 // Whoops, we are below the focused app... no focus
9980 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009981 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009982 TAG, "Reached focused app: " + mFocusedApp);
9983 return null;
9984 }
9985 nextAppIndex--;
9986 nextApp = mAppTokens.get(nextAppIndex);
9987 if (nextApp == thisApp) {
9988 break;
9989 }
9990 }
9991 if (thisApp != nextApp) {
9992 // Uh oh, the app token doesn't exist! This shouldn't
9993 // happen, but if it does we can get totally hosed...
9994 // so restart at the original app.
9995 nextAppIndex = origAppIndex;
9996 nextApp = mAppTokens.get(nextAppIndex);
9997 }
9998 }
9999
10000 // Dispatch to this window if it is wants key events.
10001 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010002 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 TAG, "Found focus @ " + i + " = " + win);
10004 result = win;
10005 break;
10006 }
10007
10008 i--;
10009 }
10010
10011 return result;
10012 }
10013
10014 private void startFreezingDisplayLocked() {
10015 if (mDisplayFrozen) {
10016 return;
10017 }
Romain Guy06882f82009-06-10 13:36:04 -070010018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010019 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010022 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010023 if (mFreezeGcPending != 0) {
10024 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010025 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010026 mH.removeMessages(H.FORCE_GC);
10027 Runtime.getRuntime().gc();
10028 mFreezeGcPending = now;
10029 }
10030 } else {
10031 mFreezeGcPending = now;
10032 }
Romain Guy06882f82009-06-10 13:36:04 -070010033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010034 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010035
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010036 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010037
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010038 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10039 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010040 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010041 mAppTransitionReady = true;
10042 }
Romain Guy06882f82009-06-10 13:36:04 -070010043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010044 if (PROFILE_ORIENTATION) {
10045 File file = new File("/data/system/frozen");
10046 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10047 }
10048 Surface.freezeDisplay(0);
10049 }
Romain Guy06882f82009-06-10 13:36:04 -070010050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010051 private void stopFreezingDisplayLocked() {
10052 if (!mDisplayFrozen) {
10053 return;
10054 }
Romain Guy06882f82009-06-10 13:36:04 -070010055
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010056 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10057 return;
10058 }
10059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010060 mDisplayFrozen = false;
10061 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10062 if (PROFILE_ORIENTATION) {
10063 Debug.stopMethodTracing();
10064 }
10065 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010066
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010067 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068
Christopher Tateb696aee2010-04-02 19:08:30 -070010069 // While the display is frozen we don't re-compute the orientation
10070 // to avoid inconsistent states. However, something interesting
10071 // could have actually changed during that time so re-evaluate it
10072 // now to catch that.
10073 if (updateOrientationFromAppTokensLocked()) {
10074 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10075 }
10076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 // A little kludge: a lot could have happened while the
10078 // display was frozen, so now that we are coming back we
10079 // do a gc so that any remote references the system
10080 // processes holds on others can be released if they are
10081 // no longer needed.
10082 mH.removeMessages(H.FORCE_GC);
10083 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10084 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010086 mScreenFrozenLock.release();
10087 }
Romain Guy06882f82009-06-10 13:36:04 -070010088
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010089 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10090 DisplayMetrics dm) {
10091 if (index < tokens.length) {
10092 String str = tokens[index];
10093 if (str != null && str.length() > 0) {
10094 try {
10095 int val = Integer.parseInt(str);
10096 return val;
10097 } catch (Exception e) {
10098 }
10099 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010100 }
10101 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10102 return defDps;
10103 }
10104 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10105 return val;
10106 }
10107
10108 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010109 final String[] mTokens;
10110 final String mText;
10111 final Paint mTextPaint;
10112 final int mTextWidth;
10113 final int mTextHeight;
10114 final int mTextAscent;
10115 final int mTextDescent;
10116 final int mDeltaX;
10117 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010118
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010119 Surface mSurface;
10120 int mLastDW;
10121 int mLastDH;
10122 boolean mDrawNeeded;
10123
10124 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010125 final DisplayMetrics dm = new DisplayMetrics();
10126 mDisplay.getMetrics(dm);
10127
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010128 if (false) {
10129 Log.i(TAG, "*********************** WATERMARK");
10130 for (int i=0; i<tokens.length; i++) {
10131 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10132 }
10133 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010134
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010135 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010136
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010137 StringBuilder builder = new StringBuilder(32);
10138 int len = mTokens[0].length();
10139 len = len & ~1;
10140 for (int i=0; i<len; i+=2) {
10141 int c1 = mTokens[0].charAt(i);
10142 int c2 = mTokens[0].charAt(i+1);
10143 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10144 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10145 else c1 -= '0';
10146 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10147 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10148 else c2 -= '0';
10149 builder.append((char)(255-((c1*16)+c2)));
10150 }
10151 mText = builder.toString();
10152 if (false) {
10153 Log.i(TAG, "Final text: " + mText);
10154 }
10155
10156 int fontSize = getPropertyInt(tokens, 1,
10157 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10158
10159 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10160 mTextPaint.setTextSize(fontSize);
10161 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10162
10163 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10164 mTextWidth = (int)mTextPaint.measureText(mText);
10165 mTextAscent = fm.ascent;
10166 mTextDescent = fm.descent;
10167 mTextHeight = fm.descent - fm.ascent;
10168
10169 mDeltaX = getPropertyInt(tokens, 2,
10170 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10171 mDeltaY = getPropertyInt(tokens, 3,
10172 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10173 int shadowColor = getPropertyInt(tokens, 4,
10174 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10175 int color = getPropertyInt(tokens, 5,
10176 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10177 int shadowRadius = getPropertyInt(tokens, 6,
10178 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10179 int shadowDx = getPropertyInt(tokens, 8,
10180 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10181 int shadowDy = getPropertyInt(tokens, 9,
10182 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10183
10184 mTextPaint.setColor(color);
10185 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010186
10187 try {
10188 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010189 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010190 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010191 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010192 mSurface.show();
10193 } catch (OutOfResourcesException e) {
10194 }
10195 }
10196
10197 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010198 if (mLastDW != dw || mLastDH != dh) {
10199 mLastDW = dw;
10200 mLastDH = dh;
10201 mSurface.setSize(dw, dh);
10202 mDrawNeeded = true;
10203 }
10204 }
10205
10206 void drawIfNeeded() {
10207 if (mDrawNeeded) {
10208 final int dw = mLastDW;
10209 final int dh = mLastDH;
10210
10211 mDrawNeeded = false;
10212 Rect dirty = new Rect(0, 0, dw, dh);
10213 Canvas c = null;
10214 try {
10215 c = mSurface.lockCanvas(dirty);
10216 } catch (IllegalArgumentException e) {
10217 } catch (OutOfResourcesException e) {
10218 }
10219 if (c != null) {
10220 int deltaX = mDeltaX;
10221 int deltaY = mDeltaY;
10222
10223 // deltaX shouldn't be close to a round fraction of our
10224 // x step, or else things will line up too much.
10225 int div = (dw+mTextWidth)/deltaX;
10226 int rem = (dw+mTextWidth) - (div*deltaX);
10227 int qdelta = deltaX/4;
10228 if (rem < qdelta || rem > (deltaX-qdelta)) {
10229 deltaX += deltaX/3;
10230 }
10231
10232 int y = -mTextHeight;
10233 int x = -mTextWidth;
10234 while (y < (dh+mTextHeight)) {
10235 c.drawText(mText, x, y, mTextPaint);
10236 x += deltaX;
10237 if (x >= dw) {
10238 x -= (dw+mTextWidth);
10239 y += deltaY;
10240 }
10241 }
10242 mSurface.unlockCanvasAndPost(c);
10243 }
10244 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010245 }
10246 }
10247
10248 void createWatermark() {
10249 if (mWatermark != null) {
10250 return;
10251 }
10252
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010253 File file = new File("/system/etc/setup.conf");
10254 FileInputStream in = null;
10255 try {
10256 in = new FileInputStream(file);
10257 DataInputStream ind = new DataInputStream(in);
10258 String line = ind.readLine();
10259 if (line != null) {
10260 String[] toks = line.split("%");
10261 if (toks != null && toks.length > 0) {
10262 mWatermark = new Watermark(mFxSession, toks);
10263 }
10264 }
10265 } catch (FileNotFoundException e) {
10266 } catch (IOException e) {
10267 } finally {
10268 if (in != null) {
10269 try {
10270 in.close();
10271 } catch (IOException e) {
10272 }
10273 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010274 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010275 }
10276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 @Override
10278 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10279 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10280 != PackageManager.PERMISSION_GRANTED) {
10281 pw.println("Permission Denial: can't dump WindowManager from from pid="
10282 + Binder.getCallingPid()
10283 + ", uid=" + Binder.getCallingUid());
10284 return;
10285 }
Romain Guy06882f82009-06-10 13:36:04 -070010286
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010287 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010288 pw.println(" ");
10289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 synchronized(mWindowMap) {
10291 pw.println("Current Window Manager state:");
10292 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010293 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010294 pw.print(" Window #"); pw.print(i); pw.print(' ');
10295 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010296 w.dump(pw, " ");
10297 }
10298 if (mInputMethodDialogs.size() > 0) {
10299 pw.println(" ");
10300 pw.println(" Input method dialogs:");
10301 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10302 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010303 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 }
10305 }
10306 if (mPendingRemove.size() > 0) {
10307 pw.println(" ");
10308 pw.println(" Remove pending for:");
10309 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10310 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010311 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10312 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 w.dump(pw, " ");
10314 }
10315 }
10316 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10317 pw.println(" ");
10318 pw.println(" Windows force removing:");
10319 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10320 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010321 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10322 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010323 w.dump(pw, " ");
10324 }
10325 }
10326 if (mDestroySurface.size() > 0) {
10327 pw.println(" ");
10328 pw.println(" Windows waiting to destroy their surface:");
10329 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10330 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010331 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10332 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010333 w.dump(pw, " ");
10334 }
10335 }
10336 if (mLosingFocus.size() > 0) {
10337 pw.println(" ");
10338 pw.println(" Windows losing focus:");
10339 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10340 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010341 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10342 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010343 w.dump(pw, " ");
10344 }
10345 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010346 if (mResizingWindows.size() > 0) {
10347 pw.println(" ");
10348 pw.println(" Windows waiting to resize:");
10349 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10350 WindowState w = mResizingWindows.get(i);
10351 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10352 pw.print(w); pw.println(":");
10353 w.dump(pw, " ");
10354 }
10355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010356 if (mSessions.size() > 0) {
10357 pw.println(" ");
10358 pw.println(" All active sessions:");
10359 Iterator<Session> it = mSessions.iterator();
10360 while (it.hasNext()) {
10361 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010362 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 s.dump(pw, " ");
10364 }
10365 }
10366 if (mTokenMap.size() > 0) {
10367 pw.println(" ");
10368 pw.println(" All tokens:");
10369 Iterator<WindowToken> it = mTokenMap.values().iterator();
10370 while (it.hasNext()) {
10371 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010372 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 token.dump(pw, " ");
10374 }
10375 }
10376 if (mTokenList.size() > 0) {
10377 pw.println(" ");
10378 pw.println(" Window token list:");
10379 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010380 pw.print(" #"); pw.print(i); pw.print(": ");
10381 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010382 }
10383 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010384 if (mWallpaperTokens.size() > 0) {
10385 pw.println(" ");
10386 pw.println(" Wallpaper tokens:");
10387 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10388 WindowToken token = mWallpaperTokens.get(i);
10389 pw.print(" Wallpaper #"); pw.print(i);
10390 pw.print(' '); pw.print(token); pw.println(':');
10391 token.dump(pw, " ");
10392 }
10393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 if (mAppTokens.size() > 0) {
10395 pw.println(" ");
10396 pw.println(" Application tokens in Z order:");
10397 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010398 pw.print(" App #"); pw.print(i); pw.print(": ");
10399 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010400 }
10401 }
10402 if (mFinishedStarting.size() > 0) {
10403 pw.println(" ");
10404 pw.println(" Finishing start of application tokens:");
10405 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10406 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010407 pw.print(" Finished Starting #"); pw.print(i);
10408 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010409 token.dump(pw, " ");
10410 }
10411 }
10412 if (mExitingTokens.size() > 0) {
10413 pw.println(" ");
10414 pw.println(" Exiting tokens:");
10415 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10416 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010417 pw.print(" Exiting #"); pw.print(i);
10418 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419 token.dump(pw, " ");
10420 }
10421 }
10422 if (mExitingAppTokens.size() > 0) {
10423 pw.println(" ");
10424 pw.println(" Exiting application tokens:");
10425 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10426 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010427 pw.print(" Exiting App #"); pw.print(i);
10428 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 token.dump(pw, " ");
10430 }
10431 }
10432 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010433 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10434 pw.print(" mLastFocus="); pw.println(mLastFocus);
10435 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10436 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10437 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010438 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010439 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10440 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10441 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10442 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010443 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10444 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10445 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010446 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10447 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10448 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10449 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010450 if (mDimAnimator != null) {
10451 mDimAnimator.printTo(pw);
10452 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010453 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010454 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010455 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010456 pw.print(mInputMethodAnimLayerAdjustment);
10457 pw.print(" mWallpaperAnimLayerAdjustment=");
10458 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010459 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10460 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010461 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10462 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010463 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10464 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010465 pw.print(" mRotation="); pw.print(mRotation);
10466 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10467 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10468 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10469 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10470 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10471 pw.print(" mNextAppTransition=0x");
10472 pw.print(Integer.toHexString(mNextAppTransition));
10473 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010474 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010475 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010476 if (mNextAppTransitionPackage != null) {
10477 pw.print(" mNextAppTransitionPackage=");
10478 pw.print(mNextAppTransitionPackage);
10479 pw.print(", mNextAppTransitionEnter=0x");
10480 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10481 pw.print(", mNextAppTransitionExit=0x");
10482 pw.print(Integer.toHexString(mNextAppTransitionExit));
10483 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010484 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10485 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010486 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10487 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10488 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10489 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010490 if (mOpeningApps.size() > 0) {
10491 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10492 }
10493 if (mClosingApps.size() > 0) {
10494 pw.print(" mClosingApps="); pw.println(mClosingApps);
10495 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010496 if (mToTopApps.size() > 0) {
10497 pw.print(" mToTopApps="); pw.println(mToTopApps);
10498 }
10499 if (mToBottomApps.size() > 0) {
10500 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10501 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010502 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10503 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 }
10505 }
10506
Jeff Brown349703e2010-06-22 01:27:15 -070010507 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 public void monitor() {
10509 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010510 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010511 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010512
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010513 /**
10514 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010515 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010516 */
10517 private static class DimAnimator {
10518 Surface mDimSurface;
10519 boolean mDimShown = false;
10520 float mDimCurrentAlpha;
10521 float mDimTargetAlpha;
10522 float mDimDeltaPerMs;
10523 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010524
10525 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010526
10527 DimAnimator (SurfaceSession session) {
10528 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010529 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010530 + mDimSurface + ": CREATE");
10531 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010532 mDimSurface = new Surface(session, 0,
10533 "DimSurface",
10534 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010535 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010536 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010537 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010538 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010539 }
10540 }
10541 }
10542
10543 /**
10544 * Show the dim surface.
10545 */
10546 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010547 if (!mDimShown) {
10548 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10549 dw + "x" + dh + ")");
10550 mDimShown = true;
10551 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010552 mLastDimWidth = dw;
10553 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010554 mDimSurface.setPosition(0, 0);
10555 mDimSurface.setSize(dw, dh);
10556 mDimSurface.show();
10557 } catch (RuntimeException e) {
10558 Slog.w(TAG, "Failure showing dim surface", e);
10559 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010560 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10561 mLastDimWidth = dw;
10562 mLastDimHeight = dh;
10563 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010564 }
10565 }
10566
10567 /**
10568 * Set's the dim surface's layer and update dim parameters that will be used in
10569 * {@link updateSurface} after all windows are examined.
10570 */
10571 void updateParameters(WindowState w, long currentTime) {
10572 mDimSurface.setLayer(w.mAnimLayer-1);
10573
10574 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010575 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010576 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010577 if (mDimTargetAlpha != target) {
10578 // If the desired dim level has changed, then
10579 // start an animation to it.
10580 mLastDimAnimTime = currentTime;
10581 long duration = (w.mAnimating && w.mAnimation != null)
10582 ? w.mAnimation.computeDurationHint()
10583 : DEFAULT_DIM_DURATION;
10584 if (target > mDimTargetAlpha) {
10585 // This is happening behind the activity UI,
10586 // so we can make it run a little longer to
10587 // give a stronger impression without disrupting
10588 // the user.
10589 duration *= DIM_DURATION_MULTIPLIER;
10590 }
10591 if (duration < 1) {
10592 // Don't divide by zero
10593 duration = 1;
10594 }
10595 mDimTargetAlpha = target;
10596 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10597 }
10598 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010599
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010600 /**
10601 * Updating the surface's alpha. Returns true if the animation continues, or returns
10602 * false when the animation is finished and the dim surface is hidden.
10603 */
10604 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10605 if (!dimming) {
10606 if (mDimTargetAlpha != 0) {
10607 mLastDimAnimTime = currentTime;
10608 mDimTargetAlpha = 0;
10609 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10610 }
10611 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010612
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010613 boolean animating = false;
10614 if (mLastDimAnimTime != 0) {
10615 mDimCurrentAlpha += mDimDeltaPerMs
10616 * (currentTime-mLastDimAnimTime);
10617 boolean more = true;
10618 if (displayFrozen) {
10619 // If the display is frozen, there is no reason to animate.
10620 more = false;
10621 } else if (mDimDeltaPerMs > 0) {
10622 if (mDimCurrentAlpha > mDimTargetAlpha) {
10623 more = false;
10624 }
10625 } else if (mDimDeltaPerMs < 0) {
10626 if (mDimCurrentAlpha < mDimTargetAlpha) {
10627 more = false;
10628 }
10629 } else {
10630 more = false;
10631 }
10632
10633 // Do we need to continue animating?
10634 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010635 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010636 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10637 mLastDimAnimTime = currentTime;
10638 mDimSurface.setAlpha(mDimCurrentAlpha);
10639 animating = true;
10640 } else {
10641 mDimCurrentAlpha = mDimTargetAlpha;
10642 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010643 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010644 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10645 mDimSurface.setAlpha(mDimCurrentAlpha);
10646 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010647 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010648 + ": HIDE");
10649 try {
10650 mDimSurface.hide();
10651 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010652 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010653 }
10654 mDimShown = false;
10655 }
10656 }
10657 }
10658 return animating;
10659 }
10660
10661 public void printTo(PrintWriter pw) {
10662 pw.print(" mDimShown="); pw.print(mDimShown);
10663 pw.print(" current="); pw.print(mDimCurrentAlpha);
10664 pw.print(" target="); pw.print(mDimTargetAlpha);
10665 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10666 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10667 }
10668 }
10669
10670 /**
10671 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10672 * This is used for opening/closing transition for apps in compatible mode.
10673 */
10674 private static class FadeInOutAnimation extends Animation {
10675 int mWidth;
10676 boolean mFadeIn;
10677
10678 public FadeInOutAnimation(boolean fadeIn) {
10679 setInterpolator(new AccelerateInterpolator());
10680 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10681 mFadeIn = fadeIn;
10682 }
10683
10684 @Override
10685 protected void applyTransformation(float interpolatedTime, Transformation t) {
10686 float x = interpolatedTime;
10687 if (!mFadeIn) {
10688 x = 1.0f - x; // reverse the interpolation for fade out
10689 }
10690 if (x < 0.5) {
10691 // move the window out of the screen.
10692 t.getMatrix().setTranslate(mWidth, 0);
10693 } else {
10694 t.getMatrix().setTranslate(0, 0);// show
10695 t.setAlpha((x - 0.5f) * 2);
10696 }
10697 }
10698
10699 @Override
10700 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10701 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10702 mWidth = width;
10703 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010704
10705 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010706 public int getZAdjustment() {
10707 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010708 }
10709 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710}