blob: 667b5449439bdbbffe61f6a3d909cf2b7b319ae9 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
27import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
28import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070029import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
31import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
33import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
34import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070037import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
39import com.android.internal.app.IBatteryStats;
40import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080041import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import com.android.internal.view.IInputContext;
43import com.android.internal.view.IInputMethodClient;
44import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080045import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import com.android.server.am.BatteryStatsService;
47
48import android.Manifest;
49import android.app.ActivityManagerNative;
50import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.Intent;
55import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.content.pm.ActivityInfo;
57import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070058import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070060import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070062import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.graphics.PixelFormat;
64import android.graphics.Rect;
65import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Typeface;
67import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.os.BatteryStats;
69import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070070import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.Debug;
72import android.os.Handler;
73import android.os.IBinder;
74import android.os.LocalPowerManager;
75import android.os.Looper;
76import android.os.Message;
77import android.os.Parcel;
78import android.os.ParcelFileDescriptor;
79import android.os.Power;
80import android.os.PowerManager;
81import android.os.Process;
82import android.os.RemoteException;
83import android.os.ServiceManager;
84import android.os.SystemClock;
85import android.os.SystemProperties;
86import android.os.TokenWatcher;
87import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070088import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070090import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080091import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070093import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.view.Display;
95import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070096import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.view.IApplicationToken;
98import android.view.IOnKeyguardExitResult;
99import android.view.IRotationWatcher;
100import android.view.IWindow;
101import android.view.IWindowManager;
102import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700103import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700104import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -0700105import android.view.InputEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106import android.view.KeyEvent;
107import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.Surface;
109import android.view.SurfaceSession;
110import android.view.View;
111import android.view.ViewTreeObserver;
112import android.view.WindowManager;
113import android.view.WindowManagerImpl;
114import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700115import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700117import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118import android.view.animation.Animation;
119import android.view.animation.AnimationUtils;
120import android.view.animation.Transformation;
121
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700122import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700124import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import java.io.File;
126import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700127import java.io.FileInputStream;
128import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129import java.io.IOException;
130import java.io.OutputStream;
131import java.io.OutputStreamWriter;
132import java.io.PrintWriter;
133import java.io.StringWriter;
134import java.net.Socket;
135import java.util.ArrayList;
136import java.util.HashMap;
137import java.util.HashSet;
138import java.util.Iterator;
139import java.util.List;
140
141/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700142public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700143 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 static final String TAG = "WindowManager";
145 static final boolean DEBUG = false;
146 static final boolean DEBUG_FOCUS = false;
147 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800148 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800149 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final boolean DEBUG_LAYERS = false;
151 static final boolean DEBUG_INPUT = false;
152 static final boolean DEBUG_INPUT_METHOD = false;
153 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700154 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700156 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_APP_TRANSITIONS = false;
158 static final boolean DEBUG_STARTING_WINDOW = false;
159 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700160 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700161 static final boolean DEBUG_FREEZE = 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 }
Jozef BABJAK06e57b52011-01-20 08:09:25 +0100525 return thr.mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 }
Romain Guy06882f82009-06-10 13:36:04 -0700528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 static class WMThread extends Thread {
530 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 private final Context mContext;
533 private final PowerManagerService mPM;
534 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 public WMThread(Context context, PowerManagerService pm,
537 boolean haveInputMethods) {
538 super("WindowManager");
539 mContext = context;
540 mPM = pm;
541 mHaveInputMethods = haveInputMethods;
542 }
Romain Guy06882f82009-06-10 13:36:04 -0700543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 public void run() {
545 Looper.prepare();
546 WindowManagerService s = new WindowManagerService(mContext, mPM,
547 mHaveInputMethods);
548 android.os.Process.setThreadPriority(
549 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700550 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 synchronized (this) {
553 mService = s;
554 notifyAll();
555 }
Romain Guy06882f82009-06-10 13:36:04 -0700556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 Looper.loop();
558 }
559 }
560
561 static class PolicyThread extends Thread {
562 private final WindowManagerPolicy mPolicy;
563 private final WindowManagerService mService;
564 private final Context mContext;
565 private final PowerManagerService mPM;
566 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 public PolicyThread(WindowManagerPolicy policy,
569 WindowManagerService service, Context context,
570 PowerManagerService pm) {
571 super("WindowManagerPolicy");
572 mPolicy = policy;
573 mService = service;
574 mContext = context;
575 mPM = pm;
576 }
Romain Guy06882f82009-06-10 13:36:04 -0700577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 public void run() {
579 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800580 WindowManagerPolicyThread.set(this, Looper.myLooper());
581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800583 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 android.os.Process.setThreadPriority(
585 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700586 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 synchronized (this) {
590 mRunning = true;
591 notifyAll();
592 }
Romain Guy06882f82009-06-10 13:36:04 -0700593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 Looper.loop();
595 }
596 }
597
598 private WindowManagerService(Context context, PowerManagerService pm,
599 boolean haveInputMethods) {
600 mContext = context;
601 mHaveInputMethods = haveInputMethods;
602 mLimitedAlphaCompositing = context.getResources().getBoolean(
603 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 mPowerManager = pm;
606 mPowerManager.setPolicy(mPolicy);
607 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
608 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
609 "SCREEN_FROZEN");
610 mScreenFrozenLock.setReferenceCounted(false);
611
612 mActivityManager = ActivityManagerNative.getDefault();
613 mBatteryStats = BatteryStatsService.getService();
614
615 // Get persisted window scale setting
616 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
617 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
618 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
619 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700620
Jim Miller284b62e2010-06-08 14:27:42 -0700621 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
622 IntentFilter filter = new IntentFilter();
623 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
624 mContext.registerReceiver(mBroadcastReceiver, filter);
625
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700626 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
627 "KEEP_SCREEN_ON_FLAG");
628 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629
Jeff Browne33348b2010-07-15 23:54:05 -0700630 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
633 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 synchronized (thr) {
636 while (!thr.mRunning) {
637 try {
638 thr.wait();
639 } catch (InterruptedException e) {
640 }
641 }
642 }
Romain Guy06882f82009-06-10 13:36:04 -0700643
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700644 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 // Add ourself to the Watchdog monitors.
647 Watchdog.getInstance().addMonitor(this);
648 }
649
650 @Override
651 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
652 throws RemoteException {
653 try {
654 return super.onTransact(code, data, reply, flags);
655 } catch (RuntimeException e) {
656 // The window manager only throws security exceptions, so let's
657 // log all others.
658 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800659 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 }
661 throw e;
662 }
663 }
664
Jeff Browne33348b2010-07-15 23:54:05 -0700665 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800667 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 TAG, "Adding window " + window + " at "
669 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
670 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700671 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 }
673
Jeff Browne33348b2010-07-15 23:54:05 -0700674 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800676 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 TAG, "Adding window " + window + " at "
678 + i + " of " + mWindows.size() + " (before " + pos + ")");
679 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700680 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 }
682
683 //This method finds out the index of a window that has the same app token as
684 //win. used for z ordering the windows in mWindows
685 private int findIdxBasedOnAppTokens(WindowState win) {
686 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700687 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 int jmax = localmWindows.size();
689 if(jmax == 0) {
690 return -1;
691 }
692 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700693 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 if(wentry.mAppToken == win.mAppToken) {
695 return j;
696 }
697 }
698 return -1;
699 }
Romain Guy06882f82009-06-10 13:36:04 -0700700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
702 final IWindow client = win.mClient;
703 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700704 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 final int N = localmWindows.size();
707 final WindowState attached = win.mAttachedWindow;
708 int i;
709 if (attached == null) {
710 int tokenWindowsPos = token.windows.size();
711 if (token.appWindowToken != null) {
712 int index = tokenWindowsPos-1;
713 if (index >= 0) {
714 // If this application has existing windows, we
715 // simply place the new window on top of them... but
716 // keep the starting window on top.
717 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
718 // Base windows go behind everything else.
719 placeWindowBefore(token.windows.get(0), win);
720 tokenWindowsPos = 0;
721 } else {
722 AppWindowToken atoken = win.mAppToken;
723 if (atoken != null &&
724 token.windows.get(index) == atoken.startingWindow) {
725 placeWindowBefore(token.windows.get(index), win);
726 tokenWindowsPos--;
727 } else {
728 int newIdx = findIdxBasedOnAppTokens(win);
729 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700730 //there is a window above this one associated with the same
731 //apptoken note that the window could be a floating window
732 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800734 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700735 TAG, "Adding window " + win + " at "
736 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700738 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700739 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 }
741 }
742 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800743 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 TAG, "Figuring out where to add app window "
745 + client.asBinder() + " (token=" + token + ")");
746 // Figure out where the window should go, based on the
747 // order of applications.
748 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700749 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 for (i=NA-1; i>=0; i--) {
751 AppWindowToken t = mAppTokens.get(i);
752 if (t == token) {
753 i--;
754 break;
755 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800756
Dianne Hackborna8f60182009-09-01 19:01:50 -0700757 // We haven't reached the token yet; if this token
758 // is not going to the bottom and has windows, we can
759 // use it as an anchor for when we do reach the token.
760 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 pos = t.windows.get(0);
762 }
763 }
764 // We now know the index into the apps. If we found
765 // an app window above, that gives us the position; else
766 // we need to look some more.
767 if (pos != null) {
768 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700769 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 if (atoken != null) {
771 final int NC = atoken.windows.size();
772 if (NC > 0) {
773 WindowState bottom = atoken.windows.get(0);
774 if (bottom.mSubLayer < 0) {
775 pos = bottom;
776 }
777 }
778 }
779 placeWindowBefore(pos, win);
780 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700781 // Continue looking down until we find the first
782 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 while (i >= 0) {
784 AppWindowToken t = mAppTokens.get(i);
785 final int NW = t.windows.size();
786 if (NW > 0) {
787 pos = t.windows.get(NW-1);
788 break;
789 }
790 i--;
791 }
792 if (pos != null) {
793 // Move in front of any windows attached to this
794 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700795 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 if (atoken != null) {
797 final int NC = atoken.windows.size();
798 if (NC > 0) {
799 WindowState top = atoken.windows.get(NC-1);
800 if (top.mSubLayer >= 0) {
801 pos = top;
802 }
803 }
804 }
805 placeWindowAfter(pos, win);
806 } else {
807 // Just search for the start of this layer.
808 final int myLayer = win.mBaseLayer;
809 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700810 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 if (w.mBaseLayer > myLayer) {
812 break;
813 }
814 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800815 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700816 TAG, "Adding window " + win + " at "
817 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700819 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 }
821 }
822 }
823 } else {
824 // Figure out where window should go, based on layer.
825 final int myLayer = win.mBaseLayer;
826 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700827 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 i++;
829 break;
830 }
831 }
832 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800833 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700834 TAG, "Adding window " + win + " at "
835 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700837 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 }
839 if (addToToken) {
840 token.windows.add(tokenWindowsPos, win);
841 }
842
843 } else {
844 // Figure out this window's ordering relative to the window
845 // it is attached to.
846 final int NA = token.windows.size();
847 final int sublayer = win.mSubLayer;
848 int largestSublayer = Integer.MIN_VALUE;
849 WindowState windowWithLargestSublayer = null;
850 for (i=0; i<NA; i++) {
851 WindowState w = token.windows.get(i);
852 final int wSublayer = w.mSubLayer;
853 if (wSublayer >= largestSublayer) {
854 largestSublayer = wSublayer;
855 windowWithLargestSublayer = w;
856 }
857 if (sublayer < 0) {
858 // For negative sublayers, we go below all windows
859 // in the same sublayer.
860 if (wSublayer >= sublayer) {
861 if (addToToken) {
862 token.windows.add(i, win);
863 }
864 placeWindowBefore(
865 wSublayer >= 0 ? attached : w, win);
866 break;
867 }
868 } else {
869 // For positive sublayers, we go above all windows
870 // in the same sublayer.
871 if (wSublayer > sublayer) {
872 if (addToToken) {
873 token.windows.add(i, win);
874 }
875 placeWindowBefore(w, win);
876 break;
877 }
878 }
879 }
880 if (i >= NA) {
881 if (addToToken) {
882 token.windows.add(win);
883 }
884 if (sublayer < 0) {
885 placeWindowBefore(attached, win);
886 } else {
887 placeWindowAfter(largestSublayer >= 0
888 ? windowWithLargestSublayer
889 : attached,
890 win);
891 }
892 }
893 }
Romain Guy06882f82009-06-10 13:36:04 -0700894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 if (win.mAppToken != null && addToToken) {
896 win.mAppToken.allAppWindows.add(win);
897 }
898 }
Romain Guy06882f82009-06-10 13:36:04 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 static boolean canBeImeTarget(WindowState w) {
901 final int fl = w.mAttrs.flags
902 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
903 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
904 return w.isVisibleOrAdding();
905 }
906 return false;
907 }
Romain Guy06882f82009-06-10 13:36:04 -0700908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700910 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 final int N = localmWindows.size();
912 WindowState w = null;
913 int i = N;
914 while (i > 0) {
915 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700916 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700917
Joe Onorato8a9b2202010-02-26 18:56:32 -0800918 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 // + Integer.toHexString(w.mAttrs.flags));
920 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800921 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 // Yet more tricksyness! If this window is a "starting"
924 // window, we do actually want to be on top of it, but
925 // it is not -really- where input will go. So if the caller
926 // is not actually looking to move the IME, look down below
927 // for a real window to target...
928 if (!willMove
929 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
930 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700931 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
933 i--;
934 w = wb;
935 }
936 }
937 break;
938 }
939 }
Romain Guy06882f82009-06-10 13:36:04 -0700940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700942
Joe Onorato8a9b2202010-02-26 18:56:32 -0800943 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 if (willMove && w != null) {
947 final WindowState curTarget = mInputMethodTarget;
948 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 // Now some fun for dealing with window animations that
951 // modify the Z order. We need to look at all windows below
952 // the current target that are in this app, finding the highest
953 // visible one in layering.
954 AppWindowToken token = curTarget.mAppToken;
955 WindowState highestTarget = null;
956 int highestPos = 0;
957 if (token.animating || token.animation != null) {
958 int pos = 0;
959 pos = localmWindows.indexOf(curTarget);
960 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700961 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 if (win.mAppToken != token) {
963 break;
964 }
965 if (!win.mRemoved) {
966 if (highestTarget == null || win.mAnimLayer >
967 highestTarget.mAnimLayer) {
968 highestTarget = win;
969 highestPos = pos;
970 }
971 }
972 pos--;
973 }
974 }
Romain Guy06882f82009-06-10 13:36:04 -0700975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800977 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 + mNextAppTransition + " " + highestTarget
979 + " animating=" + highestTarget.isAnimating()
980 + " layer=" + highestTarget.mAnimLayer
981 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700982
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700983 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 // If we are currently setting up for an animation,
985 // hold everything until we can find out what will happen.
986 mInputMethodTargetWaitingAnim = true;
987 mInputMethodTarget = highestTarget;
988 return highestPos + 1;
989 } else if (highestTarget.isAnimating() &&
990 highestTarget.mAnimLayer > w.mAnimLayer) {
991 // If the window we are currently targeting is involved
992 // with an animation, and it is on top of the next target
993 // we will be over, then hold off on moving until
994 // that is done.
995 mInputMethodTarget = highestTarget;
996 return highestPos + 1;
997 }
998 }
999 }
1000 }
Romain Guy06882f82009-06-10 13:36:04 -07001001
Joe Onorato8a9b2202010-02-26 18:56:32 -08001002 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 if (w != null) {
1004 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001005 if (DEBUG_INPUT_METHOD) {
1006 RuntimeException e = null;
1007 if (!HIDE_STACK_CRAWLS) {
1008 e = new RuntimeException();
1009 e.fillInStackTrace();
1010 }
1011 Slog.w(TAG, "Moving IM target from "
1012 + mInputMethodTarget + " to " + w, e);
1013 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 mInputMethodTarget = w;
1015 if (w.mAppToken != null) {
1016 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1017 } else {
1018 setInputMethodAnimLayerAdjustment(0);
1019 }
1020 }
1021 return i+1;
1022 }
1023 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001024 if (DEBUG_INPUT_METHOD) {
1025 RuntimeException e = null;
1026 if (!HIDE_STACK_CRAWLS) {
1027 e = new RuntimeException();
1028 e.fillInStackTrace();
1029 }
1030 Slog.w(TAG, "Moving IM target from "
1031 + mInputMethodTarget + " to null", e);
1032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 mInputMethodTarget = null;
1034 setInputMethodAnimLayerAdjustment(0);
1035 }
1036 return -1;
1037 }
Romain Guy06882f82009-06-10 13:36:04 -07001038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 void addInputMethodWindowToListLocked(WindowState win) {
1040 int pos = findDesiredInputMethodWindowIndexLocked(true);
1041 if (pos >= 0) {
1042 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001043 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001044 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001046 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 moveInputMethodDialogsLocked(pos+1);
1048 return;
1049 }
1050 win.mTargetAppToken = null;
1051 addWindowToListInOrderLocked(win, true);
1052 moveInputMethodDialogsLocked(pos);
1053 }
Romain Guy06882f82009-06-10 13:36:04 -07001054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001056 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 mInputMethodAnimLayerAdjustment = adj;
1058 WindowState imw = mInputMethodWindow;
1059 if (imw != null) {
1060 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001061 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 + " anim layer: " + imw.mAnimLayer);
1063 int wi = imw.mChildWindows.size();
1064 while (wi > 0) {
1065 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001066 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 + " anim layer: " + cw.mAnimLayer);
1070 }
1071 }
1072 int di = mInputMethodDialogs.size();
1073 while (di > 0) {
1074 di --;
1075 imw = mInputMethodDialogs.get(di);
1076 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001077 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 + " anim layer: " + imw.mAnimLayer);
1079 }
1080 }
Romain Guy06882f82009-06-10 13:36:04 -07001081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1083 int wpos = mWindows.indexOf(win);
1084 if (wpos >= 0) {
1085 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001086 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001088 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 int NC = win.mChildWindows.size();
1090 while (NC > 0) {
1091 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001092 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 int cpos = mWindows.indexOf(cw);
1094 if (cpos >= 0) {
1095 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001096 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001097 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 mWindows.remove(cpos);
1099 }
1100 }
1101 }
1102 return interestingPos;
1103 }
Romain Guy06882f82009-06-10 13:36:04 -07001104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 private void reAddWindowToListInOrderLocked(WindowState win) {
1106 addWindowToListInOrderLocked(win, false);
1107 // This is a hack to get all of the child windows added as well
1108 // at the right position. Child windows should be rare and
1109 // this case should be rare, so it shouldn't be that big a deal.
1110 int wpos = mWindows.indexOf(win);
1111 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001112 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001113 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001115 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 reAddWindowLocked(wpos, win);
1117 }
1118 }
Romain Guy06882f82009-06-10 13:36:04 -07001119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 void logWindowList(String prefix) {
1121 int N = mWindows.size();
1122 while (N > 0) {
1123 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001124 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 }
1126 }
Romain Guy06882f82009-06-10 13:36:04 -07001127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 void moveInputMethodDialogsLocked(int pos) {
1129 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001132 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 for (int i=0; i<N; i++) {
1134 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1135 }
1136 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001137 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 logWindowList(" ");
1139 }
Romain Guy06882f82009-06-10 13:36:04 -07001140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 if (pos >= 0) {
1142 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1143 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001144 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (wp == mInputMethodWindow) {
1146 pos++;
1147 }
1148 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001149 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 for (int i=0; i<N; i++) {
1151 WindowState win = dialogs.get(i);
1152 win.mTargetAppToken = targetAppToken;
1153 pos = reAddWindowLocked(pos, win);
1154 }
1155 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001156 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 logWindowList(" ");
1158 }
1159 return;
1160 }
1161 for (int i=0; i<N; i++) {
1162 WindowState win = dialogs.get(i);
1163 win.mTargetAppToken = null;
1164 reAddWindowToListInOrderLocked(win);
1165 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001166 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 logWindowList(" ");
1168 }
1169 }
1170 }
Romain Guy06882f82009-06-10 13:36:04 -07001171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1173 final WindowState imWin = mInputMethodWindow;
1174 final int DN = mInputMethodDialogs.size();
1175 if (imWin == null && DN == 0) {
1176 return false;
1177 }
Romain Guy06882f82009-06-10 13:36:04 -07001178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1180 if (imPos >= 0) {
1181 // In this case, the input method windows are to be placed
1182 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 // First check to see if the input method windows are already
1185 // located here, and contiguous.
1186 final int N = mWindows.size();
1187 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001188 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 // Figure out the actual input method window that should be
1191 // at the bottom of their stack.
1192 WindowState baseImWin = imWin != null
1193 ? imWin : mInputMethodDialogs.get(0);
1194 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001195 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 if (cw.mSubLayer < 0) baseImWin = cw;
1197 }
Romain Guy06882f82009-06-10 13:36:04 -07001198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 if (firstImWin == baseImWin) {
1200 // The windows haven't moved... but are they still contiguous?
1201 // First find the top IM window.
1202 int pos = imPos+1;
1203 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001204 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 break;
1206 }
1207 pos++;
1208 }
1209 pos++;
1210 // Now there should be no more input method windows above.
1211 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001212 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 break;
1214 }
1215 pos++;
1216 }
1217 if (pos >= N) {
1218 // All is good!
1219 return false;
1220 }
1221 }
Romain Guy06882f82009-06-10 13:36:04 -07001222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 if (imWin != null) {
1224 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001225 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 logWindowList(" ");
1227 }
1228 imPos = tmpRemoveWindowLocked(imPos, imWin);
1229 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001230 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 logWindowList(" ");
1232 }
1233 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1234 reAddWindowLocked(imPos, imWin);
1235 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001236 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 logWindowList(" ");
1238 }
1239 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1240 } else {
1241 moveInputMethodDialogsLocked(imPos);
1242 }
Romain Guy06882f82009-06-10 13:36:04 -07001243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 } else {
1245 // In this case, the input method windows go in a fixed layer,
1246 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001249 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 tmpRemoveWindowLocked(0, imWin);
1251 imWin.mTargetAppToken = null;
1252 reAddWindowToListInOrderLocked(imWin);
1253 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001254 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 logWindowList(" ");
1256 }
1257 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1258 } else {
1259 moveInputMethodDialogsLocked(-1);;
1260 }
Romain Guy06882f82009-06-10 13:36:04 -07001261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 }
Romain Guy06882f82009-06-10 13:36:04 -07001263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 if (needAssignLayers) {
1265 assignLayersLocked();
1266 }
Romain Guy06882f82009-06-10 13:36:04 -07001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 return true;
1269 }
Romain Guy06882f82009-06-10 13:36:04 -07001270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 void adjustInputMethodDialogsLocked() {
1272 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
Dianne Hackborn25994b42009-09-04 14:21:19 -07001275 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001276 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001277 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1278 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1279 ? wallpaperTarget.mAppToken.animation : null)
1280 + " upper=" + mUpperWallpaperTarget
1281 + " lower=" + mLowerWallpaperTarget);
1282 return (wallpaperTarget != null
1283 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1284 && wallpaperTarget.mAppToken.animation != null)))
1285 || mUpperWallpaperTarget != null
1286 || mLowerWallpaperTarget != null;
1287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001288
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001289 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1290 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001291
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001292 int adjustWallpaperWindowsLocked() {
1293 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001294
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001295 final int dw = mDisplay.getWidth();
1296 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001297
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001298 // First find top-most window that has asked to be on top of the
1299 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001300 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001301 int N = localmWindows.size();
1302 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001303 WindowState foundW = null;
1304 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001305 WindowState topCurW = null;
1306 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001307 int i = N;
1308 while (i > 0) {
1309 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001310 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001311 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1312 if (topCurW == null) {
1313 topCurW = w;
1314 topCurI = i;
1315 }
1316 continue;
1317 }
1318 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001319 if (w.mAppToken != null) {
1320 // If this window's app token is hidden and not animating,
1321 // it is of no interest to us.
1322 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001323 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001324 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001325 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001326 continue;
1327 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001328 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001329 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001330 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1331 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001332 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001333 && (mWallpaperTarget == w
1334 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001335 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001336 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001337 foundW = w;
1338 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001339 if (w == mWallpaperTarget && ((w.mAppToken != null
1340 && w.mAppToken.animation != null)
1341 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001342 // The current wallpaper target is animating, so we'll
1343 // look behind it for another possible target and figure
1344 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001345 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001346 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001347 continue;
1348 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001349 break;
1350 }
1351 }
1352
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001353 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001354 // If we are currently waiting for an app transition, and either
1355 // the current target or the next target are involved with it,
1356 // then hold off on doing anything with the wallpaper.
1357 // Note that we are checking here for just whether the target
1358 // is part of an app token... which is potentially overly aggressive
1359 // (the app token may not be involved in the transition), but good
1360 // enough (we'll just wait until whatever transition is pending
1361 // executes).
1362 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001363 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001364 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001365 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001366 }
1367 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001368 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001369 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001370 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001371 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001372 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001373
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001374 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001375 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001376 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001377 + " oldTarget: " + mWallpaperTarget);
1378 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001379
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 mLowerWallpaperTarget = null;
1381 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001382
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001383 WindowState oldW = mWallpaperTarget;
1384 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001385
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 // Now what is happening... if the current and new targets are
1387 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001388 if (foundW != null && oldW != null) {
1389 boolean oldAnim = oldW.mAnimation != null
1390 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1391 boolean foundAnim = foundW.mAnimation != null
1392 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001394 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001395 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001396 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001397 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001398 int oldI = localmWindows.indexOf(oldW);
1399 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001400 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 }
1402 if (oldI >= 0) {
1403 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001404 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 + "=" + oldW + "; new#" + foundI
1406 + "=" + foundW);
1407 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001408
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001409 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001410 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001411 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001412 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001413 }
1414 mWallpaperTarget = oldW;
1415 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001416
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001417 // Now set the upper and lower wallpaper targets
1418 // correctly, and make sure that we are positioning
1419 // the wallpaper below the lower.
1420 if (foundI > oldI) {
1421 // The new target is on top of the old one.
1422 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001423 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001424 }
1425 mUpperWallpaperTarget = foundW;
1426 mLowerWallpaperTarget = oldW;
1427 foundW = oldW;
1428 foundI = oldI;
1429 } else {
1430 // The new target is below the old one.
1431 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001432 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001433 }
1434 mUpperWallpaperTarget = oldW;
1435 mLowerWallpaperTarget = foundW;
1436 }
1437 }
1438 }
1439 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001440
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001441 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001442 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001443 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1444 || (mLowerWallpaperTarget.mAppToken != null
1445 && mLowerWallpaperTarget.mAppToken.animation != null);
1446 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1447 || (mUpperWallpaperTarget.mAppToken != null
1448 && mUpperWallpaperTarget.mAppToken.animation != null);
1449 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001450 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001452 }
1453 mLowerWallpaperTarget = null;
1454 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001455 }
1456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001457
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001459 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001460 // The window is visible to the compositor... but is it visible
1461 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001462 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001463 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001464
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001465 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001466 // its layer adjustment. Only do this if we are not transfering
1467 // between two wallpaper targets.
1468 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001469 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001470 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001471
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001472 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1473 * TYPE_LAYER_MULTIPLIER
1474 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001475
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001476 // Now w is the window we are supposed to be behind... but we
1477 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001478 // AND any starting window associated with it, AND below the
1479 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001480 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001481 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001482 if (wb.mBaseLayer < maxLayer &&
1483 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001484 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001485 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001486 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001487 // This window is not related to the previous one in any
1488 // interesting way, so stop here.
1489 break;
1490 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001491 foundW = wb;
1492 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001493 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001494 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001495 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001496 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001497
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001498 if (foundW == null && topCurW != null) {
1499 // There is no wallpaper target, so it goes at the bottom.
1500 // We will assume it is the same place as last time, if known.
1501 foundW = topCurW;
1502 foundI = topCurI+1;
1503 } else {
1504 // Okay i is the position immediately above the wallpaper. Look at
1505 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001506 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001508
Dianne Hackborn284ac932009-08-28 10:34:25 -07001509 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001510 if (mWallpaperTarget.mWallpaperX >= 0) {
1511 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001512 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001513 }
1514 if (mWallpaperTarget.mWallpaperY >= 0) {
1515 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001516 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001517 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001519
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001520 // Start stepping backwards from here, ensuring that our wallpaper windows
1521 // are correctly placed.
1522 int curTokenIndex = mWallpaperTokens.size();
1523 while (curTokenIndex > 0) {
1524 curTokenIndex--;
1525 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001526 if (token.hidden == visible) {
1527 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1528 token.hidden = !visible;
1529 // Need to do a layout to ensure the wallpaper now has the
1530 // correct size.
1531 mLayoutNeeded = true;
1532 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001533
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001534 int curWallpaperIndex = token.windows.size();
1535 while (curWallpaperIndex > 0) {
1536 curWallpaperIndex--;
1537 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001538
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001539 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001540 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001543 // First, make sure the client has the current visibility
1544 // state.
1545 if (wallpaper.mWallpaperVisible != visible) {
1546 wallpaper.mWallpaperVisible = visible;
1547 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001549 "Setting visibility of wallpaper " + wallpaper
1550 + ": " + visible);
1551 wallpaper.mClient.dispatchAppVisibility(visible);
1552 } catch (RemoteException e) {
1553 }
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001556 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001558 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001559
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001560 // First, if this window is at the current index, then all
1561 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001562 if (wallpaper == foundW) {
1563 foundI--;
1564 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001565 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001566 continue;
1567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001568
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 // The window didn't match... the current wallpaper window,
1570 // wherever it is, is in the wrong place, so make sure it is
1571 // not in the list.
1572 int oldIndex = localmWindows.indexOf(wallpaper);
1573 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001574 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001575 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001577 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001578 if (oldIndex < foundI) {
1579 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001580 }
1581 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001582
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001583 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001585 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001586 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001587
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001588 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001589 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001590 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001591 }
1592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001593
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001594 return changed;
1595 }
1596
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001597 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001598 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001599 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001600 mWallpaperAnimLayerAdjustment = adj;
1601 int curTokenIndex = mWallpaperTokens.size();
1602 while (curTokenIndex > 0) {
1603 curTokenIndex--;
1604 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1605 int curWallpaperIndex = token.windows.size();
1606 while (curWallpaperIndex > 0) {
1607 curWallpaperIndex--;
1608 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1609 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001610 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001611 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001612 }
1613 }
1614 }
1615
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001616 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1617 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001618 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001619 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001620 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001621 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001622 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1623 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1624 changed = wallpaperWin.mXOffset != offset;
1625 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001627 + wallpaperWin + " x: " + offset);
1628 wallpaperWin.mXOffset = offset;
1629 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001630 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001631 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001632 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001633 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001635
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001637 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001638 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1639 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1640 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001641 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001642 + wallpaperWin + " y: " + offset);
1643 changed = true;
1644 wallpaperWin.mYOffset = offset;
1645 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001646 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001647 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001648 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001649 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001650 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001651
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001652 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001653 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001655 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1656 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001657 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001658 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001659 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001660 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001661 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1662 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001663 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001664 if (mWaitingOnWallpaper != null) {
1665 long start = SystemClock.uptimeMillis();
1666 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1667 < start) {
1668 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001669 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001670 "Waiting for offset complete...");
1671 mWindowMap.wait(WALLPAPER_TIMEOUT);
1672 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001673 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001674 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001675 if ((start+WALLPAPER_TIMEOUT)
1676 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 + wallpaperWin);
1679 mLastWallpaperTimeoutTime = start;
1680 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001681 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001682 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
1684 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001685 } catch (RemoteException e) {
1686 }
1687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001688
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001689 return changed;
1690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001692 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001693 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001694 if (mWaitingOnWallpaper != null &&
1695 mWaitingOnWallpaper.mClient.asBinder() == window) {
1696 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001697 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001698 }
1699 }
1700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001701
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001702 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001703 final int dw = mDisplay.getWidth();
1704 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001706 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001707
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001708 WindowState target = mWallpaperTarget;
1709 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001710 if (target.mWallpaperX >= 0) {
1711 mLastWallpaperX = target.mWallpaperX;
1712 } else if (changingTarget.mWallpaperX >= 0) {
1713 mLastWallpaperX = changingTarget.mWallpaperX;
1714 }
1715 if (target.mWallpaperY >= 0) {
1716 mLastWallpaperY = target.mWallpaperY;
1717 } else if (changingTarget.mWallpaperY >= 0) {
1718 mLastWallpaperY = changingTarget.mWallpaperY;
1719 }
1720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001721
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001722 int curTokenIndex = mWallpaperTokens.size();
1723 while (curTokenIndex > 0) {
1724 curTokenIndex--;
1725 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1726 int curWallpaperIndex = token.windows.size();
1727 while (curWallpaperIndex > 0) {
1728 curWallpaperIndex--;
1729 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1730 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1731 wallpaper.computeShownFrameLocked();
1732 changed = true;
1733 // We only want to be synchronous with one wallpaper.
1734 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001735 }
1736 }
1737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001738
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001739 return changed;
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001742 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001743 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001744 final int dw = mDisplay.getWidth();
1745 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001746
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 int curTokenIndex = mWallpaperTokens.size();
1748 while (curTokenIndex > 0) {
1749 curTokenIndex--;
1750 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001751 if (token.hidden == visible) {
1752 token.hidden = !visible;
1753 // Need to do a layout to ensure the wallpaper now has the
1754 // correct size.
1755 mLayoutNeeded = true;
1756 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001757
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001758 int curWallpaperIndex = token.windows.size();
1759 while (curWallpaperIndex > 0) {
1760 curWallpaperIndex--;
1761 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1762 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001763 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001764 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001765
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001766 if (wallpaper.mWallpaperVisible != visible) {
1767 wallpaper.mWallpaperVisible = visible;
1768 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001770 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001771 + ": " + visible);
1772 wallpaper.mClient.dispatchAppVisibility(visible);
1773 } catch (RemoteException e) {
1774 }
1775 }
1776 }
1777 }
1778 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 public int addWindow(Session session, IWindow client,
1781 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001782 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 int res = mPolicy.checkAddPermission(attrs);
1784 if (res != WindowManagerImpl.ADD_OKAY) {
1785 return res;
1786 }
Romain Guy06882f82009-06-10 13:36:04 -07001787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 boolean reportNewConfig = false;
1789 WindowState attachedWindow = null;
1790 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 synchronized(mWindowMap) {
1793 // Instantiating a Display requires talking with the simulator,
1794 // so don't do it until we know the system is mostly up and
1795 // running.
1796 if (mDisplay == null) {
1797 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1798 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001799 mInitialDisplayWidth = mDisplay.getWidth();
1800 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001801 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 reportNewConfig = true;
1803 }
Romain Guy06882f82009-06-10 13:36:04 -07001804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001806 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1808 }
1809
1810 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001811 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 + attrs.token + ". Aborting.");
1815 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1816 }
1817 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1818 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001819 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 + attrs.token + ". Aborting.");
1821 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1822 }
1823 }
1824
1825 boolean addToken = false;
1826 WindowToken token = mTokenMap.get(attrs.token);
1827 if (token == null) {
1828 if (attrs.type >= FIRST_APPLICATION_WINDOW
1829 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001830 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 + attrs.token + ". Aborting.");
1832 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1833 }
1834 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001835 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 + attrs.token + ". Aborting.");
1837 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1838 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001839 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001840 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001841 + attrs.token + ". Aborting.");
1842 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 token = new WindowToken(attrs.token, -1, false);
1845 addToken = true;
1846 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1847 && attrs.type <= LAST_APPLICATION_WINDOW) {
1848 AppWindowToken atoken = token.appWindowToken;
1849 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001850 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 + token + ". Aborting.");
1852 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1853 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 + token + ". Aborting.");
1856 return WindowManagerImpl.ADD_APP_EXITING;
1857 }
1858 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1859 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1862 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1863 }
1864 } else if (attrs.type == TYPE_INPUT_METHOD) {
1865 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001866 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 + attrs.token + ". Aborting.");
1868 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1869 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001870 } else if (attrs.type == TYPE_WALLPAPER) {
1871 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001872 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001873 + attrs.token + ". Aborting.");
1874 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 }
1877
1878 win = new WindowState(session, client, token,
1879 attachedWindow, attrs, viewVisibility);
1880 if (win.mDeathRecipient == null) {
1881 // Client has apparently died, so there is no reason to
1882 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 + " that is dead, aborting.");
1885 return WindowManagerImpl.ADD_APP_EXITING;
1886 }
1887
1888 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 res = mPolicy.prepareAddWindowLw(win, attrs);
1891 if (res != WindowManagerImpl.ADD_OKAY) {
1892 return res;
1893 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001894
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001895 if (outInputChannel != null) {
1896 String name = win.makeInputChannelName();
1897 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1898 win.mInputChannel = inputChannels[0];
1899 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1900
1901 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903
1904 // From now on, no exceptions or errors allowed!
1905
1906 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001908 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 if (addToken) {
1911 mTokenMap.put(attrs.token, token);
1912 mTokenList.add(token);
1913 }
1914 win.attach();
1915 mWindowMap.put(client.asBinder(), win);
1916
1917 if (attrs.type == TYPE_APPLICATION_STARTING &&
1918 token.appWindowToken != null) {
1919 token.appWindowToken.startingWindow = win;
1920 }
1921
1922 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 if (attrs.type == TYPE_INPUT_METHOD) {
1925 mInputMethodWindow = win;
1926 addInputMethodWindowToListLocked(win);
1927 imMayMove = false;
1928 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1929 mInputMethodDialogs.add(win);
1930 addWindowToListInOrderLocked(win, true);
1931 adjustInputMethodDialogsLocked();
1932 imMayMove = false;
1933 } else {
1934 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001935 if (attrs.type == TYPE_WALLPAPER) {
1936 mLastWallpaperTimeoutTime = 0;
1937 adjustWallpaperWindowsLocked();
1938 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001939 adjustWallpaperWindowsLocked();
1940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 }
Romain Guy06882f82009-06-10 13:36:04 -07001942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 if (mInTouchMode) {
1948 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1949 }
1950 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1951 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1952 }
Romain Guy06882f82009-06-10 13:36:04 -07001953
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001954 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001956 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1957 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 imMayMove = false;
1959 }
1960 }
Romain Guy06882f82009-06-10 13:36:04 -07001961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001963 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 }
Romain Guy06882f82009-06-10 13:36:04 -07001965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 assignLayersLocked();
1967 // Don't do layout here, the window must call
1968 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 //dump();
1971
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001972 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001973 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001974 }
Jeff Brown349703e2010-06-22 01:27:15 -07001975
Joe Onorato8a9b2202010-02-26 18:56:32 -08001976 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 TAG, "New client " + client.asBinder()
1978 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001979
1980 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1981 reportNewConfig = true;
1982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 }
1984
1985 // sendNewConfiguration() checks caller permissions so we must call it with
1986 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1987 // identity anyway, so it's safe to just clear & restore around this whole
1988 // block.
1989 final long origId = Binder.clearCallingIdentity();
1990 if (reportNewConfig) {
1991 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 }
1993 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 return res;
1996 }
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 public void removeWindow(Session session, IWindow client) {
1999 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002000 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 if (win == null) {
2002 return;
2003 }
2004 removeWindowLocked(session, win);
2005 }
2006 }
Romain Guy06882f82009-06-10 13:36:04 -07002007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008 public void removeWindowLocked(Session session, WindowState win) {
2009
Joe Onorato8a9b2202010-02-26 18:56:32 -08002010 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 TAG, "Remove " + win + " client="
2012 + Integer.toHexString(System.identityHashCode(
2013 win.mClient.asBinder()))
2014 + ", surface=" + win.mSurface);
2015
2016 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002017
2018 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002019
Joe Onorato8a9b2202010-02-26 18:56:32 -08002020 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2022 + " mExiting=" + win.mExiting
2023 + " isAnimating=" + win.isAnimating()
2024 + " app-animation="
2025 + (win.mAppToken != null ? win.mAppToken.animation : null)
2026 + " inPendingTransaction="
2027 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2028 + " mDisplayFrozen=" + mDisplayFrozen);
2029 // Visibility of the removed window. Will be used later to update orientation later on.
2030 boolean wasVisible = false;
2031 // First, see if we need to run an animation. If we do, we have
2032 // to hold off on removing the window until the animation is done.
2033 // If the display is frozen, just remove immediately, since the
2034 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002035 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 // If we are not currently running the exit animation, we
2037 // need to see about starting one.
2038 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2041 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2042 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2043 }
2044 // Try starting an animation.
2045 if (applyAnimationLocked(win, transit, false)) {
2046 win.mExiting = true;
2047 }
2048 }
2049 if (win.mExiting || win.isAnimating()) {
2050 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002051 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 win.mExiting = true;
2053 win.mRemoveOnExit = true;
2054 mLayoutNeeded = true;
2055 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2056 performLayoutAndPlaceSurfacesLocked();
2057 if (win.mAppToken != null) {
2058 win.mAppToken.updateReportedVisibilityLocked();
2059 }
2060 //dump();
2061 Binder.restoreCallingIdentity(origId);
2062 return;
2063 }
2064 }
2065
2066 removeWindowInnerLocked(session, win);
2067 // Removing a visible window will effect the computed orientation
2068 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002069 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002070 != mForcedAppOrientation
2071 && updateOrientationFromAppTokensLocked()) {
2072 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 }
2074 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2075 Binder.restoreCallingIdentity(origId);
2076 }
Romain Guy06882f82009-06-10 13:36:04 -07002077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 if (mInputMethodTarget == win) {
2082 moveInputMethodWindowsIfNeededLocked(false);
2083 }
Romain Guy06882f82009-06-10 13:36:04 -07002084
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002085 if (false) {
2086 RuntimeException e = new RuntimeException("here");
2087 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002088 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002089 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 mPolicy.removeWindowLw(win);
2092 win.removeLocked();
2093
2094 mWindowMap.remove(win.mClient.asBinder());
2095 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002096 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098
2099 if (mInputMethodWindow == win) {
2100 mInputMethodWindow = null;
2101 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2102 mInputMethodDialogs.remove(win);
2103 }
Romain Guy06882f82009-06-10 13:36:04 -07002104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002105 final WindowToken token = win.mToken;
2106 final AppWindowToken atoken = win.mAppToken;
2107 token.windows.remove(win);
2108 if (atoken != null) {
2109 atoken.allAppWindows.remove(win);
2110 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002111 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 TAG, "**** Removing window " + win + ": count="
2113 + token.windows.size());
2114 if (token.windows.size() == 0) {
2115 if (!token.explicit) {
2116 mTokenMap.remove(token.token);
2117 mTokenList.remove(token);
2118 } else if (atoken != null) {
2119 atoken.firstWindowDrawn = false;
2120 }
2121 }
2122
2123 if (atoken != null) {
2124 if (atoken.startingWindow == win) {
2125 atoken.startingWindow = null;
2126 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2127 // If this is the last window and we had requested a starting
2128 // transition window, well there is no point now.
2129 atoken.startingData = null;
2130 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2131 // If this is the last window except for a starting transition
2132 // window, we need to get rid of the starting transition.
2133 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002134 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 + ": no more real windows");
2136 }
2137 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2138 mH.sendMessage(m);
2139 }
2140 }
Romain Guy06882f82009-06-10 13:36:04 -07002141
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002142 if (win.mAttrs.type == TYPE_WALLPAPER) {
2143 mLastWallpaperTimeoutTime = 0;
2144 adjustWallpaperWindowsLocked();
2145 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002146 adjustWallpaperWindowsLocked();
2147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 if (!mInLayout) {
2150 assignLayersLocked();
2151 mLayoutNeeded = true;
2152 performLayoutAndPlaceSurfacesLocked();
2153 if (win.mAppToken != null) {
2154 win.mAppToken.updateReportedVisibilityLocked();
2155 }
2156 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002157
2158 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 }
2160
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002161 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2162 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2163 + ": " + msg + " / " + w.mAttrs.getTitle();
2164 if (where != null) {
2165 Slog.i(TAG, str, where);
2166 } else {
2167 Slog.i(TAG, str);
2168 }
2169 }
2170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2172 long origId = Binder.clearCallingIdentity();
2173 try {
2174 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002175 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002177 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 Surface.openTransaction();
2179 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002180 if (SHOW_TRANSACTIONS) logSurface(w,
2181 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 w.mSurface.setTransparentRegionHint(region);
2183 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 Surface.closeTransaction();
2186 }
2187 }
2188 }
2189 } finally {
2190 Binder.restoreCallingIdentity(origId);
2191 }
2192 }
2193
2194 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002195 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 Rect visibleInsets) {
2197 long origId = Binder.clearCallingIdentity();
2198 try {
2199 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002200 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 if (w != null) {
2202 w.mGivenInsetsPending = false;
2203 w.mGivenContentInsets.set(contentInsets);
2204 w.mGivenVisibleInsets.set(visibleInsets);
2205 w.mTouchableInsets = touchableInsets;
2206 mLayoutNeeded = true;
2207 performLayoutAndPlaceSurfacesLocked();
2208 }
2209 }
2210 } finally {
2211 Binder.restoreCallingIdentity(origId);
2212 }
2213 }
Romain Guy06882f82009-06-10 13:36:04 -07002214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 public void getWindowDisplayFrame(Session session, IWindow client,
2216 Rect outDisplayFrame) {
2217 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002218 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 if (win == null) {
2220 outDisplayFrame.setEmpty();
2221 return;
2222 }
2223 outDisplayFrame.set(win.mDisplayFrame);
2224 }
2225 }
2226
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002227 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2228 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002229 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2230 window.mWallpaperX = x;
2231 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002232 window.mWallpaperXStep = xStep;
2233 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002234 if (updateWallpaperOffsetLocked(window, true)) {
2235 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002236 }
2237 }
2238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002239
Dianne Hackborn75804932009-10-20 20:15:20 -07002240 void wallpaperCommandComplete(IBinder window, Bundle result) {
2241 synchronized (mWindowMap) {
2242 if (mWaitingOnWallpaper != null &&
2243 mWaitingOnWallpaper.mClient.asBinder() == window) {
2244 mWaitingOnWallpaper = null;
2245 mWindowMap.notifyAll();
2246 }
2247 }
2248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002249
Dianne Hackborn75804932009-10-20 20:15:20 -07002250 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2251 String action, int x, int y, int z, Bundle extras, boolean sync) {
2252 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2253 || window == mUpperWallpaperTarget) {
2254 boolean doWait = sync;
2255 int curTokenIndex = mWallpaperTokens.size();
2256 while (curTokenIndex > 0) {
2257 curTokenIndex--;
2258 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2259 int curWallpaperIndex = token.windows.size();
2260 while (curWallpaperIndex > 0) {
2261 curWallpaperIndex--;
2262 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2263 try {
2264 wallpaper.mClient.dispatchWallpaperCommand(action,
2265 x, y, z, extras, sync);
2266 // We only want to be synchronous with one wallpaper.
2267 sync = false;
2268 } catch (RemoteException e) {
2269 }
2270 }
2271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002272
Dianne Hackborn75804932009-10-20 20:15:20 -07002273 if (doWait) {
2274 // XXX Need to wait for result.
2275 }
2276 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002277
Dianne Hackborn75804932009-10-20 20:15:20 -07002278 return null;
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 public int relayoutWindow(Session session, IWindow client,
2282 WindowManager.LayoutParams attrs, int requestedWidth,
2283 int requestedHeight, int viewVisibility, boolean insetsPending,
2284 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002285 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 boolean displayed = false;
2287 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002288 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002292 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 if (win == null) {
2294 return 0;
2295 }
2296 win.mRequestedWidth = requestedWidth;
2297 win.mRequestedHeight = requestedHeight;
2298
2299 if (attrs != null) {
2300 mPolicy.adjustWindowParamsLw(attrs);
2301 }
Romain Guy06882f82009-06-10 13:36:04 -07002302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 int attrChanges = 0;
2304 int flagChanges = 0;
2305 if (attrs != null) {
2306 flagChanges = win.mAttrs.flags ^= attrs.flags;
2307 attrChanges = win.mAttrs.copyFrom(attrs);
2308 }
2309
Joe Onorato8a9b2202010-02-26 18:56:32 -08002310 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311
2312 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2313 win.mAlpha = attrs.alpha;
2314 }
2315
2316 final boolean scaledWindow =
2317 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2318
2319 if (scaledWindow) {
2320 // requested{Width|Height} Surface's physical size
2321 // attrs.{width|height} Size on screen
2322 win.mHScale = (attrs.width != requestedWidth) ?
2323 (attrs.width / (float)requestedWidth) : 1.0f;
2324 win.mVScale = (attrs.height != requestedHeight) ?
2325 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002326 } else {
2327 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 }
2329
2330 boolean imMayMove = (flagChanges&(
2331 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2332 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 boolean focusMayChange = win.mViewVisibility != viewVisibility
2335 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2336 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002337
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002338 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2339 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 win.mRelayoutCalled = true;
2342 final int oldVisibility = win.mViewVisibility;
2343 win.mViewVisibility = viewVisibility;
2344 if (viewVisibility == View.VISIBLE &&
2345 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2346 displayed = !win.isVisibleLw();
2347 if (win.mExiting) {
2348 win.mExiting = false;
2349 win.mAnimation = null;
2350 }
2351 if (win.mDestroying) {
2352 win.mDestroying = false;
2353 mDestroySurface.remove(win);
2354 }
2355 if (oldVisibility == View.GONE) {
2356 win.mEnterAnimationPending = true;
2357 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002358 if (displayed) {
2359 if (win.mSurface != null && !win.mDrawPending
2360 && !win.mCommitDrawPending && !mDisplayFrozen
2361 && mPolicy.isScreenOn()) {
2362 applyEnterAnimationLocked(win);
2363 }
2364 if ((win.mAttrs.flags
2365 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2366 if (DEBUG_VISIBILITY) Slog.v(TAG,
2367 "Relayout window turning screen on: " + win);
2368 win.mTurnOnScreen = true;
2369 }
2370 int diff = 0;
2371 if (win.mConfiguration != mCurConfiguration
2372 && (win.mConfiguration == null
2373 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2374 win.mConfiguration = mCurConfiguration;
2375 if (DEBUG_CONFIGURATION) {
2376 Slog.i(TAG, "Window " + win + " visible with new config: "
2377 + win.mConfiguration + " / 0x"
2378 + Integer.toHexString(diff));
2379 }
2380 outConfig.setTo(mCurConfiguration);
2381 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2384 // To change the format, we need to re-build the surface.
2385 win.destroySurfaceLocked();
2386 displayed = true;
2387 }
2388 try {
2389 Surface surface = win.createSurfaceLocked();
2390 if (surface != null) {
2391 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002392 win.mReportDestroySurface = false;
2393 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002394 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002395 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002397 // For some reason there isn't a surface. Clear the
2398 // caller's object so they see the same state.
2399 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 }
2401 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002402 mInputMonitor.updateInputWindowsLw();
2403
Joe Onorato8a9b2202010-02-26 18:56:32 -08002404 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002405 + client + " (" + win.mAttrs.getTitle() + ")",
2406 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 Binder.restoreCallingIdentity(origId);
2408 return 0;
2409 }
2410 if (displayed) {
2411 focusMayChange = true;
2412 }
2413 if (win.mAttrs.type == TYPE_INPUT_METHOD
2414 && mInputMethodWindow == null) {
2415 mInputMethodWindow = win;
2416 imMayMove = true;
2417 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002418 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2419 && win.mAppToken != null
2420 && win.mAppToken.startingWindow != null) {
2421 // Special handling of starting window over the base
2422 // window of the app: propagate lock screen flags to it,
2423 // to provide the correct semantics while starting.
2424 final int mask =
2425 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002426 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2427 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002428 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2429 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 } else {
2432 win.mEnterAnimationPending = false;
2433 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002434 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002435 + ": mExiting=" + win.mExiting
2436 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 // If we are not currently running the exit animation, we
2438 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002439 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 // Try starting an animation; if there isn't one, we
2441 // can destroy the surface right away.
2442 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2443 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2444 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2445 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002446 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002448 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 } else if (win.isAnimating()) {
2451 // Currently in a hide animation... turn this into
2452 // an exit.
2453 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002454 } else if (win == mWallpaperTarget) {
2455 // If the wallpaper is currently behind this
2456 // window, we need to change both of them inside
2457 // of a transaction to avoid artifacts.
2458 win.mExiting = true;
2459 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 } else {
2461 if (mInputMethodWindow == win) {
2462 mInputMethodWindow = null;
2463 }
2464 win.destroySurfaceLocked();
2465 }
2466 }
2467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002468
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002469 if (win.mSurface == null || (win.getAttrs().flags
2470 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2471 || win.mSurfacePendingDestroy) {
2472 // We are being called from a local process, which
2473 // means outSurface holds its current surface. Ensure the
2474 // surface object is cleared, but we don't want it actually
2475 // destroyed at this point.
2476 win.mSurfacePendingDestroy = false;
2477 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002479 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002480 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002481 "Keeping surface, will report destroy: " + win);
2482 win.mReportDestroySurface = true;
2483 outSurface.copyFrom(win.mSurface);
2484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 }
2486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 if (focusMayChange) {
2488 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2489 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 imMayMove = false;
2491 }
2492 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2493 }
Romain Guy06882f82009-06-10 13:36:04 -07002494
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002495 // updateFocusedWindowLocked() already assigned layers so we only need to
2496 // reassign them at this point if the IM window state gets shuffled
2497 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002500 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2501 // Little hack here -- we -should- be able to rely on the
2502 // function to return true if the IME has moved and needs
2503 // its layer recomputed. However, if the IME was hidden
2504 // and isn't actually moved in the list, its layer may be
2505 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 assignLayers = true;
2507 }
2508 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002509 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002510 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002511 assignLayers = true;
2512 }
2513 }
Romain Guy06882f82009-06-10 13:36:04 -07002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 mLayoutNeeded = true;
2516 win.mGivenInsetsPending = insetsPending;
2517 if (assignLayers) {
2518 assignLayersLocked();
2519 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002520 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002522 if (displayed && win.mIsWallpaper) {
2523 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002524 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002525 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 if (win.mAppToken != null) {
2527 win.mAppToken.updateReportedVisibilityLocked();
2528 }
2529 outFrame.set(win.mFrame);
2530 outContentInsets.set(win.mContentInsets);
2531 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002532 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002534 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 + ", requestedHeight=" + requestedHeight
2536 + ", viewVisibility=" + viewVisibility
2537 + "\nRelayout returning frame=" + outFrame
2538 + ", surface=" + outSurface);
2539
Joe Onorato8a9b2202010-02-26 18:56:32 -08002540 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2542
2543 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002544
2545 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 }
2547
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002548 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 sendNewConfiguration();
2550 }
Romain Guy06882f82009-06-10 13:36:04 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2555 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2556 }
2557
2558 public void finishDrawingWindow(Session session, IWindow client) {
2559 final long origId = Binder.clearCallingIdentity();
2560 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002561 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002563 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2564 adjustWallpaperWindowsLocked();
2565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 mLayoutNeeded = true;
2567 performLayoutAndPlaceSurfacesLocked();
2568 }
2569 }
2570 Binder.restoreCallingIdentity(origId);
2571 }
2572
2573 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002574 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 + (lp != null ? lp.packageName : null)
2576 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2577 if (lp != null && lp.windowAnimations != 0) {
2578 // If this is a system resource, don't try to load it from the
2579 // application resources. It is nice to avoid loading application
2580 // resources if we can.
2581 String packageName = lp.packageName != null ? lp.packageName : "android";
2582 int resId = lp.windowAnimations;
2583 if ((resId&0xFF000000) == 0x01000000) {
2584 packageName = "android";
2585 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 + packageName);
2588 return AttributeCache.instance().get(packageName, resId,
2589 com.android.internal.R.styleable.WindowAnimation);
2590 }
2591 return null;
2592 }
Romain Guy06882f82009-06-10 13:36:04 -07002593
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002594 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002595 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002596 + packageName + " resId=0x" + Integer.toHexString(resId));
2597 if (packageName != null) {
2598 if ((resId&0xFF000000) == 0x01000000) {
2599 packageName = "android";
2600 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002601 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002602 + packageName);
2603 return AttributeCache.instance().get(packageName, resId,
2604 com.android.internal.R.styleable.WindowAnimation);
2605 }
2606 return null;
2607 }
2608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 private void applyEnterAnimationLocked(WindowState win) {
2610 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2611 if (win.mEnterAnimationPending) {
2612 win.mEnterAnimationPending = false;
2613 transit = WindowManagerPolicy.TRANSIT_ENTER;
2614 }
2615
2616 applyAnimationLocked(win, transit, true);
2617 }
2618
2619 private boolean applyAnimationLocked(WindowState win,
2620 int transit, boolean isEntrance) {
2621 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2622 // If we are trying to apply an animation, but already running
2623 // an animation of the same type, then just leave that one alone.
2624 return true;
2625 }
Romain Guy06882f82009-06-10 13:36:04 -07002626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 // Only apply an animation if the display isn't frozen. If it is
2628 // frozen, there is no reason to animate and it can cause strange
2629 // artifacts when we unfreeze the display if some different animation
2630 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002631 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 int anim = mPolicy.selectAnimationLw(win, transit);
2633 int attr = -1;
2634 Animation a = null;
2635 if (anim != 0) {
2636 a = AnimationUtils.loadAnimation(mContext, anim);
2637 } else {
2638 switch (transit) {
2639 case WindowManagerPolicy.TRANSIT_ENTER:
2640 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2641 break;
2642 case WindowManagerPolicy.TRANSIT_EXIT:
2643 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2644 break;
2645 case WindowManagerPolicy.TRANSIT_SHOW:
2646 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2647 break;
2648 case WindowManagerPolicy.TRANSIT_HIDE:
2649 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2650 break;
2651 }
2652 if (attr >= 0) {
2653 a = loadAnimation(win.mAttrs, attr);
2654 }
2655 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002656 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2658 + " mAnimation=" + win.mAnimation
2659 + " isEntrance=" + isEntrance);
2660 if (a != null) {
2661 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002662 RuntimeException e = null;
2663 if (!HIDE_STACK_CRAWLS) {
2664 e = new RuntimeException();
2665 e.fillInStackTrace();
2666 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002667 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 }
2669 win.setAnimation(a);
2670 win.mAnimationIsEntrance = isEntrance;
2671 }
2672 } else {
2673 win.clearAnimation();
2674 }
2675
2676 return win.mAnimation != null;
2677 }
2678
2679 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2680 int anim = 0;
2681 Context context = mContext;
2682 if (animAttr >= 0) {
2683 AttributeCache.Entry ent = getCachedAnimations(lp);
2684 if (ent != null) {
2685 context = ent.context;
2686 anim = ent.array.getResourceId(animAttr, 0);
2687 }
2688 }
2689 if (anim != 0) {
2690 return AnimationUtils.loadAnimation(context, anim);
2691 }
2692 return null;
2693 }
Romain Guy06882f82009-06-10 13:36:04 -07002694
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002695 private Animation loadAnimation(String packageName, int resId) {
2696 int anim = 0;
2697 Context context = mContext;
2698 if (resId >= 0) {
2699 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2700 if (ent != null) {
2701 context = ent.context;
2702 anim = resId;
2703 }
2704 }
2705 if (anim != 0) {
2706 return AnimationUtils.loadAnimation(context, anim);
2707 }
2708 return null;
2709 }
2710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 private boolean applyAnimationLocked(AppWindowToken wtoken,
2712 WindowManager.LayoutParams lp, int transit, boolean enter) {
2713 // Only apply an animation if the display isn't frozen. If it is
2714 // frozen, there is no reason to animate and it can cause strange
2715 // artifacts when we unfreeze the display if some different animation
2716 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002717 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002718 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002719 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002720 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002721 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002722 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002723 } else if (mNextAppTransitionPackage != null) {
2724 a = loadAnimation(mNextAppTransitionPackage, enter ?
2725 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002726 } else {
2727 int animAttr = 0;
2728 switch (transit) {
2729 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2730 animAttr = enter
2731 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2732 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2733 break;
2734 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2735 animAttr = enter
2736 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2737 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2738 break;
2739 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2740 animAttr = enter
2741 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2742 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2743 break;
2744 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2745 animAttr = enter
2746 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2747 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2748 break;
2749 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2750 animAttr = enter
2751 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2752 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2753 break;
2754 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2755 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002756 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002757 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2758 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002759 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002760 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002761 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2762 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002763 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002764 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002765 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002766 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2767 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2768 break;
2769 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2770 animAttr = enter
2771 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2772 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2773 break;
2774 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2775 animAttr = enter
2776 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2777 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002778 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002779 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002780 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002781 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002782 + " anim=" + a
2783 + " animAttr=0x" + Integer.toHexString(animAttr)
2784 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 if (a != null) {
2787 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002788 RuntimeException e = null;
2789 if (!HIDE_STACK_CRAWLS) {
2790 e = new RuntimeException();
2791 e.fillInStackTrace();
2792 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002793 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 }
2795 wtoken.setAnimation(a);
2796 }
2797 } else {
2798 wtoken.clearAnimation();
2799 }
2800
2801 return wtoken.animation != null;
2802 }
2803
2804 // -------------------------------------------------------------
2805 // Application Window Tokens
2806 // -------------------------------------------------------------
2807
2808 public void validateAppTokens(List tokens) {
2809 int v = tokens.size()-1;
2810 int m = mAppTokens.size()-1;
2811 while (v >= 0 && m >= 0) {
2812 AppWindowToken wtoken = mAppTokens.get(m);
2813 if (wtoken.removed) {
2814 m--;
2815 continue;
2816 }
2817 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002818 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2820 }
2821 v--;
2822 m--;
2823 }
2824 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002825 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 v--;
2827 }
2828 while (m >= 0) {
2829 AppWindowToken wtoken = mAppTokens.get(m);
2830 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002831 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 }
2833 m--;
2834 }
2835 }
2836
2837 boolean checkCallingPermission(String permission, String func) {
2838 // Quick check: if the calling permission is me, it's all okay.
2839 if (Binder.getCallingPid() == Process.myPid()) {
2840 return true;
2841 }
Romain Guy06882f82009-06-10 13:36:04 -07002842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 if (mContext.checkCallingPermission(permission)
2844 == PackageManager.PERMISSION_GRANTED) {
2845 return true;
2846 }
2847 String msg = "Permission Denial: " + func + " from pid="
2848 + Binder.getCallingPid()
2849 + ", uid=" + Binder.getCallingUid()
2850 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002851 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 return false;
2853 }
Romain Guy06882f82009-06-10 13:36:04 -07002854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 AppWindowToken findAppWindowToken(IBinder token) {
2856 WindowToken wtoken = mTokenMap.get(token);
2857 if (wtoken == null) {
2858 return null;
2859 }
2860 return wtoken.appWindowToken;
2861 }
Romain Guy06882f82009-06-10 13:36:04 -07002862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 public void addWindowToken(IBinder token, int type) {
2864 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2865 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002866 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 }
Romain Guy06882f82009-06-10 13:36:04 -07002868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 synchronized(mWindowMap) {
2870 WindowToken wtoken = mTokenMap.get(token);
2871 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002872 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 return;
2874 }
2875 wtoken = new WindowToken(token, type, true);
2876 mTokenMap.put(token, wtoken);
2877 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002878 if (type == TYPE_WALLPAPER) {
2879 mWallpaperTokens.add(wtoken);
2880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 }
2882 }
Romain Guy06882f82009-06-10 13:36:04 -07002883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 public void removeWindowToken(IBinder token) {
2885 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2886 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002887 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 }
2889
2890 final long origId = Binder.clearCallingIdentity();
2891 synchronized(mWindowMap) {
2892 WindowToken wtoken = mTokenMap.remove(token);
2893 mTokenList.remove(wtoken);
2894 if (wtoken != null) {
2895 boolean delayed = false;
2896 if (!wtoken.hidden) {
2897 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 final int N = wtoken.windows.size();
2900 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 for (int i=0; i<N; i++) {
2903 WindowState win = wtoken.windows.get(i);
2904
2905 if (win.isAnimating()) {
2906 delayed = true;
2907 }
Romain Guy06882f82009-06-10 13:36:04 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 if (win.isVisibleNow()) {
2910 applyAnimationLocked(win,
2911 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 changed = true;
2913 }
2914 }
2915
2916 if (changed) {
2917 mLayoutNeeded = true;
2918 performLayoutAndPlaceSurfacesLocked();
2919 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2920 }
Romain Guy06882f82009-06-10 13:36:04 -07002921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 if (delayed) {
2923 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002924 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2925 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 }
2927 }
Romain Guy06882f82009-06-10 13:36:04 -07002928
Jeff Brownc5ed5912010-07-14 18:48:53 -07002929 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002931 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
2933 }
2934 Binder.restoreCallingIdentity(origId);
2935 }
2936
2937 public void addAppToken(int addPos, IApplicationToken token,
2938 int groupId, int requestedOrientation, boolean fullscreen) {
2939 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2940 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002941 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 }
Jeff Brown349703e2010-06-22 01:27:15 -07002943
2944 // Get the dispatching timeout here while we are not holding any locks so that it
2945 // can be cached by the AppWindowToken. The timeout value is used later by the
2946 // input dispatcher in code that does hold locks. If we did not cache the value
2947 // here we would run the chance of introducing a deadlock between the window manager
2948 // (which holds locks while updating the input dispatcher state) and the activity manager
2949 // (which holds locks while querying the application token).
2950 long inputDispatchingTimeoutNanos;
2951 try {
2952 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2953 } catch (RemoteException ex) {
2954 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2955 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2956 }
Romain Guy06882f82009-06-10 13:36:04 -07002957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 synchronized(mWindowMap) {
2959 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2960 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002961 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 return;
2963 }
2964 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002965 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 wtoken.groupId = groupId;
2967 wtoken.appFullscreen = fullscreen;
2968 wtoken.requestedOrientation = requestedOrientation;
2969 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002970 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 mTokenMap.put(token.asBinder(), wtoken);
2972 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 // Application tokens start out hidden.
2975 wtoken.hidden = true;
2976 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 //dump();
2979 }
2980 }
Romain Guy06882f82009-06-10 13:36:04 -07002981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 public void setAppGroupId(IBinder token, int groupId) {
2983 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2984 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002985 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 }
2987
2988 synchronized(mWindowMap) {
2989 AppWindowToken wtoken = findAppWindowToken(token);
2990 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002991 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 return;
2993 }
2994 wtoken.groupId = groupId;
2995 }
2996 }
Romain Guy06882f82009-06-10 13:36:04 -07002997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 public int getOrientationFromWindowsLocked() {
2999 int pos = mWindows.size() - 1;
3000 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003001 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 pos--;
3003 if (wtoken.mAppToken != null) {
3004 // We hit an application window. so the orientation will be determined by the
3005 // app window. No point in continuing further.
3006 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3007 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003008 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 continue;
3010 }
3011 int req = wtoken.mAttrs.screenOrientation;
3012 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3013 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3014 continue;
3015 } else {
3016 return req;
3017 }
3018 }
3019 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3020 }
Romain Guy06882f82009-06-10 13:36:04 -07003021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003023 int pos = mAppTokens.size() - 1;
3024 int curGroup = 0;
3025 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3026 boolean findingBehind = false;
3027 boolean haveGroup = false;
3028 boolean lastFullscreen = false;
3029 while (pos >= 0) {
3030 AppWindowToken wtoken = mAppTokens.get(pos);
3031 pos--;
3032 // if we're about to tear down this window and not seek for
3033 // the behind activity, don't use it for orientation
3034 if (!findingBehind
3035 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3036 continue;
3037 }
3038
3039 if (!haveGroup) {
3040 // We ignore any hidden applications on the top.
3041 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003042 continue;
3043 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003044 haveGroup = true;
3045 curGroup = wtoken.groupId;
3046 lastOrientation = wtoken.requestedOrientation;
3047 } else if (curGroup != wtoken.groupId) {
3048 // If we have hit a new application group, and the bottom
3049 // of the previous group didn't explicitly say to use
3050 // the orientation behind it, and the last app was
3051 // full screen, then we'll stick with the
3052 // user's orientation.
3053 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3054 && lastFullscreen) {
3055 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003058 int or = wtoken.requestedOrientation;
3059 // If this application is fullscreen, and didn't explicitly say
3060 // to use the orientation behind it, then just take whatever
3061 // orientation it has and ignores whatever is under it.
3062 lastFullscreen = wtoken.appFullscreen;
3063 if (lastFullscreen
3064 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3065 return or;
3066 }
3067 // If this application has requested an explicit orientation,
3068 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003069 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3070 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003071 return or;
3072 }
3073 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3074 }
3075 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 }
Romain Guy06882f82009-06-10 13:36:04 -07003077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003079 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003080 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3081 "updateOrientationFromAppTokens()")) {
3082 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3083 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003084
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003085 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003087
3088 synchronized(mWindowMap) {
3089 if (updateOrientationFromAppTokensLocked()) {
3090 if (freezeThisOneIfNeeded != null) {
3091 AppWindowToken wtoken = findAppWindowToken(
3092 freezeThisOneIfNeeded);
3093 if (wtoken != null) {
3094 startAppFreezingScreenLocked(wtoken,
3095 ActivityInfo.CONFIG_ORIENTATION);
3096 }
3097 }
3098 config = computeNewConfigurationLocked();
3099
3100 } else if (currentConfig != null) {
3101 // No obvious action we need to take, but if our current
repo sync . build/envsetup.sh lunch passion-eng4fc3d2f2010-09-27 17:39:50 -07003102 // state mismatches the activity manager's, update it,
3103 // disregarding font scale, which should remain set to
3104 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003105 mTempConfiguration.setToDefaults();
repo sync . build/envsetup.sh lunch passion-eng4fc3d2f2010-09-27 17:39:50 -07003106 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003107 if (computeNewConfigurationLocked(mTempConfiguration)) {
3108 if (currentConfig.diff(mTempConfiguration) != 0) {
3109 mWaitingForConfig = true;
3110 mLayoutNeeded = true;
3111 startFreezingDisplayLocked();
3112 config = new Configuration(mTempConfiguration);
3113 }
3114 }
3115 }
3116 }
3117
Dianne Hackborncfaef692009-06-15 14:24:44 -07003118 Binder.restoreCallingIdentity(ident);
3119 return config;
3120 }
3121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003123 * Determine the new desired orientation of the display, returning
3124 * a non-null new Configuration if it has changed from the current
3125 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3126 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3127 * SCREEN. This will typically be done for you if you call
3128 * sendNewConfiguration().
3129 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 * The orientation is computed from non-application windows first. If none of
3131 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003132 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3134 * android.os.IBinder)
3135 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003136 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003137 if (mDisplayFrozen) {
3138 // If the display is frozen, some activities may be in the middle
3139 // of restarting, and thus have removed their old window. If the
3140 // window has the flag to hide the lock screen, then the lock screen
3141 // can re-appear and inflict its own orientation on us. Keep the
3142 // orientation stable until this all settles down.
3143 return false;
3144 }
3145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 long ident = Binder.clearCallingIdentity();
3148 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003149 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 mForcedAppOrientation = req;
3153 //send a message to Policy indicating orientation change to take
3154 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003155 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003156 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3157 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3158 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 }
3160 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003161
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003162 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 } finally {
3164 Binder.restoreCallingIdentity(ident);
3165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003168 int computeForcedAppOrientationLocked() {
3169 int req = getOrientationFromWindowsLocked();
3170 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3171 req = getOrientationFromAppTokensLocked();
3172 }
3173 return req;
3174 }
Romain Guy06882f82009-06-10 13:36:04 -07003175
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003176 public void setNewConfiguration(Configuration config) {
3177 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3178 "setNewConfiguration()")) {
3179 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3180 }
3181
3182 synchronized(mWindowMap) {
3183 mCurConfiguration = new Configuration(config);
3184 mWaitingForConfig = false;
3185 performLayoutAndPlaceSurfacesLocked();
3186 }
3187 }
3188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3190 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3191 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003192 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 }
Romain Guy06882f82009-06-10 13:36:04 -07003194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 synchronized(mWindowMap) {
3196 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3197 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003198 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 return;
3200 }
Romain Guy06882f82009-06-10 13:36:04 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 wtoken.requestedOrientation = requestedOrientation;
3203 }
3204 }
Romain Guy06882f82009-06-10 13:36:04 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 public int getAppOrientation(IApplicationToken token) {
3207 synchronized(mWindowMap) {
3208 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3209 if (wtoken == null) {
3210 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3211 }
Romain Guy06882f82009-06-10 13:36:04 -07003212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 return wtoken.requestedOrientation;
3214 }
3215 }
Romain Guy06882f82009-06-10 13:36:04 -07003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3218 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3219 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003220 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 }
3222
3223 synchronized(mWindowMap) {
3224 boolean changed = false;
3225 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003226 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 changed = mFocusedApp != null;
3228 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003229 if (changed) {
3230 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 } else {
3233 AppWindowToken newFocus = findAppWindowToken(token);
3234 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003235 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 return;
3237 }
3238 changed = mFocusedApp != newFocus;
3239 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003240 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003241 if (changed) {
3242 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244 }
3245
3246 if (moveFocusNow && changed) {
3247 final long origId = Binder.clearCallingIdentity();
3248 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3249 Binder.restoreCallingIdentity(origId);
3250 }
3251 }
3252 }
3253
3254 public void prepareAppTransition(int transit) {
3255 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3256 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003257 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
Romain Guy06882f82009-06-10 13:36:04 -07003259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003261 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 TAG, "Prepare app transition: transit=" + transit
3263 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003264 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003265 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3266 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003268 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3269 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3270 // Opening a new task always supersedes a close for the anim.
3271 mNextAppTransition = transit;
3272 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3273 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3274 // Opening a new activity always supersedes a close for the anim.
3275 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 }
3277 mAppTransitionReady = false;
3278 mAppTransitionTimeout = false;
3279 mStartingIconInTransition = false;
3280 mSkipAppTransitionAnimation = false;
3281 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3282 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3283 5000);
3284 }
3285 }
3286 }
3287
3288 public int getPendingAppTransition() {
3289 return mNextAppTransition;
3290 }
Romain Guy06882f82009-06-10 13:36:04 -07003291
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003292 public void overridePendingAppTransition(String packageName,
3293 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003294 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003295 mNextAppTransitionPackage = packageName;
3296 mNextAppTransitionEnter = enterAnim;
3297 mNextAppTransitionExit = exitAnim;
3298 }
3299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 public void executeAppTransition() {
3302 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3303 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003304 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 }
Romain Guy06882f82009-06-10 13:36:04 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003308 if (DEBUG_APP_TRANSITIONS) {
3309 RuntimeException e = new RuntimeException("here");
3310 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003312 + mNextAppTransition, e);
3313 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003314 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 mAppTransitionReady = true;
3316 final long origId = Binder.clearCallingIdentity();
3317 performLayoutAndPlaceSurfacesLocked();
3318 Binder.restoreCallingIdentity(origId);
3319 }
3320 }
3321 }
3322
3323 public void setAppStartingWindow(IBinder token, String pkg,
3324 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3325 IBinder transferFrom, boolean createIfNeeded) {
3326 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3327 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003328 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 }
3330
3331 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003332 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3334 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 AppWindowToken wtoken = findAppWindowToken(token);
3337 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003338 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 return;
3340 }
3341
3342 // If the display is frozen, we won't do anything until the
3343 // actual window is displayed so there is no reason to put in
3344 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003345 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 return;
3347 }
Romain Guy06882f82009-06-10 13:36:04 -07003348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 if (wtoken.startingData != null) {
3350 return;
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 if (transferFrom != null) {
3354 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3355 if (ttoken != null) {
3356 WindowState startingWindow = ttoken.startingWindow;
3357 if (startingWindow != null) {
3358 if (mStartingIconInTransition) {
3359 // In this case, the starting icon has already
3360 // been displayed, so start letting windows get
3361 // shown immediately without any more transitions.
3362 mSkipAppTransitionAnimation = true;
3363 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003364 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 "Moving existing starting from " + ttoken
3366 + " to " + wtoken);
3367 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 // Transfer the starting window over to the new
3370 // token.
3371 wtoken.startingData = ttoken.startingData;
3372 wtoken.startingView = ttoken.startingView;
3373 wtoken.startingWindow = startingWindow;
3374 ttoken.startingData = null;
3375 ttoken.startingView = null;
3376 ttoken.startingWindow = null;
3377 ttoken.startingMoved = true;
3378 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003379 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003381 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003382 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003384 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 ttoken.windows.remove(startingWindow);
3386 ttoken.allAppWindows.remove(startingWindow);
3387 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 // Propagate other interesting state between the
3390 // tokens. If the old token is displayed, we should
3391 // immediately force the new one to be displayed. If
3392 // it is animating, we need to move that animation to
3393 // the new one.
3394 if (ttoken.allDrawn) {
3395 wtoken.allDrawn = true;
3396 }
3397 if (ttoken.firstWindowDrawn) {
3398 wtoken.firstWindowDrawn = true;
3399 }
3400 if (!ttoken.hidden) {
3401 wtoken.hidden = false;
3402 wtoken.hiddenRequested = false;
3403 wtoken.willBeHidden = false;
3404 }
3405 if (wtoken.clientHidden != ttoken.clientHidden) {
3406 wtoken.clientHidden = ttoken.clientHidden;
3407 wtoken.sendAppVisibilityToClients();
3408 }
3409 if (ttoken.animation != null) {
3410 wtoken.animation = ttoken.animation;
3411 wtoken.animating = ttoken.animating;
3412 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3413 ttoken.animation = null;
3414 ttoken.animLayerAdjustment = 0;
3415 wtoken.updateLayers();
3416 ttoken.updateLayers();
3417 }
Romain Guy06882f82009-06-10 13:36:04 -07003418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 mLayoutNeeded = true;
3421 performLayoutAndPlaceSurfacesLocked();
3422 Binder.restoreCallingIdentity(origId);
3423 return;
3424 } else if (ttoken.startingData != null) {
3425 // The previous app was getting ready to show a
3426 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003427 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 "Moving pending starting from " + ttoken
3429 + " to " + wtoken);
3430 wtoken.startingData = ttoken.startingData;
3431 ttoken.startingData = null;
3432 ttoken.startingMoved = true;
3433 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3434 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3435 // want to process the message ASAP, before any other queued
3436 // messages.
3437 mH.sendMessageAtFrontOfQueue(m);
3438 return;
3439 }
3440 }
3441 }
3442
3443 // There is no existing starting window, and the caller doesn't
3444 // want us to create one, so that's it!
3445 if (!createIfNeeded) {
3446 return;
3447 }
Romain Guy06882f82009-06-10 13:36:04 -07003448
Dianne Hackborn284ac932009-08-28 10:34:25 -07003449 // If this is a translucent or wallpaper window, then don't
3450 // show a starting window -- the current effect (a full-screen
3451 // opaque starting window that fades away to the real contents
3452 // when it is ready) does not work for this.
3453 if (theme != 0) {
3454 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3455 com.android.internal.R.styleable.Window);
3456 if (ent.array.getBoolean(
3457 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3458 return;
3459 }
3460 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003461 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3462 return;
3463 }
3464 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003465 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3466 return;
3467 }
3468 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 mStartingIconInTransition = true;
3471 wtoken.startingData = new StartingData(
3472 pkg, theme, nonLocalizedLabel,
3473 labelRes, icon);
3474 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3475 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3476 // want to process the message ASAP, before any other queued
3477 // messages.
3478 mH.sendMessageAtFrontOfQueue(m);
3479 }
3480 }
3481
3482 public void setAppWillBeHidden(IBinder token) {
3483 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3484 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003485 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 }
3487
3488 AppWindowToken wtoken;
3489
3490 synchronized(mWindowMap) {
3491 wtoken = findAppWindowToken(token);
3492 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003493 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 -08003494 return;
3495 }
3496 wtoken.willBeHidden = true;
3497 }
3498 }
Romain Guy06882f82009-06-10 13:36:04 -07003499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3501 boolean visible, int transit, boolean performLayout) {
3502 boolean delayed = false;
3503
3504 if (wtoken.clientHidden == visible) {
3505 wtoken.clientHidden = !visible;
3506 wtoken.sendAppVisibilityToClients();
3507 }
Romain Guy06882f82009-06-10 13:36:04 -07003508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 wtoken.willBeHidden = false;
3510 if (wtoken.hidden == visible) {
3511 final int N = wtoken.allAppWindows.size();
3512 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003513 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3515 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003518
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003519 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 if (wtoken.animation == sDummyAnimation) {
3521 wtoken.animation = null;
3522 }
3523 applyAnimationLocked(wtoken, lp, transit, visible);
3524 changed = true;
3525 if (wtoken.animation != null) {
3526 delayed = runningAppAnimation = true;
3527 }
3528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 for (int i=0; i<N; i++) {
3531 WindowState win = wtoken.allAppWindows.get(i);
3532 if (win == wtoken.startingWindow) {
3533 continue;
3534 }
3535
3536 if (win.isAnimating()) {
3537 delayed = true;
3538 }
Romain Guy06882f82009-06-10 13:36:04 -07003539
Joe Onorato8a9b2202010-02-26 18:56:32 -08003540 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 //win.dump(" ");
3542 if (visible) {
3543 if (!win.isVisibleNow()) {
3544 if (!runningAppAnimation) {
3545 applyAnimationLocked(win,
3546 WindowManagerPolicy.TRANSIT_ENTER, true);
3547 }
3548 changed = true;
3549 }
3550 } else if (win.isVisibleNow()) {
3551 if (!runningAppAnimation) {
3552 applyAnimationLocked(win,
3553 WindowManagerPolicy.TRANSIT_EXIT, false);
3554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003555 changed = true;
3556 }
3557 }
3558
3559 wtoken.hidden = wtoken.hiddenRequested = !visible;
3560 if (!visible) {
3561 unsetAppFreezingScreenLocked(wtoken, true, true);
3562 } else {
3563 // If we are being set visible, and the starting window is
3564 // not yet displayed, then make sure it doesn't get displayed.
3565 WindowState swin = wtoken.startingWindow;
3566 if (swin != null && (swin.mDrawPending
3567 || swin.mCommitDrawPending)) {
3568 swin.mPolicyVisibility = false;
3569 swin.mPolicyVisibilityAfterAnim = false;
3570 }
3571 }
Romain Guy06882f82009-06-10 13:36:04 -07003572
Joe Onorato8a9b2202010-02-26 18:56:32 -08003573 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3575 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003576
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003577 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003579 if (performLayout) {
3580 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3581 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003582 } else {
3583 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 }
3586 }
3587
3588 if (wtoken.animation != null) {
3589 delayed = true;
3590 }
Romain Guy06882f82009-06-10 13:36:04 -07003591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 return delayed;
3593 }
3594
3595 public void setAppVisibility(IBinder token, boolean visible) {
3596 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3597 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003598 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 }
3600
3601 AppWindowToken wtoken;
3602
3603 synchronized(mWindowMap) {
3604 wtoken = findAppWindowToken(token);
3605 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003606 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 return;
3608 }
3609
3610 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003611 RuntimeException e = null;
3612 if (!HIDE_STACK_CRAWLS) {
3613 e = new RuntimeException();
3614 e.fillInStackTrace();
3615 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003616 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 + "): mNextAppTransition=" + mNextAppTransition
3618 + " hidden=" + wtoken.hidden
3619 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3620 }
Romain Guy06882f82009-06-10 13:36:04 -07003621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 // If we are preparing an app transition, then delay changing
3623 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003624 if (!mDisplayFrozen && mPolicy.isScreenOn()
3625 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 // Already in requested state, don't do anything more.
3627 if (wtoken.hiddenRequested != visible) {
3628 return;
3629 }
3630 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003631
Joe Onorato8a9b2202010-02-26 18:56:32 -08003632 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 TAG, "Setting dummy animation on: " + wtoken);
3634 wtoken.setDummyAnimation();
3635 mOpeningApps.remove(wtoken);
3636 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003637 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 wtoken.inPendingTransaction = true;
3639 if (visible) {
3640 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 wtoken.startingDisplayed = false;
3642 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003643
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003644 // If the token is currently hidden (should be the
3645 // common case), then we need to set up to wait for
3646 // its windows to be ready.
3647 if (wtoken.hidden) {
3648 wtoken.allDrawn = false;
3649 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003650
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003651 if (wtoken.clientHidden) {
3652 // In the case where we are making an app visible
3653 // but holding off for a transition, we still need
3654 // to tell the client to make its windows visible so
3655 // they get drawn. Otherwise, we will wait on
3656 // performing the transition until all windows have
3657 // been drawn, they never will be, and we are sad.
3658 wtoken.clientHidden = false;
3659 wtoken.sendAppVisibilityToClients();
3660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 }
3662 } else {
3663 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003664
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003665 // If the token is currently visible (should be the
3666 // common case), then set up to wait for it to be hidden.
3667 if (!wtoken.hidden) {
3668 wtoken.waitingToHide = true;
3669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 }
3671 return;
3672 }
Romain Guy06882f82009-06-10 13:36:04 -07003673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003675 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 wtoken.updateReportedVisibilityLocked();
3677 Binder.restoreCallingIdentity(origId);
3678 }
3679 }
3680
3681 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3682 boolean unfreezeSurfaceNow, boolean force) {
3683 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003684 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 + " force=" + force);
3686 final int N = wtoken.allAppWindows.size();
3687 boolean unfrozeWindows = false;
3688 for (int i=0; i<N; i++) {
3689 WindowState w = wtoken.allAppWindows.get(i);
3690 if (w.mAppFreezing) {
3691 w.mAppFreezing = false;
3692 if (w.mSurface != null && !w.mOrientationChanging) {
3693 w.mOrientationChanging = true;
3694 }
3695 unfrozeWindows = true;
3696 }
3697 }
3698 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003699 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 wtoken.freezingScreen = false;
3701 mAppsFreezingScreen--;
3702 }
3703 if (unfreezeSurfaceNow) {
3704 if (unfrozeWindows) {
3705 mLayoutNeeded = true;
3706 performLayoutAndPlaceSurfacesLocked();
3707 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003708 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 }
3710 }
3711 }
Romain Guy06882f82009-06-10 13:36:04 -07003712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3714 int configChanges) {
3715 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003716 RuntimeException e = null;
3717 if (!HIDE_STACK_CRAWLS) {
3718 e = new RuntimeException();
3719 e.fillInStackTrace();
3720 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003721 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 + ": hidden=" + wtoken.hidden + " freezing="
3723 + wtoken.freezingScreen, e);
3724 }
3725 if (!wtoken.hiddenRequested) {
3726 if (!wtoken.freezingScreen) {
3727 wtoken.freezingScreen = true;
3728 mAppsFreezingScreen++;
3729 if (mAppsFreezingScreen == 1) {
3730 startFreezingDisplayLocked();
3731 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3732 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3733 5000);
3734 }
3735 }
3736 final int N = wtoken.allAppWindows.size();
3737 for (int i=0; i<N; i++) {
3738 WindowState w = wtoken.allAppWindows.get(i);
3739 w.mAppFreezing = true;
3740 }
3741 }
3742 }
Romain Guy06882f82009-06-10 13:36:04 -07003743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 public void startAppFreezingScreen(IBinder token, int configChanges) {
3745 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3746 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003747 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 }
3749
3750 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003751 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003752 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 return;
3754 }
Romain Guy06882f82009-06-10 13:36:04 -07003755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 AppWindowToken wtoken = findAppWindowToken(token);
3757 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003758 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 return;
3760 }
3761 final long origId = Binder.clearCallingIdentity();
3762 startAppFreezingScreenLocked(wtoken, configChanges);
3763 Binder.restoreCallingIdentity(origId);
3764 }
3765 }
Romain Guy06882f82009-06-10 13:36:04 -07003766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 public void stopAppFreezingScreen(IBinder token, boolean force) {
3768 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3769 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003770 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 }
3772
3773 synchronized(mWindowMap) {
3774 AppWindowToken wtoken = findAppWindowToken(token);
3775 if (wtoken == null || wtoken.appToken == null) {
3776 return;
3777 }
3778 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003779 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3781 unsetAppFreezingScreenLocked(wtoken, true, force);
3782 Binder.restoreCallingIdentity(origId);
3783 }
3784 }
Romain Guy06882f82009-06-10 13:36:04 -07003785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 public void removeAppToken(IBinder token) {
3787 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3788 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003789 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 }
3791
3792 AppWindowToken wtoken = null;
3793 AppWindowToken startingToken = null;
3794 boolean delayed = false;
3795
3796 final long origId = Binder.clearCallingIdentity();
3797 synchronized(mWindowMap) {
3798 WindowToken basewtoken = mTokenMap.remove(token);
3799 mTokenList.remove(basewtoken);
3800 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003801 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003802 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 wtoken.inPendingTransaction = false;
3804 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003805 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 if (mClosingApps.contains(wtoken)) {
3807 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003808 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003810 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 delayed = true;
3812 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003813 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 TAG, "Removing app " + wtoken + " delayed=" + delayed
3815 + " animation=" + wtoken.animation
3816 + " animating=" + wtoken.animating);
3817 if (delayed) {
3818 // set the token aside because it has an active animation to be finished
3819 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003820 } else {
3821 // Make sure there is no animation running on this token,
3822 // so any windows associated with it will be removed as
3823 // soon as their animations are complete
3824 wtoken.animation = null;
3825 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 }
3827 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003828 if (mLastEnterAnimToken == wtoken) {
3829 mLastEnterAnimToken = null;
3830 mLastEnterAnimParams = null;
3831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 wtoken.removed = true;
3833 if (wtoken.startingData != null) {
3834 startingToken = wtoken;
3835 }
3836 unsetAppFreezingScreenLocked(wtoken, true, true);
3837 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003838 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 mFocusedApp = null;
3840 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003841 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 }
3843 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003844 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 }
Romain Guy06882f82009-06-10 13:36:04 -07003846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 if (!delayed && wtoken != null) {
3848 wtoken.updateReportedVisibilityLocked();
3849 }
3850 }
3851 Binder.restoreCallingIdentity(origId);
3852
3853 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003854 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 + startingToken + ": app token removed");
3856 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3857 mH.sendMessage(m);
3858 }
3859 }
3860
3861 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3862 final int NW = token.windows.size();
3863 for (int i=0; i<NW; i++) {
3864 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003865 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003866 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003867 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 int j = win.mChildWindows.size();
3869 while (j > 0) {
3870 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003871 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003872 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003873 "Tmp removing child window " + cwin);
3874 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 }
3876 }
3877 return NW > 0;
3878 }
3879
3880 void dumpAppTokensLocked() {
3881 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003882 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 }
3884 }
Romain Guy06882f82009-06-10 13:36:04 -07003885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 void dumpWindowsLocked() {
3887 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003888 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 }
3890 }
Romain Guy06882f82009-06-10 13:36:04 -07003891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003892 private int findWindowOffsetLocked(int tokenPos) {
3893 final int NW = mWindows.size();
3894
3895 if (tokenPos >= mAppTokens.size()) {
3896 int i = NW;
3897 while (i > 0) {
3898 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003899 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003900 if (win.getAppToken() != null) {
3901 return i+1;
3902 }
3903 }
3904 }
3905
3906 while (tokenPos > 0) {
3907 // Find the first app token below the new position that has
3908 // a window displayed.
3909 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003910 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003912 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003913 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003914 "Skipping token -- currently sending to bottom");
3915 tokenPos--;
3916 continue;
3917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 int i = wtoken.windows.size();
3919 while (i > 0) {
3920 i--;
3921 WindowState win = wtoken.windows.get(i);
3922 int j = win.mChildWindows.size();
3923 while (j > 0) {
3924 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003925 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003926 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 for (int pos=NW-1; pos>=0; pos--) {
3928 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003929 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 "Found child win @" + (pos+1));
3931 return pos+1;
3932 }
3933 }
3934 }
3935 }
3936 for (int pos=NW-1; pos>=0; pos--) {
3937 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003938 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 return pos+1;
3940 }
3941 }
3942 }
3943 tokenPos--;
3944 }
3945
3946 return 0;
3947 }
3948
3949 private final int reAddWindowLocked(int index, WindowState win) {
3950 final int NCW = win.mChildWindows.size();
3951 boolean added = false;
3952 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003953 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003955 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003956 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 mWindows.add(index, win);
3958 index++;
3959 added = true;
3960 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003961 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003962 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003963 mWindows.add(index, cwin);
3964 index++;
3965 }
3966 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003967 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003968 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 mWindows.add(index, win);
3970 index++;
3971 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003972 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 return index;
3974 }
Romain Guy06882f82009-06-10 13:36:04 -07003975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3977 final int NW = token.windows.size();
3978 for (int i=0; i<NW; i++) {
3979 index = reAddWindowLocked(index, token.windows.get(i));
3980 }
3981 return index;
3982 }
3983
3984 public void moveAppToken(int index, IBinder token) {
3985 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3986 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003987 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 }
3989
3990 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003991 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 if (DEBUG_REORDER) dumpAppTokensLocked();
3993 final AppWindowToken wtoken = findAppWindowToken(token);
3994 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 + token + " (" + wtoken + ")");
3997 return;
3998 }
3999 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004000 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 if (DEBUG_REORDER) dumpWindowsLocked();
4006 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004007 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 if (DEBUG_REORDER) dumpWindowsLocked();
4009 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 if (DEBUG_REORDER) dumpWindowsLocked();
4012 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 mLayoutNeeded = true;
4014 performLayoutAndPlaceSurfacesLocked();
4015 }
4016 Binder.restoreCallingIdentity(origId);
4017 }
4018 }
4019
4020 private void removeAppTokensLocked(List<IBinder> tokens) {
4021 // XXX This should be done more efficiently!
4022 // (take advantage of the fact that both lists should be
4023 // ordered in the same way.)
4024 int N = tokens.size();
4025 for (int i=0; i<N; i++) {
4026 IBinder token = tokens.get(i);
4027 final AppWindowToken wtoken = findAppWindowToken(token);
4028 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004029 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 + token + " (" + wtoken + ")");
4031 i--;
4032 N--;
4033 }
4034 }
4035 }
4036
Dianne Hackborna8f60182009-09-01 19:01:50 -07004037 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4038 boolean updateFocusAndLayout) {
4039 // First remove all of the windows from the list.
4040 tmpRemoveAppWindowsLocked(wtoken);
4041
4042 // Where to start adding?
4043 int pos = findWindowOffsetLocked(tokenPos);
4044
4045 // And now add them back at the correct place.
4046 pos = reAddAppWindowsLocked(pos, wtoken);
4047
4048 if (updateFocusAndLayout) {
4049 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4050 assignLayersLocked();
4051 }
4052 mLayoutNeeded = true;
4053 performLayoutAndPlaceSurfacesLocked();
4054 }
4055 }
4056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4058 // First remove all of the windows from the list.
4059 final int N = tokens.size();
4060 int i;
4061 for (i=0; i<N; i++) {
4062 WindowToken token = mTokenMap.get(tokens.get(i));
4063 if (token != null) {
4064 tmpRemoveAppWindowsLocked(token);
4065 }
4066 }
4067
4068 // Where to start adding?
4069 int pos = findWindowOffsetLocked(tokenPos);
4070
4071 // And now add them back at the correct place.
4072 for (i=0; i<N; i++) {
4073 WindowToken token = mTokenMap.get(tokens.get(i));
4074 if (token != null) {
4075 pos = reAddAppWindowsLocked(pos, token);
4076 }
4077 }
4078
Dianne Hackborna8f60182009-09-01 19:01:50 -07004079 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4080 assignLayersLocked();
4081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 mLayoutNeeded = true;
4083 performLayoutAndPlaceSurfacesLocked();
4084
4085 //dump();
4086 }
4087
4088 public void moveAppTokensToTop(List<IBinder> tokens) {
4089 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4090 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004091 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 }
4093
4094 final long origId = Binder.clearCallingIdentity();
4095 synchronized(mWindowMap) {
4096 removeAppTokensLocked(tokens);
4097 final int N = tokens.size();
4098 for (int i=0; i<N; i++) {
4099 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4100 if (wt != null) {
4101 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004102 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004103 mToTopApps.remove(wt);
4104 mToBottomApps.remove(wt);
4105 mToTopApps.add(wt);
4106 wt.sendingToBottom = false;
4107 wt.sendingToTop = true;
4108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004109 }
4110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004111
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004112 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004113 moveAppWindowsLocked(tokens, mAppTokens.size());
4114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 }
4116 Binder.restoreCallingIdentity(origId);
4117 }
4118
4119 public void moveAppTokensToBottom(List<IBinder> tokens) {
4120 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4121 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004122 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 }
4124
4125 final long origId = Binder.clearCallingIdentity();
4126 synchronized(mWindowMap) {
4127 removeAppTokensLocked(tokens);
4128 final int N = tokens.size();
4129 int pos = 0;
4130 for (int i=0; i<N; i++) {
4131 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4132 if (wt != null) {
4133 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004134 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004135 mToTopApps.remove(wt);
4136 mToBottomApps.remove(wt);
4137 mToBottomApps.add(i, wt);
4138 wt.sendingToTop = false;
4139 wt.sendingToBottom = true;
4140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 pos++;
4142 }
4143 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004144
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004145 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004146 moveAppWindowsLocked(tokens, 0);
4147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004148 }
4149 Binder.restoreCallingIdentity(origId);
4150 }
4151
4152 // -------------------------------------------------------------
4153 // Misc IWindowSession methods
4154 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004155
Jim Miller284b62e2010-06-08 14:27:42 -07004156 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004157 {
Jim Miller284b62e2010-06-08 14:27:42 -07004158 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4159 // called before DevicePolicyManagerService has started.
4160 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4161 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4162 Context.DEVICE_POLICY_SERVICE);
4163 if (dpm != null) {
4164 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4165 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4166 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4167 }
Jim Millerd6b57052010-06-07 17:52:42 -07004168 }
Jim Miller284b62e2010-06-08 14:27:42 -07004169 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004170 }
4171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004173 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 != PackageManager.PERMISSION_GRANTED) {
4175 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4176 }
Jim Millerd6b57052010-06-07 17:52:42 -07004177
Jim Miller284b62e2010-06-08 14:27:42 -07004178 synchronized (mKeyguardTokenWatcher) {
4179 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 }
4182
4183 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004184 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 != PackageManager.PERMISSION_GRANTED) {
4186 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188
Jim Miller284b62e2010-06-08 14:27:42 -07004189 synchronized (mKeyguardTokenWatcher) {
4190 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004191
Jim Miller284b62e2010-06-08 14:27:42 -07004192 if (!mKeyguardTokenWatcher.isAcquired()) {
4193 // If we are the last one to reenable the keyguard wait until
4194 // we have actually finished reenabling until returning.
4195 // It is possible that reenableKeyguard() can be called before
4196 // the previous disableKeyguard() is handled, in which case
4197 // neither mKeyguardTokenWatcher.acquired() or released() would
4198 // be called. In that case mKeyguardDisabled will be false here
4199 // and we have nothing to wait for.
4200 while (mKeyguardDisabled) {
4201 try {
4202 mKeyguardTokenWatcher.wait();
4203 } catch (InterruptedException e) {
4204 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 }
4206 }
4207 }
4208 }
4209 }
4210
4211 /**
4212 * @see android.app.KeyguardManager#exitKeyguardSecurely
4213 */
4214 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004215 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 != PackageManager.PERMISSION_GRANTED) {
4217 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4218 }
4219 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4220 public void onKeyguardExitResult(boolean success) {
4221 try {
4222 callback.onKeyguardExitResult(success);
4223 } catch (RemoteException e) {
4224 // Client has died, we don't care.
4225 }
4226 }
4227 });
4228 }
4229
4230 public boolean inKeyguardRestrictedInputMode() {
4231 return mPolicy.inKeyguardRestrictedKeyInputMode();
4232 }
Romain Guy06882f82009-06-10 13:36:04 -07004233
Dianne Hackbornffa42482009-09-23 22:20:11 -07004234 public void closeSystemDialogs(String reason) {
4235 synchronized(mWindowMap) {
4236 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004237 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004238 if (w.mSurface != null) {
4239 try {
4240 w.mClient.closeSystemDialogs(reason);
4241 } catch (RemoteException e) {
4242 }
4243 }
4244 }
4245 }
4246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 static float fixScale(float scale) {
4249 if (scale < 0) scale = 0;
4250 else if (scale > 20) scale = 20;
4251 return Math.abs(scale);
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 public void setAnimationScale(int which, float scale) {
4255 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4256 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004257 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
4259
4260 if (scale < 0) scale = 0;
4261 else if (scale > 20) scale = 20;
4262 scale = Math.abs(scale);
4263 switch (which) {
4264 case 0: mWindowAnimationScale = fixScale(scale); break;
4265 case 1: mTransitionAnimationScale = fixScale(scale); break;
4266 }
Romain Guy06882f82009-06-10 13:36:04 -07004267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 // Persist setting
4269 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4270 }
Romain Guy06882f82009-06-10 13:36:04 -07004271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 public void setAnimationScales(float[] scales) {
4273 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4274 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004275 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 }
4277
4278 if (scales != null) {
4279 if (scales.length >= 1) {
4280 mWindowAnimationScale = fixScale(scales[0]);
4281 }
4282 if (scales.length >= 2) {
4283 mTransitionAnimationScale = fixScale(scales[1]);
4284 }
4285 }
Romain Guy06882f82009-06-10 13:36:04 -07004286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 // Persist setting
4288 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 public float getAnimationScale(int which) {
4292 switch (which) {
4293 case 0: return mWindowAnimationScale;
4294 case 1: return mTransitionAnimationScale;
4295 }
4296 return 0;
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 public float[] getAnimationScales() {
4300 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public int getSwitchState(int sw) {
4304 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4305 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004306 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004308 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
Romain Guy06882f82009-06-10 13:36:04 -07004310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 public int getSwitchStateForDevice(int devid, int sw) {
4312 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4313 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004314 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004316 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Romain Guy06882f82009-06-10 13:36:04 -07004318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 public int getScancodeState(int sw) {
4320 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4321 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004322 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004324 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Romain Guy06882f82009-06-10 13:36:04 -07004326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 public int getScancodeStateForDevice(int devid, int sw) {
4328 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4329 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004330 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004332 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
Romain Guy06882f82009-06-10 13:36:04 -07004334
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004335 public int getTrackballScancodeState(int sw) {
4336 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4337 "getTrackballScancodeState()")) {
4338 throw new SecurityException("Requires READ_INPUT_STATE permission");
4339 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004340 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004341 }
4342
4343 public int getDPadScancodeState(int sw) {
4344 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4345 "getDPadScancodeState()")) {
4346 throw new SecurityException("Requires READ_INPUT_STATE permission");
4347 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004348 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004349 }
4350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 public int getKeycodeState(int sw) {
4352 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4353 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004354 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004356 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Romain Guy06882f82009-06-10 13:36:04 -07004358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 public int getKeycodeStateForDevice(int devid, int sw) {
4360 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4361 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004362 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004364 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
Romain Guy06882f82009-06-10 13:36:04 -07004366
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004367 public int getTrackballKeycodeState(int sw) {
4368 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4369 "getTrackballKeycodeState()")) {
4370 throw new SecurityException("Requires READ_INPUT_STATE permission");
4371 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004372 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004373 }
4374
4375 public int getDPadKeycodeState(int sw) {
4376 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4377 "getDPadKeycodeState()")) {
4378 throw new SecurityException("Requires READ_INPUT_STATE permission");
4379 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004380 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004381 }
Jeff Browna41ca772010-08-11 14:46:32 -07004382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004384 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 }
Romain Guy06882f82009-06-10 13:36:04 -07004386
Jeff Browna41ca772010-08-11 14:46:32 -07004387 public InputChannel monitorInput(String inputChannelName) {
4388 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4389 "monitorInput()")) {
4390 throw new SecurityException("Requires READ_INPUT_STATE permission");
4391 }
4392 return mInputManager.monitorInput(inputChannelName);
4393 }
4394
Jeff Brown8d608662010-08-30 03:02:23 -07004395 public InputDevice getInputDevice(int deviceId) {
4396 return mInputManager.getInputDevice(deviceId);
4397 }
4398
4399 public int[] getInputDeviceIds() {
4400 return mInputManager.getInputDeviceIds();
4401 }
4402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 public void enableScreenAfterBoot() {
4404 synchronized(mWindowMap) {
4405 if (mSystemBooted) {
4406 return;
4407 }
4408 mSystemBooted = true;
4409 }
Romain Guy06882f82009-06-10 13:36:04 -07004410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 performEnableScreen();
4412 }
Romain Guy06882f82009-06-10 13:36:04 -07004413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004414 public void enableScreenIfNeededLocked() {
4415 if (mDisplayEnabled) {
4416 return;
4417 }
4418 if (!mSystemBooted) {
4419 return;
4420 }
4421 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4422 }
Romain Guy06882f82009-06-10 13:36:04 -07004423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 public void performEnableScreen() {
4425 synchronized(mWindowMap) {
4426 if (mDisplayEnabled) {
4427 return;
4428 }
4429 if (!mSystemBooted) {
4430 return;
4431 }
Romain Guy06882f82009-06-10 13:36:04 -07004432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 // Don't enable the screen until all existing windows
4434 // have been drawn.
4435 final int N = mWindows.size();
4436 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004437 WindowState w = mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004438 if (w.isVisibleLw() && !w.mObscured
4439 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 return;
4441 }
4442 }
Romain Guy06882f82009-06-10 13:36:04 -07004443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 mDisplayEnabled = true;
4445 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004446 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 StringWriter sw = new StringWriter();
4448 PrintWriter pw = new PrintWriter(sw);
4449 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004450 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 }
4452 try {
4453 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4454 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004455 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 Parcel data = Parcel.obtain();
4457 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4458 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4459 data, null, 0);
4460 data.recycle();
4461 }
4462 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004463 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 }
4465 }
Romain Guy06882f82009-06-10 13:36:04 -07004466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004470 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4471 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
Romain Guy06882f82009-06-10 13:36:04 -07004473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 public void setInTouchMode(boolean mode) {
4475 synchronized(mWindowMap) {
4476 mInTouchMode = mode;
4477 }
4478 }
4479
Romain Guy06882f82009-06-10 13:36:04 -07004480 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004481 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004483 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004484 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 }
4486
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004487 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 }
Romain Guy06882f82009-06-10 13:36:04 -07004489
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004490 public void setRotationUnchecked(int rotation,
4491 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004492 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004493 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 long origId = Binder.clearCallingIdentity();
4496 boolean changed;
4497 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004498 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 }
Romain Guy06882f82009-06-10 13:36:04 -07004500
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004501 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 sendNewConfiguration();
4503 }
Romain Guy06882f82009-06-10 13:36:04 -07004504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 Binder.restoreCallingIdentity(origId);
4506 }
Romain Guy06882f82009-06-10 13:36:04 -07004507
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004508 /**
4509 * Apply a new rotation to the screen, respecting the requests of
4510 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4511 * re-evaluate the desired rotation.
4512 *
4513 * Returns null if the rotation has been changed. In this case YOU
4514 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4515 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004516 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 boolean changed;
4518 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4519 rotation = mRequestedRotation;
4520 } else {
4521 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004522 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004524 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004525 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004526 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004527 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004531 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 "Rotation changed to " + rotation
4533 + " from " + mRotation
4534 + " (forceApp=" + mForcedAppOrientation
4535 + ", req=" + mRequestedRotation + ")");
4536 mRotation = rotation;
4537 mWindowsFreezingScreen = true;
4538 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4539 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4540 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004541 mWaitingForConfig = true;
4542 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004544 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004545 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004546 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004547 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 }
4549 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004550 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551 if (w.mSurface != null) {
4552 w.mOrientationChanging = true;
4553 }
4554 }
4555 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4556 try {
4557 mRotationWatchers.get(i).onRotationChanged(rotation);
4558 } catch (RemoteException e) {
4559 }
4560 }
4561 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004563 return changed;
4564 }
Romain Guy06882f82009-06-10 13:36:04 -07004565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004566 public int getRotation() {
4567 return mRotation;
4568 }
4569
4570 public int watchRotation(IRotationWatcher watcher) {
4571 final IBinder watcherBinder = watcher.asBinder();
4572 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4573 public void binderDied() {
4574 synchronized (mWindowMap) {
4575 for (int i=0; i<mRotationWatchers.size(); i++) {
4576 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004577 IRotationWatcher removed = mRotationWatchers.remove(i);
4578 if (removed != null) {
4579 removed.asBinder().unlinkToDeath(this, 0);
4580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 i--;
4582 }
4583 }
4584 }
4585 }
4586 };
Romain Guy06882f82009-06-10 13:36:04 -07004587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 synchronized (mWindowMap) {
4589 try {
4590 watcher.asBinder().linkToDeath(dr, 0);
4591 mRotationWatchers.add(watcher);
4592 } catch (RemoteException e) {
4593 // Client died, no cleanup needed.
4594 }
Romain Guy06882f82009-06-10 13:36:04 -07004595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 return mRotation;
4597 }
4598 }
4599
4600 /**
4601 * Starts the view server on the specified port.
4602 *
4603 * @param port The port to listener to.
4604 *
4605 * @return True if the server was successfully started, false otherwise.
4606 *
4607 * @see com.android.server.ViewServer
4608 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4609 */
4610 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004611 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 return false;
4613 }
4614
4615 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4616 return false;
4617 }
4618
4619 if (port < 1024) {
4620 return false;
4621 }
4622
4623 if (mViewServer != null) {
4624 if (!mViewServer.isRunning()) {
4625 try {
4626 return mViewServer.start();
4627 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004628 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 }
4630 }
4631 return false;
4632 }
4633
4634 try {
4635 mViewServer = new ViewServer(this, port);
4636 return mViewServer.start();
4637 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004638 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 }
4640 return false;
4641 }
4642
Romain Guy06882f82009-06-10 13:36:04 -07004643 private boolean isSystemSecure() {
4644 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4645 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4646 }
4647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004648 /**
4649 * Stops the view server if it exists.
4650 *
4651 * @return True if the server stopped, false if it wasn't started or
4652 * couldn't be stopped.
4653 *
4654 * @see com.android.server.ViewServer
4655 */
4656 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004657 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 return false;
4659 }
4660
4661 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4662 return false;
4663 }
4664
4665 if (mViewServer != null) {
4666 return mViewServer.stop();
4667 }
4668 return false;
4669 }
4670
4671 /**
4672 * Indicates whether the view server is running.
4673 *
4674 * @return True if the server is running, false otherwise.
4675 *
4676 * @see com.android.server.ViewServer
4677 */
4678 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004679 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 return false;
4681 }
4682
4683 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4684 return false;
4685 }
4686
4687 return mViewServer != null && mViewServer.isRunning();
4688 }
4689
4690 /**
4691 * Lists all availble windows in the system. The listing is written in the
4692 * specified Socket's output stream with the following syntax:
4693 * windowHashCodeInHexadecimal windowName
4694 * Each line of the ouput represents a different window.
4695 *
4696 * @param client The remote client to send the listing to.
4697 * @return False if an error occured, true otherwise.
4698 */
4699 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004700 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004701 return false;
4702 }
4703
4704 boolean result = true;
4705
Jeff Browne33348b2010-07-15 23:54:05 -07004706 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004708 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004709 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 }
4711
4712 BufferedWriter out = null;
4713
4714 // Any uncaught exception will crash the system process
4715 try {
4716 OutputStream clientStream = client.getOutputStream();
4717 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4718
4719 final int count = windows.length;
4720 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004721 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 out.write(Integer.toHexString(System.identityHashCode(w)));
4723 out.write(' ');
4724 out.append(w.mAttrs.getTitle());
4725 out.write('\n');
4726 }
4727
4728 out.write("DONE.\n");
4729 out.flush();
4730 } catch (Exception e) {
4731 result = false;
4732 } finally {
4733 if (out != null) {
4734 try {
4735 out.close();
4736 } catch (IOException e) {
4737 result = false;
4738 }
4739 }
4740 }
4741
4742 return result;
4743 }
4744
4745 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004746 * Returns the focused window in the following format:
4747 * windowHashCodeInHexadecimal windowName
4748 *
4749 * @param client The remote client to send the listing to.
4750 * @return False if an error occurred, true otherwise.
4751 */
4752 boolean viewServerGetFocusedWindow(Socket client) {
4753 if (isSystemSecure()) {
4754 return false;
4755 }
4756
4757 boolean result = true;
4758
4759 WindowState focusedWindow = getFocusedWindow();
4760
4761 BufferedWriter out = null;
4762
4763 // Any uncaught exception will crash the system process
4764 try {
4765 OutputStream clientStream = client.getOutputStream();
4766 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4767
4768 if(focusedWindow != null) {
4769 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4770 out.write(' ');
4771 out.append(focusedWindow.mAttrs.getTitle());
4772 }
4773 out.write('\n');
4774 out.flush();
4775 } catch (Exception e) {
4776 result = false;
4777 } finally {
4778 if (out != null) {
4779 try {
4780 out.close();
4781 } catch (IOException e) {
4782 result = false;
4783 }
4784 }
4785 }
4786
4787 return result;
4788 }
4789
4790 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004791 * Sends a command to a target window. The result of the command, if any, will be
4792 * written in the output stream of the specified socket.
4793 *
4794 * The parameters must follow this syntax:
4795 * windowHashcode extra
4796 *
4797 * Where XX is the length in characeters of the windowTitle.
4798 *
4799 * The first parameter is the target window. The window with the specified hashcode
4800 * will be the target. If no target can be found, nothing happens. The extra parameters
4801 * will be delivered to the target window and as parameters to the command itself.
4802 *
4803 * @param client The remote client to sent the result, if any, to.
4804 * @param command The command to execute.
4805 * @param parameters The command parameters.
4806 *
4807 * @return True if the command was successfully delivered, false otherwise. This does
4808 * not indicate whether the command itself was successful.
4809 */
4810 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004811 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 return false;
4813 }
4814
4815 boolean success = true;
4816 Parcel data = null;
4817 Parcel reply = null;
4818
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004819 BufferedWriter out = null;
4820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 // Any uncaught exception will crash the system process
4822 try {
4823 // Find the hashcode of the window
4824 int index = parameters.indexOf(' ');
4825 if (index == -1) {
4826 index = parameters.length();
4827 }
4828 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004829 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830
4831 // Extract the command's parameter after the window description
4832 if (index < parameters.length()) {
4833 parameters = parameters.substring(index + 1);
4834 } else {
4835 parameters = "";
4836 }
4837
4838 final WindowManagerService.WindowState window = findWindow(hashCode);
4839 if (window == null) {
4840 return false;
4841 }
4842
4843 data = Parcel.obtain();
4844 data.writeInterfaceToken("android.view.IWindow");
4845 data.writeString(command);
4846 data.writeString(parameters);
4847 data.writeInt(1);
4848 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4849
4850 reply = Parcel.obtain();
4851
4852 final IBinder binder = window.mClient.asBinder();
4853 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4854 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4855
4856 reply.readException();
4857
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004858 if (!client.isOutputShutdown()) {
4859 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
4860 out.write("DONE\n");
4861 out.flush();
4862 }
4863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004865 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 success = false;
4867 } finally {
4868 if (data != null) {
4869 data.recycle();
4870 }
4871 if (reply != null) {
4872 reply.recycle();
4873 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004874 if (out != null) {
4875 try {
4876 out.close();
4877 } catch (IOException e) {
4878
4879 }
4880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 }
4882
4883 return success;
4884 }
4885
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004886 public void addWindowChangeListener(WindowChangeListener listener) {
4887 synchronized(mWindowMap) {
4888 mWindowChangeListeners.add(listener);
4889 }
4890 }
4891
4892 public void removeWindowChangeListener(WindowChangeListener listener) {
4893 synchronized(mWindowMap) {
4894 mWindowChangeListeners.remove(listener);
4895 }
4896 }
4897
4898 private void notifyWindowsChanged() {
4899 WindowChangeListener[] windowChangeListeners;
4900 synchronized(mWindowMap) {
4901 if(mWindowChangeListeners.isEmpty()) {
4902 return;
4903 }
4904 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4905 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4906 }
4907 int N = windowChangeListeners.length;
4908 for(int i = 0; i < N; i++) {
4909 windowChangeListeners[i].windowsChanged();
4910 }
4911 }
4912
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004913 private void notifyFocusChanged() {
4914 WindowChangeListener[] windowChangeListeners;
4915 synchronized(mWindowMap) {
4916 if(mWindowChangeListeners.isEmpty()) {
4917 return;
4918 }
4919 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4920 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4921 }
4922 int N = windowChangeListeners.length;
4923 for(int i = 0; i < N; i++) {
4924 windowChangeListeners[i].focusChanged();
4925 }
4926 }
4927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 private WindowState findWindow(int hashCode) {
4929 if (hashCode == -1) {
4930 return getFocusedWindow();
4931 }
4932
4933 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004934 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 final int count = windows.size();
4936
4937 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004938 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 if (System.identityHashCode(w) == hashCode) {
4940 return w;
4941 }
4942 }
4943 }
4944
4945 return null;
4946 }
4947
4948 /*
4949 * Instruct the Activity Manager to fetch the current configuration and broadcast
4950 * that to config-changed listeners if appropriate.
4951 */
4952 void sendNewConfiguration() {
4953 try {
4954 mActivityManager.updateConfiguration(null);
4955 } catch (RemoteException e) {
4956 }
4957 }
Romain Guy06882f82009-06-10 13:36:04 -07004958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 public Configuration computeNewConfiguration() {
4960 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004961 return computeNewConfigurationLocked();
4962 }
4963 }
Romain Guy06882f82009-06-10 13:36:04 -07004964
Dianne Hackbornc485a602009-03-24 22:39:49 -07004965 Configuration computeNewConfigurationLocked() {
4966 Configuration config = new Configuration();
4967 if (!computeNewConfigurationLocked(config)) {
4968 return null;
4969 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004970 return config;
4971 }
Romain Guy06882f82009-06-10 13:36:04 -07004972
Dianne Hackbornc485a602009-03-24 22:39:49 -07004973 boolean computeNewConfigurationLocked(Configuration config) {
4974 if (mDisplay == null) {
4975 return false;
4976 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004977
4978 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004979
4980 // Use the effective "visual" dimensions based on current rotation
4981 final boolean rotated = (mRotation == Surface.ROTATION_90
4982 || mRotation == Surface.ROTATION_270);
4983 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4984 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4985
Dianne Hackbornc485a602009-03-24 22:39:49 -07004986 int orientation = Configuration.ORIENTATION_SQUARE;
4987 if (dw < dh) {
4988 orientation = Configuration.ORIENTATION_PORTRAIT;
4989 } else if (dw > dh) {
4990 orientation = Configuration.ORIENTATION_LANDSCAPE;
4991 }
4992 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004993
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004994 DisplayMetrics dm = new DisplayMetrics();
4995 mDisplay.getMetrics(dm);
4996 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4997
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004998 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004999 // Note we only do this once because at this point we don't
5000 // expect the screen to change in this way at runtime, and want
5001 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005002 int longSize = dw;
5003 int shortSize = dh;
5004 if (longSize < shortSize) {
5005 int tmp = longSize;
5006 longSize = shortSize;
5007 shortSize = tmp;
5008 }
5009 longSize = (int)(longSize/dm.density);
5010 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005011
Dianne Hackborn723738c2009-06-25 19:48:04 -07005012 // These semi-magic numbers define our compatibility modes for
5013 // applications with different screens. Don't change unless you
5014 // make sure to test lots and lots of apps!
5015 if (longSize < 470) {
5016 // This is shorter than an HVGA normal density screen (which
5017 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005018 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5019 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005020 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005021 // What size is this screen screen?
5022 if (longSize >= 800 && shortSize >= 600) {
5023 // SVGA or larger screens at medium density are the point
5024 // at which we consider it to be an extra large screen.
5025 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005026 } else if (longSize >= 530 && shortSize >= 400) {
5027 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005028 // at which we consider it to be a large screen.
5029 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5030 } else {
5031 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborn726318b2011-01-29 13:22:02 -08005032 }
5033
5034 // If this screen is wider than normal HVGA, or taller
5035 // than FWVGA, then for old apps we want to run in size
5036 // compatibility mode.
5037 if (shortSize > 321 || longSize > 570) {
5038 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005039 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005040
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005041 // Is this a long screen?
5042 if (((longSize*3)/5) >= (shortSize-1)) {
5043 // Anything wider than WVGA (5:3) is considering to be long.
5044 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5045 } else {
5046 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5047 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005048 }
5049 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005050 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005051
Dianne Hackbornc485a602009-03-24 22:39:49 -07005052 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5053 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5054 mPolicy.adjustConfigurationLw(config);
5055 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005056 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005058 // -------------------------------------------------------------
5059 // Input Events and Focus Management
5060 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005061
Jeff Brown349703e2010-06-22 01:27:15 -07005062 InputMonitor mInputMonitor = new InputMonitor();
5063
5064 /* Tracks the progress of input dispatch and ensures that input dispatch state
5065 * is kept in sync with changes in window focus, visibility, registration, and
5066 * other relevant Window Manager state transitions. */
5067 final class InputMonitor {
5068 // Current window with input focus for keys and other non-touch events. May be null.
5069 private WindowState mInputFocus;
5070
5071 // When true, prevents input dispatch from proceeding until set to false again.
5072 private boolean mInputDispatchFrozen;
5073
5074 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5075 private boolean mInputDispatchEnabled = true;
5076
5077 // Temporary list of windows information to provide to the input dispatcher.
5078 private InputWindowList mTempInputWindows = new InputWindowList();
5079
5080 // Temporary input application object to provide to the input dispatcher.
5081 private InputApplication mTempInputApplication = new InputApplication();
5082
5083 /* Notifies the window manager about a broken input channel.
5084 *
5085 * Called by the InputManager.
5086 */
5087 public void notifyInputChannelBroken(InputChannel inputChannel) {
5088 synchronized (mWindowMap) {
5089 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5090 if (windowState == null) {
5091 return; // irrelevant
5092 }
5093
5094 Slog.i(TAG, "WINDOW DIED " + windowState);
5095 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005096 }
5097 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005098
Jeff Brown519e0242010-09-15 15:18:56 -07005099 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005100 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005101 *
5102 * Called by the InputManager.
5103 */
Jeff Brown519e0242010-09-15 15:18:56 -07005104 public long notifyANR(Object token, InputChannel inputChannel) {
5105 AppWindowToken appWindowToken = null;
5106 if (inputChannel != null) {
5107 synchronized (mWindowMap) {
5108 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5109 if (windowState != null) {
5110 Slog.i(TAG, "Input event dispatching timed out sending to "
5111 + windowState.mAttrs.getTitle());
5112 appWindowToken = windowState.mAppToken;
5113 }
Jeff Brown349703e2010-06-22 01:27:15 -07005114 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005115 }
5116
Jeff Brown519e0242010-09-15 15:18:56 -07005117 if (appWindowToken == null && token != null) {
5118 appWindowToken = (AppWindowToken) token;
5119 Slog.i(TAG, "Input event dispatching timed out sending to application "
5120 + appWindowToken.stringName);
5121 }
Jeff Brown349703e2010-06-22 01:27:15 -07005122
Jeff Brown519e0242010-09-15 15:18:56 -07005123 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005124 try {
5125 // Notify the activity manager about the timeout and let it decide whether
5126 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005127 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005128 if (! abort) {
5129 // The activity manager declined to abort dispatching.
5130 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005131 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005132 }
Jeff Brown349703e2010-06-22 01:27:15 -07005133 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005134 }
5135 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005136 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005137 }
5138
Jeff Brown349703e2010-06-22 01:27:15 -07005139 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5140 synchronized (mWindowMap) {
5141 return getWindowStateForInputChannelLocked(inputChannel);
5142 }
5143 }
5144
5145 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5146 int windowCount = mWindows.size();
5147 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005148 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005149 if (windowState.mInputChannel == inputChannel) {
5150 return windowState;
5151 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005152 }
5153
Jeff Brown349703e2010-06-22 01:27:15 -07005154 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005155 }
5156
Jeff Brown349703e2010-06-22 01:27:15 -07005157 /* Updates the cached window information provided to the input dispatcher. */
5158 public void updateInputWindowsLw() {
5159 // Populate the input window list with information about all of the windows that
5160 // could potentially receive input.
5161 // As an optimization, we could try to prune the list of windows but this turns
5162 // out to be difficult because only the native code knows for sure which window
5163 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005164 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005165 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005166 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005167 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005168 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005169 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005170 continue;
5171 }
5172
Jeff Brown349703e2010-06-22 01:27:15 -07005173 final int flags = child.mAttrs.flags;
5174 final int type = child.mAttrs.type;
5175
5176 final boolean hasFocus = (child == mInputFocus);
5177 final boolean isVisible = child.isVisibleLw();
5178 final boolean hasWallpaper = (child == mWallpaperTarget)
5179 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5180
5181 // Add a window to our list of input windows.
5182 final InputWindow inputWindow = mTempInputWindows.add();
5183 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005184 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005185 inputWindow.layoutParamsFlags = flags;
5186 inputWindow.layoutParamsType = type;
5187 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5188 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005189 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005190 inputWindow.hasFocus = hasFocus;
5191 inputWindow.hasWallpaper = hasWallpaper;
5192 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005193 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005194 inputWindow.ownerPid = child.mSession.mPid;
5195 inputWindow.ownerUid = child.mSession.mUid;
5196
5197 final Rect frame = child.mFrame;
5198 inputWindow.frameLeft = frame.left;
5199 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005200 inputWindow.frameRight = frame.right;
5201 inputWindow.frameBottom = frame.bottom;
5202
5203 final Rect visibleFrame = child.mVisibleFrame;
5204 inputWindow.visibleFrameLeft = visibleFrame.left;
5205 inputWindow.visibleFrameTop = visibleFrame.top;
5206 inputWindow.visibleFrameRight = visibleFrame.right;
5207 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005208
5209 switch (child.mTouchableInsets) {
5210 default:
5211 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5212 inputWindow.touchableAreaLeft = frame.left;
5213 inputWindow.touchableAreaTop = frame.top;
5214 inputWindow.touchableAreaRight = frame.right;
5215 inputWindow.touchableAreaBottom = frame.bottom;
5216 break;
5217
5218 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5219 Rect inset = child.mGivenContentInsets;
5220 inputWindow.touchableAreaLeft = frame.left + inset.left;
5221 inputWindow.touchableAreaTop = frame.top + inset.top;
5222 inputWindow.touchableAreaRight = frame.right - inset.right;
5223 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5224 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005225 }
Jeff Brown349703e2010-06-22 01:27:15 -07005226
5227 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5228 Rect inset = child.mGivenVisibleInsets;
5229 inputWindow.touchableAreaLeft = frame.left + inset.left;
5230 inputWindow.touchableAreaTop = frame.top + inset.top;
5231 inputWindow.touchableAreaRight = frame.right - inset.right;
5232 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005233 break;
5234 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005235 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005236 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005237
Jeff Brown349703e2010-06-22 01:27:15 -07005238 // Send windows to native code.
5239 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005240
Jeff Brown349703e2010-06-22 01:27:15 -07005241 // Clear the list in preparation for the next round.
5242 // Also avoids keeping InputChannel objects referenced unnecessarily.
5243 mTempInputWindows.clear();
5244 }
5245
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005246 /* Notifies that the lid switch changed state. */
5247 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5248 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5249 }
5250
Jeff Brown349703e2010-06-22 01:27:15 -07005251 /* Provides an opportunity for the window manager policy to intercept early key
5252 * processing as soon as the key has been read from the device. */
Jeff Browneb9f7a02010-10-29 21:50:21 -07005253 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5254 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5255 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5256 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005257 }
5258
5259 /* Provides an opportunity for the window manager policy to process a key before
5260 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005261 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Browneb9f7a02010-10-29 21:50:21 -07005262 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005263 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005264 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005265 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Browneb9f7a02010-10-29 21:50:21 -07005266 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005267 }
5268
5269 /* Called when the current input focus changes.
5270 * Layer assignment is assumed to be complete by the time this is called.
5271 */
5272 public void setInputFocusLw(WindowState newWindow) {
5273 if (DEBUG_INPUT) {
5274 Slog.d(TAG, "Input focus has changed to " + newWindow);
5275 }
5276
5277 if (newWindow != mInputFocus) {
5278 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005279 // Displaying a window implicitly causes dispatching to be unpaused.
5280 // This is to protect against bugs if someone pauses dispatching but
5281 // forgets to resume.
5282 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005283 }
Jeff Brown349703e2010-06-22 01:27:15 -07005284
5285 mInputFocus = newWindow;
5286 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005287 }
5288 }
5289
Jeff Brown349703e2010-06-22 01:27:15 -07005290 public void setFocusedAppLw(AppWindowToken newApp) {
5291 // Focused app has changed.
5292 if (newApp == null) {
5293 mInputManager.setFocusedApplication(null);
5294 } else {
5295 mTempInputApplication.name = newApp.toString();
5296 mTempInputApplication.dispatchingTimeoutNanos =
5297 newApp.inputDispatchingTimeoutNanos;
5298 mTempInputApplication.token = newApp;
5299
5300 mInputManager.setFocusedApplication(mTempInputApplication);
5301 }
5302 }
5303
Jeff Brown349703e2010-06-22 01:27:15 -07005304 public void pauseDispatchingLw(WindowToken window) {
5305 if (! window.paused) {
5306 if (DEBUG_INPUT) {
5307 Slog.v(TAG, "Pausing WindowToken " + window);
5308 }
5309
5310 window.paused = true;
5311 updateInputWindowsLw();
5312 }
5313 }
5314
5315 public void resumeDispatchingLw(WindowToken window) {
5316 if (window.paused) {
5317 if (DEBUG_INPUT) {
5318 Slog.v(TAG, "Resuming WindowToken " + window);
5319 }
5320
5321 window.paused = false;
5322 updateInputWindowsLw();
5323 }
5324 }
5325
5326 public void freezeInputDispatchingLw() {
5327 if (! mInputDispatchFrozen) {
5328 if (DEBUG_INPUT) {
5329 Slog.v(TAG, "Freezing input dispatching");
5330 }
5331
5332 mInputDispatchFrozen = true;
5333 updateInputDispatchModeLw();
5334 }
5335 }
5336
5337 public void thawInputDispatchingLw() {
5338 if (mInputDispatchFrozen) {
5339 if (DEBUG_INPUT) {
5340 Slog.v(TAG, "Thawing input dispatching");
5341 }
5342
5343 mInputDispatchFrozen = false;
5344 updateInputDispatchModeLw();
5345 }
5346 }
5347
5348 public void setEventDispatchingLw(boolean enabled) {
5349 if (mInputDispatchEnabled != enabled) {
5350 if (DEBUG_INPUT) {
5351 Slog.v(TAG, "Setting event dispatching to " + enabled);
5352 }
5353
5354 mInputDispatchEnabled = enabled;
5355 updateInputDispatchModeLw();
5356 }
5357 }
5358
5359 private void updateInputDispatchModeLw() {
5360 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5361 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005364 public void pauseKeyDispatching(IBinder _token) {
5365 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5366 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005367 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368 }
5369
5370 synchronized (mWindowMap) {
5371 WindowToken token = mTokenMap.get(_token);
5372 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005373 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374 }
5375 }
5376 }
5377
5378 public void resumeKeyDispatching(IBinder _token) {
5379 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5380 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005381 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 }
5383
5384 synchronized (mWindowMap) {
5385 WindowToken token = mTokenMap.get(_token);
5386 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005387 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005388 }
5389 }
5390 }
5391
5392 public void setEventDispatching(boolean enabled) {
5393 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5394 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005395 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005396 }
5397
5398 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005399 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005400 }
5401 }
Romain Guy06882f82009-06-10 13:36:04 -07005402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005403 /**
5404 * Injects a keystroke event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005405 * Even when sync is false, this method may block while waiting for current
5406 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005407 *
5408 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005409 * {@link SystemClock#uptimeMillis()} as the timebase.)
5410 * @param sync If true, wait for the event to be completed before returning to the caller.
5411 * @return Returns true if event was dispatched, false if it was dropped for any reason
5412 */
5413 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5414 long downTime = ev.getDownTime();
5415 long eventTime = ev.getEventTime();
5416
5417 int action = ev.getAction();
5418 int code = ev.getKeyCode();
5419 int repeatCount = ev.getRepeatCount();
5420 int metaState = ev.getMetaState();
5421 int deviceId = ev.getDeviceId();
5422 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005423 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00005424 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005425
5426 if (source == InputDevice.SOURCE_UNKNOWN) {
5427 source = InputDevice.SOURCE_KEYBOARD;
5428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005429
5430 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5431 if (downTime == 0) downTime = eventTime;
5432
5433 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08005434 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005435
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005436 final int pid = Binder.getCallingPid();
5437 final int uid = Binder.getCallingUid();
5438 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005439
Jeff Brown6ec402b2010-07-28 15:48:59 -07005440 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5441 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5442 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5443 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005444
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005445 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005446 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005447 }
5448
5449 /**
5450 * Inject a pointer (touch) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005451 * Even when sync is false, this method may block while waiting for current
5452 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005453 *
5454 * @param ev A motion event describing the pointer (touch) action. (As noted in
5455 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005456 * {@link SystemClock#uptimeMillis()} as the timebase.)
5457 * @param sync If true, wait for the event to be completed before returning to the caller.
5458 * @return Returns true if event was dispatched, false if it was dropped for any reason
5459 */
5460 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005461 final int pid = Binder.getCallingPid();
5462 final int uid = Binder.getCallingUid();
5463 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005464
Jeff Brownc5ed5912010-07-14 18:48:53 -07005465 MotionEvent newEvent = MotionEvent.obtain(ev);
5466 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5467 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5468 }
5469
Jeff Brown6ec402b2010-07-28 15:48:59 -07005470 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5471 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5472 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5473 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005474
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005475 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005476 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005477 }
Romain Guy06882f82009-06-10 13:36:04 -07005478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005479 /**
5480 * Inject a trackball (navigation device) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005481 * Even when sync is false, this method may block while waiting for current
5482 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005483 *
5484 * @param ev A motion event describing the trackball action. (As noted in
5485 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005486 * {@link SystemClock#uptimeMillis()} as the timebase.)
5487 * @param sync If true, wait for the event to be completed before returning to the caller.
5488 * @return Returns true if event was dispatched, false if it was dropped for any reason
5489 */
5490 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005491 final int pid = Binder.getCallingPid();
5492 final int uid = Binder.getCallingUid();
5493 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005494
Jeff Brownc5ed5912010-07-14 18:48:53 -07005495 MotionEvent newEvent = MotionEvent.obtain(ev);
5496 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5497 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5498 }
5499
Jeff Brown6ec402b2010-07-28 15:48:59 -07005500 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5501 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5502 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5503 INJECTION_TIMEOUT_MILLIS);
5504
5505 Binder.restoreCallingIdentity(ident);
5506 return reportInjectionResult(result);
5507 }
5508
5509 /**
5510 * Inject an input event into the UI without waiting for dispatch to commence.
5511 * This variant is useful for fire-and-forget input event injection. It does not
5512 * block any longer than it takes to enqueue the input event.
5513 *
5514 * @param ev An input event. (Be sure to set the input source correctly.)
5515 * @return Returns true if event was dispatched, false if it was dropped for any reason
5516 */
5517 public boolean injectInputEventNoWait(InputEvent ev) {
5518 final int pid = Binder.getCallingPid();
5519 final int uid = Binder.getCallingUid();
5520 final long ident = Binder.clearCallingIdentity();
5521
5522 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5523 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5524 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005525
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005526 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005527 return reportInjectionResult(result);
5528 }
5529
5530 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005531 switch (result) {
5532 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5533 Slog.w(TAG, "Input event injection permission denied.");
5534 throw new SecurityException(
5535 "Injecting to another application requires INJECT_EVENTS permission");
5536 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005537 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005538 return true;
5539 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5540 Slog.w(TAG, "Input event injection timed out.");
5541 return false;
5542 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5543 default:
5544 Slog.w(TAG, "Input event injection failed.");
5545 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547 }
Romain Guy06882f82009-06-10 13:36:04 -07005548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005549 private WindowState getFocusedWindow() {
5550 synchronized (mWindowMap) {
5551 return getFocusedWindowLocked();
5552 }
5553 }
5554
5555 private WindowState getFocusedWindowLocked() {
5556 return mCurrentFocus;
5557 }
Romain Guy06882f82009-06-10 13:36:04 -07005558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005559 public boolean detectSafeMode() {
5560 mSafeMode = mPolicy.detectSafeMode();
5561 return mSafeMode;
5562 }
Romain Guy06882f82009-06-10 13:36:04 -07005563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005564 public void systemReady() {
5565 mPolicy.systemReady();
5566 }
Romain Guy06882f82009-06-10 13:36:04 -07005567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005568 // -------------------------------------------------------------
5569 // Client Session State
5570 // -------------------------------------------------------------
5571
5572 private final class Session extends IWindowSession.Stub
5573 implements IBinder.DeathRecipient {
5574 final IInputMethodClient mClient;
5575 final IInputContext mInputContext;
5576 final int mUid;
5577 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005578 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005579 SurfaceSession mSurfaceSession;
5580 int mNumWindow = 0;
5581 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005583 public Session(IInputMethodClient client, IInputContext inputContext) {
5584 mClient = client;
5585 mInputContext = inputContext;
5586 mUid = Binder.getCallingUid();
5587 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005588 StringBuilder sb = new StringBuilder();
5589 sb.append("Session{");
5590 sb.append(Integer.toHexString(System.identityHashCode(this)));
5591 sb.append(" uid ");
5592 sb.append(mUid);
5593 sb.append("}");
5594 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005596 synchronized (mWindowMap) {
5597 if (mInputMethodManager == null && mHaveInputMethods) {
5598 IBinder b = ServiceManager.getService(
5599 Context.INPUT_METHOD_SERVICE);
5600 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5601 }
5602 }
5603 long ident = Binder.clearCallingIdentity();
5604 try {
5605 // Note: it is safe to call in to the input method manager
5606 // here because we are not holding our lock.
5607 if (mInputMethodManager != null) {
5608 mInputMethodManager.addClient(client, inputContext,
5609 mUid, mPid);
5610 } else {
5611 client.setUsingInputMethod(false);
5612 }
5613 client.asBinder().linkToDeath(this, 0);
5614 } catch (RemoteException e) {
5615 // The caller has died, so we can just forget about this.
5616 try {
5617 if (mInputMethodManager != null) {
5618 mInputMethodManager.removeClient(client);
5619 }
5620 } catch (RemoteException ee) {
5621 }
5622 } finally {
5623 Binder.restoreCallingIdentity(ident);
5624 }
5625 }
Romain Guy06882f82009-06-10 13:36:04 -07005626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005627 @Override
5628 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5629 throws RemoteException {
5630 try {
5631 return super.onTransact(code, data, reply, flags);
5632 } catch (RuntimeException e) {
5633 // Log all 'real' exceptions thrown to the caller
5634 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005635 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636 }
5637 throw e;
5638 }
5639 }
5640
5641 public void binderDied() {
5642 // Note: it is safe to call in to the input method manager
5643 // here because we are not holding our lock.
5644 try {
5645 if (mInputMethodManager != null) {
5646 mInputMethodManager.removeClient(mClient);
5647 }
5648 } catch (RemoteException e) {
5649 }
5650 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005651 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005652 mClientDead = true;
5653 killSessionLocked();
5654 }
5655 }
5656
5657 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005658 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5659 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5660 outInputChannel);
5661 }
5662
5663 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005664 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005665 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005666 }
Romain Guy06882f82009-06-10 13:36:04 -07005667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005668 public void remove(IWindow window) {
5669 removeWindow(this, window);
5670 }
Romain Guy06882f82009-06-10 13:36:04 -07005671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005672 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5673 int requestedWidth, int requestedHeight, int viewFlags,
5674 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005675 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07005676 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
5677 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005678 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005679 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07005680 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
5681 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 }
Romain Guy06882f82009-06-10 13:36:04 -07005683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005684 public void setTransparentRegion(IWindow window, Region region) {
5685 setTransparentRegionWindow(this, window, region);
5686 }
Romain Guy06882f82009-06-10 13:36:04 -07005687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005688 public void setInsets(IWindow window, int touchableInsets,
5689 Rect contentInsets, Rect visibleInsets) {
5690 setInsetsWindow(this, window, touchableInsets, contentInsets,
5691 visibleInsets);
5692 }
Romain Guy06882f82009-06-10 13:36:04 -07005693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005694 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5695 getWindowDisplayFrame(this, window, outDisplayFrame);
5696 }
Romain Guy06882f82009-06-10 13:36:04 -07005697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005698 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005699 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005700 TAG, "IWindow finishDrawing called for " + window);
5701 finishDrawingWindow(this, window);
5702 }
5703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005704 public void setInTouchMode(boolean mode) {
5705 synchronized(mWindowMap) {
5706 mInTouchMode = mode;
5707 }
5708 }
5709
5710 public boolean getInTouchMode() {
5711 synchronized(mWindowMap) {
5712 return mInTouchMode;
5713 }
5714 }
5715
5716 public boolean performHapticFeedback(IWindow window, int effectId,
5717 boolean always) {
5718 synchronized(mWindowMap) {
5719 long ident = Binder.clearCallingIdentity();
5720 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005721 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005722 windowForClientLocked(this, window, true),
5723 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005724 } finally {
5725 Binder.restoreCallingIdentity(ident);
5726 }
5727 }
5728 }
Romain Guy06882f82009-06-10 13:36:04 -07005729
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005730 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005731 synchronized(mWindowMap) {
5732 long ident = Binder.clearCallingIdentity();
5733 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005734 setWindowWallpaperPositionLocked(
5735 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005736 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005737 } finally {
5738 Binder.restoreCallingIdentity(ident);
5739 }
5740 }
5741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005742
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005743 public void wallpaperOffsetsComplete(IBinder window) {
5744 WindowManagerService.this.wallpaperOffsetsComplete(window);
5745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005746
Dianne Hackborn75804932009-10-20 20:15:20 -07005747 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5748 int z, Bundle extras, boolean sync) {
5749 synchronized(mWindowMap) {
5750 long ident = Binder.clearCallingIdentity();
5751 try {
5752 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005753 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005754 action, x, y, z, extras, sync);
5755 } finally {
5756 Binder.restoreCallingIdentity(ident);
5757 }
5758 }
5759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005760
Dianne Hackborn75804932009-10-20 20:15:20 -07005761 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5762 WindowManagerService.this.wallpaperCommandComplete(window, result);
5763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005765 void windowAddedLocked() {
5766 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005767 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005768 TAG, "First window added to " + this + ", creating SurfaceSession");
5769 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005770 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005771 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005772 mSessions.add(this);
5773 }
5774 mNumWindow++;
5775 }
5776
5777 void windowRemovedLocked() {
5778 mNumWindow--;
5779 killSessionLocked();
5780 }
Romain Guy06882f82009-06-10 13:36:04 -07005781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005782 void killSessionLocked() {
5783 if (mNumWindow <= 0 && mClientDead) {
5784 mSessions.remove(this);
5785 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005786 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 TAG, "Last window removed from " + this
5788 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005789 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005790 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 try {
5792 mSurfaceSession.kill();
5793 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005794 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005795 + mSurfaceSession + " in session " + this
5796 + ": " + e.toString());
5797 }
5798 mSurfaceSession = null;
5799 }
5800 }
5801 }
Romain Guy06882f82009-06-10 13:36:04 -07005802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005803 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005804 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5805 pw.print(" mClientDead="); pw.print(mClientDead);
5806 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005807 }
5808
5809 @Override
5810 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005811 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005812 }
5813 }
5814
5815 // -------------------------------------------------------------
5816 // Client Window State
5817 // -------------------------------------------------------------
5818
5819 private final class WindowState implements WindowManagerPolicy.WindowState {
5820 final Session mSession;
5821 final IWindow mClient;
5822 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005823 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005824 AppWindowToken mAppToken;
5825 AppWindowToken mTargetAppToken;
5826 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5827 final DeathRecipient mDeathRecipient;
5828 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005829 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 final int mBaseLayer;
5831 final int mSubLayer;
5832 final boolean mLayoutAttached;
5833 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005834 final boolean mIsWallpaper;
5835 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005836 int mViewVisibility;
5837 boolean mPolicyVisibility = true;
5838 boolean mPolicyVisibilityAfterAnim = true;
5839 boolean mAppFreezing;
5840 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005841 boolean mReportDestroySurface;
5842 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005843 boolean mAttachedHidden; // is our parent window hidden?
5844 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005845 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005846 int mRequestedWidth;
5847 int mRequestedHeight;
5848 int mLastRequestedWidth;
5849 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 int mLayer;
5851 int mAnimLayer;
5852 int mLastLayer;
5853 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005854 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005855 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005856
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005857 int mLayoutSeq = -1;
5858
5859 Configuration mConfiguration = null;
5860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005861 // Actual frame shown on-screen (may be modified by animation)
5862 final Rect mShownFrame = new Rect();
5863 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005866 * Set when we have changed the size of the surface, to know that
5867 * we must tell them application to resize (and thus redraw itself).
5868 */
5869 boolean mSurfaceResized;
5870
5871 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005872 * Insets that determine the actually visible area
5873 */
5874 final Rect mVisibleInsets = new Rect();
5875 final Rect mLastVisibleInsets = new Rect();
5876 boolean mVisibleInsetsChanged;
5877
5878 /**
5879 * Insets that are covered by system windows
5880 */
5881 final Rect mContentInsets = new Rect();
5882 final Rect mLastContentInsets = new Rect();
5883 boolean mContentInsetsChanged;
5884
5885 /**
5886 * Set to true if we are waiting for this window to receive its
5887 * given internal insets before laying out other windows based on it.
5888 */
5889 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005891 /**
5892 * These are the content insets that were given during layout for
5893 * this window, to be applied to windows behind it.
5894 */
5895 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005897 /**
5898 * These are the visible insets that were given during layout for
5899 * this window, to be applied to windows behind it.
5900 */
5901 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005903 /**
5904 * Flag indicating whether the touchable region should be adjusted by
5905 * the visible insets; if false the area outside the visible insets is
5906 * NOT touchable, so we must use those to adjust the frame during hit
5907 * tests.
5908 */
5909 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 // Current transformation being applied.
5912 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5913 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5914 float mHScale=1, mVScale=1;
5915 float mLastHScale=1, mLastVScale=1;
5916 final Matrix mTmpMatrix = new Matrix();
5917
5918 // "Real" frame that the application sees.
5919 final Rect mFrame = new Rect();
5920 final Rect mLastFrame = new Rect();
5921
5922 final Rect mContainingFrame = new Rect();
5923 final Rect mDisplayFrame = new Rect();
5924 final Rect mContentFrame = new Rect();
5925 final Rect mVisibleFrame = new Rect();
5926
5927 float mShownAlpha = 1;
5928 float mAlpha = 1;
5929 float mLastAlpha = 1;
5930
5931 // Set to true if, when the window gets displayed, it should perform
5932 // an enter animation.
5933 boolean mEnterAnimationPending;
5934
5935 // Currently running animation.
5936 boolean mAnimating;
5937 boolean mLocalAnimating;
5938 Animation mAnimation;
5939 boolean mAnimationIsEntrance;
5940 boolean mHasTransformation;
5941 boolean mHasLocalTransformation;
5942 final Transformation mTransformation = new Transformation();
5943
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005944 // If a window showing a wallpaper: the requested offset for the
5945 // wallpaper; if a wallpaper window: the currently applied offset.
5946 float mWallpaperX = -1;
5947 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005948
5949 // If a window showing a wallpaper: what fraction of the offset
5950 // range corresponds to a full virtual screen.
5951 float mWallpaperXStep = -1;
5952 float mWallpaperYStep = -1;
5953
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005954 // Wallpaper windows: pixels offset based on above variables.
5955 int mXOffset;
5956 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005958 // This is set after IWindowSession.relayout() has been called at
5959 // least once for the window. It allows us to detect the situation
5960 // where we don't yet have a surface, but should have one soon, so
5961 // we can give the window focus before waiting for the relayout.
5962 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005964 // This is set after the Surface has been created but before the
5965 // window has been drawn. During this time the surface is hidden.
5966 boolean mDrawPending;
5967
5968 // This is set after the window has finished drawing for the first
5969 // time but before its surface is shown. The surface will be
5970 // displayed when the next layout is run.
5971 boolean mCommitDrawPending;
5972
5973 // This is set during the time after the window's drawing has been
5974 // committed, and before its surface is actually shown. It is used
5975 // to delay showing the surface until all windows in a token are ready
5976 // to be shown.
5977 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005979 // Set when the window has been shown in the screen the first time.
5980 boolean mHasDrawn;
5981
5982 // Currently running an exit animation?
5983 boolean mExiting;
5984
5985 // Currently on the mDestroySurface list?
5986 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005988 // Completely remove from window manager after exit animation?
5989 boolean mRemoveOnExit;
5990
5991 // Set when the orientation is changing and this window has not yet
5992 // been updated for the new orientation.
5993 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005995 // Is this window now (or just being) removed?
5996 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005997
Dianne Hackborn16064f92010-03-25 00:47:24 -07005998 // For debugging, this is the last information given to the surface flinger.
5999 boolean mSurfaceShown;
6000 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6001 int mSurfaceLayer;
6002 float mSurfaceAlpha;
6003
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006004 // Input channel
6005 InputChannel mInputChannel;
6006
Mattias Petersson1622eee2010-12-21 10:15:11 +01006007 // Used to improve performance of toString()
6008 String mStringNameCache;
6009 CharSequence mLastTitle;
6010 boolean mWasPaused;
6011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006012 WindowState(Session s, IWindow c, WindowToken token,
6013 WindowState attachedWindow, WindowManager.LayoutParams a,
6014 int viewVisibility) {
6015 mSession = s;
6016 mClient = c;
6017 mToken = token;
6018 mAttrs.copyFrom(a);
6019 mViewVisibility = viewVisibility;
6020 DeathRecipient deathRecipient = new DeathRecipient();
6021 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006022 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023 TAG, "Window " + this + " client=" + c.asBinder()
6024 + " token=" + token + " (" + mAttrs.token + ")");
6025 try {
6026 c.asBinder().linkToDeath(deathRecipient, 0);
6027 } catch (RemoteException e) {
6028 mDeathRecipient = null;
6029 mAttachedWindow = null;
6030 mLayoutAttached = false;
6031 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006032 mIsWallpaper = false;
6033 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006034 mBaseLayer = 0;
6035 mSubLayer = 0;
6036 return;
6037 }
6038 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006040 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6041 mAttrs.type <= LAST_SUB_WINDOW)) {
6042 // The multiplier here is to reserve space for multiple
6043 // windows in the same type layer.
6044 mBaseLayer = mPolicy.windowTypeToLayerLw(
6045 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6046 + TYPE_LAYER_OFFSET;
6047 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6048 mAttachedWindow = attachedWindow;
6049 mAttachedWindow.mChildWindows.add(this);
6050 mLayoutAttached = mAttrs.type !=
6051 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6052 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6053 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006054 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6055 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006056 } else {
6057 // The multiplier here is to reserve space for multiple
6058 // windows in the same type layer.
6059 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6060 * TYPE_LAYER_MULTIPLIER
6061 + TYPE_LAYER_OFFSET;
6062 mSubLayer = 0;
6063 mAttachedWindow = null;
6064 mLayoutAttached = false;
6065 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6066 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006067 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6068 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069 }
6070
6071 WindowState appWin = this;
6072 while (appWin.mAttachedWindow != null) {
6073 appWin = mAttachedWindow;
6074 }
6075 WindowToken appToken = appWin.mToken;
6076 while (appToken.appWindowToken == null) {
6077 WindowToken parent = mTokenMap.get(appToken.token);
6078 if (parent == null || appToken == parent) {
6079 break;
6080 }
6081 appToken = parent;
6082 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006083 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 mAppToken = appToken.appWindowToken;
6085
6086 mSurface = null;
6087 mRequestedWidth = 0;
6088 mRequestedHeight = 0;
6089 mLastRequestedWidth = 0;
6090 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006091 mXOffset = 0;
6092 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006093 mLayer = 0;
6094 mAnimLayer = 0;
6095 mLastLayer = 0;
6096 }
6097
6098 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006099 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006100 TAG, "Attaching " + this + " token=" + mToken
6101 + ", list=" + mToken.windows);
6102 mSession.windowAddedLocked();
6103 }
6104
6105 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6106 mHaveFrame = true;
6107
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006108 final Rect container = mContainingFrame;
6109 container.set(pf);
6110
6111 final Rect display = mDisplayFrame;
6112 display.set(df);
6113
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006114 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006115 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006116 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6117 display.intersect(mCompatibleScreenFrame);
6118 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006119 }
6120
6121 final int pw = container.right - container.left;
6122 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123
6124 int w,h;
6125 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6126 w = mAttrs.width < 0 ? pw : mAttrs.width;
6127 h = mAttrs.height< 0 ? ph : mAttrs.height;
6128 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006129 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6130 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006131 }
Romain Guy06882f82009-06-10 13:36:04 -07006132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 final Rect content = mContentFrame;
6134 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136 final Rect visible = mVisibleFrame;
6137 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006139 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006140 final int fw = frame.width();
6141 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6144 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6145
6146 Gravity.apply(mAttrs.gravity, w, h, container,
6147 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6148 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6149
6150 //System.out.println("Out: " + mFrame);
6151
6152 // Now make sure the window fits in the overall display.
6153 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 // Make sure the content and visible frames are inside of the
6156 // final window frame.
6157 if (content.left < frame.left) content.left = frame.left;
6158 if (content.top < frame.top) content.top = frame.top;
6159 if (content.right > frame.right) content.right = frame.right;
6160 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6161 if (visible.left < frame.left) visible.left = frame.left;
6162 if (visible.top < frame.top) visible.top = frame.top;
6163 if (visible.right > frame.right) visible.right = frame.right;
6164 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 final Rect contentInsets = mContentInsets;
6167 contentInsets.left = content.left-frame.left;
6168 contentInsets.top = content.top-frame.top;
6169 contentInsets.right = frame.right-content.right;
6170 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 final Rect visibleInsets = mVisibleInsets;
6173 visibleInsets.left = visible.left-frame.left;
6174 visibleInsets.top = visible.top-frame.top;
6175 visibleInsets.right = frame.right-visible.right;
6176 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006177
Dianne Hackborn284ac932009-08-28 10:34:25 -07006178 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6179 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006180 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006181 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006183 if (localLOGV) {
6184 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6185 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006186 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 + mRequestedWidth + ", mRequestedheight="
6188 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6189 + "): frame=" + mFrame.toShortString()
6190 + " ci=" + contentInsets.toShortString()
6191 + " vi=" + visibleInsets.toShortString());
6192 //}
6193 }
6194 }
Romain Guy06882f82009-06-10 13:36:04 -07006195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 public Rect getFrameLw() {
6197 return mFrame;
6198 }
6199
6200 public Rect getShownFrameLw() {
6201 return mShownFrame;
6202 }
6203
6204 public Rect getDisplayFrameLw() {
6205 return mDisplayFrame;
6206 }
6207
6208 public Rect getContentFrameLw() {
6209 return mContentFrame;
6210 }
6211
6212 public Rect getVisibleFrameLw() {
6213 return mVisibleFrame;
6214 }
6215
6216 public boolean getGivenInsetsPendingLw() {
6217 return mGivenInsetsPending;
6218 }
6219
6220 public Rect getGivenContentInsetsLw() {
6221 return mGivenContentInsets;
6222 }
Romain Guy06882f82009-06-10 13:36:04 -07006223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006224 public Rect getGivenVisibleInsetsLw() {
6225 return mGivenVisibleInsets;
6226 }
Romain Guy06882f82009-06-10 13:36:04 -07006227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 public WindowManager.LayoutParams getAttrs() {
6229 return mAttrs;
6230 }
6231
6232 public int getSurfaceLayer() {
6233 return mLayer;
6234 }
Romain Guy06882f82009-06-10 13:36:04 -07006235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006236 public IApplicationToken getAppToken() {
6237 return mAppToken != null ? mAppToken.appToken : null;
6238 }
Jeff Brown349703e2010-06-22 01:27:15 -07006239
6240 public long getInputDispatchingTimeoutNanos() {
6241 return mAppToken != null
6242 ? mAppToken.inputDispatchingTimeoutNanos
6243 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006245
6246 public boolean hasAppShownWindows() {
6247 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6248 }
6249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006251 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006252 TAG, "Setting animation in " + this + ": " + anim);
6253 mAnimating = false;
6254 mLocalAnimating = false;
6255 mAnimation = anim;
6256 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6257 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6258 }
6259
6260 public void clearAnimation() {
6261 if (mAnimation != null) {
6262 mAnimating = true;
6263 mLocalAnimating = false;
6264 mAnimation = null;
6265 }
6266 }
Romain Guy06882f82009-06-10 13:36:04 -07006267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 Surface createSurfaceLocked() {
6269 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006270 mReportDestroySurface = false;
6271 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006272 mDrawPending = true;
6273 mCommitDrawPending = false;
6274 mReadyToShow = false;
6275 if (mAppToken != null) {
6276 mAppToken.allDrawn = false;
6277 }
6278
6279 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006280 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 flags |= Surface.PUSH_BUFFERS;
6282 }
6283
6284 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6285 flags |= Surface.SECURE;
6286 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006287 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006288 TAG, "Creating surface in session "
6289 + mSession.mSurfaceSession + " window " + this
6290 + " w=" + mFrame.width()
6291 + " h=" + mFrame.height() + " format="
6292 + mAttrs.format + " flags=" + flags);
6293
6294 int w = mFrame.width();
6295 int h = mFrame.height();
6296 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6297 // for a scaled surface, we always want the requested
6298 // size.
6299 w = mRequestedWidth;
6300 h = mRequestedHeight;
6301 }
6302
Romain Guy9825ec62009-10-01 00:58:09 -07006303 // Something is wrong and SurfaceFlinger will not like this,
6304 // try to revert to sane values
6305 if (w <= 0) w = 1;
6306 if (h <= 0) h = 1;
6307
Dianne Hackborn16064f92010-03-25 00:47:24 -07006308 mSurfaceShown = false;
6309 mSurfaceLayer = 0;
6310 mSurfaceAlpha = 1;
6311 mSurfaceX = 0;
6312 mSurfaceY = 0;
6313 mSurfaceW = w;
6314 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006315 try {
6316 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006317 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006318 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006319 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006320 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006321 + mSurface + " IN SESSION "
6322 + mSession.mSurfaceSession
6323 + ": pid=" + mSession.mPid + " format="
6324 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006325 + Integer.toHexString(flags)
6326 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006328 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 reclaimSomeSurfaceMemoryLocked(this, "create");
6330 return null;
6331 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006332 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333 return null;
6334 }
Romain Guy06882f82009-06-10 13:36:04 -07006335
Joe Onorato8a9b2202010-02-26 18:56:32 -08006336 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006337 TAG, "Got surface: " + mSurface
6338 + ", set left=" + mFrame.left + " top=" + mFrame.top
6339 + ", animLayer=" + mAnimLayer);
6340 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006341 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006342 if (SHOW_TRANSACTIONS) logSurface(this,
6343 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6344 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6345 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006346 }
6347 Surface.openTransaction();
6348 try {
6349 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006350 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006351 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006352 mSurface.setPosition(mSurfaceX, mSurfaceY);
6353 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006355 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 mSurface.hide();
6357 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006358 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 mSurface.setFlags(Surface.SURFACE_DITHER,
6360 Surface.SURFACE_DITHER);
6361 }
6362 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006363 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006364 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6365 }
6366 mLastHidden = true;
6367 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006368 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 Surface.closeTransaction();
6370 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006371 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 TAG, "Created surface " + this);
6373 }
6374 return mSurface;
6375 }
Romain Guy06882f82009-06-10 13:36:04 -07006376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 if (mAppToken != null && this == mAppToken.startingWindow) {
6379 mAppToken.startingDisplayed = false;
6380 }
Romain Guy06882f82009-06-10 13:36:04 -07006381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006383 mDrawPending = false;
6384 mCommitDrawPending = false;
6385 mReadyToShow = false;
6386
6387 int i = mChildWindows.size();
6388 while (i > 0) {
6389 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006390 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006391 c.mAttachedHidden = true;
6392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006393
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006394 if (mReportDestroySurface) {
6395 mReportDestroySurface = false;
6396 mSurfacePendingDestroy = true;
6397 try {
6398 mClient.dispatchGetNewSurface();
6399 // We'll really destroy on the next time around.
6400 return;
6401 } catch (RemoteException e) {
6402 }
6403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006405 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006406 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006407 RuntimeException e = null;
6408 if (!HIDE_STACK_CRAWLS) {
6409 e = new RuntimeException();
6410 e.fillInStackTrace();
6411 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006412 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006413 + mSurface + ", session " + mSession, e);
6414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006416 RuntimeException e = null;
6417 if (!HIDE_STACK_CRAWLS) {
6418 e = new RuntimeException();
6419 e.fillInStackTrace();
6420 }
6421 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006422 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006423 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006424 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006425 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 + " surface " + mSurface + " session " + mSession
6427 + ": " + e.toString());
6428 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006429
Dianne Hackborn16064f92010-03-25 00:47:24 -07006430 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 }
6433 }
6434
6435 boolean finishDrawingLocked() {
6436 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006437 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 TAG, "finishDrawingLocked: " + mSurface);
6439 mCommitDrawPending = true;
6440 mDrawPending = false;
6441 return true;
6442 }
6443 return false;
6444 }
6445
6446 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006447 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006448 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006450 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 }
6452 mCommitDrawPending = false;
6453 mReadyToShow = true;
6454 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6455 final AppWindowToken atoken = mAppToken;
6456 if (atoken == null || atoken.allDrawn || starting) {
6457 performShowLocked();
6458 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006459 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 }
6461
6462 // This must be called while inside a transaction.
6463 boolean performShowLocked() {
6464 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006465 RuntimeException e = null;
6466 if (!HIDE_STACK_CRAWLS) {
6467 e = new RuntimeException();
6468 e.fillInStackTrace();
6469 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006470 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006471 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6472 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6473 }
6474 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006475 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6476 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006477 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478 + " during animation: policyVis=" + mPolicyVisibility
6479 + " attHidden=" + mAttachedHidden
6480 + " tok.hiddenRequested="
6481 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006482 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 + (mAppToken != null ? mAppToken.hidden : false)
6484 + " animating=" + mAnimating
6485 + " tok animating="
6486 + (mAppToken != null ? mAppToken.animating : false));
6487 if (!showSurfaceRobustlyLocked(this)) {
6488 return false;
6489 }
6490 mLastAlpha = -1;
6491 mHasDrawn = true;
6492 mLastHidden = false;
6493 mReadyToShow = false;
6494 enableScreenIfNeededLocked();
6495
6496 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 int i = mChildWindows.size();
6499 while (i > 0) {
6500 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006501 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006502 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006504 if (c.mSurface != null) {
6505 c.performShowLocked();
6506 // It hadn't been shown, which means layout not
6507 // performed on it, so now we want to make sure to
6508 // do a layout. If called from within the transaction
6509 // loop, this will cause it to restart with a new
6510 // layout.
6511 mLayoutNeeded = true;
6512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 }
6514 }
Romain Guy06882f82009-06-10 13:36:04 -07006515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006516 if (mAttrs.type != TYPE_APPLICATION_STARTING
6517 && mAppToken != null) {
6518 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006519
Dianne Hackborn248b1882009-09-16 16:46:44 -07006520 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006521 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006522 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006523 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006524 // If this initial window is animating, stop it -- we
6525 // will do an animation to reveal it from behind the
6526 // starting window, so there is no need for it to also
6527 // be doing its own stuff.
6528 if (mAnimation != null) {
6529 mAnimation = null;
6530 // Make sure we clean up the animation.
6531 mAnimating = true;
6532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 mFinishedStarting.add(mAppToken);
6534 mH.sendEmptyMessage(H.FINISHED_STARTING);
6535 }
6536 mAppToken.updateReportedVisibilityLocked();
6537 }
6538 }
6539 return true;
6540 }
Romain Guy06882f82009-06-10 13:36:04 -07006541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 // This must be called while inside a transaction. Returns true if
6543 // there is more animation to run.
6544 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006545 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006546 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6549 mHasTransformation = true;
6550 mHasLocalTransformation = true;
6551 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006552 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 TAG, "Starting animation in " + this +
6554 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6555 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6556 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6557 mAnimation.setStartTime(currentTime);
6558 mLocalAnimating = true;
6559 mAnimating = true;
6560 }
6561 mTransformation.clear();
6562 final boolean more = mAnimation.getTransformation(
6563 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006564 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 TAG, "Stepped animation in " + this +
6566 ": more=" + more + ", xform=" + mTransformation);
6567 if (more) {
6568 // we're not done!
6569 return true;
6570 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006571 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006572 TAG, "Finished animation in " + this +
6573 " @ " + currentTime);
6574 mAnimation = null;
6575 //WindowManagerService.this.dump();
6576 }
6577 mHasLocalTransformation = false;
6578 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006579 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580 // When our app token is animating, we kind-of pretend like
6581 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6582 // part of this check means that we will only do this if
6583 // our window is not currently exiting, or it is not
6584 // locally animating itself. The idea being that one that
6585 // is exiting and doing a local animation should be removed
6586 // once that animation is done.
6587 mAnimating = true;
6588 mHasTransformation = true;
6589 mTransformation.clear();
6590 return false;
6591 } else if (mHasTransformation) {
6592 // Little trick to get through the path below to act like
6593 // we have finished an animation.
6594 mAnimating = true;
6595 } else if (isAnimating()) {
6596 mAnimating = true;
6597 }
6598 } else if (mAnimation != null) {
6599 // If the display is frozen, and there is a pending animation,
6600 // clear it and make sure we run the cleanup code.
6601 mAnimating = true;
6602 mLocalAnimating = true;
6603 mAnimation = null;
6604 }
Romain Guy06882f82009-06-10 13:36:04 -07006605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 if (!mAnimating && !mLocalAnimating) {
6607 return false;
6608 }
6609
Joe Onorato8a9b2202010-02-26 18:56:32 -08006610 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006611 TAG, "Animation done in " + this + ": exiting=" + mExiting
6612 + ", reportedVisible="
6613 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 mAnimating = false;
6616 mLocalAnimating = false;
6617 mAnimation = null;
6618 mAnimLayer = mLayer;
6619 if (mIsImWindow) {
6620 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006621 } else if (mIsWallpaper) {
6622 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006623 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006624 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 + " anim layer: " + mAnimLayer);
6626 mHasTransformation = false;
6627 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006628 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6629 if (DEBUG_VISIBILITY) {
6630 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6631 + mPolicyVisibilityAfterAnim);
6632 }
6633 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6634 if (!mPolicyVisibility) {
6635 if (mCurrentFocus == this) {
6636 mFocusMayChange = true;
6637 }
6638 // Window is no longer visible -- make sure if we were waiting
6639 // for it to be displayed before enabling the display, that
6640 // we allow the display to be enabled now.
6641 enableScreenIfNeededLocked();
6642 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006644 mTransformation.clear();
6645 if (mHasDrawn
6646 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6647 && mAppToken != null
6648 && mAppToken.firstWindowDrawn
6649 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006650 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 + mToken + ": first real window done animating");
6652 mFinishedStarting.add(mAppToken);
6653 mH.sendEmptyMessage(H.FINISHED_STARTING);
6654 }
Romain Guy06882f82009-06-10 13:36:04 -07006655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 finishExit();
6657
6658 if (mAppToken != null) {
6659 mAppToken.updateReportedVisibilityLocked();
6660 }
6661
6662 return false;
6663 }
6664
6665 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006666 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 TAG, "finishExit in " + this
6668 + ": exiting=" + mExiting
6669 + " remove=" + mRemoveOnExit
6670 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006672 final int N = mChildWindows.size();
6673 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006674 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006675 }
Romain Guy06882f82009-06-10 13:36:04 -07006676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006677 if (!mExiting) {
6678 return;
6679 }
Romain Guy06882f82009-06-10 13:36:04 -07006680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006681 if (isWindowAnimating()) {
6682 return;
6683 }
6684
Joe Onorato8a9b2202010-02-26 18:56:32 -08006685 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 TAG, "Exit animation finished in " + this
6687 + ": remove=" + mRemoveOnExit);
6688 if (mSurface != null) {
6689 mDestroySurface.add(this);
6690 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006691 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006692 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006693 try {
6694 mSurface.hide();
6695 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006696 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 }
6698 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 }
6700 mExiting = false;
6701 if (mRemoveOnExit) {
6702 mPendingRemove.add(this);
6703 mRemoveOnExit = false;
6704 }
6705 }
Romain Guy06882f82009-06-10 13:36:04 -07006706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006707 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6708 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6709 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6710 if (dtdx < -.000001f || dtdx > .000001f) return false;
6711 if (dsdy < -.000001f || dsdy > .000001f) return false;
6712 return true;
6713 }
Romain Guy06882f82009-06-10 13:36:04 -07006714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 void computeShownFrameLocked() {
6716 final boolean selfTransformation = mHasLocalTransformation;
6717 Transformation attachedTransformation =
6718 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6719 ? mAttachedWindow.mTransformation : null;
6720 Transformation appTransformation =
6721 (mAppToken != null && mAppToken.hasTransformation)
6722 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006723
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006724 // Wallpapers are animated based on the "real" window they
6725 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006726 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006727 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006728 if (mWallpaperTarget.mHasLocalTransformation &&
6729 mWallpaperTarget.mAnimation != null &&
6730 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006731 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006732 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006733 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006734 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006735 }
6736 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006737 mWallpaperTarget.mAppToken.hasTransformation &&
6738 mWallpaperTarget.mAppToken.animation != null &&
6739 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006740 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006741 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006742 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006743 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006744 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 if (selfTransformation || attachedTransformation != null
6748 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006749 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 final Rect frame = mFrame;
6751 final float tmpFloats[] = mTmpFloats;
6752 final Matrix tmpMatrix = mTmpMatrix;
6753
6754 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006755 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006756 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006757 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006759 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006761 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 }
6763 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006764 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 }
6766
6767 // "convert" it into SurfaceFlinger's format
6768 // (a 2x2 matrix + an offset)
6769 // Here we must not transform the position of the surface
6770 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006771 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 tmpMatrix.getValues(tmpFloats);
6774 mDsDx = tmpFloats[Matrix.MSCALE_X];
6775 mDtDx = tmpFloats[Matrix.MSKEW_X];
6776 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6777 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006778 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6779 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 int w = frame.width();
6781 int h = frame.height();
6782 mShownFrame.set(x, y, x+w, y+h);
6783
6784 // Now set the alpha... but because our current hardware
6785 // can't do alpha transformation on a non-opaque surface,
6786 // turn it off if we are running an animation that is also
6787 // transforming since it is more important to have that
6788 // animation be smooth.
6789 mShownAlpha = mAlpha;
6790 if (!mLimitedAlphaCompositing
6791 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6792 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6793 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006794 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006795 if (selfTransformation) {
6796 mShownAlpha *= mTransformation.getAlpha();
6797 }
6798 if (attachedTransformation != null) {
6799 mShownAlpha *= attachedTransformation.getAlpha();
6800 }
6801 if (appTransformation != null) {
6802 mShownAlpha *= appTransformation.getAlpha();
6803 }
6804 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006805 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 }
Romain Guy06882f82009-06-10 13:36:04 -07006807
Joe Onorato8a9b2202010-02-26 18:56:32 -08006808 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006809 TAG, "Continuing animation in " + this +
6810 ": " + mShownFrame +
6811 ", alpha=" + mTransformation.getAlpha());
6812 return;
6813 }
Romain Guy06882f82009-06-10 13:36:04 -07006814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006816 if (mXOffset != 0 || mYOffset != 0) {
6817 mShownFrame.offset(mXOffset, mYOffset);
6818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006819 mShownAlpha = mAlpha;
6820 mDsDx = 1;
6821 mDtDx = 0;
6822 mDsDy = 0;
6823 mDtDy = 1;
6824 }
Romain Guy06882f82009-06-10 13:36:04 -07006825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006826 /**
6827 * Is this window visible? It is not visible if there is no
6828 * surface, or we are in the process of running an exit animation
6829 * that will remove the surface, or its app token has been hidden.
6830 */
6831 public boolean isVisibleLw() {
6832 final AppWindowToken atoken = mAppToken;
6833 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6834 && (atoken == null || !atoken.hiddenRequested)
6835 && !mExiting && !mDestroying;
6836 }
6837
6838 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006839 * Like {@link #isVisibleLw}, but also counts a window that is currently
6840 * "hidden" behind the keyguard as visible. This allows us to apply
6841 * things like window flags that impact the keyguard.
6842 * XXX I am starting to think we need to have ANOTHER visibility flag
6843 * for this "hidden behind keyguard" state rather than overloading
6844 * mPolicyVisibility. Ungh.
6845 */
6846 public boolean isVisibleOrBehindKeyguardLw() {
6847 final AppWindowToken atoken = mAppToken;
6848 return mSurface != null && !mAttachedHidden
6849 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006850 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006851 && !mExiting && !mDestroying;
6852 }
6853
6854 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006855 * Is this window visible, ignoring its app token? It is not visible
6856 * if there is no surface, or we are in the process of running an exit animation
6857 * that will remove the surface.
6858 */
6859 public boolean isWinVisibleLw() {
6860 final AppWindowToken atoken = mAppToken;
6861 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6862 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6863 && !mExiting && !mDestroying;
6864 }
6865
6866 /**
6867 * The same as isVisible(), but follows the current hidden state of
6868 * the associated app token, not the pending requested hidden state.
6869 */
6870 boolean isVisibleNow() {
6871 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006872 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006873 }
6874
6875 /**
6876 * Same as isVisible(), but we also count it as visible between the
6877 * call to IWindowSession.add() and the first relayout().
6878 */
6879 boolean isVisibleOrAdding() {
6880 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006881 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006882 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6883 && mPolicyVisibility && !mAttachedHidden
6884 && (atoken == null || !atoken.hiddenRequested)
6885 && !mExiting && !mDestroying;
6886 }
6887
6888 /**
6889 * Is this window currently on-screen? It is on-screen either if it
6890 * is visible or it is currently running an animation before no longer
6891 * being visible.
6892 */
6893 boolean isOnScreen() {
6894 final AppWindowToken atoken = mAppToken;
6895 if (atoken != null) {
6896 return mSurface != null && mPolicyVisibility && !mDestroying
6897 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006898 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006899 } else {
6900 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006901 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006902 }
6903 }
Romain Guy06882f82009-06-10 13:36:04 -07006904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 /**
6906 * Like isOnScreen(), but we don't return true if the window is part
6907 * of a transition that has not yet been started.
6908 */
6909 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006910 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006911 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006912 return false;
6913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006915 final boolean animating = atoken != null
6916 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006917 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006918 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6919 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006920 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 }
6922
6923 /** Is the window or its container currently animating? */
6924 boolean isAnimating() {
6925 final WindowState attached = mAttachedWindow;
6926 final AppWindowToken atoken = mAppToken;
6927 return mAnimation != null
6928 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006929 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006930 (atoken.animation != null
6931 || atoken.inPendingTransaction));
6932 }
6933
6934 /** Is this window currently animating? */
6935 boolean isWindowAnimating() {
6936 return mAnimation != null;
6937 }
6938
6939 /**
6940 * Like isOnScreen, but returns false if the surface hasn't yet
6941 * been drawn.
6942 */
6943 public boolean isDisplayedLw() {
6944 final AppWindowToken atoken = mAppToken;
6945 return mSurface != null && mPolicyVisibility && !mDestroying
6946 && !mDrawPending && !mCommitDrawPending
6947 && ((!mAttachedHidden &&
6948 (atoken == null || !atoken.hiddenRequested))
6949 || mAnimating);
6950 }
6951
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006952 /**
6953 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006954 * complete UI in to. Note that this returns true if the orientation
6955 * is changing even if the window hasn't redrawn because we don't want
6956 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006957 */
6958 public boolean isDrawnLw() {
6959 final AppWindowToken atoken = mAppToken;
6960 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006961 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006962 }
6963
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006964 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006965 * Return true if the window is opaque and fully drawn. This indicates
6966 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006967 */
6968 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006969 return (mAttrs.format == PixelFormat.OPAQUE
6970 || mAttrs.type == TYPE_WALLPAPER)
6971 && mSurface != null && mAnimation == null
6972 && (mAppToken == null || mAppToken.animation == null)
6973 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006974 }
6975
6976 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6977 return
6978 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006979 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6980 // only if it's visible
6981 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006982 // and only if the application fills the compatible screen
6983 mFrame.left <= mCompatibleScreenFrame.left &&
6984 mFrame.top <= mCompatibleScreenFrame.top &&
6985 mFrame.right >= mCompatibleScreenFrame.right &&
6986 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006987 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006988 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006989 }
6990
6991 boolean isFullscreen(int screenWidth, int screenHeight) {
6992 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006993 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006994 }
6995
6996 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07006997 disposeInputChannel();
6998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 if (mAttachedWindow != null) {
7000 mAttachedWindow.mChildWindows.remove(this);
7001 }
7002 destroySurfaceLocked();
7003 mSession.windowRemovedLocked();
7004 try {
7005 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7006 } catch (RuntimeException e) {
7007 // Ignore if it has already been removed (usually because
7008 // we are doing this as part of processing a death note.)
7009 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007010 }
7011
7012 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007013 if (mInputChannel != null) {
7014 mInputManager.unregisterInputChannel(mInputChannel);
7015
7016 mInputChannel.dispose();
7017 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007019 }
7020
7021 private class DeathRecipient implements IBinder.DeathRecipient {
7022 public void binderDied() {
7023 try {
7024 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007025 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007026 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007027 if (win != null) {
7028 removeWindowLocked(mSession, win);
7029 }
7030 }
7031 } catch (IllegalArgumentException ex) {
7032 // This will happen if the window has already been
7033 // removed.
7034 }
7035 }
7036 }
7037
7038 /** Returns true if this window desires key events. */
7039 public final boolean canReceiveKeys() {
7040 return isVisibleOrAdding()
7041 && (mViewVisibility == View.VISIBLE)
7042 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7043 }
7044
7045 public boolean hasDrawnLw() {
7046 return mHasDrawn;
7047 }
7048
7049 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007050 return showLw(doAnimation, true);
7051 }
7052
7053 boolean showLw(boolean doAnimation, boolean requestAnim) {
7054 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7055 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007056 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007057 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007058 if (doAnimation) {
7059 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7060 + mPolicyVisibility + " mAnimation=" + mAnimation);
7061 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7062 doAnimation = false;
7063 } else if (mPolicyVisibility && mAnimation == null) {
7064 // Check for the case where we are currently visible and
7065 // not animating; we do not want to do animation at such a
7066 // point to become visible when we already are.
7067 doAnimation = false;
7068 }
7069 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007070 mPolicyVisibility = true;
7071 mPolicyVisibilityAfterAnim = true;
7072 if (doAnimation) {
7073 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7074 }
7075 if (requestAnim) {
7076 requestAnimationLocked(0);
7077 }
7078 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 }
7080
7081 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007082 return hideLw(doAnimation, true);
7083 }
7084
7085 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007086 if (doAnimation) {
7087 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7088 doAnimation = false;
7089 }
7090 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7092 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007093 if (!current) {
7094 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007096 if (doAnimation) {
7097 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7098 if (mAnimation == null) {
7099 doAnimation = false;
7100 }
7101 }
7102 if (doAnimation) {
7103 mPolicyVisibilityAfterAnim = false;
7104 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007105 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007106 mPolicyVisibilityAfterAnim = false;
7107 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007108 // Window is no longer visible -- make sure if we were waiting
7109 // for it to be displayed before enabling the display, that
7110 // we allow the display to be enabled now.
7111 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007112 if (mCurrentFocus == this) {
7113 mFocusMayChange = true;
7114 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007115 }
7116 if (requestAnim) {
7117 requestAnimationLocked(0);
7118 }
7119 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007120 }
7121
7122 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007123 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7124 pw.print(" mClient="); pw.println(mClient.asBinder());
7125 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7126 if (mAttachedWindow != null || mLayoutAttached) {
7127 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7128 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7129 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007130 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7131 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7132 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007133 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7134 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007135 }
7136 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7137 pw.print(" mSubLayer="); pw.print(mSubLayer);
7138 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7139 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7140 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7141 pw.print("="); pw.print(mAnimLayer);
7142 pw.print(" mLastLayer="); pw.println(mLastLayer);
7143 if (mSurface != null) {
7144 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007145 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7146 pw.print(" layer="); pw.print(mSurfaceLayer);
7147 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7148 pw.print(" rect=("); pw.print(mSurfaceX);
7149 pw.print(","); pw.print(mSurfaceY);
7150 pw.print(") "); pw.print(mSurfaceW);
7151 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007152 }
7153 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7154 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7155 if (mAppToken != null) {
7156 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7157 }
7158 if (mTargetAppToken != null) {
7159 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7160 }
7161 pw.print(prefix); pw.print("mViewVisibility=0x");
7162 pw.print(Integer.toHexString(mViewVisibility));
7163 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007164 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7165 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007166 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7167 pw.print(prefix); pw.print("mPolicyVisibility=");
7168 pw.print(mPolicyVisibility);
7169 pw.print(" mPolicyVisibilityAfterAnim=");
7170 pw.print(mPolicyVisibilityAfterAnim);
7171 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7172 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007173 if (!mRelayoutCalled) {
7174 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7175 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007176 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007177 pw.print(" h="); pw.print(mRequestedHeight);
7178 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007179 if (mXOffset != 0 || mYOffset != 0) {
7180 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7181 pw.print(" y="); pw.println(mYOffset);
7182 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007183 pw.print(prefix); pw.print("mGivenContentInsets=");
7184 mGivenContentInsets.printShortString(pw);
7185 pw.print(" mGivenVisibleInsets=");
7186 mGivenVisibleInsets.printShortString(pw);
7187 pw.println();
7188 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7189 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7190 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7191 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007192 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007193 pw.print(prefix); pw.print("mShownFrame=");
7194 mShownFrame.printShortString(pw);
7195 pw.print(" last="); mLastShownFrame.printShortString(pw);
7196 pw.println();
7197 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7198 pw.print(" last="); mLastFrame.printShortString(pw);
7199 pw.println();
7200 pw.print(prefix); pw.print("mContainingFrame=");
7201 mContainingFrame.printShortString(pw);
7202 pw.print(" mDisplayFrame=");
7203 mDisplayFrame.printShortString(pw);
7204 pw.println();
7205 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7206 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7207 pw.println();
7208 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7209 pw.print(" last="); mLastContentInsets.printShortString(pw);
7210 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7211 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7212 pw.println();
7213 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7214 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7215 pw.print(" mAlpha="); pw.print(mAlpha);
7216 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7217 }
7218 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7219 || mAnimation != null) {
7220 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7221 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7222 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7223 pw.print(" mAnimation="); pw.println(mAnimation);
7224 }
7225 if (mHasTransformation || mHasLocalTransformation) {
7226 pw.print(prefix); pw.print("XForm: has=");
7227 pw.print(mHasTransformation);
7228 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7229 pw.print(" "); mTransformation.printShortString(pw);
7230 pw.println();
7231 }
7232 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7233 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7234 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7235 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7236 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7237 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7238 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7239 pw.print(" mDestroying="); pw.print(mDestroying);
7240 pw.print(" mRemoved="); pw.println(mRemoved);
7241 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007242 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007243 pw.print(prefix); pw.print("mOrientationChanging=");
7244 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007245 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7246 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007247 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007248 if (mHScale != 1 || mVScale != 1) {
7249 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7250 pw.print(" mVScale="); pw.println(mVScale);
7251 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007252 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007253 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7254 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7255 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007256 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7257 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7258 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7259 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007260 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007261
7262 String makeInputChannelName() {
7263 return Integer.toHexString(System.identityHashCode(this))
7264 + " " + mAttrs.getTitle();
7265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266
7267 @Override
7268 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01007269 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
7270 || mWasPaused != mToken.paused) {
7271 mLastTitle = mAttrs.getTitle();
7272 mWasPaused = mToken.paused;
7273 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
7274 + " " + mLastTitle + " paused=" + mWasPaused + "}";
7275 }
7276 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 }
7278 }
Romain Guy06882f82009-06-10 13:36:04 -07007279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007280 // -------------------------------------------------------------
7281 // Window Token State
7282 // -------------------------------------------------------------
7283
7284 class WindowToken {
7285 // The actual token.
7286 final IBinder token;
7287
7288 // The type of window this token is for, as per WindowManager.LayoutParams.
7289 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 // Set if this token was explicitly added by a client, so should
7292 // not be removed when all windows are removed.
7293 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007294
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007295 // For printing.
7296 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 // If this is an AppWindowToken, this is non-null.
7299 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301 // All of the windows associated with this token.
7302 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7303
7304 // Is key dispatching paused for this token?
7305 boolean paused = false;
7306
7307 // Should this token's windows be hidden?
7308 boolean hidden;
7309
7310 // Temporary for finding which tokens no longer have visible windows.
7311 boolean hasVisible;
7312
Dianne Hackborna8f60182009-09-01 19:01:50 -07007313 // Set to true when this token is in a pending transaction where it
7314 // will be shown.
7315 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007316
Dianne Hackborna8f60182009-09-01 19:01:50 -07007317 // Set to true when this token is in a pending transaction where it
7318 // will be hidden.
7319 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007320
Dianne Hackborna8f60182009-09-01 19:01:50 -07007321 // Set to true when this token is in a pending transaction where its
7322 // windows will be put to the bottom of the list.
7323 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007324
Dianne Hackborna8f60182009-09-01 19:01:50 -07007325 // Set to true when this token is in a pending transaction where its
7326 // windows will be put to the top of the list.
7327 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 WindowToken(IBinder _token, int type, boolean _explicit) {
7330 token = _token;
7331 windowType = type;
7332 explicit = _explicit;
7333 }
7334
7335 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007336 pw.print(prefix); pw.print("token="); pw.println(token);
7337 pw.print(prefix); pw.print("windows="); pw.println(windows);
7338 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7339 pw.print(" hidden="); pw.print(hidden);
7340 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007341 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7342 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7343 pw.print(" waitingToHide="); pw.print(waitingToHide);
7344 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7345 pw.print(" sendingToTop="); pw.println(sendingToTop);
7346 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 }
7348
7349 @Override
7350 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007351 if (stringName == null) {
7352 StringBuilder sb = new StringBuilder();
7353 sb.append("WindowToken{");
7354 sb.append(Integer.toHexString(System.identityHashCode(this)));
7355 sb.append(" token="); sb.append(token); sb.append('}');
7356 stringName = sb.toString();
7357 }
7358 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 }
7360 };
7361
7362 class AppWindowToken extends WindowToken {
7363 // Non-null only for application tokens.
7364 final IApplicationToken appToken;
7365
7366 // All of the windows and child windows that are included in this
7367 // application token. Note this list is NOT sorted!
7368 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7369
7370 int groupId = -1;
7371 boolean appFullscreen;
7372 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007373
7374 // The input dispatching timeout for this application token in nanoseconds.
7375 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007377 // These are used for determining when all windows associated with
7378 // an activity have been drawn, so they can be made visible together
7379 // at the same time.
7380 int lastTransactionSequence = mTransactionSequence-1;
7381 int numInterestingWindows;
7382 int numDrawnWindows;
7383 boolean inPendingTransaction;
7384 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 // Is this token going to be hidden in a little while? If so, it
7387 // won't be taken into account for setting the screen orientation.
7388 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007390 // Is this window's surface needed? This is almost like hidden, except
7391 // it will sometimes be true a little earlier: when the token has
7392 // been shown, but is still waiting for its app transition to execute
7393 // before making its windows shown.
7394 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 // Have we told the window clients to hide themselves?
7397 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 // Last visibility state we reported to the app token.
7400 boolean reportedVisible;
7401
7402 // Set to true when the token has been removed from the window mgr.
7403 boolean removed;
7404
7405 // Have we been asked to have this token keep the screen frozen?
7406 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 boolean animating;
7409 Animation animation;
7410 boolean hasTransformation;
7411 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 // Offset to the window of all layers in the token, for use by
7414 // AppWindowToken animations.
7415 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007417 // Information about an application starting window if displayed.
7418 StartingData startingData;
7419 WindowState startingWindow;
7420 View startingView;
7421 boolean startingDisplayed;
7422 boolean startingMoved;
7423 boolean firstWindowDrawn;
7424
7425 AppWindowToken(IApplicationToken _token) {
7426 super(_token.asBinder(),
7427 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7428 appWindowToken = this;
7429 appToken = _token;
7430 }
Romain Guy06882f82009-06-10 13:36:04 -07007431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007433 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007434 TAG, "Setting animation in " + this + ": " + anim);
7435 animation = anim;
7436 animating = false;
7437 anim.restrictDuration(MAX_ANIMATION_DURATION);
7438 anim.scaleCurrentDuration(mTransitionAnimationScale);
7439 int zorder = anim.getZAdjustment();
7440 int adj = 0;
7441 if (zorder == Animation.ZORDER_TOP) {
7442 adj = TYPE_LAYER_OFFSET;
7443 } else if (zorder == Animation.ZORDER_BOTTOM) {
7444 adj = -TYPE_LAYER_OFFSET;
7445 }
Romain Guy06882f82009-06-10 13:36:04 -07007446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 if (animLayerAdjustment != adj) {
7448 animLayerAdjustment = adj;
7449 updateLayers();
7450 }
7451 }
Romain Guy06882f82009-06-10 13:36:04 -07007452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 public void setDummyAnimation() {
7454 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007455 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 TAG, "Setting dummy animation in " + this);
7457 animation = sDummyAnimation;
7458 }
7459 }
7460
7461 public void clearAnimation() {
7462 if (animation != null) {
7463 animation = null;
7464 animating = true;
7465 }
7466 }
Romain Guy06882f82009-06-10 13:36:04 -07007467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007468 void updateLayers() {
7469 final int N = allAppWindows.size();
7470 final int adj = animLayerAdjustment;
7471 for (int i=0; i<N; i++) {
7472 WindowState w = allAppWindows.get(i);
7473 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007474 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007475 + w.mAnimLayer);
7476 if (w == mInputMethodTarget) {
7477 setInputMethodAnimLayerAdjustment(adj);
7478 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007479 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007480 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007482 }
7483 }
Romain Guy06882f82009-06-10 13:36:04 -07007484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 void sendAppVisibilityToClients() {
7486 final int N = allAppWindows.size();
7487 for (int i=0; i<N; i++) {
7488 WindowState win = allAppWindows.get(i);
7489 if (win == startingWindow && clientHidden) {
7490 // Don't hide the starting window.
7491 continue;
7492 }
7493 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007494 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 "Setting visibility of " + win + ": " + (!clientHidden));
7496 win.mClient.dispatchAppVisibility(!clientHidden);
7497 } catch (RemoteException e) {
7498 }
7499 }
7500 }
Romain Guy06882f82009-06-10 13:36:04 -07007501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007502 void showAllWindowsLocked() {
7503 final int NW = allAppWindows.size();
7504 for (int i=0; i<NW; i++) {
7505 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007506 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 "performing show on: " + w);
7508 w.performShowLocked();
7509 }
7510 }
Romain Guy06882f82009-06-10 13:36:04 -07007511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 // This must be called while inside a transaction.
7513 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007514 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 if (animation == sDummyAnimation) {
7518 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007519 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 // when it is really time to animate, this will be set to
7521 // a real animation and the next call will execute normally.
7522 return false;
7523 }
Romain Guy06882f82009-06-10 13:36:04 -07007524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7526 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007527 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528 TAG, "Starting animation in " + this +
7529 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7530 + " scale=" + mTransitionAnimationScale
7531 + " allDrawn=" + allDrawn + " animating=" + animating);
7532 animation.initialize(dw, dh, dw, dh);
7533 animation.setStartTime(currentTime);
7534 animating = true;
7535 }
7536 transformation.clear();
7537 final boolean more = animation.getTransformation(
7538 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007539 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 TAG, "Stepped animation in " + this +
7541 ": more=" + more + ", xform=" + transformation);
7542 if (more) {
7543 // we're done!
7544 hasTransformation = true;
7545 return true;
7546 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007547 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 TAG, "Finished animation in " + this +
7549 " @ " + currentTime);
7550 animation = null;
7551 }
7552 } else if (animation != null) {
7553 // If the display is frozen, and there is a pending animation,
7554 // clear it and make sure we run the cleanup code.
7555 animating = true;
7556 animation = null;
7557 }
7558
7559 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007561 if (!animating) {
7562 return false;
7563 }
7564
7565 clearAnimation();
7566 animating = false;
7567 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7568 moveInputMethodWindowsIfNeededLocked(true);
7569 }
Romain Guy06882f82009-06-10 13:36:04 -07007570
Joe Onorato8a9b2202010-02-26 18:56:32 -08007571 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 TAG, "Animation done in " + this
7573 + ": reportedVisible=" + reportedVisible);
7574
7575 transformation.clear();
7576 if (animLayerAdjustment != 0) {
7577 animLayerAdjustment = 0;
7578 updateLayers();
7579 }
Romain Guy06882f82009-06-10 13:36:04 -07007580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007581 final int N = windows.size();
7582 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007583 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 }
7585 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 return false;
7588 }
7589
7590 void updateReportedVisibilityLocked() {
7591 if (appToken == null) {
7592 return;
7593 }
Romain Guy06882f82009-06-10 13:36:04 -07007594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007595 int numInteresting = 0;
7596 int numVisible = 0;
7597 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007598
Joe Onorato8a9b2202010-02-26 18:56:32 -08007599 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007600 final int N = allAppWindows.size();
7601 for (int i=0; i<N; i++) {
7602 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007603 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007604 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02007605 || win.mAttrs.type == TYPE_APPLICATION_STARTING
7606 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 continue;
7608 }
7609 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007610 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007611 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007613 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007614 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007615 + " pv=" + win.mPolicyVisibility
7616 + " dp=" + win.mDrawPending
7617 + " cdp=" + win.mCommitDrawPending
7618 + " ah=" + win.mAttachedHidden
7619 + " th="
7620 + (win.mAppToken != null
7621 ? win.mAppToken.hiddenRequested : false)
7622 + " a=" + win.mAnimating);
7623 }
7624 }
7625 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007626 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 if (!win.isAnimating()) {
7628 numVisible++;
7629 }
7630 nowGone = false;
7631 } else if (win.isAnimating()) {
7632 nowGone = false;
7633 }
7634 }
Romain Guy06882f82009-06-10 13:36:04 -07007635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007636 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007637 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 + numInteresting + " visible=" + numVisible);
7639 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007640 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007641 TAG, "Visibility changed in " + this
7642 + ": vis=" + nowVisible);
7643 reportedVisible = nowVisible;
7644 Message m = mH.obtainMessage(
7645 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7646 nowVisible ? 1 : 0,
7647 nowGone ? 1 : 0,
7648 this);
7649 mH.sendMessage(m);
7650 }
7651 }
Romain Guy06882f82009-06-10 13:36:04 -07007652
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007653 WindowState findMainWindow() {
7654 int j = windows.size();
7655 while (j > 0) {
7656 j--;
7657 WindowState win = windows.get(j);
7658 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7659 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7660 return win;
7661 }
7662 }
7663 return null;
7664 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007666 void dump(PrintWriter pw, String prefix) {
7667 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007668 if (appToken != null) {
7669 pw.print(prefix); pw.println("app=true");
7670 }
7671 if (allAppWindows.size() > 0) {
7672 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7673 }
7674 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007675 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007676 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7677 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7678 pw.print(" clientHidden="); pw.print(clientHidden);
7679 pw.print(" willBeHidden="); pw.print(willBeHidden);
7680 pw.print(" reportedVisible="); pw.println(reportedVisible);
7681 if (paused || freezingScreen) {
7682 pw.print(prefix); pw.print("paused="); pw.print(paused);
7683 pw.print(" freezingScreen="); pw.println(freezingScreen);
7684 }
7685 if (numInterestingWindows != 0 || numDrawnWindows != 0
7686 || inPendingTransaction || allDrawn) {
7687 pw.print(prefix); pw.print("numInterestingWindows=");
7688 pw.print(numInterestingWindows);
7689 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7690 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7691 pw.print(" allDrawn="); pw.println(allDrawn);
7692 }
7693 if (animating || animation != null) {
7694 pw.print(prefix); pw.print("animating="); pw.print(animating);
7695 pw.print(" animation="); pw.println(animation);
7696 }
7697 if (animLayerAdjustment != 0) {
7698 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7699 }
7700 if (hasTransformation) {
7701 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7702 pw.print(" transformation="); transformation.printShortString(pw);
7703 pw.println();
7704 }
7705 if (startingData != null || removed || firstWindowDrawn) {
7706 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7707 pw.print(" removed="); pw.print(removed);
7708 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7709 }
7710 if (startingWindow != null || startingView != null
7711 || startingDisplayed || startingMoved) {
7712 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7713 pw.print(" startingView="); pw.print(startingView);
7714 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7715 pw.print(" startingMoved"); pw.println(startingMoved);
7716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007717 }
7718
7719 @Override
7720 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007721 if (stringName == null) {
7722 StringBuilder sb = new StringBuilder();
7723 sb.append("AppWindowToken{");
7724 sb.append(Integer.toHexString(System.identityHashCode(this)));
7725 sb.append(" token="); sb.append(token); sb.append('}');
7726 stringName = sb.toString();
7727 }
7728 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007729 }
7730 }
Romain Guy06882f82009-06-10 13:36:04 -07007731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 // -------------------------------------------------------------
7733 // DummyAnimation
7734 // -------------------------------------------------------------
7735
7736 // This is an animation that does nothing: it just immediately finishes
7737 // itself every time it is called. It is used as a stub animation in cases
7738 // where we want to synchronize multiple things that may be animating.
7739 static final class DummyAnimation extends Animation {
7740 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7741 return false;
7742 }
7743 }
7744 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007746 // -------------------------------------------------------------
7747 // Async Handler
7748 // -------------------------------------------------------------
7749
7750 static final class StartingData {
7751 final String pkg;
7752 final int theme;
7753 final CharSequence nonLocalizedLabel;
7754 final int labelRes;
7755 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007757 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7758 int _labelRes, int _icon) {
7759 pkg = _pkg;
7760 theme = _theme;
7761 nonLocalizedLabel = _nonLocalizedLabel;
7762 labelRes = _labelRes;
7763 icon = _icon;
7764 }
7765 }
7766
7767 private final class H extends Handler {
7768 public static final int REPORT_FOCUS_CHANGE = 2;
7769 public static final int REPORT_LOSING_FOCUS = 3;
7770 public static final int ANIMATE = 4;
7771 public static final int ADD_STARTING = 5;
7772 public static final int REMOVE_STARTING = 6;
7773 public static final int FINISHED_STARTING = 7;
7774 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7776 public static final int HOLD_SCREEN_CHANGED = 12;
7777 public static final int APP_TRANSITION_TIMEOUT = 13;
7778 public static final int PERSIST_ANIMATION_SCALE = 14;
7779 public static final int FORCE_GC = 15;
7780 public static final int ENABLE_SCREEN = 16;
7781 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007782 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007783 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007785 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 public H() {
7788 }
Romain Guy06882f82009-06-10 13:36:04 -07007789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 @Override
7791 public void handleMessage(Message msg) {
7792 switch (msg.what) {
7793 case REPORT_FOCUS_CHANGE: {
7794 WindowState lastFocus;
7795 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797 synchronized(mWindowMap) {
7798 lastFocus = mLastFocus;
7799 newFocus = mCurrentFocus;
7800 if (lastFocus == newFocus) {
7801 // Focus is not changing, so nothing to do.
7802 return;
7803 }
7804 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007805 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007806 // + " to " + newFocus);
7807 if (newFocus != null && lastFocus != null
7808 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007809 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007810 mLosingFocus.add(lastFocus);
7811 lastFocus = null;
7812 }
7813 }
7814
7815 if (lastFocus != newFocus) {
7816 //System.out.println("Changing focus from " + lastFocus
7817 // + " to " + newFocus);
7818 if (newFocus != null) {
7819 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007820 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7822 } catch (RemoteException e) {
7823 // Ignore if process has died.
7824 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007825 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 }
7827
7828 if (lastFocus != null) {
7829 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007830 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007831 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7832 } catch (RemoteException e) {
7833 // Ignore if process has died.
7834 }
7835 }
7836 }
7837 } break;
7838
7839 case REPORT_LOSING_FOCUS: {
7840 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 synchronized(mWindowMap) {
7843 losers = mLosingFocus;
7844 mLosingFocus = new ArrayList<WindowState>();
7845 }
7846
7847 final int N = losers.size();
7848 for (int i=0; i<N; i++) {
7849 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007850 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7852 } catch (RemoteException e) {
7853 // Ignore if process has died.
7854 }
7855 }
7856 } break;
7857
7858 case ANIMATE: {
7859 synchronized(mWindowMap) {
7860 mAnimationPending = false;
7861 performLayoutAndPlaceSurfacesLocked();
7862 }
7863 } break;
7864
7865 case ADD_STARTING: {
7866 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7867 final StartingData sd = wtoken.startingData;
7868
7869 if (sd == null) {
7870 // Animation has been canceled... do nothing.
7871 return;
7872 }
Romain Guy06882f82009-06-10 13:36:04 -07007873
Joe Onorato8a9b2202010-02-26 18:56:32 -08007874 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007877 View view = null;
7878 try {
7879 view = mPolicy.addStartingWindow(
7880 wtoken.token, sd.pkg,
7881 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7882 sd.icon);
7883 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007884 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 }
7886
7887 if (view != null) {
7888 boolean abort = false;
7889
7890 synchronized(mWindowMap) {
7891 if (wtoken.removed || wtoken.startingData == null) {
7892 // If the window was successfully added, then
7893 // we need to remove it.
7894 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007895 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007896 "Aborted starting " + wtoken
7897 + ": removed=" + wtoken.removed
7898 + " startingData=" + wtoken.startingData);
7899 wtoken.startingWindow = null;
7900 wtoken.startingData = null;
7901 abort = true;
7902 }
7903 } else {
7904 wtoken.startingView = view;
7905 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007906 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 "Added starting " + wtoken
7908 + ": startingWindow="
7909 + wtoken.startingWindow + " startingView="
7910 + wtoken.startingView);
7911 }
7912
7913 if (abort) {
7914 try {
7915 mPolicy.removeStartingWindow(wtoken.token, view);
7916 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007917 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007918 }
7919 }
7920 }
7921 } break;
7922
7923 case REMOVE_STARTING: {
7924 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7925 IBinder token = null;
7926 View view = null;
7927 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007928 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 + wtoken + ": startingWindow="
7930 + wtoken.startingWindow + " startingView="
7931 + wtoken.startingView);
7932 if (wtoken.startingWindow != null) {
7933 view = wtoken.startingView;
7934 token = wtoken.token;
7935 wtoken.startingData = null;
7936 wtoken.startingView = null;
7937 wtoken.startingWindow = null;
7938 }
7939 }
7940 if (view != null) {
7941 try {
7942 mPolicy.removeStartingWindow(token, view);
7943 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007944 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007945 }
7946 }
7947 } break;
7948
7949 case FINISHED_STARTING: {
7950 IBinder token = null;
7951 View view = null;
7952 while (true) {
7953 synchronized (mWindowMap) {
7954 final int N = mFinishedStarting.size();
7955 if (N <= 0) {
7956 break;
7957 }
7958 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7959
Joe Onorato8a9b2202010-02-26 18:56:32 -08007960 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007961 "Finished starting " + wtoken
7962 + ": startingWindow=" + wtoken.startingWindow
7963 + " startingView=" + wtoken.startingView);
7964
7965 if (wtoken.startingWindow == null) {
7966 continue;
7967 }
7968
7969 view = wtoken.startingView;
7970 token = wtoken.token;
7971 wtoken.startingData = null;
7972 wtoken.startingView = null;
7973 wtoken.startingWindow = null;
7974 }
7975
7976 try {
7977 mPolicy.removeStartingWindow(token, view);
7978 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007979 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 }
7981 }
7982 } break;
7983
7984 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7985 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7986
7987 boolean nowVisible = msg.arg1 != 0;
7988 boolean nowGone = msg.arg2 != 0;
7989
7990 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007991 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007992 TAG, "Reporting visible in " + wtoken
7993 + " visible=" + nowVisible
7994 + " gone=" + nowGone);
7995 if (nowVisible) {
7996 wtoken.appToken.windowsVisible();
7997 } else {
7998 wtoken.appToken.windowsGone();
7999 }
8000 } catch (RemoteException ex) {
8001 }
8002 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 case WINDOW_FREEZE_TIMEOUT: {
8005 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008006 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008007 int i = mWindows.size();
8008 while (i > 0) {
8009 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008010 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011 if (w.mOrientationChanging) {
8012 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008013 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008014 }
8015 }
8016 performLayoutAndPlaceSurfacesLocked();
8017 }
8018 break;
8019 }
Romain Guy06882f82009-06-10 13:36:04 -07008020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 case HOLD_SCREEN_CHANGED: {
8022 Session oldHold;
8023 Session newHold;
8024 synchronized (mWindowMap) {
8025 oldHold = mLastReportedHold;
8026 newHold = (Session)msg.obj;
8027 mLastReportedHold = newHold;
8028 }
Romain Guy06882f82009-06-10 13:36:04 -07008029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008030 if (oldHold != newHold) {
8031 try {
8032 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008033 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 "window",
8035 BatteryStats.WAKE_TYPE_WINDOW);
8036 }
8037 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008038 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008039 "window",
8040 BatteryStats.WAKE_TYPE_WINDOW);
8041 }
8042 } catch (RemoteException e) {
8043 }
8044 }
8045 break;
8046 }
Romain Guy06882f82009-06-10 13:36:04 -07008047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 case APP_TRANSITION_TIMEOUT: {
8049 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008050 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008051 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 "*** APP TRANSITION TIMEOUT");
8053 mAppTransitionReady = true;
8054 mAppTransitionTimeout = true;
8055 performLayoutAndPlaceSurfacesLocked();
8056 }
8057 }
8058 break;
8059 }
Romain Guy06882f82009-06-10 13:36:04 -07008060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008061 case PERSIST_ANIMATION_SCALE: {
8062 Settings.System.putFloat(mContext.getContentResolver(),
8063 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8064 Settings.System.putFloat(mContext.getContentResolver(),
8065 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8066 break;
8067 }
Romain Guy06882f82009-06-10 13:36:04 -07008068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 case FORCE_GC: {
8070 synchronized(mWindowMap) {
8071 if (mAnimationPending) {
8072 // If we are animating, don't do the gc now but
8073 // delay a bit so we don't interrupt the animation.
8074 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8075 2000);
8076 return;
8077 }
8078 // If we are currently rotating the display, it will
8079 // schedule a new message when done.
8080 if (mDisplayFrozen) {
8081 return;
8082 }
8083 mFreezeGcPending = 0;
8084 }
8085 Runtime.getRuntime().gc();
8086 break;
8087 }
Romain Guy06882f82009-06-10 13:36:04 -07008088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 case ENABLE_SCREEN: {
8090 performEnableScreen();
8091 break;
8092 }
Romain Guy06882f82009-06-10 13:36:04 -07008093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 case APP_FREEZE_TIMEOUT: {
8095 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008096 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008097 int i = mAppTokens.size();
8098 while (i > 0) {
8099 i--;
8100 AppWindowToken tok = mAppTokens.get(i);
8101 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008102 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 unsetAppFreezingScreenLocked(tok, true, true);
8104 }
8105 }
8106 }
8107 break;
8108 }
Romain Guy06882f82009-06-10 13:36:04 -07008109
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008110 case SEND_NEW_CONFIGURATION: {
8111 removeMessages(SEND_NEW_CONFIGURATION);
8112 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008113 break;
8114 }
Romain Guy06882f82009-06-10 13:36:04 -07008115
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008116 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008117 if (mWindowsChanged) {
8118 synchronized (mWindowMap) {
8119 mWindowsChanged = false;
8120 }
8121 notifyWindowsChanged();
8122 }
8123 break;
8124 }
8125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008126 }
8127 }
8128 }
8129
8130 // -------------------------------------------------------------
8131 // IWindowManager API
8132 // -------------------------------------------------------------
8133
8134 public IWindowSession openSession(IInputMethodClient client,
8135 IInputContext inputContext) {
8136 if (client == null) throw new IllegalArgumentException("null client");
8137 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008138 Session session = new Session(client, inputContext);
8139 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 }
8141
8142 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8143 synchronized (mWindowMap) {
8144 // The focus for the client is the window immediately below
8145 // where we would place the input method window.
8146 int idx = findDesiredInputMethodWindowIndexLocked(false);
8147 WindowState imFocus;
8148 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008149 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008150 if (imFocus != null) {
8151 if (imFocus.mSession.mClient != null &&
8152 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8153 return true;
8154 }
8155 }
8156 }
8157 }
8158 return false;
8159 }
Romain Guy06882f82009-06-10 13:36:04 -07008160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008161 // -------------------------------------------------------------
8162 // Internals
8163 // -------------------------------------------------------------
8164
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008165 final WindowState windowForClientLocked(Session session, IWindow client,
8166 boolean throwOnError) {
8167 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008168 }
Romain Guy06882f82009-06-10 13:36:04 -07008169
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008170 final WindowState windowForClientLocked(Session session, IBinder client,
8171 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008172 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008173 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008174 TAG, "Looking up client " + client + ": " + win);
8175 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008176 RuntimeException ex = new IllegalArgumentException(
8177 "Requested window " + client + " does not exist");
8178 if (throwOnError) {
8179 throw ex;
8180 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008181 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008182 return null;
8183 }
8184 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008185 RuntimeException ex = new IllegalArgumentException(
8186 "Requested window " + client + " is in session " +
8187 win.mSession + ", not " + session);
8188 if (throwOnError) {
8189 throw ex;
8190 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008191 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 return null;
8193 }
8194
8195 return win;
8196 }
8197
Dianne Hackborna8f60182009-09-01 19:01:50 -07008198 final void rebuildAppWindowListLocked() {
8199 int NW = mWindows.size();
8200 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008201 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008202 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008203
Dianne Hackborna8f60182009-09-01 19:01:50 -07008204 // First remove all existing app windows.
8205 i=0;
8206 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008207 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008208 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008209 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008210 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008211 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008212 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008213 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008214 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008215 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008216 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8217 && lastWallpaper == i-1) {
8218 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008219 }
8220 i++;
8221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008222
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008223 // The wallpaper window(s) typically live at the bottom of the stack,
8224 // so skip them before adding app tokens.
8225 lastWallpaper++;
8226 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008227
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008228 // First add all of the exiting app tokens... these are no longer
8229 // in the main app list, but still have windows shown. We put them
8230 // in the back because now that the animation is over we no longer
8231 // will care about them.
8232 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008233 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008234 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8235 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008236
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008237 // And add in the still active app tokens in Z order.
8238 NT = mAppTokens.size();
8239 for (int j=0; j<NT; j++) {
8240 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008241 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008242
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008243 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008244 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008245 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008246 + " windows but added " + i);
8247 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 private final void assignLayersLocked() {
8251 int N = mWindows.size();
8252 int curBaseLayer = 0;
8253 int curLayer = 0;
8254 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008256 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008257 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008258 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8259 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008260 curLayer += WINDOW_LAYER_MULTIPLIER;
8261 w.mLayer = curLayer;
8262 } else {
8263 curBaseLayer = curLayer = w.mBaseLayer;
8264 w.mLayer = curLayer;
8265 }
8266 if (w.mTargetAppToken != null) {
8267 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8268 } else if (w.mAppToken != null) {
8269 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8270 } else {
8271 w.mAnimLayer = w.mLayer;
8272 }
8273 if (w.mIsImWindow) {
8274 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008275 } else if (w.mIsWallpaper) {
8276 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008278 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 + w.mAnimLayer);
8280 //System.out.println(
8281 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8282 }
8283 }
8284
8285 private boolean mInLayout = false;
8286 private final void performLayoutAndPlaceSurfacesLocked() {
8287 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008288 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008289 throw new RuntimeException("Recursive call!");
8290 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008291 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008292 return;
8293 }
8294
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008295 if (mWaitingForConfig) {
8296 // Our configuration has changed (most likely rotation), but we
8297 // don't yet have the complete configuration to report to
8298 // applications. Don't do any window layout until we have it.
8299 return;
8300 }
8301
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008302 if (mDisplay == null) {
8303 // Not yet initialized, nothing to do.
8304 return;
8305 }
8306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307 boolean recoveringMemory = false;
8308 if (mForceRemoves != null) {
8309 recoveringMemory = true;
8310 // Wait a little it for things to settle down, and off we go.
8311 for (int i=0; i<mForceRemoves.size(); i++) {
8312 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008313 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008314 removeWindowInnerLocked(ws.mSession, ws);
8315 }
8316 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008317 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008318 Object tmp = new Object();
8319 synchronized (tmp) {
8320 try {
8321 tmp.wait(250);
8322 } catch (InterruptedException e) {
8323 }
8324 }
8325 }
Romain Guy06882f82009-06-10 13:36:04 -07008326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008327 mInLayout = true;
8328 try {
8329 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008331 int i = mPendingRemove.size()-1;
8332 if (i >= 0) {
8333 while (i >= 0) {
8334 WindowState w = mPendingRemove.get(i);
8335 removeWindowInnerLocked(w.mSession, w);
8336 i--;
8337 }
8338 mPendingRemove.clear();
8339
8340 mInLayout = false;
8341 assignLayersLocked();
8342 mLayoutNeeded = true;
8343 performLayoutAndPlaceSurfacesLocked();
8344
8345 } else {
8346 mInLayout = false;
8347 if (mLayoutNeeded) {
8348 requestAnimationLocked(0);
8349 }
8350 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008351 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008352 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8353 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008355 } catch (RuntimeException e) {
8356 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008357 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008358 }
8359 }
8360
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008361 private final int performLayoutLockedInner() {
8362 if (!mLayoutNeeded) {
8363 return 0;
8364 }
8365
8366 mLayoutNeeded = false;
8367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008368 final int dw = mDisplay.getWidth();
8369 final int dh = mDisplay.getHeight();
8370
8371 final int N = mWindows.size();
8372 int i;
8373
Joe Onorato8a9b2202010-02-26 18:56:32 -08008374 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008375 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8376
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008377 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008378
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008379 int seq = mLayoutSeq+1;
8380 if (seq < 0) seq = 0;
8381 mLayoutSeq = seq;
8382
8383 // First perform layout of any root windows (not attached
8384 // to another window).
8385 int topAttached = -1;
8386 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008387 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008388
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008389 // Don't do layout of a window if it is not visible, or
8390 // soon won't be visible, to avoid wasting time and funky
8391 // changes while a window is animating away.
8392 final AppWindowToken atoken = win.mAppToken;
8393 final boolean gone = win.mViewVisibility == View.GONE
8394 || !win.mRelayoutCalled
8395 || win.mRootToken.hidden
8396 || (atoken != null && atoken.hiddenRequested)
8397 || win.mAttachedHidden
8398 || win.mExiting || win.mDestroying;
8399
8400 if (!win.mLayoutAttached) {
8401 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8402 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8403 + " mLayoutAttached=" + win.mLayoutAttached);
8404 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8405 + win.mViewVisibility + " mRelayoutCalled="
8406 + win.mRelayoutCalled + " hidden="
8407 + win.mRootToken.hidden + " hiddenRequested="
8408 + (atoken != null && atoken.hiddenRequested)
8409 + " mAttachedHidden=" + win.mAttachedHidden);
8410 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008411
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008412 // If this view is GONE, then skip it -- keep the current
8413 // frame, and let the caller know so they can ignore it
8414 // if they want. (We do the normal layout for INVISIBLE
8415 // windows, since that means "perform layout as normal,
8416 // just don't display").
8417 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008418 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008419 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8420 win.mLayoutSeq = seq;
8421 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8422 + win.mFrame + " mContainingFrame="
8423 + win.mContainingFrame + " mDisplayFrame="
8424 + win.mDisplayFrame);
8425 } else {
8426 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008427 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008429 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008430
8431 // Now perform layout of attached windows, which usually
8432 // depend on the position of the window they are attached to.
8433 // XXX does not deal with windows that are attached to windows
8434 // that are themselves attached.
8435 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008436 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008437
8438 // If this view is GONE, then skip it -- keep the current
8439 // frame, and let the caller know so they can ignore it
8440 // if they want. (We do the normal layout for INVISIBLE
8441 // windows, since that means "perform layout as normal,
8442 // just don't display").
8443 if (win.mLayoutAttached) {
8444 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8445 + " mHaveFrame=" + win.mHaveFrame
8446 + " mViewVisibility=" + win.mViewVisibility
8447 + " mRelayoutCalled=" + win.mRelayoutCalled);
8448 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8449 || !win.mHaveFrame) {
8450 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8451 win.mLayoutSeq = seq;
8452 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8453 + win.mFrame + " mContainingFrame="
8454 + win.mContainingFrame + " mDisplayFrame="
8455 + win.mDisplayFrame);
8456 }
8457 }
8458 }
Jeff Brown349703e2010-06-22 01:27:15 -07008459
8460 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008461 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008462
8463 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464 }
Romain Guy06882f82009-06-10 13:36:04 -07008465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 private final void performLayoutAndPlaceSurfacesLockedInner(
8467 boolean recoveringMemory) {
8468 final long currentTime = SystemClock.uptimeMillis();
8469 final int dw = mDisplay.getWidth();
8470 final int dh = mDisplay.getHeight();
8471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008472 int i;
8473
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008474 if (mFocusMayChange) {
8475 mFocusMayChange = false;
8476 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8477 }
8478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 // Initialize state of exiting tokens.
8480 for (i=mExitingTokens.size()-1; i>=0; i--) {
8481 mExitingTokens.get(i).hasVisible = false;
8482 }
8483
8484 // Initialize state of exiting applications.
8485 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8486 mExitingAppTokens.get(i).hasVisible = false;
8487 }
8488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008489 boolean orientationChangeComplete = true;
8490 Session holdScreen = null;
8491 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008492 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 boolean focusDisplayed = false;
8494 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008495 boolean createWatermark = false;
8496
8497 if (mFxSession == null) {
8498 mFxSession = new SurfaceSession();
8499 createWatermark = true;
8500 }
8501
8502 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503
8504 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008505
8506 if (createWatermark) {
8507 createWatermark();
8508 }
8509 if (mWatermark != null) {
8510 mWatermark.positionSurface(dw, dh);
8511 }
8512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008514 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008515 int repeats = 0;
8516 int changes = 0;
8517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008519 repeats++;
8520 if (repeats > 6) {
8521 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8522 mLayoutNeeded = false;
8523 break;
8524 }
8525
8526 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8527 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8528 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8529 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8530 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8531 assignLayersLocked();
8532 mLayoutNeeded = true;
8533 }
8534 }
8535 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8536 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8537 if (updateOrientationFromAppTokensLocked()) {
8538 mLayoutNeeded = true;
8539 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8540 }
8541 }
8542 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8543 mLayoutNeeded = true;
8544 }
8545 }
8546
8547 // FIRST LOOP: Perform a layout, if needed.
8548 if (repeats < 4) {
8549 changes = performLayoutLockedInner();
8550 if (changes != 0) {
8551 continue;
8552 }
8553 } else {
8554 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8555 changes = 0;
8556 }
8557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 final int transactionSequence = ++mTransactionSequence;
8559
8560 // Update animations of all applications, including those
8561 // associated with exiting/removed apps
8562 boolean tokensAnimating = false;
8563 final int NAT = mAppTokens.size();
8564 for (i=0; i<NAT; i++) {
8565 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8566 tokensAnimating = true;
8567 }
8568 }
8569 final int NEAT = mExitingAppTokens.size();
8570 for (i=0; i<NEAT; i++) {
8571 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8572 tokensAnimating = true;
8573 }
8574 }
8575
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008576 // SECOND LOOP: Execute animations and update visibility of windows.
8577
Joe Onorato8a9b2202010-02-26 18:56:32 -08008578 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008579 + transactionSequence + " tokensAnimating="
8580 + tokensAnimating);
8581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583
8584 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008585 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008586 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587
8588 mPolicy.beginAnimationLw(dw, dh);
8589
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008590 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008592 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008593 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008594
8595 final WindowManager.LayoutParams attrs = w.mAttrs;
8596
8597 if (w.mSurface != null) {
8598 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008599 if (w.commitFinishDrawingLocked(currentTime)) {
8600 if ((w.mAttrs.flags
8601 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008602 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008603 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008604 wallpaperMayChange = true;
8605 }
8606 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008607
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008608 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008609 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8610 animating = true;
8611 //w.dump(" ");
8612 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008613 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8614 wallpaperMayChange = true;
8615 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008616
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008617 if (mPolicy.doesForceHide(w, attrs)) {
8618 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008619 if (DEBUG_VISIBILITY) Slog.v(TAG,
8620 "Animation done that could impact force hide: "
8621 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008622 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008623 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008624 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8625 forceHiding = true;
8626 }
8627 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8628 boolean changed;
8629 if (forceHiding) {
8630 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008631 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8632 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008633 } else {
8634 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008635 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8636 "Now policy shown: " + w);
8637 if (changed) {
8638 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008639 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008640 // Assume we will need to animate. If
8641 // we don't (because the wallpaper will
8642 // stay with the lock screen), then we will
8643 // clean up later.
8644 Animation a = mPolicy.createForceHideEnterAnimation();
8645 if (a != null) {
8646 w.setAnimation(a);
8647 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008648 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008649 if (mCurrentFocus == null ||
8650 mCurrentFocus.mLayer < w.mLayer) {
8651 // We are showing on to of the current
8652 // focus, so re-evaluate focus to make
8653 // sure it is correct.
8654 mFocusMayChange = true;
8655 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008656 }
8657 }
8658 if (changed && (attrs.flags
8659 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8660 wallpaperMayChange = true;
8661 }
8662 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664 mPolicy.animatingWindowLw(w, attrs);
8665 }
8666
8667 final AppWindowToken atoken = w.mAppToken;
8668 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8669 if (atoken.lastTransactionSequence != transactionSequence) {
8670 atoken.lastTransactionSequence = transactionSequence;
8671 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8672 atoken.startingDisplayed = false;
8673 }
8674 if ((w.isOnScreen() || w.mAttrs.type
8675 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8676 && !w.mExiting && !w.mDestroying) {
8677 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008678 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008679 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008681 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008682 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 + " pv=" + w.mPolicyVisibility
8684 + " dp=" + w.mDrawPending
8685 + " cdp=" + w.mCommitDrawPending
8686 + " ah=" + w.mAttachedHidden
8687 + " th=" + atoken.hiddenRequested
8688 + " a=" + w.mAnimating);
8689 }
8690 }
8691 if (w != atoken.startingWindow) {
8692 if (!atoken.freezingScreen || !w.mAppFreezing) {
8693 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008694 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008695 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008696 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008697 "tokenMayBeDrawn: " + atoken
8698 + " freezingScreen=" + atoken.freezingScreen
8699 + " mAppFreezing=" + w.mAppFreezing);
8700 tokenMayBeDrawn = true;
8701 }
8702 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008703 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 atoken.startingDisplayed = true;
8705 }
8706 }
8707 } else if (w.mReadyToShow) {
8708 w.performShowLocked();
8709 }
8710 }
8711
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008712 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713
8714 if (tokenMayBeDrawn) {
8715 // See if any windows have been drawn, so they (and others
8716 // associated with them) can now be shown.
8717 final int NT = mTokenList.size();
8718 for (i=0; i<NT; i++) {
8719 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8720 if (wtoken == null) {
8721 continue;
8722 }
8723 if (wtoken.freezingScreen) {
8724 int numInteresting = wtoken.numInterestingWindows;
8725 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008726 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008727 "allDrawn: " + wtoken
8728 + " interesting=" + numInteresting
8729 + " drawn=" + wtoken.numDrawnWindows);
8730 wtoken.showAllWindowsLocked();
8731 unsetAppFreezingScreenLocked(wtoken, false, true);
8732 orientationChangeComplete = true;
8733 }
8734 } else if (!wtoken.allDrawn) {
8735 int numInteresting = wtoken.numInterestingWindows;
8736 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008737 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008738 "allDrawn: " + wtoken
8739 + " interesting=" + numInteresting
8740 + " drawn=" + wtoken.numDrawnWindows);
8741 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008742 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008743
8744 // We can now show all of the drawn windows!
8745 if (!mOpeningApps.contains(wtoken)) {
8746 wtoken.showAllWindowsLocked();
8747 }
8748 }
8749 }
8750 }
8751 }
8752
8753 // If we are ready to perform an app transition, check through
8754 // all of the app tokens to be shown and see if they are ready
8755 // to go.
8756 if (mAppTransitionReady) {
8757 int NN = mOpeningApps.size();
8758 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008759 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008760 "Checking " + NN + " opening apps (frozen="
8761 + mDisplayFrozen + " timeout="
8762 + mAppTransitionTimeout + ")...");
8763 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8764 // If the display isn't frozen, wait to do anything until
8765 // all of the apps are ready. Otherwise just go because
8766 // we'll unfreeze the display when everyone is ready.
8767 for (i=0; i<NN && goodToGo; i++) {
8768 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008769 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008770 "Check opening app" + wtoken + ": allDrawn="
8771 + wtoken.allDrawn + " startingDisplayed="
8772 + wtoken.startingDisplayed);
8773 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8774 && !wtoken.startingMoved) {
8775 goodToGo = false;
8776 }
8777 }
8778 }
8779 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008780 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008781 int transit = mNextAppTransition;
8782 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008783 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008784 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008785 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008787 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008788 mAppTransitionTimeout = false;
8789 mStartingIconInTransition = false;
8790 mSkipAppTransitionAnimation = false;
8791
8792 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8793
Dianne Hackborna8f60182009-09-01 19:01:50 -07008794 // If there are applications waiting to come to the
8795 // top of the stack, now is the time to move their windows.
8796 // (Note that we don't do apps going to the bottom
8797 // here -- we want to keep their windows in the old
8798 // Z-order until the animation completes.)
8799 if (mToTopApps.size() > 0) {
8800 NN = mAppTokens.size();
8801 for (i=0; i<NN; i++) {
8802 AppWindowToken wtoken = mAppTokens.get(i);
8803 if (wtoken.sendingToTop) {
8804 wtoken.sendingToTop = false;
8805 moveAppWindowsLocked(wtoken, NN, false);
8806 }
8807 }
8808 mToTopApps.clear();
8809 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008810
Dianne Hackborn25994b42009-09-04 14:21:19 -07008811 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008812
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008813 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008814 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008815
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008816 // The top-most window will supply the layout params,
8817 // and we will determine it below.
8818 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008819 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008820 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008821
Joe Onorato8a9b2202010-02-26 18:56:32 -08008822 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008823 "New wallpaper target=" + mWallpaperTarget
8824 + ", lower target=" + mLowerWallpaperTarget
8825 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008826 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008827 // Do a first pass through the tokens for two
8828 // things:
8829 // (1) Determine if both the closing and opening
8830 // app token sets are wallpaper targets, in which
8831 // case special animations are needed
8832 // (since the wallpaper needs to stay static
8833 // behind them).
8834 // (2) Find the layout params of the top-most
8835 // application window in the tokens, which is
8836 // what will control the animation theme.
8837 final int NC = mClosingApps.size();
8838 NN = NC + mOpeningApps.size();
8839 for (i=0; i<NN; i++) {
8840 AppWindowToken wtoken;
8841 int mode;
8842 if (i < NC) {
8843 wtoken = mClosingApps.get(i);
8844 mode = 1;
8845 } else {
8846 wtoken = mOpeningApps.get(i-NC);
8847 mode = 2;
8848 }
8849 if (mLowerWallpaperTarget != null) {
8850 if (mLowerWallpaperTarget.mAppToken == wtoken
8851 || mUpperWallpaperTarget.mAppToken == wtoken) {
8852 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008853 }
8854 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008855 if (wtoken.appFullscreen) {
8856 WindowState ws = wtoken.findMainWindow();
8857 if (ws != null) {
8858 // If this is a compatibility mode
8859 // window, we will always use its anim.
8860 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8861 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008862 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008863 bestAnimLayer = Integer.MAX_VALUE;
8864 } else if (ws.mLayer > bestAnimLayer) {
8865 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008866 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008867 bestAnimLayer = ws.mLayer;
8868 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008869 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008870 }
8871 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008872
Dianne Hackborn25994b42009-09-04 14:21:19 -07008873 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008874 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008875 "Wallpaper animation!");
8876 switch (transit) {
8877 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8878 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8879 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8880 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8881 break;
8882 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8883 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8884 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8885 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8886 break;
8887 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008888 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008889 "New transit: " + transit);
8890 } else if (oldWallpaper != null) {
8891 // We are transitioning from an activity with
8892 // a wallpaper to one without.
8893 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008894 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008895 "New transit away from wallpaper: " + transit);
8896 } else if (mWallpaperTarget != null) {
8897 // We are transitioning from an activity without
8898 // a wallpaper to now showing the wallpaper
8899 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008900 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008901 "New transit into wallpaper: " + transit);
8902 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008903
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008904 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8905 mLastEnterAnimToken = animToken;
8906 mLastEnterAnimParams = animLp;
8907 } else if (mLastEnterAnimParams != null) {
8908 animLp = mLastEnterAnimParams;
8909 mLastEnterAnimToken = null;
8910 mLastEnterAnimParams = null;
8911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008912
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008913 // If all closing windows are obscured, then there is
8914 // no need to do an animation. This is the case, for
8915 // example, when this transition is being done behind
8916 // the lock screen.
8917 if (!mPolicy.allowAppAnimationsLw()) {
8918 animLp = null;
8919 }
8920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008921 NN = mOpeningApps.size();
8922 for (i=0; i<NN; i++) {
8923 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008924 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008925 "Now opening app" + wtoken);
8926 wtoken.reportedVisible = false;
8927 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008928 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008929 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008930 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008931 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 wtoken.showAllWindowsLocked();
8933 }
8934 NN = mClosingApps.size();
8935 for (i=0; i<NN; i++) {
8936 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008937 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008938 "Now closing app" + wtoken);
8939 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008940 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008941 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008942 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008943 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008944 // Force the allDrawn flag, because we want to start
8945 // this guy's animations regardless of whether it's
8946 // gotten drawn.
8947 wtoken.allDrawn = true;
8948 }
8949
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008950 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008952 mOpeningApps.clear();
8953 mClosingApps.clear();
8954
8955 // This has changed the visibility of windows, so perform
8956 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008957 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008958 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008959 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8960 assignLayersLocked();
8961 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008962 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008963 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008964 }
8965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008966
Dianne Hackborn16064f92010-03-25 00:47:24 -07008967 int adjResult = 0;
8968
Dianne Hackborna8f60182009-09-01 19:01:50 -07008969 if (!animating && mAppTransitionRunning) {
8970 // We have finished the animation of an app transition. To do
8971 // this, we have delayed a lot of operations like showing and
8972 // hiding apps, moving apps in Z-order, etc. The app token list
8973 // reflects the correct Z-order, but the window list may now
8974 // be out of sync with it. So here we will just rebuild the
8975 // entire app window list. Fun!
8976 mAppTransitionRunning = false;
8977 // Clear information about apps that were moving.
8978 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008979
Dianne Hackborna8f60182009-09-01 19:01:50 -07008980 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008981 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008982 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008983 moveInputMethodWindowsIfNeededLocked(false);
8984 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008985 // Since the window list has been rebuilt, focus might
8986 // have to be recomputed since the actual order of windows
8987 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008988 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008989 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008990
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008991 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008992 // At this point, there was a window with a wallpaper that
8993 // was force hiding other windows behind it, but now it
8994 // is going away. This may be simple -- just animate
8995 // away the wallpaper and its window -- or it may be
8996 // hard -- the wallpaper now needs to be shown behind
8997 // something that was hidden.
8998 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008999 if (mLowerWallpaperTarget != null
9000 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009001 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009002 "wallpaperForceHiding changed with lower="
9003 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009004 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009005 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9006 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9007 if (mLowerWallpaperTarget.mAppToken.hidden) {
9008 // The lower target has become hidden before we
9009 // actually started the animation... let's completely
9010 // re-evaluate everything.
9011 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009012 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009013 }
9014 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009015 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009016 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009017 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009018 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009019 + " NEW: " + mWallpaperTarget
9020 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009021 if (mLowerWallpaperTarget == null) {
9022 // Whoops, we don't need a special wallpaper animation.
9023 // Clear them out.
9024 forceHiding = false;
9025 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009026 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009027 if (w.mSurface != null) {
9028 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009029 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009030 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009031 forceHiding = true;
9032 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9033 if (!w.mAnimating) {
9034 // We set the animation above so it
9035 // is not yet running.
9036 w.clearAnimation();
9037 }
9038 }
9039 }
9040 }
9041 }
9042 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009043
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009044 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009045 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009046 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009047 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009048 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009049
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009050 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009051 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009052 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009053 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009054 assignLayersLocked();
9055 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009056 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009057 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009058 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009059 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009060
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009061 if (mFocusMayChange) {
9062 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009063 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009064 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009065 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009066 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009067 }
9068
9069 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009070 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009071 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009072
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009073 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9074 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009075
Jeff Browne33348b2010-07-15 23:54:05 -07009076 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009077 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009078
9079 // THIRD LOOP: Update the surfaces of all windows.
9080
9081 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9082
9083 boolean obscured = false;
9084 boolean blurring = false;
9085 boolean dimming = false;
9086 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009087 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009088 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009089
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009090 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009092 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009093 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009094
9095 boolean displayed = false;
9096 final WindowManager.LayoutParams attrs = w.mAttrs;
9097 final int attrFlags = attrs.flags;
9098
9099 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009100 // XXX NOTE: The logic here could be improved. We have
9101 // the decision about whether to resize a window separated
9102 // from whether to hide the surface. This can cause us to
9103 // resize a surface even if we are going to hide it. You
9104 // can see this by (1) holding device in landscape mode on
9105 // home screen; (2) tapping browser icon (device will rotate
9106 // to landscape; (3) tap home. The wallpaper will be resized
9107 // in step 2 but then immediately hidden, causing us to
9108 // have to resize and then redraw it again in step 3. It
9109 // would be nice to figure out how to avoid this, but it is
9110 // difficult because we do need to resize surfaces in some
9111 // cases while they are hidden such as when first showing a
9112 // window.
9113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009114 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009115 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009116 TAG, "Placing surface #" + i + " " + w.mSurface
9117 + ": new=" + w.mShownFrame + ", old="
9118 + w.mLastShownFrame);
9119
9120 boolean resize;
9121 int width, height;
9122 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9123 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9124 w.mLastRequestedHeight != w.mRequestedHeight;
9125 // for a scaled surface, we just want to use
9126 // the requested size.
9127 width = w.mRequestedWidth;
9128 height = w.mRequestedHeight;
9129 w.mLastRequestedWidth = width;
9130 w.mLastRequestedHeight = height;
9131 w.mLastShownFrame.set(w.mShownFrame);
9132 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009133 if (SHOW_TRANSACTIONS) logSurface(w,
9134 "POS " + w.mShownFrame.left
9135 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009136 w.mSurfaceX = w.mShownFrame.left;
9137 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009138 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9139 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009140 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 if (!recoveringMemory) {
9142 reclaimSomeSurfaceMemoryLocked(w, "position");
9143 }
9144 }
9145 } else {
9146 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9147 width = w.mShownFrame.width();
9148 height = w.mShownFrame.height();
9149 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 }
9151
9152 if (resize) {
9153 if (width < 1) width = 1;
9154 if (height < 1) height = 1;
9155 if (w.mSurface != null) {
9156 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009157 if (SHOW_TRANSACTIONS) logSurface(w,
9158 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009159 + w.mShownFrame.top + " SIZE "
9160 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009161 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009162 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009163 w.mSurfaceW = width;
9164 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009165 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009166 w.mSurfaceX = w.mShownFrame.left;
9167 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009168 w.mSurface.setPosition(w.mShownFrame.left,
9169 w.mShownFrame.top);
9170 } catch (RuntimeException e) {
9171 // If something goes wrong with the surface (such
9172 // as running out of memory), don't take down the
9173 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009174 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009175 + "size=(" + width + "x" + height
9176 + "), pos=(" + w.mShownFrame.left
9177 + "," + w.mShownFrame.top + ")", e);
9178 if (!recoveringMemory) {
9179 reclaimSomeSurfaceMemoryLocked(w, "size");
9180 }
9181 }
9182 }
9183 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009184 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009185 w.mContentInsetsChanged =
9186 !w.mLastContentInsets.equals(w.mContentInsets);
9187 w.mVisibleInsetsChanged =
9188 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009189 boolean configChanged =
9190 w.mConfiguration != mCurConfiguration
9191 && (w.mConfiguration == null
9192 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009193 if (DEBUG_CONFIGURATION && configChanged) {
9194 Slog.v(TAG, "Win " + w + " config changed: "
9195 + mCurConfiguration);
9196 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009197 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009198 + ": configChanged=" + configChanged
9199 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009200 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009201 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009202 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009203 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009204 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 w.mLastFrame.set(w.mFrame);
9206 w.mLastContentInsets.set(w.mContentInsets);
9207 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009208 // If the screen is currently frozen, then keep
9209 // it frozen until this window draws at its new
9210 // orientation.
9211 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009212 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009213 "Resizing while display frozen: " + w);
9214 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009215 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009216 mWindowsFreezingScreen = true;
9217 // XXX should probably keep timeout from
9218 // when we first froze the display.
9219 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9220 mH.sendMessageDelayed(mH.obtainMessage(
9221 H.WINDOW_FREEZE_TIMEOUT), 2000);
9222 }
9223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224 // If the orientation is changing, then we need to
9225 // hold off on unfreezing the display until this
9226 // window has been redrawn; to do that, we need
9227 // to go through the process of getting informed
9228 // by the application when it has finished drawing.
9229 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009230 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009231 "Orientation start waiting for draw in "
9232 + w + ", surface " + w.mSurface);
9233 w.mDrawPending = true;
9234 w.mCommitDrawPending = false;
9235 w.mReadyToShow = false;
9236 if (w.mAppToken != null) {
9237 w.mAppToken.allDrawn = false;
9238 }
9239 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009240 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009241 "Resizing window " + w + " to " + w.mFrame);
9242 mResizingWindows.add(w);
9243 } else if (w.mOrientationChanging) {
9244 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009245 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009246 "Orientation not waiting for draw in "
9247 + w + ", surface " + w.mSurface);
9248 w.mOrientationChanging = false;
9249 }
9250 }
9251 }
9252
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009253 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254 if (!w.mLastHidden) {
9255 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009256 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9257 + w.mRootToken.waitingToShow + " polvis="
9258 + w.mPolicyVisibility + " atthid="
9259 + w.mAttachedHidden + " tokhid="
9260 + w.mRootToken.hidden + " vis="
9261 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009263 if (SHOW_TRANSACTIONS) logSurface(w,
9264 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009265 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009266 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009267 try {
9268 w.mSurface.hide();
9269 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009270 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009271 }
9272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009273 }
9274 // If we are waiting for this window to handle an
9275 // orientation change, well, it is hidden, so
9276 // doesn't really matter. Note that this does
9277 // introduce a potential glitch if the window
9278 // becomes unhidden before it has drawn for the
9279 // new orientation.
9280 if (w.mOrientationChanging) {
9281 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009282 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 "Orientation change skips hidden " + w);
9284 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009285 } else if (w.mLastLayer != w.mAnimLayer
9286 || w.mLastAlpha != w.mShownAlpha
9287 || w.mLastDsDx != w.mDsDx
9288 || w.mLastDtDx != w.mDtDx
9289 || w.mLastDsDy != w.mDsDy
9290 || w.mLastDtDy != w.mDtDy
9291 || w.mLastHScale != w.mHScale
9292 || w.mLastVScale != w.mVScale
9293 || w.mLastHidden) {
9294 displayed = true;
9295 w.mLastAlpha = w.mShownAlpha;
9296 w.mLastLayer = w.mAnimLayer;
9297 w.mLastDsDx = w.mDsDx;
9298 w.mLastDtDx = w.mDtDx;
9299 w.mLastDsDy = w.mDsDy;
9300 w.mLastDtDy = w.mDtDy;
9301 w.mLastHScale = w.mHScale;
9302 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009303 if (SHOW_TRANSACTIONS) logSurface(w,
9304 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009305 + " matrix=[" + (w.mDsDx*w.mHScale)
9306 + "," + (w.mDtDx*w.mVScale)
9307 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009308 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009309 if (w.mSurface != null) {
9310 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009311 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009313 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009314 w.mSurface.setLayer(w.mAnimLayer);
9315 w.mSurface.setMatrix(
9316 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9317 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9318 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009319 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 if (!recoveringMemory) {
9321 reclaimSomeSurfaceMemoryLocked(w, "update");
9322 }
9323 }
9324 }
9325
9326 if (w.mLastHidden && !w.mDrawPending
9327 && !w.mCommitDrawPending
9328 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009329 if (SHOW_TRANSACTIONS) logSurface(w,
9330 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009331 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009332 + " during relayout");
9333 if (showSurfaceRobustlyLocked(w)) {
9334 w.mHasDrawn = true;
9335 w.mLastHidden = false;
9336 } else {
9337 w.mOrientationChanging = false;
9338 }
9339 }
9340 if (w.mSurface != null) {
9341 w.mToken.hasVisible = true;
9342 }
9343 } else {
9344 displayed = true;
9345 }
9346
9347 if (displayed) {
9348 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009349 if (attrs.width == LayoutParams.MATCH_PARENT
9350 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009351 covered = true;
9352 }
9353 }
9354 if (w.mOrientationChanging) {
9355 if (w.mDrawPending || w.mCommitDrawPending) {
9356 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009357 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 "Orientation continue waiting for draw in " + w);
9359 } else {
9360 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009361 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009362 "Orientation change complete in " + w);
9363 }
9364 }
9365 w.mToken.hasVisible = true;
9366 }
9367 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009368 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009369 "Orientation change skips hidden " + w);
9370 w.mOrientationChanging = false;
9371 }
9372
9373 final boolean canBeSeen = w.isDisplayedLw();
9374
9375 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9376 focusDisplayed = true;
9377 }
9378
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009379 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009382 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 if (w.mSurface != null) {
9384 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9385 holdScreen = w.mSession;
9386 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009387 if (!syswin && w.mAttrs.screenBrightness >= 0
9388 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009389 screenBrightness = w.mAttrs.screenBrightness;
9390 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009391 if (!syswin && w.mAttrs.buttonBrightness >= 0
9392 && buttonBrightness < 0) {
9393 buttonBrightness = w.mAttrs.buttonBrightness;
9394 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009395 if (canBeSeen
9396 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9397 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9398 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009399 syswin = true;
9400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009401 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009402
Dianne Hackborn25994b42009-09-04 14:21:19 -07009403 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9404 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009405 // This window completely covers everything behind it,
9406 // so we want to leave all of them as unblurred (for
9407 // performance reasons).
9408 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009409 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009410 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009411 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009412 obscured = true;
9413 if (mBackgroundFillerSurface == null) {
9414 try {
9415 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009416 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009417 0, dw, dh,
9418 PixelFormat.OPAQUE,
9419 Surface.FX_SURFACE_NORMAL);
9420 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009421 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009422 }
9423 }
9424 try {
9425 mBackgroundFillerSurface.setPosition(0, 0);
9426 mBackgroundFillerSurface.setSize(dw, dh);
9427 // Using the same layer as Dim because they will never be shown at the
9428 // same time.
9429 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9430 mBackgroundFillerSurface.show();
9431 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009432 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009433 }
9434 backgroundFillerShown = true;
9435 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009436 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009437 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009438 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009439 + ": blurring=" + blurring
9440 + " obscured=" + obscured
9441 + " displayed=" + displayed);
9442 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9443 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009444 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009446 if (mDimAnimator == null) {
9447 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009448 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009449 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009450 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009451 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009452 }
9453 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9454 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009455 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009456 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009457 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009458 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009459 + mBlurSurface + ": CREATE");
9460 try {
Romain Guy06882f82009-06-10 13:36:04 -07009461 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009462 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009463 -1, 16, 16,
9464 PixelFormat.OPAQUE,
9465 Surface.FX_SURFACE_BLUR);
9466 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009467 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468 }
9469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009470 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009471 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9472 + mBlurSurface + ": pos=(0,0) (" +
9473 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 mBlurSurface.setPosition(0, 0);
9475 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009476 mBlurSurface.setLayer(w.mAnimLayer-2);
9477 if (!mBlurShown) {
9478 try {
9479 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9480 + mBlurSurface + ": SHOW");
9481 mBlurSurface.show();
9482 } catch (RuntimeException e) {
9483 Slog.w(TAG, "Failure showing blur surface", e);
9484 }
9485 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486 }
9487 }
9488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489 }
9490 }
9491 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009492
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009493 if (obscuredChanged && mWallpaperTarget == w) {
9494 // This is the wallpaper target and its obscured state
9495 // changed... make sure the current wallaper's visibility
9496 // has been updated accordingly.
9497 updateWallpaperVisibilityLocked();
9498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009500
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009501 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9502 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009503 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009504 try {
9505 mBackgroundFillerSurface.hide();
9506 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009507 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009508 }
9509 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009511 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009512 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9513 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514 }
Romain Guy06882f82009-06-10 13:36:04 -07009515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009517 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009518 + ": HIDE");
9519 try {
9520 mBlurSurface.hide();
9521 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009522 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 }
9524 mBlurShown = false;
9525 }
9526
Joe Onorato8a9b2202010-02-26 18:56:32 -08009527 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009528 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009529 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009530 }
9531
Jeff Browne33348b2010-07-15 23:54:05 -07009532 mInputMonitor.updateInputWindowsLw();
9533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009535
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07009536 if (mWatermark != null) {
9537 mWatermark.drawIfNeeded();
9538 }
9539
Joe Onorato8a9b2202010-02-26 18:56:32 -08009540 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009541 "With display frozen, orientationChangeComplete="
9542 + orientationChangeComplete);
9543 if (orientationChangeComplete) {
9544 if (mWindowsFreezingScreen) {
9545 mWindowsFreezingScreen = false;
9546 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9547 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009548 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009549 }
Romain Guy06882f82009-06-10 13:36:04 -07009550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 i = mResizingWindows.size();
9552 if (i > 0) {
9553 do {
9554 i--;
9555 WindowState win = mResizingWindows.get(i);
9556 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009557 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9558 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009559 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009560 boolean configChanged =
9561 win.mConfiguration != mCurConfiguration
9562 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009563 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9564 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9565 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009566 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009567 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009568 + " / " + mCurConfiguration + " / 0x"
9569 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009570 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009571 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 win.mClient.resized(win.mFrame.width(),
9573 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009574 win.mLastVisibleInsets, win.mDrawPending,
9575 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009576 win.mContentInsetsChanged = false;
9577 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009578 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009579 } catch (RemoteException e) {
9580 win.mOrientationChanging = false;
9581 }
9582 } while (i > 0);
9583 mResizingWindows.clear();
9584 }
Romain Guy06882f82009-06-10 13:36:04 -07009585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009587 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588 i = mDestroySurface.size();
9589 if (i > 0) {
9590 do {
9591 i--;
9592 WindowState win = mDestroySurface.get(i);
9593 win.mDestroying = false;
9594 if (mInputMethodWindow == win) {
9595 mInputMethodWindow = null;
9596 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009597 if (win == mWallpaperTarget) {
9598 wallpaperDestroyed = true;
9599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 win.destroySurfaceLocked();
9601 } while (i > 0);
9602 mDestroySurface.clear();
9603 }
9604
9605 // Time to remove any exiting tokens?
9606 for (i=mExitingTokens.size()-1; i>=0; i--) {
9607 WindowToken token = mExitingTokens.get(i);
9608 if (!token.hasVisible) {
9609 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009610 if (token.windowType == TYPE_WALLPAPER) {
9611 mWallpaperTokens.remove(token);
9612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 }
9614 }
9615
9616 // Time to remove any exiting applications?
9617 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9618 AppWindowToken token = mExitingAppTokens.get(i);
9619 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009620 // Make sure there is no animation running on this token,
9621 // so any windows associated with it will be removed as
9622 // soon as their animations are complete
9623 token.animation = null;
9624 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625 mAppTokens.remove(token);
9626 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009627 if (mLastEnterAnimToken == token) {
9628 mLastEnterAnimToken = null;
9629 mLastEnterAnimParams = null;
9630 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009631 }
9632 }
9633
Dianne Hackborna8f60182009-09-01 19:01:50 -07009634 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009635
Dianne Hackborna8f60182009-09-01 19:01:50 -07009636 if (!animating && mAppTransitionRunning) {
9637 // We have finished the animation of an app transition. To do
9638 // this, we have delayed a lot of operations like showing and
9639 // hiding apps, moving apps in Z-order, etc. The app token list
9640 // reflects the correct Z-order, but the window list may now
9641 // be out of sync with it. So here we will just rebuild the
9642 // entire app window list. Fun!
9643 mAppTransitionRunning = false;
9644 needRelayout = true;
9645 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009646 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009647 // Clear information about apps that were moving.
9648 mToBottomApps.clear();
9649 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 if (focusDisplayed) {
9652 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9653 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009654 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009655 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009656 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009657 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009658 requestAnimationLocked(0);
9659 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009660 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9661 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009662
Jeff Browne33348b2010-07-15 23:54:05 -07009663 mInputMonitor.updateInputWindowsLw();
9664
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009665 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9666 + " holdScreen=" + holdScreen);
9667 if (!mDisplayFrozen) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009668 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009669 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9670 mPowerManager.setScreenBrightnessOverride(-1);
9671 } else {
9672 mPowerManager.setScreenBrightnessOverride((int)
9673 (screenBrightness * Power.BRIGHTNESS_ON));
9674 }
9675 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9676 mPowerManager.setButtonBrightnessOverride(-1);
9677 } else {
9678 mPowerManager.setButtonBrightnessOverride((int)
9679 (buttonBrightness * Power.BRIGHTNESS_ON));
9680 }
9681 if (holdScreen != mHoldingScreenOn) {
9682 mHoldingScreenOn = holdScreen;
9683 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9684 mH.sendMessage(m);
9685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009687
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009688 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009689 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009690 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9691 LocalPowerManager.BUTTON_EVENT, true);
9692 mTurnOnScreen = false;
9693 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009694
9695 // Check to see if we are now in a state where the screen should
9696 // be enabled, because the window obscured flags have changed.
9697 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009698 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009699
9700 /**
9701 * Must be called with the main window manager lock held.
9702 */
9703 void setHoldScreenLocked(boolean holding) {
9704 boolean state = mHoldingScreenWakeLock.isHeld();
9705 if (holding != state) {
9706 if (holding) {
9707 mHoldingScreenWakeLock.acquire();
9708 } else {
9709 mPolicy.screenOnStoppedLw();
9710 mHoldingScreenWakeLock.release();
9711 }
9712 }
9713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009714
9715 void requestAnimationLocked(long delay) {
9716 if (!mAnimationPending) {
9717 mAnimationPending = true;
9718 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9719 }
9720 }
Romain Guy06882f82009-06-10 13:36:04 -07009721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009722 /**
9723 * Have the surface flinger show a surface, robustly dealing with
9724 * error conditions. In particular, if there is not enough memory
9725 * to show the surface, then we will try to get rid of other surfaces
9726 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009727 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 * @return Returns true if the surface was successfully shown.
9729 */
9730 boolean showSurfaceRobustlyLocked(WindowState win) {
9731 try {
9732 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009733 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009734 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009735 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009736 if (DEBUG_VISIBILITY) Slog.v(TAG,
9737 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009738 win.mTurnOnScreen = false;
9739 mTurnOnScreen = true;
9740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 }
9742 return true;
9743 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009744 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009745 }
Romain Guy06882f82009-06-10 13:36:04 -07009746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009749 return false;
9750 }
Romain Guy06882f82009-06-10 13:36:04 -07009751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009752 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9753 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009754
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009755 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009756 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 if (mForceRemoves == null) {
9759 mForceRemoves = new ArrayList<WindowState>();
9760 }
Romain Guy06882f82009-06-10 13:36:04 -07009761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 long callingIdentity = Binder.clearCallingIdentity();
9763 try {
9764 // There was some problem... first, do a sanity check of the
9765 // window list to make sure we haven't left any dangling surfaces
9766 // around.
9767 int N = mWindows.size();
9768 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009769 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009770 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009771 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 if (ws.mSurface != null) {
9773 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009774 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 + ws + " surface=" + ws.mSurface
9776 + " token=" + win.mToken
9777 + " pid=" + ws.mSession.mPid
9778 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009779 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009780 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781 ws.mSurface = null;
9782 mForceRemoves.add(ws);
9783 i--;
9784 N--;
9785 leakedSurface = true;
9786 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009787 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 + ws + " surface=" + ws.mSurface
9789 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009790 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009791 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009792 ws.mSurface = null;
9793 leakedSurface = true;
9794 }
9795 }
9796 }
Romain Guy06882f82009-06-10 13:36:04 -07009797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009798 boolean killedApps = false;
9799 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009800 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 SparseIntArray pidCandidates = new SparseIntArray();
9802 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009803 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 if (ws.mSurface != null) {
9805 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9806 }
9807 }
9808 if (pidCandidates.size() > 0) {
9809 int[] pids = new int[pidCandidates.size()];
9810 for (int i=0; i<pids.length; i++) {
9811 pids[i] = pidCandidates.keyAt(i);
9812 }
9813 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009814 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 killedApps = true;
9816 }
9817 } catch (RemoteException e) {
9818 }
9819 }
9820 }
Romain Guy06882f82009-06-10 13:36:04 -07009821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009822 if (leakedSurface || killedApps) {
9823 // We managed to reclaim some memory, so get rid of the trouble
9824 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009825 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009827 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009828 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 win.mSurface = null;
9830 }
Romain Guy06882f82009-06-10 13:36:04 -07009831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009832 try {
9833 win.mClient.dispatchGetNewSurface();
9834 } catch (RemoteException e) {
9835 }
9836 }
9837 } finally {
9838 Binder.restoreCallingIdentity(callingIdentity);
9839 }
9840 }
Romain Guy06882f82009-06-10 13:36:04 -07009841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009842 private boolean updateFocusedWindowLocked(int mode) {
9843 WindowState newFocus = computeFocusedWindowLocked();
9844 if (mCurrentFocus != newFocus) {
9845 // This check makes sure that we don't already have the focus
9846 // change message pending.
9847 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9848 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009849 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009850 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9851 final WindowState oldFocus = mCurrentFocus;
9852 mCurrentFocus = newFocus;
9853 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855 final WindowState imWindow = mInputMethodWindow;
9856 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009857 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009858 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009859 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9860 mLayoutNeeded = true;
9861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009862 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9863 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009864 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9865 // Client will do the layout, but we need to assign layers
9866 // for handleNewWindowLocked() below.
9867 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 }
9869 }
Jeff Brown349703e2010-06-22 01:27:15 -07009870
9871 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9872 // If we defer assigning layers, then the caller is responsible for
9873 // doing this part.
9874 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876 return true;
9877 }
9878 return false;
9879 }
Jeff Brown349703e2010-06-22 01:27:15 -07009880
9881 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009882 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009884
9885 private WindowState computeFocusedWindowLocked() {
9886 WindowState result = null;
9887 WindowState win;
9888
9889 int i = mWindows.size() - 1;
9890 int nextAppIndex = mAppTokens.size()-1;
9891 WindowToken nextApp = nextAppIndex >= 0
9892 ? mAppTokens.get(nextAppIndex) : null;
9893
9894 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009895 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896
Joe Onorato8a9b2202010-02-26 18:56:32 -08009897 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009898 TAG, "Looking for focus: " + i
9899 + " = " + win
9900 + ", flags=" + win.mAttrs.flags
9901 + ", canReceive=" + win.canReceiveKeys());
9902
9903 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 // If this window's application has been removed, just skip it.
9906 if (thisApp != null && thisApp.removed) {
9907 i--;
9908 continue;
9909 }
Romain Guy06882f82009-06-10 13:36:04 -07009910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009911 // If there is a focused app, don't allow focus to go to any
9912 // windows below it. If this is an application window, step
9913 // through the app tokens until we find its app.
9914 if (thisApp != null && nextApp != null && thisApp != nextApp
9915 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9916 int origAppIndex = nextAppIndex;
9917 while (nextAppIndex > 0) {
9918 if (nextApp == mFocusedApp) {
9919 // Whoops, we are below the focused app... no focus
9920 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009921 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 TAG, "Reached focused app: " + mFocusedApp);
9923 return null;
9924 }
9925 nextAppIndex--;
9926 nextApp = mAppTokens.get(nextAppIndex);
9927 if (nextApp == thisApp) {
9928 break;
9929 }
9930 }
9931 if (thisApp != nextApp) {
9932 // Uh oh, the app token doesn't exist! This shouldn't
9933 // happen, but if it does we can get totally hosed...
9934 // so restart at the original app.
9935 nextAppIndex = origAppIndex;
9936 nextApp = mAppTokens.get(nextAppIndex);
9937 }
9938 }
9939
9940 // Dispatch to this window if it is wants key events.
9941 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009942 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009943 TAG, "Found focus @ " + i + " = " + win);
9944 result = win;
9945 break;
9946 }
9947
9948 i--;
9949 }
9950
9951 return result;
9952 }
9953
9954 private void startFreezingDisplayLocked() {
9955 if (mDisplayFrozen) {
9956 return;
9957 }
Romain Guy06882f82009-06-10 13:36:04 -07009958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009959 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009961 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009962 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 if (mFreezeGcPending != 0) {
9964 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009965 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009966 mH.removeMessages(H.FORCE_GC);
9967 Runtime.getRuntime().gc();
9968 mFreezeGcPending = now;
9969 }
9970 } else {
9971 mFreezeGcPending = now;
9972 }
Romain Guy06882f82009-06-10 13:36:04 -07009973
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009974 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
9975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009977
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009978 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009979
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009980 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9981 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009982 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 mAppTransitionReady = true;
9984 }
Romain Guy06882f82009-06-10 13:36:04 -07009985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 if (PROFILE_ORIENTATION) {
9987 File file = new File("/data/system/frozen");
9988 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9989 }
9990 Surface.freezeDisplay(0);
9991 }
Romain Guy06882f82009-06-10 13:36:04 -07009992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 private void stopFreezingDisplayLocked() {
9994 if (!mDisplayFrozen) {
9995 return;
9996 }
Romain Guy06882f82009-06-10 13:36:04 -07009997
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009998 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9999 return;
10000 }
10001
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010002 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
10003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 mDisplayFrozen = false;
10005 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10006 if (PROFILE_ORIENTATION) {
10007 Debug.stopMethodTracing();
10008 }
10009 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010010
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010011 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010012
Christopher Tateb696aee2010-04-02 19:08:30 -070010013 // While the display is frozen we don't re-compute the orientation
10014 // to avoid inconsistent states. However, something interesting
10015 // could have actually changed during that time so re-evaluate it
10016 // now to catch that.
10017 if (updateOrientationFromAppTokensLocked()) {
10018 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10019 }
10020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 // A little kludge: a lot could have happened while the
10022 // display was frozen, so now that we are coming back we
10023 // do a gc so that any remote references the system
10024 // processes holds on others can be released if they are
10025 // no longer needed.
10026 mH.removeMessages(H.FORCE_GC);
10027 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10028 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 mScreenFrozenLock.release();
10031 }
Romain Guy06882f82009-06-10 13:36:04 -070010032
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010033 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10034 DisplayMetrics dm) {
10035 if (index < tokens.length) {
10036 String str = tokens[index];
10037 if (str != null && str.length() > 0) {
10038 try {
10039 int val = Integer.parseInt(str);
10040 return val;
10041 } catch (Exception e) {
10042 }
10043 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010044 }
10045 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10046 return defDps;
10047 }
10048 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10049 return val;
10050 }
10051
10052 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010053 final String[] mTokens;
10054 final String mText;
10055 final Paint mTextPaint;
10056 final int mTextWidth;
10057 final int mTextHeight;
10058 final int mTextAscent;
10059 final int mTextDescent;
10060 final int mDeltaX;
10061 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010062
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010063 Surface mSurface;
10064 int mLastDW;
10065 int mLastDH;
10066 boolean mDrawNeeded;
10067
10068 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010069 final DisplayMetrics dm = new DisplayMetrics();
10070 mDisplay.getMetrics(dm);
10071
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010072 if (false) {
10073 Log.i(TAG, "*********************** WATERMARK");
10074 for (int i=0; i<tokens.length; i++) {
10075 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10076 }
10077 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010078
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010079 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010080
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010081 StringBuilder builder = new StringBuilder(32);
10082 int len = mTokens[0].length();
10083 len = len & ~1;
10084 for (int i=0; i<len; i+=2) {
10085 int c1 = mTokens[0].charAt(i);
10086 int c2 = mTokens[0].charAt(i+1);
10087 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10088 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10089 else c1 -= '0';
10090 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10091 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10092 else c2 -= '0';
10093 builder.append((char)(255-((c1*16)+c2)));
10094 }
10095 mText = builder.toString();
10096 if (false) {
10097 Log.i(TAG, "Final text: " + mText);
10098 }
10099
10100 int fontSize = getPropertyInt(tokens, 1,
10101 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10102
10103 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10104 mTextPaint.setTextSize(fontSize);
10105 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10106
10107 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10108 mTextWidth = (int)mTextPaint.measureText(mText);
10109 mTextAscent = fm.ascent;
10110 mTextDescent = fm.descent;
10111 mTextHeight = fm.descent - fm.ascent;
10112
10113 mDeltaX = getPropertyInt(tokens, 2,
10114 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10115 mDeltaY = getPropertyInt(tokens, 3,
10116 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10117 int shadowColor = getPropertyInt(tokens, 4,
10118 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10119 int color = getPropertyInt(tokens, 5,
10120 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10121 int shadowRadius = getPropertyInt(tokens, 6,
10122 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10123 int shadowDx = getPropertyInt(tokens, 8,
10124 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10125 int shadowDy = getPropertyInt(tokens, 9,
10126 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10127
10128 mTextPaint.setColor(color);
10129 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010130
10131 try {
10132 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010133 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010134 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010135 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010136 mSurface.show();
10137 } catch (OutOfResourcesException e) {
10138 }
10139 }
10140
10141 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010142 if (mLastDW != dw || mLastDH != dh) {
10143 mLastDW = dw;
10144 mLastDH = dh;
10145 mSurface.setSize(dw, dh);
10146 mDrawNeeded = true;
10147 }
10148 }
10149
10150 void drawIfNeeded() {
10151 if (mDrawNeeded) {
10152 final int dw = mLastDW;
10153 final int dh = mLastDH;
10154
10155 mDrawNeeded = false;
10156 Rect dirty = new Rect(0, 0, dw, dh);
10157 Canvas c = null;
10158 try {
10159 c = mSurface.lockCanvas(dirty);
10160 } catch (IllegalArgumentException e) {
10161 } catch (OutOfResourcesException e) {
10162 }
10163 if (c != null) {
10164 int deltaX = mDeltaX;
10165 int deltaY = mDeltaY;
10166
10167 // deltaX shouldn't be close to a round fraction of our
10168 // x step, or else things will line up too much.
10169 int div = (dw+mTextWidth)/deltaX;
10170 int rem = (dw+mTextWidth) - (div*deltaX);
10171 int qdelta = deltaX/4;
10172 if (rem < qdelta || rem > (deltaX-qdelta)) {
10173 deltaX += deltaX/3;
10174 }
10175
10176 int y = -mTextHeight;
10177 int x = -mTextWidth;
10178 while (y < (dh+mTextHeight)) {
10179 c.drawText(mText, x, y, mTextPaint);
10180 x += deltaX;
10181 if (x >= dw) {
10182 x -= (dw+mTextWidth);
10183 y += deltaY;
10184 }
10185 }
10186 mSurface.unlockCanvasAndPost(c);
10187 }
10188 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010189 }
10190 }
10191
10192 void createWatermark() {
10193 if (mWatermark != null) {
10194 return;
10195 }
10196
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010197 File file = new File("/system/etc/setup.conf");
10198 FileInputStream in = null;
10199 try {
10200 in = new FileInputStream(file);
10201 DataInputStream ind = new DataInputStream(in);
10202 String line = ind.readLine();
10203 if (line != null) {
10204 String[] toks = line.split("%");
10205 if (toks != null && toks.length > 0) {
10206 mWatermark = new Watermark(mFxSession, toks);
10207 }
10208 }
10209 } catch (FileNotFoundException e) {
10210 } catch (IOException e) {
10211 } finally {
10212 if (in != null) {
10213 try {
10214 in.close();
10215 } catch (IOException e) {
10216 }
10217 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010218 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010219 }
10220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010221 @Override
10222 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10223 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10224 != PackageManager.PERMISSION_GRANTED) {
10225 pw.println("Permission Denial: can't dump WindowManager from from pid="
10226 + Binder.getCallingPid()
10227 + ", uid=" + Binder.getCallingUid());
10228 return;
10229 }
Romain Guy06882f82009-06-10 13:36:04 -070010230
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010231 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010232 pw.println(" ");
10233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010234 synchronized(mWindowMap) {
10235 pw.println("Current Window Manager state:");
10236 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010237 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010238 pw.print(" Window #"); pw.print(i); pw.print(' ');
10239 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010240 w.dump(pw, " ");
10241 }
10242 if (mInputMethodDialogs.size() > 0) {
10243 pw.println(" ");
10244 pw.println(" Input method dialogs:");
10245 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10246 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010247 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010248 }
10249 }
10250 if (mPendingRemove.size() > 0) {
10251 pw.println(" ");
10252 pw.println(" Remove pending for:");
10253 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10254 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010255 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10256 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010257 w.dump(pw, " ");
10258 }
10259 }
10260 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10261 pw.println(" ");
10262 pw.println(" Windows force removing:");
10263 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10264 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010265 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10266 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010267 w.dump(pw, " ");
10268 }
10269 }
10270 if (mDestroySurface.size() > 0) {
10271 pw.println(" ");
10272 pw.println(" Windows waiting to destroy their surface:");
10273 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10274 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010275 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10276 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 w.dump(pw, " ");
10278 }
10279 }
10280 if (mLosingFocus.size() > 0) {
10281 pw.println(" ");
10282 pw.println(" Windows losing focus:");
10283 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10284 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010285 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10286 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010287 w.dump(pw, " ");
10288 }
10289 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010290 if (mResizingWindows.size() > 0) {
10291 pw.println(" ");
10292 pw.println(" Windows waiting to resize:");
10293 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10294 WindowState w = mResizingWindows.get(i);
10295 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10296 pw.print(w); pw.println(":");
10297 w.dump(pw, " ");
10298 }
10299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010300 if (mSessions.size() > 0) {
10301 pw.println(" ");
10302 pw.println(" All active sessions:");
10303 Iterator<Session> it = mSessions.iterator();
10304 while (it.hasNext()) {
10305 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010306 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 s.dump(pw, " ");
10308 }
10309 }
10310 if (mTokenMap.size() > 0) {
10311 pw.println(" ");
10312 pw.println(" All tokens:");
10313 Iterator<WindowToken> it = mTokenMap.values().iterator();
10314 while (it.hasNext()) {
10315 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010316 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010317 token.dump(pw, " ");
10318 }
10319 }
10320 if (mTokenList.size() > 0) {
10321 pw.println(" ");
10322 pw.println(" Window token list:");
10323 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010324 pw.print(" #"); pw.print(i); pw.print(": ");
10325 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010326 }
10327 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010328 if (mWallpaperTokens.size() > 0) {
10329 pw.println(" ");
10330 pw.println(" Wallpaper tokens:");
10331 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10332 WindowToken token = mWallpaperTokens.get(i);
10333 pw.print(" Wallpaper #"); pw.print(i);
10334 pw.print(' '); pw.print(token); pw.println(':');
10335 token.dump(pw, " ");
10336 }
10337 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010338 if (mAppTokens.size() > 0) {
10339 pw.println(" ");
10340 pw.println(" Application tokens in Z order:");
10341 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010342 pw.print(" App #"); pw.print(i); pw.print(": ");
10343 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010344 }
10345 }
10346 if (mFinishedStarting.size() > 0) {
10347 pw.println(" ");
10348 pw.println(" Finishing start of application tokens:");
10349 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10350 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010351 pw.print(" Finished Starting #"); pw.print(i);
10352 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 token.dump(pw, " ");
10354 }
10355 }
10356 if (mExitingTokens.size() > 0) {
10357 pw.println(" ");
10358 pw.println(" Exiting tokens:");
10359 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10360 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010361 pw.print(" Exiting #"); pw.print(i);
10362 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 token.dump(pw, " ");
10364 }
10365 }
10366 if (mExitingAppTokens.size() > 0) {
10367 pw.println(" ");
10368 pw.println(" Exiting application tokens:");
10369 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10370 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010371 pw.print(" Exiting App #"); pw.print(i);
10372 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 token.dump(pw, " ");
10374 }
10375 }
10376 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010377 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10378 pw.print(" mLastFocus="); pw.println(mLastFocus);
10379 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10380 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10381 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010382 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010383 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10384 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10385 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10386 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010387 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10388 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10389 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010390 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10391 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10392 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10393 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010394 if (mDimAnimator != null) {
10395 mDimAnimator.printTo(pw);
10396 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010397 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010398 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010399 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010400 pw.print(mInputMethodAnimLayerAdjustment);
10401 pw.print(" mWallpaperAnimLayerAdjustment=");
10402 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010403 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10404 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010405 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10406 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010407 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10408 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010409 pw.print(" mRotation="); pw.print(mRotation);
10410 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10411 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10412 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10413 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10414 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10415 pw.print(" mNextAppTransition=0x");
10416 pw.print(Integer.toHexString(mNextAppTransition));
10417 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010418 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010419 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010420 if (mNextAppTransitionPackage != null) {
10421 pw.print(" mNextAppTransitionPackage=");
10422 pw.print(mNextAppTransitionPackage);
10423 pw.print(", mNextAppTransitionEnter=0x");
10424 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10425 pw.print(", mNextAppTransitionExit=0x");
10426 pw.print(Integer.toHexString(mNextAppTransitionExit));
10427 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010428 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10429 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010430 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10431 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10432 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10433 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010434 if (mOpeningApps.size() > 0) {
10435 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10436 }
10437 if (mClosingApps.size() > 0) {
10438 pw.print(" mClosingApps="); pw.println(mClosingApps);
10439 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010440 if (mToTopApps.size() > 0) {
10441 pw.print(" mToTopApps="); pw.println(mToTopApps);
10442 }
10443 if (mToBottomApps.size() > 0) {
10444 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10445 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010446 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10447 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 }
10449 }
10450
Jeff Brown349703e2010-06-22 01:27:15 -070010451 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 public void monitor() {
10453 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010454 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010455 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010456
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010457 /**
10458 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010459 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010460 */
10461 private static class DimAnimator {
10462 Surface mDimSurface;
10463 boolean mDimShown = false;
10464 float mDimCurrentAlpha;
10465 float mDimTargetAlpha;
10466 float mDimDeltaPerMs;
10467 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010468
10469 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010470
10471 DimAnimator (SurfaceSession session) {
10472 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010473 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010474 + mDimSurface + ": CREATE");
10475 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010476 mDimSurface = new Surface(session, 0,
10477 "DimSurface",
10478 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010479 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010480 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010481 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010482 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010483 }
10484 }
10485 }
10486
10487 /**
10488 * Show the dim surface.
10489 */
10490 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010491 if (!mDimShown) {
10492 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10493 dw + "x" + dh + ")");
10494 mDimShown = true;
10495 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010496 mLastDimWidth = dw;
10497 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010498 mDimSurface.setPosition(0, 0);
10499 mDimSurface.setSize(dw, dh);
10500 mDimSurface.show();
10501 } catch (RuntimeException e) {
10502 Slog.w(TAG, "Failure showing dim surface", e);
10503 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010504 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10505 mLastDimWidth = dw;
10506 mLastDimHeight = dh;
10507 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010508 }
10509 }
10510
10511 /**
10512 * Set's the dim surface's layer and update dim parameters that will be used in
10513 * {@link updateSurface} after all windows are examined.
10514 */
10515 void updateParameters(WindowState w, long currentTime) {
10516 mDimSurface.setLayer(w.mAnimLayer-1);
10517
10518 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010519 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010520 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010521 if (mDimTargetAlpha != target) {
10522 // If the desired dim level has changed, then
10523 // start an animation to it.
10524 mLastDimAnimTime = currentTime;
10525 long duration = (w.mAnimating && w.mAnimation != null)
10526 ? w.mAnimation.computeDurationHint()
10527 : DEFAULT_DIM_DURATION;
10528 if (target > mDimTargetAlpha) {
10529 // This is happening behind the activity UI,
10530 // so we can make it run a little longer to
10531 // give a stronger impression without disrupting
10532 // the user.
10533 duration *= DIM_DURATION_MULTIPLIER;
10534 }
10535 if (duration < 1) {
10536 // Don't divide by zero
10537 duration = 1;
10538 }
10539 mDimTargetAlpha = target;
10540 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10541 }
10542 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010543
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010544 /**
10545 * Updating the surface's alpha. Returns true if the animation continues, or returns
10546 * false when the animation is finished and the dim surface is hidden.
10547 */
10548 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10549 if (!dimming) {
10550 if (mDimTargetAlpha != 0) {
10551 mLastDimAnimTime = currentTime;
10552 mDimTargetAlpha = 0;
10553 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10554 }
10555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010556
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010557 boolean animating = false;
10558 if (mLastDimAnimTime != 0) {
10559 mDimCurrentAlpha += mDimDeltaPerMs
10560 * (currentTime-mLastDimAnimTime);
10561 boolean more = true;
10562 if (displayFrozen) {
10563 // If the display is frozen, there is no reason to animate.
10564 more = false;
10565 } else if (mDimDeltaPerMs > 0) {
10566 if (mDimCurrentAlpha > mDimTargetAlpha) {
10567 more = false;
10568 }
10569 } else if (mDimDeltaPerMs < 0) {
10570 if (mDimCurrentAlpha < mDimTargetAlpha) {
10571 more = false;
10572 }
10573 } else {
10574 more = false;
10575 }
10576
10577 // Do we need to continue animating?
10578 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010580 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10581 mLastDimAnimTime = currentTime;
10582 mDimSurface.setAlpha(mDimCurrentAlpha);
10583 animating = true;
10584 } else {
10585 mDimCurrentAlpha = mDimTargetAlpha;
10586 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010587 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010588 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10589 mDimSurface.setAlpha(mDimCurrentAlpha);
10590 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010591 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010592 + ": HIDE");
10593 try {
10594 mDimSurface.hide();
10595 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010596 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010597 }
10598 mDimShown = false;
10599 }
10600 }
10601 }
10602 return animating;
10603 }
10604
10605 public void printTo(PrintWriter pw) {
10606 pw.print(" mDimShown="); pw.print(mDimShown);
10607 pw.print(" current="); pw.print(mDimCurrentAlpha);
10608 pw.print(" target="); pw.print(mDimTargetAlpha);
10609 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10610 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10611 }
10612 }
10613
10614 /**
10615 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10616 * This is used for opening/closing transition for apps in compatible mode.
10617 */
10618 private static class FadeInOutAnimation extends Animation {
10619 int mWidth;
10620 boolean mFadeIn;
10621
10622 public FadeInOutAnimation(boolean fadeIn) {
10623 setInterpolator(new AccelerateInterpolator());
10624 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10625 mFadeIn = fadeIn;
10626 }
10627
10628 @Override
10629 protected void applyTransformation(float interpolatedTime, Transformation t) {
10630 float x = interpolatedTime;
10631 if (!mFadeIn) {
10632 x = 1.0f - x; // reverse the interpolation for fade out
10633 }
10634 if (x < 0.5) {
10635 // move the window out of the screen.
10636 t.getMatrix().setTranslate(mWidth, 0);
10637 } else {
10638 t.getMatrix().setTranslate(0, 0);// show
10639 t.setAlpha((x - 0.5f) * 2);
10640 }
10641 }
10642
10643 @Override
10644 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10645 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10646 mWidth = width;
10647 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010648
10649 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010650 public int getZAdjustment() {
10651 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010652 }
10653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010654}