The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 21 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 24 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 26 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 29 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | import com.android.internal.app.IBatteryStats; |
| 37 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 38 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 39 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import com.android.internal.view.IInputContext; |
| 41 | import com.android.internal.view.IInputMethodClient; |
| 42 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 43 | import com.android.internal.view.WindowManagerPolicyThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 44 | import com.android.server.AttributeCache; |
| 45 | import com.android.server.EventLogTags; |
| 46 | import com.android.server.PowerManagerService; |
| 47 | import com.android.server.Watchdog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import com.android.server.am.BatteryStatsService; |
| 49 | |
| 50 | import android.Manifest; |
| 51 | import android.app.ActivityManagerNative; |
| 52 | import android.app.IActivityManager; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 53 | import android.app.StatusBarManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 54 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 55 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 57 | import android.content.Intent; |
| 58 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.pm.ActivityInfo; |
| 60 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 61 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 63 | import android.graphics.Bitmap; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 64 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.graphics.Matrix; |
| 66 | import android.graphics.PixelFormat; |
| 67 | import android.graphics.Rect; |
| 68 | import android.graphics.Region; |
| 69 | import android.os.BatteryStats; |
| 70 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 71 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
| 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
| 75 | import android.os.LocalPowerManager; |
| 76 | import android.os.Looper; |
| 77 | import android.os.Message; |
| 78 | import android.os.Parcel; |
| 79 | import android.os.ParcelFileDescriptor; |
| 80 | import android.os.Power; |
| 81 | import android.os.PowerManager; |
| 82 | import android.os.Process; |
| 83 | import android.os.RemoteException; |
| 84 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 85 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.SystemClock; |
| 87 | import android.os.SystemProperties; |
| 88 | import android.os.TokenWatcher; |
| 89 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 90 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 92 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 93 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 95 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.view.IApplicationToken; |
| 98 | import android.view.IOnKeyguardExitResult; |
| 99 | import android.view.IRotationWatcher; |
| 100 | import android.view.IWindow; |
| 101 | import android.view.IWindowManager; |
| 102 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 103 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 104 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 105 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 106 | import android.view.InputHandler; |
| 107 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.KeyEvent; |
| 109 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.Surface; |
| 111 | import android.view.SurfaceSession; |
| 112 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.WindowManager; |
| 114 | import android.view.WindowManagerImpl; |
| 115 | import android.view.WindowManagerPolicy; |
| 116 | import android.view.WindowManager.LayoutParams; |
| 117 | import android.view.animation.Animation; |
| 118 | import android.view.animation.AnimationUtils; |
| 119 | import android.view.animation.Transformation; |
| 120 | |
| 121 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 122 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import java.io.File; |
| 124 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 125 | import java.io.FileInputStream; |
| 126 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | import java.io.IOException; |
| 128 | import java.io.OutputStream; |
| 129 | import java.io.OutputStreamWriter; |
| 130 | import java.io.PrintWriter; |
| 131 | import java.io.StringWriter; |
| 132 | import java.net.Socket; |
| 133 | import java.util.ArrayList; |
| 134 | import java.util.HashMap; |
| 135 | import java.util.HashSet; |
| 136 | import java.util.Iterator; |
| 137 | import java.util.List; |
| 138 | |
| 139 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 140 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 141 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | static final String TAG = "WindowManager"; |
| 143 | static final boolean DEBUG = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 144 | static final boolean DEBUG_ADD_REMOVE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_FOCUS = false; |
| 146 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 148 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | static final boolean DEBUG_LAYERS = false; |
| 150 | static final boolean DEBUG_INPUT = false; |
| 151 | static final boolean DEBUG_INPUT_METHOD = false; |
| 152 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 153 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 154 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 156 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 158 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 159 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 160 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 161 | static final boolean DEBUG_DRAG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 163 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean PROFILE_ORIENTATION = false; |
| 166 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 167 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | /** 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 Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | /** 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 Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | /** 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 Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** 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 Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 193 | /** 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 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 198 | /** |
| 199 | * If true, the window manager will do its own custom freezing and general |
| 200 | * management of the screen during rotation. |
| 201 | */ |
| 202 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 203 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 204 | // Maximum number of milliseconds to wait for input event injection. |
| 205 | // FIXME is this value reasonable? |
| 206 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 207 | |
| 208 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 209 | // proceding with safe mode detection. |
| 210 | private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 211 | |
| 212 | // Default input dispatching timeout in nanoseconds. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 213 | static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 216 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 217 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 218 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
| 223 | /** |
| 224 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 225 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 226 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 227 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 229 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 231 | private static final int ALLOW_DISABLE_YES = 1; |
| 232 | private static final int ALLOW_DISABLE_NO = 0; |
| 233 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 234 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 235 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 236 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 237 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 239 | if (shouldAllowDisableKeyguard()) { |
| 240 | mPolicy.enableKeyguard(false); |
| 241 | mKeyguardDisabled = true; |
| 242 | } else { |
| 243 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | } |
| 246 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 247 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 248 | synchronized (mKeyguardTokenWatcher) { |
| 249 | mKeyguardDisabled = false; |
| 250 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | }; |
| 254 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 255 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 256 | @Override |
| 257 | public void onReceive(Context context, Intent intent) { |
| 258 | mPolicy.enableKeyguard(true); |
| 259 | synchronized(mKeyguardTokenWatcher) { |
| 260 | // lazily evaluate this next time we're asked to disable keyguard |
| 261 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 262 | mKeyguardDisabled = false; |
| 263 | } |
| 264 | } |
| 265 | }; |
| 266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | final Context mContext; |
| 268 | |
| 269 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 274 | |
| 275 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 278 | |
David 'Digit' Turner | 910a068 | 2011-02-05 00:34:46 +0100 | [diff] [blame] | 279 | private static final boolean mInEmulator = SystemProperties.get("ro.kernel.qemu").equals("1"); |
| 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | /** |
| 282 | * All currently active sessions with clients. |
| 283 | */ |
| 284 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Mapping from an IWindow IBinder to the server's Window object. |
| 288 | * This is also used as the lock for all of our state. |
| 289 | */ |
| 290 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 291 | |
| 292 | /** |
| 293 | * Mapping from a token IBinder to a WindowToken object. |
| 294 | */ |
| 295 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 296 | new HashMap<IBinder, WindowToken>(); |
| 297 | |
| 298 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | * Window tokens that are in the process of exiting, but still |
| 300 | * on screen for animations. |
| 301 | */ |
| 302 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 303 | |
| 304 | /** |
| 305 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 306 | * controlling the ordering of windows in different applications. This |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 307 | * contains AppWindowToken objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | */ |
| 309 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 310 | |
| 311 | /** |
| 312 | * Application tokens that are in the process of exiting, but still |
| 313 | * on screen for animations. |
| 314 | */ |
| 315 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 316 | |
| 317 | /** |
| 318 | * List of window tokens that have finished starting their application, |
| 319 | * and now need to have the policy remove their windows. |
| 320 | */ |
| 321 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 322 | |
| 323 | /** |
| 324 | * Z-ordered (bottom-most first) list of all Window objects. |
| 325 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 326 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | |
| 328 | /** |
| 329 | * Windows that are being resized. Used so we can tell the client about |
| 330 | * the resize after closing the transaction in which we resized the |
| 331 | * underlying surface. |
| 332 | */ |
| 333 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 334 | |
| 335 | /** |
| 336 | * Windows whose animations have ended and now must be removed. |
| 337 | */ |
| 338 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 339 | |
| 340 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 341 | * Used when processing mPendingRemove to avoid working on the original array. |
| 342 | */ |
| 343 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 344 | |
| 345 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | * Windows whose surface should be destroyed. |
| 347 | */ |
| 348 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 349 | |
| 350 | /** |
| 351 | * Windows that have lost input focus and are waiting for the new |
| 352 | * focus window to be displayed before they are told about this. |
| 353 | */ |
| 354 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 355 | |
| 356 | /** |
| 357 | * This is set when we have run out of memory, and will either be an empty |
| 358 | * list or contain windows that need to be force removed. |
| 359 | */ |
| 360 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 361 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 362 | /** |
| 363 | * Used when rebuilding window list to keep track of windows that have |
| 364 | * been removed. |
| 365 | */ |
| 366 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 371 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | Surface mBlurSurface; |
| 373 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 374 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 375 | StrictModeFlash mStrictModeFlash; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 376 | ScreenRotationAnimation mScreenRotationAnimation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | final float[] mTmpFloats = new float[9]; |
| 381 | |
| 382 | boolean mSafeMode; |
| 383 | boolean mDisplayEnabled = false; |
| 384 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 385 | int mInitialDisplayWidth = 0; |
| 386 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | int mRotation = 0; |
| 388 | int mRequestedRotation = 0; |
| 389 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 390 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | ArrayList<IRotationWatcher> mRotationWatchers |
| 392 | = new ArrayList<IRotationWatcher>(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 393 | int mDeferredRotation; |
| 394 | int mDeferredRotationAnimFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | boolean mLayoutNeeded = true; |
| 397 | boolean mAnimationPending = false; |
| 398 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 399 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | boolean mWindowsFreezingScreen = false; |
| 401 | long mFreezeGcPending = 0; |
| 402 | int mAppsFreezingScreen = 0; |
| 403 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 404 | int mLayoutSeq = 0; |
| 405 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 406 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 407 | boolean mFocusMayChange; |
| 408 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 409 | Configuration mCurConfiguration = new Configuration(); |
| 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | // This is held as long as we have the screen frozen, to give us time to |
| 412 | // perform a rotation animation when turning off shows the lock screen which |
| 413 | // changes the orientation. |
| 414 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | // State management of app transitions. When we are preparing for a |
| 417 | // transition, mNextAppTransition will be the kind of transition to |
| 418 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 419 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 420 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 421 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 422 | String mNextAppTransitionPackage; |
| 423 | int mNextAppTransitionEnter; |
| 424 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 426 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | boolean mAppTransitionTimeout = false; |
| 428 | boolean mStartingIconInTransition = false; |
| 429 | boolean mSkipAppTransitionAnimation = false; |
| 430 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 431 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 432 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 433 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | H mH = new H(); |
| 438 | |
| 439 | WindowState mCurrentFocus = null; |
| 440 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | // This just indicates the window the input method is on top of, not |
| 443 | // necessarily the window its input is going to. |
| 444 | WindowState mInputMethodTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | boolean mInputMethodTargetWaitingAnim; |
| 446 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | WindowState mInputMethodWindow = null; |
| 449 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 450 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 451 | boolean mHardKeyboardAvailable; |
| 452 | boolean mHardKeyboardEnabled; |
| 453 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 454 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 455 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 456 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 457 | // If non-null, this is the currently visible window that is associated |
| 458 | // with the wallpaper. |
| 459 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 460 | // If non-null, we are in the middle of animating from one wallpaper target |
| 461 | // to another, and this is the lower one in Z-order. |
| 462 | WindowState mLowerWallpaperTarget = null; |
| 463 | // If non-null, we are in the middle of animating from one wallpaper target |
| 464 | // to another, and this is the higher one in Z-order. |
| 465 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 466 | // Window currently running an animation that has requested it be detached |
| 467 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 468 | // visible behind it in case it animates in a way that would allow it to be |
| 469 | // seen. |
| 470 | WindowState mWindowDetachedWallpaper = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 471 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 472 | float mLastWallpaperX = -1; |
| 473 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 474 | float mLastWallpaperXStep = -1; |
| 475 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 476 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 477 | // changing its scroll position. |
| 478 | WindowState mWaitingOnWallpaper; |
| 479 | // The last time we had a timeout when waiting for a wallpaper. |
| 480 | long mLastWallpaperTimeoutTime; |
| 481 | // We give a wallpaper up to 150ms to finish scrolling. |
| 482 | static final long WALLPAPER_TIMEOUT = 150; |
| 483 | // Time we wait after a timeout before trying to wait again. |
| 484 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | AppWindowToken mFocusedApp = null; |
| 487 | |
| 488 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | float mWindowAnimationScale = 1.0f; |
| 491 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 492 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 493 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | |
| 495 | // Who is holding the screen on. |
| 496 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 497 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 498 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 499 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 500 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 501 | DragState mDragState = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 502 | final InputHandler mDragInputHandler = new BaseInputHandler() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 503 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 504 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 505 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 506 | try { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 507 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 508 | && mDragState != null) { |
| 509 | boolean endDrag = false; |
| 510 | final float newX = event.getRawX(); |
| 511 | final float newY = event.getRawY(); |
| 512 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 513 | switch (event.getAction()) { |
| 514 | case MotionEvent.ACTION_DOWN: { |
| 515 | if (DEBUG_DRAG) { |
| 516 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 517 | } |
| 518 | } break; |
| 519 | |
| 520 | case MotionEvent.ACTION_MOVE: { |
| 521 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 522 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 523 | mDragState.notifyMoveLw(newX, newY); |
| 524 | } |
| 525 | } break; |
| 526 | |
| 527 | case MotionEvent.ACTION_UP: { |
| 528 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 529 | + newX + "," + newY); |
| 530 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 531 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 532 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 533 | } break; |
| 534 | |
| 535 | case MotionEvent.ACTION_CANCEL: { |
| 536 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 537 | endDrag = true; |
| 538 | } break; |
| 539 | } |
| 540 | |
| 541 | if (endDrag) { |
| 542 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 543 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 544 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 545 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 546 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 547 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 548 | |
| 549 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 550 | } |
| 551 | } catch (Exception e) { |
| 552 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 553 | } finally { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 554 | finishedCallback.finished(handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | }; |
| 558 | |
| 559 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | * Whether the UI is currently running in touch mode (not showing |
| 561 | * navigational focus because the user is directly pressing the screen). |
| 562 | */ |
| 563 | boolean mInTouchMode = false; |
| 564 | |
| 565 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 566 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 567 | new ArrayList<WindowChangeListener>(); |
| 568 | private boolean mWindowsChanged = false; |
| 569 | |
| 570 | public interface WindowChangeListener { |
| 571 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 572 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 573 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 575 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 576 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 577 | |
| 578 | // The frame use to limit the size of the app running in compatibility mode. |
| 579 | Rect mCompatibleScreenFrame = new Rect(); |
| 580 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 581 | Surface mBackgroundFillerSurface = null; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 582 | WindowState mBackgroundFillerTarget = null; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | public static WindowManagerService main(Context context, |
| 585 | PowerManagerService pm, boolean haveInputMethods) { |
| 586 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 587 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | synchronized (thr) { |
| 590 | while (thr.mService == null) { |
| 591 | try { |
| 592 | thr.wait(); |
| 593 | } catch (InterruptedException e) { |
| 594 | } |
| 595 | } |
Jozef BABJAK | 06e57b5 | 2011-01-20 08:09:25 +0100 | [diff] [blame] | 596 | return thr.mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | static class WMThread extends Thread { |
| 601 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | private final Context mContext; |
| 604 | private final PowerManagerService mPM; |
| 605 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | public WMThread(Context context, PowerManagerService pm, |
| 608 | boolean haveInputMethods) { |
| 609 | super("WindowManager"); |
| 610 | mContext = context; |
| 611 | mPM = pm; |
| 612 | mHaveInputMethods = haveInputMethods; |
| 613 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | public void run() { |
| 616 | Looper.prepare(); |
| 617 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 618 | mHaveInputMethods); |
| 619 | android.os.Process.setThreadPriority( |
| 620 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 621 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | synchronized (this) { |
| 624 | mService = s; |
| 625 | notifyAll(); |
| 626 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 627 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 628 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 629 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 630 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 631 | } |
| 632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | Looper.loop(); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | static class PolicyThread extends Thread { |
| 638 | private final WindowManagerPolicy mPolicy; |
| 639 | private final WindowManagerService mService; |
| 640 | private final Context mContext; |
| 641 | private final PowerManagerService mPM; |
| 642 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | public PolicyThread(WindowManagerPolicy policy, |
| 645 | WindowManagerService service, Context context, |
| 646 | PowerManagerService pm) { |
| 647 | super("WindowManagerPolicy"); |
| 648 | mPolicy = policy; |
| 649 | mService = service; |
| 650 | mContext = context; |
| 651 | mPM = pm; |
| 652 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | public void run() { |
| 655 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 656 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 659 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | android.os.Process.setThreadPriority( |
| 661 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 662 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | synchronized (this) { |
| 666 | mRunning = true; |
| 667 | notifyAll(); |
| 668 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 669 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 670 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 671 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 672 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 673 | } |
| 674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | Looper.loop(); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | private WindowManagerService(Context context, PowerManagerService pm, |
| 680 | boolean haveInputMethods) { |
| 681 | mContext = context; |
| 682 | mHaveInputMethods = haveInputMethods; |
| 683 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 684 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | mPowerManager = pm; |
| 687 | mPowerManager.setPolicy(mPolicy); |
| 688 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 689 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 690 | "SCREEN_FROZEN"); |
| 691 | mScreenFrozenLock.setReferenceCounted(false); |
| 692 | |
| 693 | mActivityManager = ActivityManagerNative.getDefault(); |
| 694 | mBatteryStats = BatteryStatsService.getService(); |
| 695 | |
| 696 | // Get persisted window scale setting |
| 697 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 698 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 699 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 700 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 701 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 702 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 703 | IntentFilter filter = new IntentFilter(); |
| 704 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 705 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 706 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 707 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 708 | "KEEP_SCREEN_ON_FLAG"); |
| 709 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 711 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 714 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | synchronized (thr) { |
| 717 | while (!thr.mRunning) { |
| 718 | try { |
| 719 | thr.wait(); |
| 720 | } catch (InterruptedException e) { |
| 721 | } |
| 722 | } |
| 723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 724 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 725 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | // Add ourself to the Watchdog monitors. |
| 728 | Watchdog.getInstance().addMonitor(this); |
| 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 733 | throws RemoteException { |
| 734 | try { |
| 735 | return super.onTransact(code, data, reply, flags); |
| 736 | } catch (RuntimeException e) { |
| 737 | // The window manager only throws security exceptions, so let's |
| 738 | // log all others. |
| 739 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 740 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | throw e; |
| 743 | } |
| 744 | } |
| 745 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 746 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 748 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | TAG, "Adding window " + window + " at " |
| 750 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 751 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 752 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | } |
| 754 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 755 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 757 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | TAG, "Adding window " + window + " at " |
| 759 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 760 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 761 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | //This method finds out the index of a window that has the same app token as |
| 765 | //win. used for z ordering the windows in mWindows |
| 766 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 767 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 768 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | int jmax = localmWindows.size(); |
| 770 | if(jmax == 0) { |
| 771 | return -1; |
| 772 | } |
| 773 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 774 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | if(wentry.mAppToken == win.mAppToken) { |
| 776 | return j; |
| 777 | } |
| 778 | } |
| 779 | return -1; |
| 780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 783 | final IWindow client = win.mClient; |
| 784 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 785 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | final int N = localmWindows.size(); |
| 788 | final WindowState attached = win.mAttachedWindow; |
| 789 | int i; |
| 790 | if (attached == null) { |
| 791 | int tokenWindowsPos = token.windows.size(); |
| 792 | if (token.appWindowToken != null) { |
| 793 | int index = tokenWindowsPos-1; |
| 794 | if (index >= 0) { |
| 795 | // If this application has existing windows, we |
| 796 | // simply place the new window on top of them... but |
| 797 | // keep the starting window on top. |
| 798 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 799 | // Base windows go behind everything else. |
| 800 | placeWindowBefore(token.windows.get(0), win); |
| 801 | tokenWindowsPos = 0; |
| 802 | } else { |
| 803 | AppWindowToken atoken = win.mAppToken; |
| 804 | if (atoken != null && |
| 805 | token.windows.get(index) == atoken.startingWindow) { |
| 806 | placeWindowBefore(token.windows.get(index), win); |
| 807 | tokenWindowsPos--; |
| 808 | } else { |
| 809 | int newIdx = findIdxBasedOnAppTokens(win); |
| 810 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 811 | //there is a window above this one associated with the same |
| 812 | //apptoken note that the window could be a floating window |
| 813 | //that was created later or a window at the top of the list of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | //windows associated with this token. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 815 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 816 | Slog.v(TAG, "Adding window " + win + " at " |
| 817 | + (newIdx+1) + " of " + N); |
| 818 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 820 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 821 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 825 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | TAG, "Figuring out where to add app window " |
| 827 | + client.asBinder() + " (token=" + token + ")"); |
| 828 | // Figure out where the window should go, based on the |
| 829 | // order of applications. |
| 830 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 831 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | for (i=NA-1; i>=0; i--) { |
| 833 | AppWindowToken t = mAppTokens.get(i); |
| 834 | if (t == token) { |
| 835 | i--; |
| 836 | break; |
| 837 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 838 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 839 | // We haven't reached the token yet; if this token |
| 840 | // is not going to the bottom and has windows, we can |
| 841 | // use it as an anchor for when we do reach the token. |
| 842 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | pos = t.windows.get(0); |
| 844 | } |
| 845 | } |
| 846 | // We now know the index into the apps. If we found |
| 847 | // an app window above, that gives us the position; else |
| 848 | // we need to look some more. |
| 849 | if (pos != null) { |
| 850 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 851 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | if (atoken != null) { |
| 853 | final int NC = atoken.windows.size(); |
| 854 | if (NC > 0) { |
| 855 | WindowState bottom = atoken.windows.get(0); |
| 856 | if (bottom.mSubLayer < 0) { |
| 857 | pos = bottom; |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | placeWindowBefore(pos, win); |
| 862 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 863 | // Continue looking down until we find the first |
| 864 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | while (i >= 0) { |
| 866 | AppWindowToken t = mAppTokens.get(i); |
| 867 | final int NW = t.windows.size(); |
| 868 | if (NW > 0) { |
| 869 | pos = t.windows.get(NW-1); |
| 870 | break; |
| 871 | } |
| 872 | i--; |
| 873 | } |
| 874 | if (pos != null) { |
| 875 | // Move in front of any windows attached to this |
| 876 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 877 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | if (atoken != null) { |
| 879 | final int NC = atoken.windows.size(); |
| 880 | if (NC > 0) { |
| 881 | WindowState top = atoken.windows.get(NC-1); |
| 882 | if (top.mSubLayer >= 0) { |
| 883 | pos = top; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | placeWindowAfter(pos, win); |
| 888 | } else { |
| 889 | // Just search for the start of this layer. |
| 890 | final int myLayer = win.mBaseLayer; |
| 891 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 892 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | if (w.mBaseLayer > myLayer) { |
| 894 | break; |
| 895 | } |
| 896 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 897 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 898 | Slog.v(TAG, "Adding window " + win + " at " |
| 899 | + i + " of " + N); |
| 900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 902 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | } |
| 906 | } else { |
| 907 | // Figure out where window should go, based on layer. |
| 908 | final int myLayer = win.mBaseLayer; |
| 909 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 910 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | i++; |
| 912 | break; |
| 913 | } |
| 914 | } |
| 915 | if (i < 0) i = 0; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 916 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 917 | TAG, "Adding window " + win + " at " |
| 918 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 920 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | } |
| 922 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 923 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | token.windows.add(tokenWindowsPos, win); |
| 925 | } |
| 926 | |
| 927 | } else { |
| 928 | // Figure out this window's ordering relative to the window |
| 929 | // it is attached to. |
| 930 | final int NA = token.windows.size(); |
| 931 | final int sublayer = win.mSubLayer; |
| 932 | int largestSublayer = Integer.MIN_VALUE; |
| 933 | WindowState windowWithLargestSublayer = null; |
| 934 | for (i=0; i<NA; i++) { |
| 935 | WindowState w = token.windows.get(i); |
| 936 | final int wSublayer = w.mSubLayer; |
| 937 | if (wSublayer >= largestSublayer) { |
| 938 | largestSublayer = wSublayer; |
| 939 | windowWithLargestSublayer = w; |
| 940 | } |
| 941 | if (sublayer < 0) { |
| 942 | // For negative sublayers, we go below all windows |
| 943 | // in the same sublayer. |
| 944 | if (wSublayer >= sublayer) { |
| 945 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 946 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | token.windows.add(i, win); |
| 948 | } |
| 949 | placeWindowBefore( |
| 950 | wSublayer >= 0 ? attached : w, win); |
| 951 | break; |
| 952 | } |
| 953 | } else { |
| 954 | // For positive sublayers, we go above all windows |
| 955 | // in the same sublayer. |
| 956 | if (wSublayer > sublayer) { |
| 957 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 958 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | token.windows.add(i, win); |
| 960 | } |
| 961 | placeWindowBefore(w, win); |
| 962 | break; |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | if (i >= NA) { |
| 967 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 968 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | token.windows.add(win); |
| 970 | } |
| 971 | if (sublayer < 0) { |
| 972 | placeWindowBefore(attached, win); |
| 973 | } else { |
| 974 | placeWindowAfter(largestSublayer >= 0 |
| 975 | ? windowWithLargestSublayer |
| 976 | : attached, |
| 977 | win); |
| 978 | } |
| 979 | } |
| 980 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | if (win.mAppToken != null && addToToken) { |
| 983 | win.mAppToken.allAppWindows.add(win); |
| 984 | } |
| 985 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | static boolean canBeImeTarget(WindowState w) { |
| 988 | final int fl = w.mAttrs.flags |
| 989 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 990 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
| 991 | || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 992 | if (DEBUG_INPUT_METHOD) { |
| 993 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 994 | if (!w.isVisibleOrAdding()) { |
| 995 | Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface |
| 996 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
| 997 | + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden |
| 998 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 999 | if (w.mAppToken != null) { |
| 1000 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1001 | } |
| 1002 | } |
| 1003 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | return w.isVisibleOrAdding(); |
| 1005 | } |
| 1006 | return false; |
| 1007 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1010 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | final int N = localmWindows.size(); |
| 1012 | WindowState w = null; |
| 1013 | int i = N; |
| 1014 | while (i > 0) { |
| 1015 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1016 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1017 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1018 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
| 1019 | + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1021 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | // Yet more tricksyness! If this window is a "starting" |
| 1024 | // window, we do actually want to be on top of it, but |
| 1025 | // it is not -really- where input will go. So if the caller |
| 1026 | // is not actually looking to move the IME, look down below |
| 1027 | // for a real window to target... |
| 1028 | if (!willMove |
| 1029 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1030 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1031 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1033 | i--; |
| 1034 | w = wb; |
| 1035 | } |
| 1036 | } |
| 1037 | break; |
| 1038 | } |
| 1039 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1040 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1041 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w); |
| 1042 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1043 | // Now, a special case -- if the last target's window is in the |
| 1044 | // process of exiting, and is above the new target, keep on the |
| 1045 | // last target to avoid flicker. Consider for example a Dialog with |
| 1046 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1047 | // the IME above it until it is completely gone so it doesn't drop |
| 1048 | // behind the dialog or its full-screen scrim. |
| 1049 | if (mInputMethodTarget != null && w != null |
| 1050 | && mInputMethodTarget.isDisplayedLw() |
| 1051 | && mInputMethodTarget.mExiting) { |
| 1052 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1053 | w = mInputMethodTarget; |
| 1054 | i = localmWindows.indexOf(w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1055 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w); |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1056 | } |
| 1057 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1058 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1059 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | if (willMove && w != null) { |
| 1063 | final WindowState curTarget = mInputMethodTarget; |
| 1064 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | // Now some fun for dealing with window animations that |
| 1067 | // modify the Z order. We need to look at all windows below |
| 1068 | // the current target that are in this app, finding the highest |
| 1069 | // visible one in layering. |
| 1070 | AppWindowToken token = curTarget.mAppToken; |
| 1071 | WindowState highestTarget = null; |
| 1072 | int highestPos = 0; |
| 1073 | if (token.animating || token.animation != null) { |
| 1074 | int pos = 0; |
| 1075 | pos = localmWindows.indexOf(curTarget); |
| 1076 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1077 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | if (win.mAppToken != token) { |
| 1079 | break; |
| 1080 | } |
| 1081 | if (!win.mRemoved) { |
| 1082 | if (highestTarget == null || win.mAnimLayer > |
| 1083 | highestTarget.mAnimLayer) { |
| 1084 | highestTarget = win; |
| 1085 | highestPos = pos; |
| 1086 | } |
| 1087 | } |
| 1088 | pos--; |
| 1089 | } |
| 1090 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1093 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | + mNextAppTransition + " " + highestTarget |
| 1095 | + " animating=" + highestTarget.isAnimating() |
| 1096 | + " layer=" + highestTarget.mAnimLayer |
| 1097 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1098 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1099 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | // If we are currently setting up for an animation, |
| 1101 | // hold everything until we can find out what will happen. |
| 1102 | mInputMethodTargetWaitingAnim = true; |
| 1103 | mInputMethodTarget = highestTarget; |
| 1104 | return highestPos + 1; |
| 1105 | } else if (highestTarget.isAnimating() && |
| 1106 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1107 | // If the window we are currently targeting is involved |
| 1108 | // with an animation, and it is on top of the next target |
| 1109 | // we will be over, then hold off on moving until |
| 1110 | // that is done. |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1111 | mInputMethodTargetWaitingAnim = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | mInputMethodTarget = highestTarget; |
| 1113 | return highestPos + 1; |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1118 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1119 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | if (w != null) { |
| 1121 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1122 | if (DEBUG_INPUT_METHOD) { |
| 1123 | RuntimeException e = null; |
| 1124 | if (!HIDE_STACK_CRAWLS) { |
| 1125 | e = new RuntimeException(); |
| 1126 | e.fillInStackTrace(); |
| 1127 | } |
| 1128 | Slog.w(TAG, "Moving IM target from " |
| 1129 | + mInputMethodTarget + " to " + w, e); |
| 1130 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | mInputMethodTarget = w; |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1132 | mInputMethodTargetWaitingAnim = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | if (w.mAppToken != null) { |
| 1134 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1135 | } else { |
| 1136 | setInputMethodAnimLayerAdjustment(0); |
| 1137 | } |
| 1138 | } |
| 1139 | return i+1; |
| 1140 | } |
| 1141 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1142 | if (DEBUG_INPUT_METHOD) { |
| 1143 | RuntimeException e = null; |
| 1144 | if (!HIDE_STACK_CRAWLS) { |
| 1145 | e = new RuntimeException(); |
| 1146 | e.fillInStackTrace(); |
| 1147 | } |
| 1148 | Slog.w(TAG, "Moving IM target from " |
| 1149 | + mInputMethodTarget + " to null", e); |
| 1150 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | mInputMethodTarget = null; |
| 1152 | setInputMethodAnimLayerAdjustment(0); |
| 1153 | } |
| 1154 | return -1; |
| 1155 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1158 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1159 | if (pos >= 0) { |
| 1160 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1161 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1162 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1164 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | moveInputMethodDialogsLocked(pos+1); |
| 1166 | return; |
| 1167 | } |
| 1168 | win.mTargetAppToken = null; |
| 1169 | addWindowToListInOrderLocked(win, true); |
| 1170 | moveInputMethodDialogsLocked(pos); |
| 1171 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1174 | if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | mInputMethodAnimLayerAdjustment = adj; |
| 1176 | WindowState imw = mInputMethodWindow; |
| 1177 | if (imw != null) { |
| 1178 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1179 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | + " anim layer: " + imw.mAnimLayer); |
| 1181 | int wi = imw.mChildWindows.size(); |
| 1182 | while (wi > 0) { |
| 1183 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1184 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1186 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | + " anim layer: " + cw.mAnimLayer); |
| 1188 | } |
| 1189 | } |
| 1190 | int di = mInputMethodDialogs.size(); |
| 1191 | while (di > 0) { |
| 1192 | di --; |
| 1193 | imw = mInputMethodDialogs.get(di); |
| 1194 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1195 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1196 | + " anim layer: " + imw.mAnimLayer); |
| 1197 | } |
| 1198 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1201 | int wpos = mWindows.indexOf(win); |
| 1202 | if (wpos >= 0) { |
| 1203 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1204 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1206 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | int NC = win.mChildWindows.size(); |
| 1208 | while (NC > 0) { |
| 1209 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1210 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | int cpos = mWindows.indexOf(cw); |
| 1212 | if (cpos >= 0) { |
| 1213 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1214 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1215 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | mWindows.remove(cpos); |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | return interestingPos; |
| 1221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1224 | addWindowToListInOrderLocked(win, false); |
| 1225 | // This is a hack to get all of the child windows added as well |
| 1226 | // at the right position. Child windows should be rare and |
| 1227 | // this case should be rare, so it shouldn't be that big a deal. |
| 1228 | int wpos = mWindows.indexOf(win); |
| 1229 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1230 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1231 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1233 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | reAddWindowLocked(wpos, win); |
| 1235 | } |
| 1236 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | void logWindowList(String prefix) { |
| 1239 | int N = mWindows.size(); |
| 1240 | while (N > 0) { |
| 1241 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1242 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | } |
| 1244 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | void moveInputMethodDialogsLocked(int pos) { |
| 1247 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1250 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | for (int i=0; i<N; i++) { |
| 1252 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1253 | } |
| 1254 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1255 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | logWindowList(" "); |
| 1257 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | if (pos >= 0) { |
| 1260 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1261 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1262 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | if (wp == mInputMethodWindow) { |
| 1264 | pos++; |
| 1265 | } |
| 1266 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1267 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | for (int i=0; i<N; i++) { |
| 1269 | WindowState win = dialogs.get(i); |
| 1270 | win.mTargetAppToken = targetAppToken; |
| 1271 | pos = reAddWindowLocked(pos, win); |
| 1272 | } |
| 1273 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1274 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | logWindowList(" "); |
| 1276 | } |
| 1277 | return; |
| 1278 | } |
| 1279 | for (int i=0; i<N; i++) { |
| 1280 | WindowState win = dialogs.get(i); |
| 1281 | win.mTargetAppToken = null; |
| 1282 | reAddWindowToListInOrderLocked(win); |
| 1283 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1284 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | logWindowList(" "); |
| 1286 | } |
| 1287 | } |
| 1288 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1291 | final WindowState imWin = mInputMethodWindow; |
| 1292 | final int DN = mInputMethodDialogs.size(); |
| 1293 | if (imWin == null && DN == 0) { |
| 1294 | return false; |
| 1295 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1298 | if (imPos >= 0) { |
| 1299 | // In this case, the input method windows are to be placed |
| 1300 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1302 | // First check to see if the input method windows are already |
| 1303 | // located here, and contiguous. |
| 1304 | final int N = mWindows.size(); |
| 1305 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1306 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | // Figure out the actual input method window that should be |
| 1309 | // at the bottom of their stack. |
| 1310 | WindowState baseImWin = imWin != null |
| 1311 | ? imWin : mInputMethodDialogs.get(0); |
| 1312 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1313 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1315 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | if (firstImWin == baseImWin) { |
| 1318 | // The windows haven't moved... but are they still contiguous? |
| 1319 | // First find the top IM window. |
| 1320 | int pos = imPos+1; |
| 1321 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1322 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | break; |
| 1324 | } |
| 1325 | pos++; |
| 1326 | } |
| 1327 | pos++; |
| 1328 | // Now there should be no more input method windows above. |
| 1329 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1330 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | break; |
| 1332 | } |
| 1333 | pos++; |
| 1334 | } |
| 1335 | if (pos >= N) { |
| 1336 | // All is good! |
| 1337 | return false; |
| 1338 | } |
| 1339 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | if (imWin != null) { |
| 1342 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1343 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | logWindowList(" "); |
| 1345 | } |
| 1346 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1347 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1348 | Slog.v(TAG, "List after removing with new pos " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | logWindowList(" "); |
| 1350 | } |
| 1351 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1352 | reAddWindowLocked(imPos, imWin); |
| 1353 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1354 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1355 | logWindowList(" "); |
| 1356 | } |
| 1357 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1358 | } else { |
| 1359 | moveInputMethodDialogsLocked(imPos); |
| 1360 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1362 | } else { |
| 1363 | // In this case, the input method windows go in a fixed layer, |
| 1364 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1367 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | tmpRemoveWindowLocked(0, imWin); |
| 1369 | imWin.mTargetAppToken = null; |
| 1370 | reAddWindowToListInOrderLocked(imWin); |
| 1371 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1372 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1373 | logWindowList(" "); |
| 1374 | } |
| 1375 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1376 | } else { |
| 1377 | moveInputMethodDialogsLocked(-1);; |
| 1378 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | if (needAssignLayers) { |
| 1383 | assignLayersLocked(); |
| 1384 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | return true; |
| 1387 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1389 | void adjustInputMethodDialogsLocked() { |
| 1390 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1391 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1392 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1393 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1394 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1395 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1396 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1397 | ? wallpaperTarget.mAppToken.animation : null) |
| 1398 | + " upper=" + mUpperWallpaperTarget |
| 1399 | + " lower=" + mLowerWallpaperTarget); |
| 1400 | return (wallpaperTarget != null |
| 1401 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1402 | && wallpaperTarget.mAppToken.animation != null))) |
| 1403 | || mUpperWallpaperTarget != null |
| 1404 | || mLowerWallpaperTarget != null; |
| 1405 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1406 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1407 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1408 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1409 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1410 | int adjustWallpaperWindowsLocked() { |
| 1411 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1412 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1413 | final int dw = mDisplay.getWidth(); |
| 1414 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1415 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1416 | // First find top-most window that has asked to be on top of the |
| 1417 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1418 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1419 | int N = localmWindows.size(); |
| 1420 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1421 | WindowState foundW = null; |
| 1422 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1423 | WindowState topCurW = null; |
| 1424 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1425 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1426 | int i = N; |
| 1427 | while (i > 0) { |
| 1428 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1429 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1430 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1431 | if (topCurW == null) { |
| 1432 | topCurW = w; |
| 1433 | topCurI = i; |
| 1434 | } |
| 1435 | continue; |
| 1436 | } |
| 1437 | topCurW = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1438 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1439 | // If this window's app token is hidden and not animating, |
| 1440 | // it is of no interest to us. |
| 1441 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1442 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1443 | "Skipping not hidden or animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1444 | continue; |
| 1445 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1446 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1447 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1448 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1449 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1450 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1451 | && (mWallpaperTarget == w |
| 1452 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1453 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1454 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1455 | foundW = w; |
| 1456 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1457 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1458 | && w.mAppToken.animation != null) |
| 1459 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1460 | // The current wallpaper target is animating, so we'll |
| 1461 | // look behind it for another possible target and figure |
| 1462 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1463 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1464 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1465 | continue; |
| 1466 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1467 | break; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1468 | } else if (w == mWindowDetachedWallpaper) { |
| 1469 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1473 | if (foundW == null && windowDetachedI >= 0) { |
| 1474 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1475 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1476 | foundW = w; |
| 1477 | foundI = windowDetachedI; |
| 1478 | } |
| 1479 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1480 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1481 | // If we are currently waiting for an app transition, and either |
| 1482 | // the current target or the next target are involved with it, |
| 1483 | // then hold off on doing anything with the wallpaper. |
| 1484 | // Note that we are checking here for just whether the target |
| 1485 | // is part of an app token... which is potentially overly aggressive |
| 1486 | // (the app token may not be involved in the transition), but good |
| 1487 | // enough (we'll just wait until whatever transition is pending |
| 1488 | // executes). |
| 1489 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1490 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1491 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1492 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1493 | } |
| 1494 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1495 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1496 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1497 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1498 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1499 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1500 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1501 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1502 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1503 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1504 | + " oldTarget: " + mWallpaperTarget); |
| 1505 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1506 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1507 | mLowerWallpaperTarget = null; |
| 1508 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1509 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1510 | WindowState oldW = mWallpaperTarget; |
| 1511 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1512 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1513 | // Now what is happening... if the current and new targets are |
| 1514 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1515 | if (foundW != null && oldW != null) { |
| 1516 | boolean oldAnim = oldW.mAnimation != null |
| 1517 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1518 | boolean foundAnim = foundW.mAnimation != null |
| 1519 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1520 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1521 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1522 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1523 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1524 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1525 | int oldI = localmWindows.indexOf(oldW); |
| 1526 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1527 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1528 | } |
| 1529 | if (oldI >= 0) { |
| 1530 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1531 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1532 | + "=" + oldW + "; new#" + foundI |
| 1533 | + "=" + foundW); |
| 1534 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1535 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1536 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1537 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1538 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1539 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1540 | } |
| 1541 | mWallpaperTarget = oldW; |
| 1542 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1543 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1544 | // Now set the upper and lower wallpaper targets |
| 1545 | // correctly, and make sure that we are positioning |
| 1546 | // the wallpaper below the lower. |
| 1547 | if (foundI > oldI) { |
| 1548 | // The new target is on top of the old one. |
| 1549 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1550 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1551 | } |
| 1552 | mUpperWallpaperTarget = foundW; |
| 1553 | mLowerWallpaperTarget = oldW; |
| 1554 | foundW = oldW; |
| 1555 | foundI = oldI; |
| 1556 | } else { |
| 1557 | // The new target is below the old one. |
| 1558 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1559 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1560 | } |
| 1561 | mUpperWallpaperTarget = oldW; |
| 1562 | mLowerWallpaperTarget = foundW; |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1567 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1568 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1569 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1570 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1571 | || (mLowerWallpaperTarget.mAppToken != null |
| 1572 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1573 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1574 | || (mUpperWallpaperTarget.mAppToken != null |
| 1575 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1576 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1577 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1578 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1579 | } |
| 1580 | mLowerWallpaperTarget = null; |
| 1581 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1582 | } |
| 1583 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1584 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1585 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1586 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1587 | // The window is visible to the compositor... but is it visible |
| 1588 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1589 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1590 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1591 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1592 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1593 | // its layer adjustment. Only do this if we are not transfering |
| 1594 | // between two wallpaper targets. |
| 1595 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1596 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1597 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1598 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1599 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1600 | * TYPE_LAYER_MULTIPLIER |
| 1601 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1602 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1603 | // Now w is the window we are supposed to be behind... but we |
| 1604 | // need to be sure to also be behind any of its attached windows, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1605 | // AND any starting window associated with it, AND below the |
| 1606 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1607 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1608 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1609 | if (wb.mBaseLayer < maxLayer && |
| 1610 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1611 | (foundW.mAttachedWindow == null || |
| 1612 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1613 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1614 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1615 | // This window is not related to the previous one in any |
| 1616 | // interesting way, so stop here. |
| 1617 | break; |
| 1618 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1619 | foundW = wb; |
| 1620 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1621 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1622 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1623 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1624 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1625 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1626 | if (foundW == null && topCurW != null) { |
| 1627 | // There is no wallpaper target, so it goes at the bottom. |
| 1628 | // We will assume it is the same place as last time, if known. |
| 1629 | foundW = topCurW; |
| 1630 | foundI = topCurI+1; |
| 1631 | } else { |
| 1632 | // Okay i is the position immediately above the wallpaper. Look at |
| 1633 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1634 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1635 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1636 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1637 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1638 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1639 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1640 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1641 | } |
| 1642 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1643 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1644 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1645 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1646 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1647 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1648 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1649 | // are correctly placed. |
| 1650 | int curTokenIndex = mWallpaperTokens.size(); |
| 1651 | while (curTokenIndex > 0) { |
| 1652 | curTokenIndex--; |
| 1653 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1654 | if (token.hidden == visible) { |
| 1655 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1656 | token.hidden = !visible; |
| 1657 | // Need to do a layout to ensure the wallpaper now has the |
| 1658 | // correct size. |
| 1659 | mLayoutNeeded = true; |
| 1660 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1661 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1662 | int curWallpaperIndex = token.windows.size(); |
| 1663 | while (curWallpaperIndex > 0) { |
| 1664 | curWallpaperIndex--; |
| 1665 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1666 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1667 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1668 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1669 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1670 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1671 | // First, make sure the client has the current visibility |
| 1672 | // state. |
| 1673 | if (wallpaper.mWallpaperVisible != visible) { |
| 1674 | wallpaper.mWallpaperVisible = visible; |
| 1675 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1676 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1677 | "Setting visibility of wallpaper " + wallpaper |
| 1678 | + ": " + visible); |
| 1679 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1680 | } catch (RemoteException e) { |
| 1681 | } |
| 1682 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1683 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1684 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1685 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1686 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1687 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1688 | // First, if this window is at the current index, then all |
| 1689 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1690 | if (wallpaper == foundW) { |
| 1691 | foundI--; |
| 1692 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1693 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1694 | continue; |
| 1695 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1696 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1697 | // The window didn't match... the current wallpaper window, |
| 1698 | // wherever it is, is in the wrong place, so make sure it is |
| 1699 | // not in the list. |
| 1700 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1701 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1702 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1703 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1704 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1705 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1706 | if (oldIndex < foundI) { |
| 1707 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1708 | } |
| 1709 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1710 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1711 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1712 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1713 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 1714 | + " from " + oldIndex + " to " + foundI); |
| 1715 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1716 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1717 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1718 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1719 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1723 | return changed; |
| 1724 | } |
| 1725 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1726 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1727 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1728 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1729 | mWallpaperAnimLayerAdjustment = adj; |
| 1730 | int curTokenIndex = mWallpaperTokens.size(); |
| 1731 | while (curTokenIndex > 0) { |
| 1732 | curTokenIndex--; |
| 1733 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1734 | int curWallpaperIndex = token.windows.size(); |
| 1735 | while (curWallpaperIndex > 0) { |
| 1736 | curWallpaperIndex--; |
| 1737 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1738 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1739 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1740 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1745 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1746 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1747 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1748 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1749 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1750 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1751 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1752 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1753 | changed = wallpaperWin.mXOffset != offset; |
| 1754 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1755 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1756 | + wallpaperWin + " x: " + offset); |
| 1757 | wallpaperWin.mXOffset = offset; |
| 1758 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1759 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1760 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1761 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1762 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1763 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1764 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1765 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1766 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1767 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1768 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1769 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1770 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1771 | + wallpaperWin + " y: " + offset); |
| 1772 | changed = true; |
| 1773 | wallpaperWin.mYOffset = offset; |
| 1774 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1775 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1776 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1777 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1778 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1779 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1780 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1781 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1782 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1783 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1784 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1785 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1786 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1787 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1788 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1789 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1790 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1791 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1792 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1793 | if (mWaitingOnWallpaper != null) { |
| 1794 | long start = SystemClock.uptimeMillis(); |
| 1795 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1796 | < start) { |
| 1797 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1798 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1799 | "Waiting for offset complete..."); |
| 1800 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1801 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1802 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1803 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1804 | if ((start+WALLPAPER_TIMEOUT) |
| 1805 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1806 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1807 | + wallpaperWin); |
| 1808 | mLastWallpaperTimeoutTime = start; |
| 1809 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1810 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1811 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1812 | } |
| 1813 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1814 | } catch (RemoteException e) { |
| 1815 | } |
| 1816 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1817 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1818 | return changed; |
| 1819 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1820 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1821 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1822 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1823 | if (mWaitingOnWallpaper != null && |
| 1824 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1825 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1826 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1830 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1831 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1832 | final int dw = mDisplay.getWidth(); |
| 1833 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1834 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1835 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1836 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1837 | WindowState target = mWallpaperTarget; |
| 1838 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1839 | if (target.mWallpaperX >= 0) { |
| 1840 | mLastWallpaperX = target.mWallpaperX; |
| 1841 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1842 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1843 | } |
| 1844 | if (target.mWallpaperY >= 0) { |
| 1845 | mLastWallpaperY = target.mWallpaperY; |
| 1846 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1847 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1848 | } |
| 1849 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1850 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1851 | int curTokenIndex = mWallpaperTokens.size(); |
| 1852 | while (curTokenIndex > 0) { |
| 1853 | curTokenIndex--; |
| 1854 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1855 | int curWallpaperIndex = token.windows.size(); |
| 1856 | while (curWallpaperIndex > 0) { |
| 1857 | curWallpaperIndex--; |
| 1858 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1859 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1860 | wallpaper.computeShownFrameLocked(); |
| 1861 | changed = true; |
| 1862 | // We only want to be synchronous with one wallpaper. |
| 1863 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1867 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1868 | return changed; |
| 1869 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1870 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1871 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1872 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1873 | final int dw = mDisplay.getWidth(); |
| 1874 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1875 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1876 | int curTokenIndex = mWallpaperTokens.size(); |
| 1877 | while (curTokenIndex > 0) { |
| 1878 | curTokenIndex--; |
| 1879 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1880 | if (token.hidden == visible) { |
| 1881 | token.hidden = !visible; |
| 1882 | // Need to do a layout to ensure the wallpaper now has the |
| 1883 | // correct size. |
| 1884 | mLayoutNeeded = true; |
| 1885 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1886 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1887 | int curWallpaperIndex = token.windows.size(); |
| 1888 | while (curWallpaperIndex > 0) { |
| 1889 | curWallpaperIndex--; |
| 1890 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1891 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1892 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1893 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1894 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1895 | if (wallpaper.mWallpaperVisible != visible) { |
| 1896 | wallpaper.mWallpaperVisible = visible; |
| 1897 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1898 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1899 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1900 | + ": " + visible); |
| 1901 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1902 | } catch (RemoteException e) { |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | public int addWindow(Session session, IWindow client, |
| 1910 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1911 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | int res = mPolicy.checkAddPermission(attrs); |
| 1913 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1914 | return res; |
| 1915 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | boolean reportNewConfig = false; |
| 1918 | WindowState attachedWindow = null; |
| 1919 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 1920 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1923 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 1924 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1925 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1928 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1930 | } |
| 1931 | |
| 1932 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1933 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1935 | Slog.w(TAG, "Attempted to add window with token that is not a window: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | + attrs.token + ". Aborting."); |
| 1937 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1938 | } |
| 1939 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1940 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1941 | Slog.w(TAG, "Attempted to add window with token that is a sub-window: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | + attrs.token + ". Aborting."); |
| 1943 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | boolean addToken = false; |
| 1948 | WindowToken token = mTokenMap.get(attrs.token); |
| 1949 | if (token == null) { |
| 1950 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1951 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1952 | Slog.w(TAG, "Attempted to add application window with unknown token " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1953 | + attrs.token + ". Aborting."); |
| 1954 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1955 | } |
| 1956 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1957 | Slog.w(TAG, "Attempted to add input method window with unknown token " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | + attrs.token + ". Aborting."); |
| 1959 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1960 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1961 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1962 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1963 | + attrs.token + ". Aborting."); |
| 1964 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1965 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 1966 | token = new WindowToken(this, attrs.token, -1, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | addToken = true; |
| 1968 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1969 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1970 | AppWindowToken atoken = token.appWindowToken; |
| 1971 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1972 | Slog.w(TAG, "Attempted to add window with non-application token " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1973 | + token + ". Aborting."); |
| 1974 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1975 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1976 | Slog.w(TAG, "Attempted to add window with exiting application token " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1977 | + token + ". Aborting."); |
| 1978 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1979 | } |
| 1980 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1981 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1982 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1984 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1985 | } |
| 1986 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1987 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1988 | Slog.w(TAG, "Attempted to add input method window with bad token " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | + attrs.token + ". Aborting."); |
| 1990 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1991 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1992 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1993 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1994 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1995 | + attrs.token + ". Aborting."); |
| 1996 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | } |
| 1999 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 2000 | win = new WindowState(this, session, client, token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | attachedWindow, attrs, viewVisibility); |
| 2002 | if (win.mDeathRecipient == null) { |
| 2003 | // Client has apparently died, so there is no reason to |
| 2004 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2005 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2006 | + " that is dead, aborting."); |
| 2007 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2008 | } |
| 2009 | |
| 2010 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2013 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2014 | return res; |
| 2015 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2016 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2017 | if (outInputChannel != null) { |
| 2018 | String name = win.makeInputChannelName(); |
| 2019 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2020 | win.mInputChannel = inputChannels[0]; |
| 2021 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2022 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2023 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2024 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2025 | |
| 2026 | // From now on, no exceptions or errors allowed! |
| 2027 | |
| 2028 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2029 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2030 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | if (addToken) { |
| 2033 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | } |
| 2035 | win.attach(); |
| 2036 | mWindowMap.put(client.asBinder(), win); |
| 2037 | |
| 2038 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2039 | token.appWindowToken != null) { |
| 2040 | token.appWindowToken.startingWindow = win; |
| 2041 | } |
| 2042 | |
| 2043 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2046 | mInputMethodWindow = win; |
| 2047 | addInputMethodWindowToListLocked(win); |
| 2048 | imMayMove = false; |
| 2049 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2050 | mInputMethodDialogs.add(win); |
| 2051 | addWindowToListInOrderLocked(win, true); |
| 2052 | adjustInputMethodDialogsLocked(); |
| 2053 | imMayMove = false; |
| 2054 | } else { |
| 2055 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2056 | if (attrs.type == TYPE_WALLPAPER) { |
| 2057 | mLastWallpaperTimeoutTime = 0; |
| 2058 | adjustWallpaperWindowsLocked(); |
| 2059 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2060 | adjustWallpaperWindowsLocked(); |
| 2061 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2063 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | if (mInTouchMode) { |
| 2069 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2070 | } |
| 2071 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2072 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2073 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2074 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2075 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2076 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2077 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2079 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2080 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2081 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | imMayMove = false; |
| 2083 | } |
| 2084 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2087 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2088 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | assignLayersLocked(); |
| 2091 | // Don't do layout here, the window must call |
| 2092 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2094 | //dump(); |
| 2095 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2096 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2097 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2098 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2099 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2100 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2101 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | TAG, "New client " + client.asBinder() |
| 2103 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2104 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2105 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2106 | reportNewConfig = true; |
| 2107 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2108 | } |
| 2109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | if (reportNewConfig) { |
| 2111 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2116 | return res; |
| 2117 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | public void removeWindow(Session session, IWindow client) { |
| 2120 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2121 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | if (win == null) { |
| 2123 | return; |
| 2124 | } |
| 2125 | removeWindowLocked(session, win); |
| 2126 | } |
| 2127 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2129 | public void removeWindowLocked(Session session, WindowState win) { |
| 2130 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2131 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | TAG, "Remove " + win + " client=" |
| 2133 | + Integer.toHexString(System.identityHashCode( |
| 2134 | win.mClient.asBinder())) |
| 2135 | + ", surface=" + win.mSurface); |
| 2136 | |
| 2137 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2138 | |
| 2139 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2140 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2141 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2142 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2143 | + " mExiting=" + win.mExiting |
| 2144 | + " isAnimating=" + win.isAnimating() |
| 2145 | + " app-animation=" |
| 2146 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2147 | + " inPendingTransaction=" |
| 2148 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2149 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2150 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2151 | boolean wasVisible = false; |
| 2152 | // First, see if we need to run an animation. If we do, we have |
| 2153 | // to hold off on removing the window until the animation is done. |
| 2154 | // If the display is frozen, just remove immediately, since the |
| 2155 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2156 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | // If we are not currently running the exit animation, we |
| 2158 | // need to see about starting one. |
| 2159 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2161 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2162 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2163 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2164 | } |
| 2165 | // Try starting an animation. |
| 2166 | if (applyAnimationLocked(win, transit, false)) { |
| 2167 | win.mExiting = true; |
| 2168 | } |
| 2169 | } |
| 2170 | if (win.mExiting || win.isAnimating()) { |
| 2171 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2172 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | win.mExiting = true; |
| 2174 | win.mRemoveOnExit = true; |
| 2175 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2176 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2177 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2179 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2180 | if (win.mAppToken != null) { |
| 2181 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2182 | } |
| 2183 | //dump(); |
| 2184 | Binder.restoreCallingIdentity(origId); |
| 2185 | return; |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | removeWindowInnerLocked(session, win); |
| 2190 | // Removing a visible window will effect the computed orientation |
| 2191 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2192 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2193 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2194 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2195 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2197 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | Binder.restoreCallingIdentity(origId); |
| 2199 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2202 | if (win.mRemoved) { |
| 2203 | // Nothing to do. |
| 2204 | return; |
| 2205 | } |
| 2206 | |
| 2207 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2208 | WindowState cwin = win.mChildWindows.get(i); |
| 2209 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2210 | + win); |
| 2211 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2212 | } |
| 2213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | if (mInputMethodTarget == win) { |
| 2217 | moveInputMethodWindowsIfNeededLocked(false); |
| 2218 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2219 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2220 | if (false) { |
| 2221 | RuntimeException e = new RuntimeException("here"); |
| 2222 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2223 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2224 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2226 | mPolicy.removeWindowLw(win); |
| 2227 | win.removeLocked(); |
| 2228 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2229 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2230 | mWindowMap.remove(win.mClient.asBinder()); |
| 2231 | mWindows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2232 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2233 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2234 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | |
| 2236 | if (mInputMethodWindow == win) { |
| 2237 | mInputMethodWindow = null; |
| 2238 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2239 | mInputMethodDialogs.remove(win); |
| 2240 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | final WindowToken token = win.mToken; |
| 2243 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2244 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | token.windows.remove(win); |
| 2246 | if (atoken != null) { |
| 2247 | atoken.allAppWindows.remove(win); |
| 2248 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2249 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | TAG, "**** Removing window " + win + ": count=" |
| 2251 | + token.windows.size()); |
| 2252 | if (token.windows.size() == 0) { |
| 2253 | if (!token.explicit) { |
| 2254 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | } else if (atoken != null) { |
| 2256 | atoken.firstWindowDrawn = false; |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | if (atoken != null) { |
| 2261 | if (atoken.startingWindow == win) { |
| 2262 | atoken.startingWindow = null; |
| 2263 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2264 | // If this is the last window and we had requested a starting |
| 2265 | // transition window, well there is no point now. |
| 2266 | atoken.startingData = null; |
| 2267 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2268 | // If this is the last window except for a starting transition |
| 2269 | // window, we need to get rid of the starting transition. |
| 2270 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2271 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | + ": no more real windows"); |
| 2273 | } |
| 2274 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2275 | mH.sendMessage(m); |
| 2276 | } |
| 2277 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2278 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2279 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2280 | mLastWallpaperTimeoutTime = 0; |
| 2281 | adjustWallpaperWindowsLocked(); |
| 2282 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2283 | adjustWallpaperWindowsLocked(); |
| 2284 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | if (!mInLayout) { |
| 2287 | assignLayersLocked(); |
| 2288 | mLayoutNeeded = true; |
| 2289 | performLayoutAndPlaceSurfacesLocked(); |
| 2290 | if (win.mAppToken != null) { |
| 2291 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2292 | } |
| 2293 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2294 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2295 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 2298 | static void logSurface(WindowState w, String msg, RuntimeException where) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2299 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2300 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2301 | if (where != null) { |
| 2302 | Slog.i(TAG, str, where); |
| 2303 | } else { |
| 2304 | Slog.i(TAG, str); |
| 2305 | } |
| 2306 | } |
| 2307 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 2308 | void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2309 | long origId = Binder.clearCallingIdentity(); |
| 2310 | try { |
| 2311 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2312 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2313 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2314 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2315 | ">>> OPEN TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | Surface.openTransaction(); |
| 2317 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2318 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2319 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2320 | w.mSurface.setTransparentRegionHint(region); |
| 2321 | } finally { |
| 2322 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2323 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2324 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | } |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(origId); |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2334 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2335 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | long origId = Binder.clearCallingIdentity(); |
| 2337 | try { |
| 2338 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2339 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2340 | if (w != null) { |
| 2341 | w.mGivenInsetsPending = false; |
| 2342 | w.mGivenContentInsets.set(contentInsets); |
| 2343 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2344 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | w.mTouchableInsets = touchableInsets; |
| 2346 | mLayoutNeeded = true; |
| 2347 | performLayoutAndPlaceSurfacesLocked(); |
| 2348 | } |
| 2349 | } |
| 2350 | } finally { |
| 2351 | Binder.restoreCallingIdentity(origId); |
| 2352 | } |
| 2353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2356 | Rect outDisplayFrame) { |
| 2357 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2358 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | if (win == null) { |
| 2360 | outDisplayFrame.setEmpty(); |
| 2361 | return; |
| 2362 | } |
| 2363 | outDisplayFrame.set(win.mDisplayFrame); |
| 2364 | } |
| 2365 | } |
| 2366 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2367 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2368 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2369 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2370 | window.mWallpaperX = x; |
| 2371 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2372 | window.mWallpaperXStep = xStep; |
| 2373 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2374 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2375 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2379 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2380 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2381 | synchronized (mWindowMap) { |
| 2382 | if (mWaitingOnWallpaper != null && |
| 2383 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2384 | mWaitingOnWallpaper = null; |
| 2385 | mWindowMap.notifyAll(); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2389 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2390 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2391 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2392 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2393 | || window == mUpperWallpaperTarget) { |
| 2394 | boolean doWait = sync; |
| 2395 | int curTokenIndex = mWallpaperTokens.size(); |
| 2396 | while (curTokenIndex > 0) { |
| 2397 | curTokenIndex--; |
| 2398 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2399 | int curWallpaperIndex = token.windows.size(); |
| 2400 | while (curWallpaperIndex > 0) { |
| 2401 | curWallpaperIndex--; |
| 2402 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2403 | try { |
| 2404 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2405 | x, y, z, extras, sync); |
| 2406 | // We only want to be synchronous with one wallpaper. |
| 2407 | sync = false; |
| 2408 | } catch (RemoteException e) { |
| 2409 | } |
| 2410 | } |
| 2411 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2412 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2413 | if (doWait) { |
| 2414 | // XXX Need to wait for result. |
| 2415 | } |
| 2416 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2417 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2418 | return null; |
| 2419 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2421 | public int relayoutWindow(Session session, IWindow client, |
| 2422 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2423 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2424 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2425 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | boolean displayed = false; |
| 2427 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2428 | boolean configChanged; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2429 | |
| 2430 | // if they don't have this permission, mask out the status bar bits |
| 2431 | if (attrs != null) { |
| 2432 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 2433 | != PackageManager.PERMISSION_GRANTED) { |
| 2434 | attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2435 | attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2436 | } |
| 2437 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2441 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | if (win == null) { |
| 2443 | return 0; |
| 2444 | } |
| 2445 | win.mRequestedWidth = requestedWidth; |
| 2446 | win.mRequestedHeight = requestedHeight; |
| 2447 | |
| 2448 | if (attrs != null) { |
| 2449 | mPolicy.adjustWindowParamsLw(attrs); |
| 2450 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2452 | int attrChanges = 0; |
| 2453 | int flagChanges = 0; |
| 2454 | if (attrs != null) { |
| 2455 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2456 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2457 | } |
| 2458 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2459 | if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | |
| 2461 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2462 | win.mAlpha = attrs.alpha; |
| 2463 | } |
| 2464 | |
| 2465 | final boolean scaledWindow = |
| 2466 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2467 | |
| 2468 | if (scaledWindow) { |
| 2469 | // requested{Width|Height} Surface's physical size |
| 2470 | // attrs.{width|height} Size on screen |
| 2471 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2472 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2473 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2474 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2475 | } else { |
| 2476 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | boolean imMayMove = (flagChanges&( |
| 2480 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2481 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2484 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2485 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2486 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2487 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2488 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | win.mRelayoutCalled = true; |
| 2491 | final int oldVisibility = win.mViewVisibility; |
| 2492 | win.mViewVisibility = viewVisibility; |
| 2493 | if (viewVisibility == View.VISIBLE && |
| 2494 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2495 | displayed = !win.isVisibleLw(); |
| 2496 | if (win.mExiting) { |
| 2497 | win.mExiting = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2498 | if (win.mAnimation != null) { |
| 2499 | win.mAnimation.cancel(); |
| 2500 | win.mAnimation = null; |
| 2501 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | } |
| 2503 | if (win.mDestroying) { |
| 2504 | win.mDestroying = false; |
| 2505 | mDestroySurface.remove(win); |
| 2506 | } |
| 2507 | if (oldVisibility == View.GONE) { |
| 2508 | win.mEnterAnimationPending = true; |
| 2509 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2510 | if (displayed) { |
| 2511 | if (win.mSurface != null && !win.mDrawPending |
| 2512 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2513 | && mPolicy.isScreenOn()) { |
| 2514 | applyEnterAnimationLocked(win); |
| 2515 | } |
| 2516 | if ((win.mAttrs.flags |
| 2517 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2518 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2519 | "Relayout window turning screen on: " + win); |
| 2520 | win.mTurnOnScreen = true; |
| 2521 | } |
| 2522 | int diff = 0; |
| 2523 | if (win.mConfiguration != mCurConfiguration |
| 2524 | && (win.mConfiguration == null |
| 2525 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2526 | win.mConfiguration = mCurConfiguration; |
| 2527 | if (DEBUG_CONFIGURATION) { |
| 2528 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2529 | + win.mConfiguration + " / 0x" |
| 2530 | + Integer.toHexString(diff)); |
| 2531 | } |
| 2532 | outConfig.setTo(mCurConfiguration); |
| 2533 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2536 | // To change the format, we need to re-build the surface. |
| 2537 | win.destroySurfaceLocked(); |
| 2538 | displayed = true; |
| 2539 | } |
| 2540 | try { |
| 2541 | Surface surface = win.createSurfaceLocked(); |
| 2542 | if (surface != null) { |
| 2543 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2544 | win.mReportDestroySurface = false; |
| 2545 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2546 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2547 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2549 | // For some reason there isn't a surface. Clear the |
| 2550 | // caller's object so they see the same state. |
| 2551 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | } |
| 2553 | } catch (Exception e) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2554 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2555 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2556 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2557 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2558 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | Binder.restoreCallingIdentity(origId); |
| 2560 | return 0; |
| 2561 | } |
| 2562 | if (displayed) { |
| 2563 | focusMayChange = true; |
| 2564 | } |
| 2565 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2566 | && mInputMethodWindow == null) { |
| 2567 | mInputMethodWindow = win; |
| 2568 | imMayMove = true; |
| 2569 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2570 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2571 | && win.mAppToken != null |
| 2572 | && win.mAppToken.startingWindow != null) { |
| 2573 | // Special handling of starting window over the base |
| 2574 | // window of the app: propagate lock screen flags to it, |
| 2575 | // to provide the correct semantics while starting. |
| 2576 | final int mask = |
| 2577 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2578 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2579 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2580 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2581 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2582 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | } else { |
| 2584 | win.mEnterAnimationPending = false; |
| 2585 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2586 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2587 | + ": mExiting=" + win.mExiting |
| 2588 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | // If we are not currently running the exit animation, we |
| 2590 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2591 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2592 | // Try starting an animation; if there isn't one, we |
| 2593 | // can destroy the surface right away. |
| 2594 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2595 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2596 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2597 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2598 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2600 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2602 | } else if (win.isAnimating()) { |
| 2603 | // Currently in a hide animation... turn this into |
| 2604 | // an exit. |
| 2605 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2606 | } else if (win == mWallpaperTarget) { |
| 2607 | // If the wallpaper is currently behind this |
| 2608 | // window, we need to change both of them inside |
| 2609 | // of a transaction to avoid artifacts. |
| 2610 | win.mExiting = true; |
| 2611 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | } else { |
| 2613 | if (mInputMethodWindow == win) { |
| 2614 | mInputMethodWindow = null; |
| 2615 | } |
| 2616 | win.destroySurfaceLocked(); |
| 2617 | } |
| 2618 | } |
| 2619 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2620 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2621 | if (win.mSurface == null || (win.getAttrs().flags |
| 2622 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2623 | || win.mSurfacePendingDestroy) { |
| 2624 | // We are being called from a local process, which |
| 2625 | // means outSurface holds its current surface. Ensure the |
| 2626 | // surface object is cleared, but we don't want it actually |
| 2627 | // destroyed at this point. |
| 2628 | win.mSurfacePendingDestroy = false; |
| 2629 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2630 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2631 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2632 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2633 | "Keeping surface, will report destroy: " + win); |
| 2634 | win.mReportDestroySurface = true; |
| 2635 | outSurface.copyFrom(win.mSurface); |
| 2636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2637 | } |
| 2638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2639 | if (focusMayChange) { |
| 2640 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2641 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2642 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | imMayMove = false; |
| 2644 | } |
| 2645 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2646 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2647 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2648 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2649 | // reassign them at this point if the IM window state gets shuffled |
| 2650 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2653 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2654 | // Little hack here -- we -should- be able to rely on the |
| 2655 | // function to return true if the IME has moved and needs |
| 2656 | // its layer recomputed. However, if the IME was hidden |
| 2657 | // and isn't actually moved in the list, its layer may be |
| 2658 | // out of data so we make sure to recompute it. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | assignLayers = true; |
| 2660 | } |
| 2661 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2662 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2663 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2664 | assignLayers = true; |
| 2665 | } |
| 2666 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | mLayoutNeeded = true; |
| 2669 | win.mGivenInsetsPending = insetsPending; |
| 2670 | if (assignLayers) { |
| 2671 | assignLayersLocked(); |
| 2672 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2673 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2675 | if (displayed && win.mIsWallpaper) { |
| 2676 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2677 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2678 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | if (win.mAppToken != null) { |
| 2680 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2681 | } |
| 2682 | outFrame.set(win.mFrame); |
| 2683 | outContentInsets.set(win.mContentInsets); |
| 2684 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2685 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2687 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | + ", requestedHeight=" + requestedHeight |
| 2689 | + ", viewVisibility=" + viewVisibility |
| 2690 | + "\nRelayout returning frame=" + outFrame |
| 2691 | + ", surface=" + outSurface); |
| 2692 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2693 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2695 | |
| 2696 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2697 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2698 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2699 | } |
| 2700 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2701 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | sendNewConfiguration(); |
| 2703 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2708 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2709 | } |
| 2710 | |
| 2711 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2712 | final long origId = Binder.clearCallingIdentity(); |
| 2713 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2714 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2715 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2716 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2717 | adjustWallpaperWindowsLocked(); |
| 2718 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2719 | mLayoutNeeded = true; |
| 2720 | performLayoutAndPlaceSurfacesLocked(); |
| 2721 | } |
| 2722 | } |
| 2723 | Binder.restoreCallingIdentity(origId); |
| 2724 | } |
| 2725 | |
| 2726 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2727 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2728 | + (lp != null ? lp.packageName : null) |
| 2729 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2730 | if (lp != null && lp.windowAnimations != 0) { |
| 2731 | // If this is a system resource, don't try to load it from the |
| 2732 | // application resources. It is nice to avoid loading application |
| 2733 | // resources if we can. |
| 2734 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2735 | int resId = lp.windowAnimations; |
| 2736 | if ((resId&0xFF000000) == 0x01000000) { |
| 2737 | packageName = "android"; |
| 2738 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2739 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | + packageName); |
| 2741 | return AttributeCache.instance().get(packageName, resId, |
| 2742 | com.android.internal.R.styleable.WindowAnimation); |
| 2743 | } |
| 2744 | return null; |
| 2745 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2746 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2747 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2748 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2749 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2750 | if (packageName != null) { |
| 2751 | if ((resId&0xFF000000) == 0x01000000) { |
| 2752 | packageName = "android"; |
| 2753 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2754 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2755 | + packageName); |
| 2756 | return AttributeCache.instance().get(packageName, resId, |
| 2757 | com.android.internal.R.styleable.WindowAnimation); |
| 2758 | } |
| 2759 | return null; |
| 2760 | } |
| 2761 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 2762 | void applyEnterAnimationLocked(WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2764 | if (win.mEnterAnimationPending) { |
| 2765 | win.mEnterAnimationPending = false; |
| 2766 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2767 | } |
| 2768 | |
| 2769 | applyAnimationLocked(win, transit, true); |
| 2770 | } |
| 2771 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 2772 | boolean applyAnimationLocked(WindowState win, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | int transit, boolean isEntrance) { |
| 2774 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2775 | // If we are trying to apply an animation, but already running |
| 2776 | // an animation of the same type, then just leave that one alone. |
| 2777 | return true; |
| 2778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2780 | // Only apply an animation if the display isn't frozen. If it is |
| 2781 | // frozen, there is no reason to animate and it can cause strange |
| 2782 | // artifacts when we unfreeze the display if some different animation |
| 2783 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2784 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2785 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2786 | int attr = -1; |
| 2787 | Animation a = null; |
| 2788 | if (anim != 0) { |
| 2789 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2790 | } else { |
| 2791 | switch (transit) { |
| 2792 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2793 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2794 | break; |
| 2795 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2796 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2797 | break; |
| 2798 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2799 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2800 | break; |
| 2801 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2802 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2803 | break; |
| 2804 | } |
| 2805 | if (attr >= 0) { |
| 2806 | a = loadAnimation(win.mAttrs, attr); |
| 2807 | } |
| 2808 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2809 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2811 | + " mAnimation=" + win.mAnimation |
| 2812 | + " isEntrance=" + isEntrance); |
| 2813 | if (a != null) { |
| 2814 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2815 | RuntimeException e = null; |
| 2816 | if (!HIDE_STACK_CRAWLS) { |
| 2817 | e = new RuntimeException(); |
| 2818 | e.fillInStackTrace(); |
| 2819 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2820 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2821 | } |
| 2822 | win.setAnimation(a); |
| 2823 | win.mAnimationIsEntrance = isEntrance; |
| 2824 | } |
| 2825 | } else { |
| 2826 | win.clearAnimation(); |
| 2827 | } |
| 2828 | |
| 2829 | return win.mAnimation != null; |
| 2830 | } |
| 2831 | |
| 2832 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2833 | int anim = 0; |
| 2834 | Context context = mContext; |
| 2835 | if (animAttr >= 0) { |
| 2836 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2837 | if (ent != null) { |
| 2838 | context = ent.context; |
| 2839 | anim = ent.array.getResourceId(animAttr, 0); |
| 2840 | } |
| 2841 | } |
| 2842 | if (anim != 0) { |
| 2843 | return AnimationUtils.loadAnimation(context, anim); |
| 2844 | } |
| 2845 | return null; |
| 2846 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2847 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2848 | private Animation loadAnimation(String packageName, int resId) { |
| 2849 | int anim = 0; |
| 2850 | Context context = mContext; |
| 2851 | if (resId >= 0) { |
| 2852 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2853 | if (ent != null) { |
| 2854 | context = ent.context; |
| 2855 | anim = resId; |
| 2856 | } |
| 2857 | } |
| 2858 | if (anim != 0) { |
| 2859 | return AnimationUtils.loadAnimation(context, anim); |
| 2860 | } |
| 2861 | return null; |
| 2862 | } |
| 2863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2865 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2866 | // Only apply an animation if the display isn't frozen. If it is |
| 2867 | // frozen, there is no reason to animate and it can cause strange |
| 2868 | // artifacts when we unfreeze the display if some different animation |
| 2869 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2870 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2871 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2872 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2873 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2874 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2875 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2876 | } else if (mNextAppTransitionPackage != null) { |
| 2877 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2878 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2879 | } else { |
| 2880 | int animAttr = 0; |
| 2881 | switch (transit) { |
| 2882 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2883 | animAttr = enter |
| 2884 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2885 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2886 | break; |
| 2887 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2888 | animAttr = enter |
| 2889 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2890 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2891 | break; |
| 2892 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2893 | animAttr = enter |
| 2894 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2895 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2896 | break; |
| 2897 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2898 | animAttr = enter |
| 2899 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2900 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2901 | break; |
| 2902 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2903 | animAttr = enter |
| 2904 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2905 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2906 | break; |
| 2907 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2908 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2909 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2910 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2911 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2912 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2913 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2914 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2915 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2916 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2917 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2918 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2919 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2920 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2921 | break; |
| 2922 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2923 | animAttr = enter |
| 2924 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2925 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2926 | break; |
| 2927 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2928 | animAttr = enter |
| 2929 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2930 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2931 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2932 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2933 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2934 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2935 | + " anim=" + a |
| 2936 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2937 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | if (a != null) { |
| 2940 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2941 | RuntimeException e = null; |
| 2942 | if (!HIDE_STACK_CRAWLS) { |
| 2943 | e = new RuntimeException(); |
| 2944 | e.fillInStackTrace(); |
| 2945 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2946 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | } |
| 2948 | wtoken.setAnimation(a); |
| 2949 | } |
| 2950 | } else { |
| 2951 | wtoken.clearAnimation(); |
| 2952 | } |
| 2953 | |
| 2954 | return wtoken.animation != null; |
| 2955 | } |
| 2956 | |
| 2957 | // ------------------------------------------------------------- |
| 2958 | // Application Window Tokens |
| 2959 | // ------------------------------------------------------------- |
| 2960 | |
| 2961 | public void validateAppTokens(List tokens) { |
| 2962 | int v = tokens.size()-1; |
| 2963 | int m = mAppTokens.size()-1; |
| 2964 | while (v >= 0 && m >= 0) { |
| 2965 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2966 | if (wtoken.removed) { |
| 2967 | m--; |
| 2968 | continue; |
| 2969 | } |
| 2970 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2971 | Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2973 | } |
| 2974 | v--; |
| 2975 | m--; |
| 2976 | } |
| 2977 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2978 | Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | v--; |
| 2980 | } |
| 2981 | while (m >= 0) { |
| 2982 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2983 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2984 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | } |
| 2986 | m--; |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | boolean checkCallingPermission(String permission, String func) { |
| 2991 | // Quick check: if the calling permission is me, it's all okay. |
| 2992 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2993 | return true; |
| 2994 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2996 | if (mContext.checkCallingPermission(permission) |
| 2997 | == PackageManager.PERMISSION_GRANTED) { |
| 2998 | return true; |
| 2999 | } |
| 3000 | String msg = "Permission Denial: " + func + " from pid=" |
| 3001 | + Binder.getCallingPid() |
| 3002 | + ", uid=" + Binder.getCallingUid() |
| 3003 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3004 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | return false; |
| 3006 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3008 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3009 | WindowToken wtoken = mTokenMap.get(token); |
| 3010 | if (wtoken == null) { |
| 3011 | return null; |
| 3012 | } |
| 3013 | return wtoken.appWindowToken; |
| 3014 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | public void addWindowToken(IBinder token, int type) { |
| 3017 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3018 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3019 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3020 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | synchronized(mWindowMap) { |
| 3023 | WindowToken wtoken = mTokenMap.get(token); |
| 3024 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3025 | Slog.w(TAG, "Attempted to add existing input method token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3026 | return; |
| 3027 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 3028 | wtoken = new WindowToken(this, token, type, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3030 | if (type == TYPE_WALLPAPER) { |
| 3031 | mWallpaperTokens.add(wtoken); |
| 3032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | } |
| 3034 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | public void removeWindowToken(IBinder token) { |
| 3037 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3038 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3039 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | final long origId = Binder.clearCallingIdentity(); |
| 3043 | synchronized(mWindowMap) { |
| 3044 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3045 | if (wtoken != null) { |
| 3046 | boolean delayed = false; |
| 3047 | if (!wtoken.hidden) { |
| 3048 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | final int N = wtoken.windows.size(); |
| 3051 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3053 | for (int i=0; i<N; i++) { |
| 3054 | WindowState win = wtoken.windows.get(i); |
| 3055 | |
| 3056 | if (win.isAnimating()) { |
| 3057 | delayed = true; |
| 3058 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | if (win.isVisibleNow()) { |
| 3061 | applyAnimationLocked(win, |
| 3062 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3063 | changed = true; |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | if (changed) { |
| 3068 | mLayoutNeeded = true; |
| 3069 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3070 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3071 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3072 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3074 | if (delayed) { |
| 3075 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3076 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3077 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3078 | } |
| 3079 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3080 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3081 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3083 | Slog.w(TAG, "Attempted to remove non-existing token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | } |
| 3085 | } |
| 3086 | Binder.restoreCallingIdentity(origId); |
| 3087 | } |
| 3088 | |
| 3089 | public void addAppToken(int addPos, IApplicationToken token, |
| 3090 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3091 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3092 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3093 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3094 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3095 | |
| 3096 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3097 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3098 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3099 | // here we would run the chance of introducing a deadlock between the window manager |
| 3100 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3101 | // (which holds locks while querying the application token). |
| 3102 | long inputDispatchingTimeoutNanos; |
| 3103 | try { |
| 3104 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3105 | } catch (RemoteException ex) { |
| 3106 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3107 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | synchronized(mWindowMap) { |
| 3111 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3112 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3113 | Slog.w(TAG, "Attempted to add existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3114 | return; |
| 3115 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 3116 | wtoken = new AppWindowToken(this, token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3117 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3118 | wtoken.groupId = groupId; |
| 3119 | wtoken.appFullscreen = fullscreen; |
| 3120 | wtoken.requestedOrientation = requestedOrientation; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3121 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | mAppTokens.add(addPos, wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3123 | mTokenMap.put(token.asBinder(), wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3125 | // Application tokens start out hidden. |
| 3126 | wtoken.hidden = true; |
| 3127 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3129 | //dump(); |
| 3130 | } |
| 3131 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3133 | public void setAppGroupId(IBinder token, int groupId) { |
| 3134 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3135 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3136 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | synchronized(mWindowMap) { |
| 3140 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3141 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3142 | Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | return; |
| 3144 | } |
| 3145 | wtoken.groupId = groupId; |
| 3146 | } |
| 3147 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | public int getOrientationFromWindowsLocked() { |
| 3150 | int pos = mWindows.size() - 1; |
| 3151 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3152 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | pos--; |
| 3154 | if (wtoken.mAppToken != null) { |
| 3155 | // We hit an application window. so the orientation will be determined by the |
| 3156 | // app window. No point in continuing further. |
| 3157 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3158 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3159 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | continue; |
| 3161 | } |
| 3162 | int req = wtoken.mAttrs.screenOrientation; |
| 3163 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3164 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3165 | continue; |
| 3166 | } else { |
| 3167 | return req; |
| 3168 | } |
| 3169 | } |
| 3170 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3171 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3173 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3174 | int pos = mAppTokens.size() - 1; |
| 3175 | int curGroup = 0; |
| 3176 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3177 | boolean findingBehind = false; |
| 3178 | boolean haveGroup = false; |
| 3179 | boolean lastFullscreen = false; |
| 3180 | while (pos >= 0) { |
| 3181 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3182 | pos--; |
| 3183 | // if we're about to tear down this window and not seek for |
| 3184 | // the behind activity, don't use it for orientation |
| 3185 | if (!findingBehind |
| 3186 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3187 | continue; |
| 3188 | } |
| 3189 | |
| 3190 | if (!haveGroup) { |
| 3191 | // We ignore any hidden applications on the top. |
| 3192 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3193 | continue; |
| 3194 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3195 | haveGroup = true; |
| 3196 | curGroup = wtoken.groupId; |
| 3197 | lastOrientation = wtoken.requestedOrientation; |
| 3198 | } else if (curGroup != wtoken.groupId) { |
| 3199 | // If we have hit a new application group, and the bottom |
| 3200 | // of the previous group didn't explicitly say to use |
| 3201 | // the orientation behind it, and the last app was |
| 3202 | // full screen, then we'll stick with the |
| 3203 | // user's orientation. |
| 3204 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3205 | && lastFullscreen) { |
| 3206 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3209 | int or = wtoken.requestedOrientation; |
| 3210 | // If this application is fullscreen, and didn't explicitly say |
| 3211 | // to use the orientation behind it, then just take whatever |
| 3212 | // orientation it has and ignores whatever is under it. |
| 3213 | lastFullscreen = wtoken.appFullscreen; |
| 3214 | if (lastFullscreen |
| 3215 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3216 | return or; |
| 3217 | } |
| 3218 | // If this application has requested an explicit orientation, |
| 3219 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3220 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3221 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3222 | return or; |
| 3223 | } |
| 3224 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3225 | } |
| 3226 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3230 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3231 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3232 | "updateOrientationFromAppTokens()")) { |
| 3233 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3234 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3235 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3236 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3238 | |
| 3239 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3240 | if (updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3241 | if (freezeThisOneIfNeeded != null) { |
| 3242 | AppWindowToken wtoken = findAppWindowToken( |
| 3243 | freezeThisOneIfNeeded); |
| 3244 | if (wtoken != null) { |
| 3245 | startAppFreezingScreenLocked(wtoken, |
| 3246 | ActivityInfo.CONFIG_ORIENTATION); |
| 3247 | } |
| 3248 | } |
| 3249 | config = computeNewConfigurationLocked(); |
| 3250 | |
| 3251 | } else if (currentConfig != null) { |
| 3252 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3253 | // state mismatches the activity manager's, update it, |
| 3254 | // disregarding font scale, which should remain set to |
| 3255 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3256 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3257 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3258 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3259 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3260 | mWaitingForConfig = true; |
| 3261 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3262 | startFreezingDisplayLocked(false); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3263 | config = new Configuration(mTempConfiguration); |
| 3264 | } |
| 3265 | } |
| 3266 | } |
| 3267 | } |
| 3268 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3269 | Binder.restoreCallingIdentity(ident); |
| 3270 | return config; |
| 3271 | } |
| 3272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3273 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3274 | * Determine the new desired orientation of the display, returning |
| 3275 | * a non-null new Configuration if it has changed from the current |
| 3276 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3277 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3278 | * SCREEN. This will typically be done for you if you call |
| 3279 | * sendNewConfiguration(). |
| 3280 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | * The orientation is computed from non-application windows first. If none of |
| 3282 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3283 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3285 | * android.os.IBinder) |
| 3286 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3287 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3288 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3289 | // If the display is frozen, some activities may be in the middle |
| 3290 | // of restarting, and thus have removed their old window. If the |
| 3291 | // window has the flag to hide the lock screen, then the lock screen |
| 3292 | // can re-appear and inflict its own orientation on us. Keep the |
| 3293 | // orientation stable until this all settles down. |
| 3294 | return false; |
| 3295 | } |
| 3296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3297 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | long ident = Binder.clearCallingIdentity(); |
| 3299 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3300 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3303 | mForcedAppOrientation = req; |
| 3304 | //send a message to Policy indicating orientation change to take |
| 3305 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3306 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3307 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3308 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3309 | inTransaction)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3310 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | } |
| 3312 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3313 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3314 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | } finally { |
| 3316 | Binder.restoreCallingIdentity(ident); |
| 3317 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3319 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3320 | int computeForcedAppOrientationLocked() { |
| 3321 | int req = getOrientationFromWindowsLocked(); |
| 3322 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3323 | req = getOrientationFromAppTokensLocked(); |
| 3324 | } |
| 3325 | return req; |
| 3326 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3327 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3328 | public void setNewConfiguration(Configuration config) { |
| 3329 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3330 | "setNewConfiguration()")) { |
| 3331 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3332 | } |
| 3333 | |
| 3334 | synchronized(mWindowMap) { |
| 3335 | mCurConfiguration = new Configuration(config); |
| 3336 | mWaitingForConfig = false; |
| 3337 | performLayoutAndPlaceSurfacesLocked(); |
| 3338 | } |
| 3339 | } |
| 3340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3341 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3342 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3343 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3344 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | synchronized(mWindowMap) { |
| 3348 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3349 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3350 | Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3351 | return; |
| 3352 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | wtoken.requestedOrientation = requestedOrientation; |
| 3355 | } |
| 3356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3358 | public int getAppOrientation(IApplicationToken token) { |
| 3359 | synchronized(mWindowMap) { |
| 3360 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3361 | if (wtoken == null) { |
| 3362 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3363 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | return wtoken.requestedOrientation; |
| 3366 | } |
| 3367 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3370 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3371 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3372 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | synchronized(mWindowMap) { |
| 3376 | boolean changed = false; |
| 3377 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3378 | if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3379 | changed = mFocusedApp != null; |
| 3380 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3381 | if (changed) { |
| 3382 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3383 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3384 | } else { |
| 3385 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3386 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3387 | Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | return; |
| 3389 | } |
| 3390 | changed = mFocusedApp != newFocus; |
| 3391 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3392 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3393 | if (changed) { |
| 3394 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3395 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | if (moveFocusNow && changed) { |
| 3399 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3400 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | Binder.restoreCallingIdentity(origId); |
| 3402 | } |
| 3403 | } |
| 3404 | } |
| 3405 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3406 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3407 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3408 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3409 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3413 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3414 | TAG, "Prepare app transition: transit=" + transit |
| 3415 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3416 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3417 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3418 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3420 | } else if (!alwaysKeepCurrent) { |
| 3421 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3422 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3423 | // Opening a new task always supersedes a close for the anim. |
| 3424 | mNextAppTransition = transit; |
| 3425 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3426 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3427 | // Opening a new activity always supersedes a close for the anim. |
| 3428 | mNextAppTransition = transit; |
| 3429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3430 | } |
| 3431 | mAppTransitionReady = false; |
| 3432 | mAppTransitionTimeout = false; |
| 3433 | mStartingIconInTransition = false; |
| 3434 | mSkipAppTransitionAnimation = false; |
| 3435 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3436 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3437 | 5000); |
| 3438 | } |
| 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | public int getPendingAppTransition() { |
| 3443 | return mNextAppTransition; |
| 3444 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3445 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3446 | public void overridePendingAppTransition(String packageName, |
| 3447 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3448 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3449 | mNextAppTransitionPackage = packageName; |
| 3450 | mNextAppTransitionEnter = enterAnim; |
| 3451 | mNextAppTransitionExit = exitAnim; |
| 3452 | } |
| 3453 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3455 | public void executeAppTransition() { |
| 3456 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3457 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3458 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3461 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3462 | if (DEBUG_APP_TRANSITIONS) { |
| 3463 | RuntimeException e = new RuntimeException("here"); |
| 3464 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3465 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3466 | + mNextAppTransition, e); |
| 3467 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3468 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3469 | mAppTransitionReady = true; |
| 3470 | final long origId = Binder.clearCallingIdentity(); |
| 3471 | performLayoutAndPlaceSurfacesLocked(); |
| 3472 | Binder.restoreCallingIdentity(origId); |
| 3473 | } |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3478 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3479 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3481 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3482 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3486 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3488 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3490 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3491 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3492 | Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3493 | return; |
| 3494 | } |
| 3495 | |
| 3496 | // If the display is frozen, we won't do anything until the |
| 3497 | // actual window is displayed so there is no reason to put in |
| 3498 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3499 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | return; |
| 3501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | if (wtoken.startingData != null) { |
| 3504 | return; |
| 3505 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | if (transferFrom != null) { |
| 3508 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3509 | if (ttoken != null) { |
| 3510 | WindowState startingWindow = ttoken.startingWindow; |
| 3511 | if (startingWindow != null) { |
| 3512 | if (mStartingIconInTransition) { |
| 3513 | // In this case, the starting icon has already |
| 3514 | // been displayed, so start letting windows get |
| 3515 | // shown immediately without any more transitions. |
| 3516 | mSkipAppTransitionAnimation = true; |
| 3517 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3518 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | "Moving existing starting from " + ttoken |
| 3520 | + " to " + wtoken); |
| 3521 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3523 | // Transfer the starting window over to the new |
| 3524 | // token. |
| 3525 | wtoken.startingData = ttoken.startingData; |
| 3526 | wtoken.startingView = ttoken.startingView; |
| 3527 | wtoken.startingWindow = startingWindow; |
| 3528 | ttoken.startingData = null; |
| 3529 | ttoken.startingView = null; |
| 3530 | ttoken.startingWindow = null; |
| 3531 | ttoken.startingMoved = true; |
| 3532 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3533 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3535 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3536 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3538 | mWindowsChanged = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3539 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3540 | + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | ttoken.windows.remove(startingWindow); |
| 3542 | ttoken.allAppWindows.remove(startingWindow); |
| 3543 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | // Propagate other interesting state between the |
| 3546 | // tokens. If the old token is displayed, we should |
| 3547 | // immediately force the new one to be displayed. If |
| 3548 | // it is animating, we need to move that animation to |
| 3549 | // the new one. |
| 3550 | if (ttoken.allDrawn) { |
| 3551 | wtoken.allDrawn = true; |
| 3552 | } |
| 3553 | if (ttoken.firstWindowDrawn) { |
| 3554 | wtoken.firstWindowDrawn = true; |
| 3555 | } |
| 3556 | if (!ttoken.hidden) { |
| 3557 | wtoken.hidden = false; |
| 3558 | wtoken.hiddenRequested = false; |
| 3559 | wtoken.willBeHidden = false; |
| 3560 | } |
| 3561 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3562 | wtoken.clientHidden = ttoken.clientHidden; |
| 3563 | wtoken.sendAppVisibilityToClients(); |
| 3564 | } |
| 3565 | if (ttoken.animation != null) { |
| 3566 | wtoken.animation = ttoken.animation; |
| 3567 | wtoken.animating = ttoken.animating; |
| 3568 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3569 | ttoken.animation = null; |
| 3570 | ttoken.animLayerAdjustment = 0; |
| 3571 | wtoken.updateLayers(); |
| 3572 | ttoken.updateLayers(); |
| 3573 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3574 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3575 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3576 | true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | mLayoutNeeded = true; |
| 3578 | performLayoutAndPlaceSurfacesLocked(); |
| 3579 | Binder.restoreCallingIdentity(origId); |
| 3580 | return; |
| 3581 | } else if (ttoken.startingData != null) { |
| 3582 | // The previous app was getting ready to show a |
| 3583 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3584 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | "Moving pending starting from " + ttoken |
| 3586 | + " to " + wtoken); |
| 3587 | wtoken.startingData = ttoken.startingData; |
| 3588 | ttoken.startingData = null; |
| 3589 | ttoken.startingMoved = true; |
| 3590 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3591 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3592 | // want to process the message ASAP, before any other queued |
| 3593 | // messages. |
| 3594 | mH.sendMessageAtFrontOfQueue(m); |
| 3595 | return; |
| 3596 | } |
| 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | // There is no existing starting window, and the caller doesn't |
| 3601 | // want us to create one, so that's it! |
| 3602 | if (!createIfNeeded) { |
| 3603 | return; |
| 3604 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3605 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3606 | // If this is a translucent or wallpaper window, then don't |
| 3607 | // show a starting window -- the current effect (a full-screen |
| 3608 | // opaque starting window that fades away to the real contents |
| 3609 | // when it is ready) does not work for this. |
| 3610 | if (theme != 0) { |
| 3611 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3612 | com.android.internal.R.styleable.Window); |
| 3613 | if (ent.array.getBoolean( |
| 3614 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3615 | return; |
| 3616 | } |
| 3617 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3618 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3619 | return; |
| 3620 | } |
| 3621 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3622 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3623 | return; |
| 3624 | } |
| 3625 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | mStartingIconInTransition = true; |
| 3628 | wtoken.startingData = new StartingData( |
| 3629 | pkg, theme, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3630 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3631 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3632 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3633 | // want to process the message ASAP, before any other queued |
| 3634 | // messages. |
| 3635 | mH.sendMessageAtFrontOfQueue(m); |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | public void setAppWillBeHidden(IBinder token) { |
| 3640 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3641 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3642 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | AppWindowToken wtoken; |
| 3646 | |
| 3647 | synchronized(mWindowMap) { |
| 3648 | wtoken = findAppWindowToken(token); |
| 3649 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3650 | Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3651 | return; |
| 3652 | } |
| 3653 | wtoken.willBeHidden = true; |
| 3654 | } |
| 3655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3658 | boolean visible, int transit, boolean performLayout) { |
| 3659 | boolean delayed = false; |
| 3660 | |
| 3661 | if (wtoken.clientHidden == visible) { |
| 3662 | wtoken.clientHidden = !visible; |
| 3663 | wtoken.sendAppVisibilityToClients(); |
| 3664 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3666 | wtoken.willBeHidden = false; |
| 3667 | if (wtoken.hidden == visible) { |
| 3668 | final int N = wtoken.allAppWindows.size(); |
| 3669 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3670 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3672 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3675 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3676 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | if (wtoken.animation == sDummyAnimation) { |
| 3678 | wtoken.animation = null; |
| 3679 | } |
| 3680 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3681 | changed = true; |
| 3682 | if (wtoken.animation != null) { |
| 3683 | delayed = runningAppAnimation = true; |
| 3684 | } |
| 3685 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | for (int i=0; i<N; i++) { |
| 3688 | WindowState win = wtoken.allAppWindows.get(i); |
| 3689 | if (win == wtoken.startingWindow) { |
| 3690 | continue; |
| 3691 | } |
| 3692 | |
| 3693 | if (win.isAnimating()) { |
| 3694 | delayed = true; |
| 3695 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3696 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3697 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3698 | //win.dump(" "); |
| 3699 | if (visible) { |
| 3700 | if (!win.isVisibleNow()) { |
| 3701 | if (!runningAppAnimation) { |
| 3702 | applyAnimationLocked(win, |
| 3703 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3704 | } |
| 3705 | changed = true; |
| 3706 | } |
| 3707 | } else if (win.isVisibleNow()) { |
| 3708 | if (!runningAppAnimation) { |
| 3709 | applyAnimationLocked(win, |
| 3710 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3711 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3712 | changed = true; |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3717 | if (!visible) { |
| 3718 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3719 | } else { |
| 3720 | // If we are being set visible, and the starting window is |
| 3721 | // not yet displayed, then make sure it doesn't get displayed. |
| 3722 | WindowState swin = wtoken.startingWindow; |
| 3723 | if (swin != null && (swin.mDrawPending |
| 3724 | || swin.mCommitDrawPending)) { |
| 3725 | swin.mPolicyVisibility = false; |
| 3726 | swin.mPolicyVisibilityAfterAnim = false; |
| 3727 | } |
| 3728 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3729 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3730 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3731 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3732 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3733 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3734 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3736 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3737 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3738 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3739 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3740 | performLayoutAndPlaceSurfacesLocked(); |
| 3741 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3742 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | if (wtoken.animation != null) { |
| 3747 | delayed = true; |
| 3748 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3750 | return delayed; |
| 3751 | } |
| 3752 | |
| 3753 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3754 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3755 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3756 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | AppWindowToken wtoken; |
| 3760 | |
| 3761 | synchronized(mWindowMap) { |
| 3762 | wtoken = findAppWindowToken(token); |
| 3763 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3764 | Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3765 | return; |
| 3766 | } |
| 3767 | |
| 3768 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3769 | RuntimeException e = null; |
| 3770 | if (!HIDE_STACK_CRAWLS) { |
| 3771 | e = new RuntimeException(); |
| 3772 | e.fillInStackTrace(); |
| 3773 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3774 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3775 | + "): mNextAppTransition=" + mNextAppTransition |
| 3776 | + " hidden=" + wtoken.hidden |
| 3777 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | // If we are preparing an app transition, then delay changing |
| 3781 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3782 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3783 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | // Already in requested state, don't do anything more. |
| 3785 | if (wtoken.hiddenRequested != visible) { |
| 3786 | return; |
| 3787 | } |
| 3788 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3789 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3790 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | TAG, "Setting dummy animation on: " + wtoken); |
| 3792 | wtoken.setDummyAnimation(); |
| 3793 | mOpeningApps.remove(wtoken); |
| 3794 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3795 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3796 | wtoken.inPendingTransaction = true; |
| 3797 | if (visible) { |
| 3798 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | wtoken.startingDisplayed = false; |
| 3800 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3801 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3802 | // If the token is currently hidden (should be the |
| 3803 | // common case), then we need to set up to wait for |
| 3804 | // its windows to be ready. |
| 3805 | if (wtoken.hidden) { |
| 3806 | wtoken.allDrawn = false; |
| 3807 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3808 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3809 | if (wtoken.clientHidden) { |
| 3810 | // In the case where we are making an app visible |
| 3811 | // but holding off for a transition, we still need |
| 3812 | // to tell the client to make its windows visible so |
| 3813 | // they get drawn. Otherwise, we will wait on |
| 3814 | // performing the transition until all windows have |
| 3815 | // been drawn, they never will be, and we are sad. |
| 3816 | wtoken.clientHidden = false; |
| 3817 | wtoken.sendAppVisibilityToClients(); |
| 3818 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | } |
| 3820 | } else { |
| 3821 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3822 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3823 | // If the token is currently visible (should be the |
| 3824 | // common case), then set up to wait for it to be hidden. |
| 3825 | if (!wtoken.hidden) { |
| 3826 | wtoken.waitingToHide = true; |
| 3827 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | } |
| 3829 | return; |
| 3830 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3833 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3834 | wtoken.updateReportedVisibilityLocked(); |
| 3835 | Binder.restoreCallingIdentity(origId); |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3840 | boolean unfreezeSurfaceNow, boolean force) { |
| 3841 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3842 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | + " force=" + force); |
| 3844 | final int N = wtoken.allAppWindows.size(); |
| 3845 | boolean unfrozeWindows = false; |
| 3846 | for (int i=0; i<N; i++) { |
| 3847 | WindowState w = wtoken.allAppWindows.get(i); |
| 3848 | if (w.mAppFreezing) { |
| 3849 | w.mAppFreezing = false; |
| 3850 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3851 | w.mOrientationChanging = true; |
| 3852 | } |
| 3853 | unfrozeWindows = true; |
| 3854 | } |
| 3855 | } |
| 3856 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3857 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3858 | wtoken.freezingScreen = false; |
| 3859 | mAppsFreezingScreen--; |
| 3860 | } |
| 3861 | if (unfreezeSurfaceNow) { |
| 3862 | if (unfrozeWindows) { |
| 3863 | mLayoutNeeded = true; |
| 3864 | performLayoutAndPlaceSurfacesLocked(); |
| 3865 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3866 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | } |
| 3868 | } |
| 3869 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3872 | int configChanges) { |
| 3873 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3874 | RuntimeException e = null; |
| 3875 | if (!HIDE_STACK_CRAWLS) { |
| 3876 | e = new RuntimeException(); |
| 3877 | e.fillInStackTrace(); |
| 3878 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3879 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3881 | + wtoken.freezingScreen, e); |
| 3882 | } |
| 3883 | if (!wtoken.hiddenRequested) { |
| 3884 | if (!wtoken.freezingScreen) { |
| 3885 | wtoken.freezingScreen = true; |
| 3886 | mAppsFreezingScreen++; |
| 3887 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3888 | startFreezingDisplayLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3890 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3891 | 5000); |
| 3892 | } |
| 3893 | } |
| 3894 | final int N = wtoken.allAppWindows.size(); |
| 3895 | for (int i=0; i<N; i++) { |
| 3896 | WindowState w = wtoken.allAppWindows.get(i); |
| 3897 | w.mAppFreezing = true; |
| 3898 | } |
| 3899 | } |
| 3900 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3903 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3904 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3905 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3909 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3910 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3911 | return; |
| 3912 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3914 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3915 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3916 | Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3917 | return; |
| 3918 | } |
| 3919 | final long origId = Binder.clearCallingIdentity(); |
| 3920 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3921 | Binder.restoreCallingIdentity(origId); |
| 3922 | } |
| 3923 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3925 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3926 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3927 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3928 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | synchronized(mWindowMap) { |
| 3932 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3933 | if (wtoken == null || wtoken.appToken == null) { |
| 3934 | return; |
| 3935 | } |
| 3936 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3937 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3938 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3939 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3940 | Binder.restoreCallingIdentity(origId); |
| 3941 | } |
| 3942 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3944 | public void removeAppToken(IBinder token) { |
| 3945 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3946 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3947 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | AppWindowToken wtoken = null; |
| 3951 | AppWindowToken startingToken = null; |
| 3952 | boolean delayed = false; |
| 3953 | |
| 3954 | final long origId = Binder.clearCallingIdentity(); |
| 3955 | synchronized(mWindowMap) { |
| 3956 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3958 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3959 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | wtoken.inPendingTransaction = false; |
| 3961 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3962 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | if (mClosingApps.contains(wtoken)) { |
| 3964 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3965 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3966 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3967 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3968 | delayed = true; |
| 3969 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3970 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3972 | + " animation=" + wtoken.animation |
| 3973 | + " animating=" + wtoken.animating); |
| 3974 | if (delayed) { |
| 3975 | // set the token aside because it has an active animation to be finished |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3976 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 3977 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3978 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3979 | } else { |
| 3980 | // Make sure there is no animation running on this token, |
| 3981 | // so any windows associated with it will be removed as |
| 3982 | // soon as their animations are complete |
| 3983 | wtoken.animation = null; |
| 3984 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3985 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3986 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 3987 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | mAppTokens.remove(wtoken); |
| 3989 | wtoken.removed = true; |
| 3990 | if (wtoken.startingData != null) { |
| 3991 | startingToken = wtoken; |
| 3992 | } |
| 3993 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3994 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3995 | if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3997 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3998 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | } |
| 4000 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4001 | Slog.w(TAG, "Attempted to remove non-existing app token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4002 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | if (!delayed && wtoken != null) { |
| 4005 | wtoken.updateReportedVisibilityLocked(); |
| 4006 | } |
| 4007 | } |
| 4008 | Binder.restoreCallingIdentity(origId); |
| 4009 | |
| 4010 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4011 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | + startingToken + ": app token removed"); |
| 4013 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4014 | mH.sendMessage(m); |
| 4015 | } |
| 4016 | } |
| 4017 | |
| 4018 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4019 | final int NW = token.windows.size(); |
| 4020 | for (int i=0; i<NW; i++) { |
| 4021 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4022 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4024 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4025 | int j = win.mChildWindows.size(); |
| 4026 | while (j > 0) { |
| 4027 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4028 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4029 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4030 | "Tmp removing child window " + cwin); |
| 4031 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4032 | } |
| 4033 | } |
| 4034 | return NW > 0; |
| 4035 | } |
| 4036 | |
| 4037 | void dumpAppTokensLocked() { |
| 4038 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4039 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | } |
| 4041 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4042 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | void dumpWindowsLocked() { |
| 4044 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4045 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4046 | } |
| 4047 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | private int findWindowOffsetLocked(int tokenPos) { |
| 4050 | final int NW = mWindows.size(); |
| 4051 | |
| 4052 | if (tokenPos >= mAppTokens.size()) { |
| 4053 | int i = NW; |
| 4054 | while (i > 0) { |
| 4055 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4056 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | if (win.getAppToken() != null) { |
| 4058 | return i+1; |
| 4059 | } |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | while (tokenPos > 0) { |
| 4064 | // Find the first app token below the new position that has |
| 4065 | // a window displayed. |
| 4066 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4067 | if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4068 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4069 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4070 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4071 | "Skipping token -- currently sending to bottom"); |
| 4072 | tokenPos--; |
| 4073 | continue; |
| 4074 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | int i = wtoken.windows.size(); |
| 4076 | while (i > 0) { |
| 4077 | i--; |
| 4078 | WindowState win = wtoken.windows.get(i); |
| 4079 | int j = win.mChildWindows.size(); |
| 4080 | while (j > 0) { |
| 4081 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4082 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4083 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4084 | for (int pos=NW-1; pos>=0; pos--) { |
| 4085 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4086 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4087 | "Found child win @" + (pos+1)); |
| 4088 | return pos+1; |
| 4089 | } |
| 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | for (int pos=NW-1; pos>=0; pos--) { |
| 4094 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4095 | if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | return pos+1; |
| 4097 | } |
| 4098 | } |
| 4099 | } |
| 4100 | tokenPos--; |
| 4101 | } |
| 4102 | |
| 4103 | return 0; |
| 4104 | } |
| 4105 | |
| 4106 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4107 | final int NCW = win.mChildWindows.size(); |
| 4108 | boolean added = false; |
| 4109 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4110 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4111 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4112 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4113 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4114 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | mWindows.add(index, win); |
| 4116 | index++; |
| 4117 | added = true; |
| 4118 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4119 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4120 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4121 | cwin.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | mWindows.add(index, cwin); |
| 4123 | index++; |
| 4124 | } |
| 4125 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4126 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4127 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4128 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | mWindows.add(index, win); |
| 4130 | index++; |
| 4131 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4132 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4133 | return index; |
| 4134 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4136 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4137 | final int NW = token.windows.size(); |
| 4138 | for (int i=0; i<NW; i++) { |
| 4139 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4140 | } |
| 4141 | return index; |
| 4142 | } |
| 4143 | |
| 4144 | public void moveAppToken(int index, IBinder token) { |
| 4145 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4146 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4147 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4151 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4153 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4154 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4155 | "Start moving token " + wtoken + " initially at " |
| 4156 | + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4158 | Slog.w(TAG, "Attempting to reorder token that doesn't exist: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | + token + " (" + wtoken + ")"); |
| 4160 | return; |
| 4161 | } |
| 4162 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4163 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4164 | else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4168 | if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4170 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4171 | if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4173 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4174 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4176 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4177 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4178 | mLayoutNeeded = true; |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4179 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4181 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | } |
| 4183 | Binder.restoreCallingIdentity(origId); |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4188 | // XXX This should be done more efficiently! |
| 4189 | // (take advantage of the fact that both lists should be |
| 4190 | // ordered in the same way.) |
| 4191 | int N = tokens.size(); |
| 4192 | for (int i=0; i<N; i++) { |
| 4193 | IBinder token = tokens.get(i); |
| 4194 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4195 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4196 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4197 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4198 | Slog.w(TAG, "Attempting to reorder token that doesn't exist: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4199 | + token + " (" + wtoken + ")"); |
| 4200 | i--; |
| 4201 | N--; |
| 4202 | } |
| 4203 | } |
| 4204 | } |
| 4205 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4206 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4207 | boolean updateFocusAndLayout) { |
| 4208 | // First remove all of the windows from the list. |
| 4209 | tmpRemoveAppWindowsLocked(wtoken); |
| 4210 | |
| 4211 | // Where to start adding? |
| 4212 | int pos = findWindowOffsetLocked(tokenPos); |
| 4213 | |
| 4214 | // And now add them back at the correct place. |
| 4215 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4216 | |
| 4217 | if (updateFocusAndLayout) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4218 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4219 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4220 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4221 | assignLayersLocked(); |
| 4222 | } |
| 4223 | mLayoutNeeded = true; |
| 4224 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4225 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4226 | } |
| 4227 | } |
| 4228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4230 | // First remove all of the windows from the list. |
| 4231 | final int N = tokens.size(); |
| 4232 | int i; |
| 4233 | for (i=0; i<N; i++) { |
| 4234 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4235 | if (token != null) { |
| 4236 | tmpRemoveAppWindowsLocked(token); |
| 4237 | } |
| 4238 | } |
| 4239 | |
| 4240 | // Where to start adding? |
| 4241 | int pos = findWindowOffsetLocked(tokenPos); |
| 4242 | |
| 4243 | // And now add them back at the correct place. |
| 4244 | for (i=0; i<N; i++) { |
| 4245 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4246 | if (token != null) { |
| 4247 | pos = reAddAppWindowsLocked(pos, token); |
| 4248 | } |
| 4249 | } |
| 4250 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4251 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4252 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4253 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4254 | assignLayersLocked(); |
| 4255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4256 | mLayoutNeeded = true; |
| 4257 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4258 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | |
| 4260 | //dump(); |
| 4261 | } |
| 4262 | |
| 4263 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4264 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4265 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4266 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | final long origId = Binder.clearCallingIdentity(); |
| 4270 | synchronized(mWindowMap) { |
| 4271 | removeAppTokensLocked(tokens); |
| 4272 | final int N = tokens.size(); |
| 4273 | for (int i=0; i<N; i++) { |
| 4274 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4275 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4276 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4277 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4279 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4280 | mToTopApps.remove(wt); |
| 4281 | mToBottomApps.remove(wt); |
| 4282 | mToTopApps.add(wt); |
| 4283 | wt.sendingToBottom = false; |
| 4284 | wt.sendingToTop = true; |
| 4285 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | } |
| 4287 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4288 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4289 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4290 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4291 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | } |
| 4293 | Binder.restoreCallingIdentity(origId); |
| 4294 | } |
| 4295 | |
| 4296 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4297 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4298 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4299 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | final long origId = Binder.clearCallingIdentity(); |
| 4303 | synchronized(mWindowMap) { |
| 4304 | removeAppTokensLocked(tokens); |
| 4305 | final int N = tokens.size(); |
| 4306 | int pos = 0; |
| 4307 | for (int i=0; i<N; i++) { |
| 4308 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4309 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4310 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4311 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4313 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4314 | mToTopApps.remove(wt); |
| 4315 | mToBottomApps.remove(wt); |
| 4316 | mToBottomApps.add(i, wt); |
| 4317 | wt.sendingToTop = false; |
| 4318 | wt.sendingToBottom = true; |
| 4319 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | pos++; |
| 4321 | } |
| 4322 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4323 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4324 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4325 | moveAppWindowsLocked(tokens, 0); |
| 4326 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | } |
| 4328 | Binder.restoreCallingIdentity(origId); |
| 4329 | } |
| 4330 | |
| 4331 | // ------------------------------------------------------------- |
| 4332 | // Misc IWindowSession methods |
| 4333 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4334 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4335 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4336 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4337 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4338 | // called before DevicePolicyManagerService has started. |
| 4339 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4340 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4341 | Context.DEVICE_POLICY_SERVICE); |
| 4342 | if (dpm != null) { |
| 4343 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4344 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4345 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4346 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4347 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4348 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4352 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | != PackageManager.PERMISSION_GRANTED) { |
| 4354 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4355 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4356 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4357 | synchronized (mKeyguardTokenWatcher) { |
| 4358 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4359 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4363 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | != PackageManager.PERMISSION_GRANTED) { |
| 4365 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4368 | synchronized (mKeyguardTokenWatcher) { |
| 4369 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4370 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4371 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4372 | // If we are the last one to reenable the keyguard wait until |
| 4373 | // we have actually finished reenabling until returning. |
| 4374 | // It is possible that reenableKeyguard() can be called before |
| 4375 | // the previous disableKeyguard() is handled, in which case |
| 4376 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4377 | // be called. In that case mKeyguardDisabled will be false here |
| 4378 | // and we have nothing to wait for. |
| 4379 | while (mKeyguardDisabled) { |
| 4380 | try { |
| 4381 | mKeyguardTokenWatcher.wait(); |
| 4382 | } catch (InterruptedException e) { |
| 4383 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | } |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | /** |
| 4391 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4392 | */ |
| 4393 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4394 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | != PackageManager.PERMISSION_GRANTED) { |
| 4396 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4397 | } |
| 4398 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4399 | public void onKeyguardExitResult(boolean success) { |
| 4400 | try { |
| 4401 | callback.onKeyguardExitResult(success); |
| 4402 | } catch (RemoteException e) { |
| 4403 | // Client has died, we don't care. |
| 4404 | } |
| 4405 | } |
| 4406 | }); |
| 4407 | } |
| 4408 | |
| 4409 | public boolean inKeyguardRestrictedInputMode() { |
| 4410 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4411 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4412 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4413 | public void closeSystemDialogs(String reason) { |
| 4414 | synchronized(mWindowMap) { |
| 4415 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4416 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4417 | if (w.mSurface != null) { |
| 4418 | try { |
| 4419 | w.mClient.closeSystemDialogs(reason); |
| 4420 | } catch (RemoteException e) { |
| 4421 | } |
| 4422 | } |
| 4423 | } |
| 4424 | } |
| 4425 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4427 | static float fixScale(float scale) { |
| 4428 | if (scale < 0) scale = 0; |
| 4429 | else if (scale > 20) scale = 20; |
| 4430 | return Math.abs(scale); |
| 4431 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | public void setAnimationScale(int which, float scale) { |
| 4434 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4435 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4436 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | if (scale < 0) scale = 0; |
| 4440 | else if (scale > 20) scale = 20; |
| 4441 | scale = Math.abs(scale); |
| 4442 | switch (which) { |
| 4443 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4444 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | // Persist setting |
| 4448 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | public void setAnimationScales(float[] scales) { |
| 4452 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4453 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4454 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | if (scales != null) { |
| 4458 | if (scales.length >= 1) { |
| 4459 | mWindowAnimationScale = fixScale(scales[0]); |
| 4460 | } |
| 4461 | if (scales.length >= 2) { |
| 4462 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4463 | } |
| 4464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | // Persist setting |
| 4467 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4468 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4470 | public float getAnimationScale(int which) { |
| 4471 | switch (which) { |
| 4472 | case 0: return mWindowAnimationScale; |
| 4473 | case 1: return mTransitionAnimationScale; |
| 4474 | } |
| 4475 | return 0; |
| 4476 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | public float[] getAnimationScales() { |
| 4479 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | public int getSwitchState(int sw) { |
| 4483 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4484 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4485 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4486 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4487 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4491 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4492 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4493 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4495 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4496 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | public int getScancodeState(int sw) { |
| 4499 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4500 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4501 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4503 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4504 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4507 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4508 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4509 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4510 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4511 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4512 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4513 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4514 | public int getTrackballScancodeState(int sw) { |
| 4515 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4516 | "getTrackballScancodeState()")) { |
| 4517 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4518 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4519 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | public int getDPadScancodeState(int sw) { |
| 4523 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4524 | "getDPadScancodeState()")) { |
| 4525 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4526 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4527 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4528 | } |
| 4529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4530 | public int getKeycodeState(int sw) { |
| 4531 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4532 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4533 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4534 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4535 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4536 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4539 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4540 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4541 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4542 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4543 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4544 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4545 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4546 | public int getTrackballKeycodeState(int sw) { |
| 4547 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4548 | "getTrackballKeycodeState()")) { |
| 4549 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4550 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4551 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4552 | } |
| 4553 | |
| 4554 | public int getDPadKeycodeState(int sw) { |
| 4555 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4556 | "getDPadKeycodeState()")) { |
| 4557 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4558 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4559 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4560 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4563 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4565 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4566 | public InputChannel monitorInput(String inputChannelName) { |
| 4567 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4568 | "monitorInput()")) { |
| 4569 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4570 | } |
| 4571 | return mInputManager.monitorInput(inputChannelName); |
| 4572 | } |
| 4573 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4574 | public InputDevice getInputDevice(int deviceId) { |
| 4575 | return mInputManager.getInputDevice(deviceId); |
| 4576 | } |
| 4577 | |
| 4578 | public int[] getInputDeviceIds() { |
| 4579 | return mInputManager.getInputDeviceIds(); |
| 4580 | } |
| 4581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | public void enableScreenAfterBoot() { |
| 4583 | synchronized(mWindowMap) { |
| 4584 | if (mSystemBooted) { |
| 4585 | return; |
| 4586 | } |
| 4587 | mSystemBooted = true; |
| 4588 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | performEnableScreen(); |
| 4591 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4593 | public void enableScreenIfNeededLocked() { |
| 4594 | if (mDisplayEnabled) { |
| 4595 | return; |
| 4596 | } |
| 4597 | if (!mSystemBooted) { |
| 4598 | return; |
| 4599 | } |
| 4600 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4601 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | public void performEnableScreen() { |
| 4604 | synchronized(mWindowMap) { |
| 4605 | if (mDisplayEnabled) { |
| 4606 | return; |
| 4607 | } |
| 4608 | if (!mSystemBooted) { |
| 4609 | return; |
| 4610 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | // Don't enable the screen until all existing windows |
| 4613 | // have been drawn. |
| 4614 | final int N = mWindows.size(); |
| 4615 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4616 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4617 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4618 | return; |
| 4619 | } |
| 4620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | mDisplayEnabled = true; |
| 4623 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4624 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4625 | StringWriter sw = new StringWriter(); |
| 4626 | PrintWriter pw = new PrintWriter(sw); |
| 4627 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4628 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4629 | } |
| 4630 | try { |
| 4631 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4632 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4633 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4634 | Parcel data = Parcel.obtain(); |
| 4635 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4636 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4637 | data, null, 0); |
| 4638 | data.recycle(); |
| 4639 | } |
| 4640 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4641 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | } |
| 4643 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4645 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4647 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4648 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4649 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4650 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | public void setInTouchMode(boolean mode) { |
| 4653 | synchronized(mWindowMap) { |
| 4654 | mInTouchMode = mode; |
| 4655 | } |
| 4656 | } |
| 4657 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4658 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4659 | // only allow disables from pids which have count on, etc. |
| 4660 | public void showStrictModeViolation(boolean on) { |
| 4661 | int pid = Binder.getCallingPid(); |
| 4662 | synchronized(mWindowMap) { |
| 4663 | // Ignoring requests to enable the red border from clients |
| 4664 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4665 | // the background..) |
| 4666 | if (on) { |
| 4667 | boolean isVisible = false; |
| 4668 | for (WindowState ws : mWindows) { |
| 4669 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4670 | isVisible = true; |
| 4671 | break; |
| 4672 | } |
| 4673 | } |
| 4674 | if (!isVisible) { |
| 4675 | return; |
| 4676 | } |
| 4677 | } |
| 4678 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4679 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4680 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4681 | try { |
| 4682 | if (mStrictModeFlash == null) { |
| 4683 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 4684 | } |
| 4685 | mStrictModeFlash.setVisibility(on); |
| 4686 | } finally { |
| 4687 | Surface.closeTransaction(); |
| 4688 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4689 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 4693 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 4694 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 4695 | } |
| 4696 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4697 | public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4698 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 4699 | "screenshotApplications()")) { |
| 4700 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 4701 | } |
| 4702 | |
| 4703 | Bitmap rawss; |
| 4704 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4705 | int maxLayer = 0; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4706 | final Rect frame = new Rect(); |
| 4707 | |
| 4708 | float scale; |
| 4709 | int sw, sh, dw, dh; |
| 4710 | int rot; |
| 4711 | |
| 4712 | synchronized(mWindowMap) { |
| 4713 | long ident = Binder.clearCallingIdentity(); |
| 4714 | |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4715 | dw = mDisplay.getWidth(); |
| 4716 | dh = mDisplay.getHeight(); |
| 4717 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4718 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 4719 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 4720 | + TYPE_LAYER_OFFSET; |
| 4721 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 4722 | |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4723 | boolean isImeTarget = mInputMethodTarget != null |
| 4724 | && mInputMethodTarget.mAppToken != null |
| 4725 | && mInputMethodTarget.mAppToken.appToken != null |
| 4726 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 4727 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4728 | // Figure out the part of the screen that is actually the app. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4729 | boolean including = false; |
| 4730 | for (int i=mWindows.size()-1; i>=0; i--) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4731 | WindowState ws = mWindows.get(i); |
| 4732 | if (ws.mSurface == null) { |
| 4733 | continue; |
| 4734 | } |
| 4735 | if (ws.mLayer >= aboveAppLayer) { |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4736 | continue; |
| 4737 | } |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4738 | // When we will skip windows: when we are not including |
| 4739 | // ones behind a window we didn't skip, and we are actually |
| 4740 | // taking a screenshot of a specific app. |
| 4741 | if (!including && appToken != null) { |
| 4742 | // Also, we can possibly skip this window if it is not |
| 4743 | // an IME target or the application for the screenshot |
| 4744 | // is not the current IME target. |
| 4745 | if (!ws.mIsImWindow || !isImeTarget) { |
| 4746 | // And finally, this window is of no interest if it |
| 4747 | // is not associated with the screenshot app. |
| 4748 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 4749 | continue; |
| 4750 | } |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | // We keep on including windows until we go past a full-screen |
| 4755 | // window. |
| 4756 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
| 4757 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4758 | if (maxLayer < ws.mAnimLayer) { |
| 4759 | maxLayer = ws.mAnimLayer; |
| 4760 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4761 | final Rect wf = ws.mFrame; |
| 4762 | final Rect cr = ws.mContentInsets; |
| 4763 | int left = wf.left + cr.left; |
| 4764 | int top = wf.top + cr.top; |
| 4765 | int right = wf.right - cr.right; |
| 4766 | int bottom = wf.bottom - cr.bottom; |
| 4767 | frame.union(left, top, right, bottom); |
| 4768 | } |
| 4769 | Binder.restoreCallingIdentity(ident); |
| 4770 | |
Dianne Hackborn | dd962ee | 2011-02-02 11:11:50 -0800 | [diff] [blame] | 4771 | // Constrain frame to the screen size. |
| 4772 | frame.intersect(0, 0, dw, dh); |
| 4773 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4774 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4775 | return null; |
| 4776 | } |
| 4777 | |
| 4778 | // The screenshot API does not apply the current screen rotation. |
| 4779 | rot = mDisplay.getRotation(); |
| 4780 | int fw = frame.width(); |
| 4781 | int fh = frame.height(); |
| 4782 | |
| 4783 | // First try reducing to fit in x dimension. |
| 4784 | scale = maxWidth/(float)fw; |
| 4785 | sw = maxWidth; |
| 4786 | sh = (int)(fh*scale); |
| 4787 | if (sh > maxHeight) { |
| 4788 | // y dimension became too long; constrain by that. |
| 4789 | scale = maxHeight/(float)fh; |
| 4790 | sw = (int)(fw*scale); |
| 4791 | sh = maxHeight; |
| 4792 | } |
| 4793 | |
| 4794 | // The screen shot will contain the entire screen. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4795 | dw = (int)(dw*scale); |
| 4796 | dh = (int)(dh*scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4797 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 4798 | int tmp = dw; |
| 4799 | dw = dh; |
| 4800 | dh = tmp; |
| 4801 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 4802 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4803 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4804 | } |
| 4805 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4806 | if (rawss == null) { |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4807 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 4808 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4809 | return null; |
| 4810 | } |
| 4811 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4812 | Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig()); |
| 4813 | Matrix matrix = new Matrix(); |
| 4814 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 4815 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 4816 | Canvas canvas = new Canvas(bm); |
| 4817 | canvas.drawBitmap(rawss, matrix, null); |
| 4818 | |
| 4819 | rawss.recycle(); |
| 4820 | return bm; |
| 4821 | } |
| 4822 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4823 | public void freezeRotation() { |
| 4824 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 4825 | "setRotation()")) { |
| 4826 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4827 | } |
| 4828 | |
| 4829 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 4830 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4831 | } |
| 4832 | |
| 4833 | public void thawRotation() { |
| 4834 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 4835 | "setRotation()")) { |
| 4836 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4837 | } |
| 4838 | |
| 4839 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 4840 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4841 | } |
| 4842 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4843 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4844 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4846 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4847 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | } |
| 4849 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4850 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4851 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4852 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4853 | public void setRotationUnchecked(int rotation, |
| 4854 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4855 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
David 'Digit' Turner | 910a068 | 2011-02-05 00:34:46 +0100 | [diff] [blame] | 4856 | "setRotationUnchecked(rotation=" + rotation + |
| 4857 | " alwaysSendConfiguration=" + alwaysSendConfiguration + |
| 4858 | " animFlags=" + animFlags); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4860 | long origId = Binder.clearCallingIdentity(); |
| 4861 | boolean changed; |
| 4862 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4863 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4864 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4865 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4866 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4867 | sendNewConfiguration(); |
| 4868 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4870 | Binder.restoreCallingIdentity(origId); |
| 4871 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4872 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4873 | /** |
| 4874 | * Apply a new rotation to the screen, respecting the requests of |
| 4875 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4876 | * re-evaluate the desired rotation. |
| 4877 | * |
| 4878 | * Returns null if the rotation has been changed. In this case YOU |
| 4879 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4880 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4881 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4882 | if (mDragState != null || mScreenRotationAnimation != null) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 4883 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 4884 | // a note to perform the rotation later. |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4885 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation."); |
| 4886 | if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4887 | mDeferredRotation = rotation; |
| 4888 | mDeferredRotationAnimFlags = animFlags; |
| 4889 | } |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 4890 | return false; |
| 4891 | } |
| 4892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | boolean changed; |
| 4894 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4895 | if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4896 | rotation = mDeferredRotation; |
| 4897 | mRequestedRotation = rotation; |
| 4898 | mLastRotationFlags = mDeferredRotationAnimFlags; |
| 4899 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | rotation = mRequestedRotation; |
| 4901 | } else { |
| 4902 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4903 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4904 | } |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4905 | mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4906 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4907 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4909 | if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4910 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4912 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4913 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | "Rotation changed to " + rotation |
| 4915 | + " from " + mRotation |
| 4916 | + " (forceApp=" + mForcedAppOrientation |
| 4917 | + ", req=" + mRequestedRotation + ")"); |
| 4918 | mRotation = rotation; |
| 4919 | mWindowsFreezingScreen = true; |
| 4920 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4921 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4922 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4923 | mWaitingForConfig = true; |
| 4924 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4925 | startFreezingDisplayLocked(inTransaction); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4926 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4927 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4928 | if (mDisplayEnabled) { |
David 'Digit' Turner | 910a068 | 2011-02-05 00:34:46 +0100 | [diff] [blame] | 4929 | // NOTE: We disable the rotation in the emulator because |
| 4930 | // it doesn't support hardware OpenGL emulation yet. |
| 4931 | if (CUSTOM_SCREEN_ROTATION && !mInEmulator) { |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 4932 | Surface.freezeDisplay(0); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4933 | if (!inTransaction) { |
| 4934 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 4935 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 4936 | Surface.openTransaction(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 4937 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4938 | try { |
| 4939 | if (mScreenRotationAnimation != null) { |
| 4940 | mScreenRotationAnimation.setRotation(rotation); |
| 4941 | } |
| 4942 | } finally { |
| 4943 | if (!inTransaction) { |
| 4944 | Surface.closeTransaction(); |
| 4945 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 4946 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 4947 | } |
| 4948 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 4949 | Surface.setOrientation(0, rotation, animFlags); |
| 4950 | Surface.unfreezeDisplay(0); |
| 4951 | } else { |
| 4952 | Surface.setOrientation(0, rotation, animFlags); |
| 4953 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4954 | } |
| 4955 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4956 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4957 | if (w.mSurface != null) { |
| 4958 | w.mOrientationChanging = true; |
| 4959 | } |
| 4960 | } |
| 4961 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4962 | try { |
| 4963 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4964 | } catch (RemoteException e) { |
| 4965 | } |
| 4966 | } |
| 4967 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4969 | return changed; |
| 4970 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4972 | public int getRotation() { |
| 4973 | return mRotation; |
| 4974 | } |
| 4975 | |
| 4976 | public int watchRotation(IRotationWatcher watcher) { |
| 4977 | final IBinder watcherBinder = watcher.asBinder(); |
| 4978 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4979 | public void binderDied() { |
| 4980 | synchronized (mWindowMap) { |
| 4981 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4982 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4983 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4984 | if (removed != null) { |
| 4985 | removed.asBinder().unlinkToDeath(this, 0); |
| 4986 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4987 | i--; |
| 4988 | } |
| 4989 | } |
| 4990 | } |
| 4991 | } |
| 4992 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | synchronized (mWindowMap) { |
| 4995 | try { |
| 4996 | watcher.asBinder().linkToDeath(dr, 0); |
| 4997 | mRotationWatchers.add(watcher); |
| 4998 | } catch (RemoteException e) { |
| 4999 | // Client died, no cleanup needed. |
| 5000 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5002 | return mRotation; |
| 5003 | } |
| 5004 | } |
| 5005 | |
| 5006 | /** |
| 5007 | * Starts the view server on the specified port. |
| 5008 | * |
| 5009 | * @param port The port to listener to. |
| 5010 | * |
| 5011 | * @return True if the server was successfully started, false otherwise. |
| 5012 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5013 | * @see com.android.server.wm.ViewServer |
| 5014 | * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5015 | */ |
| 5016 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5017 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5018 | return false; |
| 5019 | } |
| 5020 | |
| 5021 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5022 | return false; |
| 5023 | } |
| 5024 | |
| 5025 | if (port < 1024) { |
| 5026 | return false; |
| 5027 | } |
| 5028 | |
| 5029 | if (mViewServer != null) { |
| 5030 | if (!mViewServer.isRunning()) { |
| 5031 | try { |
| 5032 | return mViewServer.start(); |
| 5033 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5034 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5035 | } |
| 5036 | } |
| 5037 | return false; |
| 5038 | } |
| 5039 | |
| 5040 | try { |
| 5041 | mViewServer = new ViewServer(this, port); |
| 5042 | return mViewServer.start(); |
| 5043 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5044 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5045 | } |
| 5046 | return false; |
| 5047 | } |
| 5048 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5049 | private boolean isSystemSecure() { |
| 5050 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5051 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5052 | } |
| 5053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5054 | /** |
| 5055 | * Stops the view server if it exists. |
| 5056 | * |
| 5057 | * @return True if the server stopped, false if it wasn't started or |
| 5058 | * couldn't be stopped. |
| 5059 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5060 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | */ |
| 5062 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5063 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5064 | return false; |
| 5065 | } |
| 5066 | |
| 5067 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5068 | return false; |
| 5069 | } |
| 5070 | |
| 5071 | if (mViewServer != null) { |
| 5072 | return mViewServer.stop(); |
| 5073 | } |
| 5074 | return false; |
| 5075 | } |
| 5076 | |
| 5077 | /** |
| 5078 | * Indicates whether the view server is running. |
| 5079 | * |
| 5080 | * @return True if the server is running, false otherwise. |
| 5081 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5082 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5083 | */ |
| 5084 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5085 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5086 | return false; |
| 5087 | } |
| 5088 | |
| 5089 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5090 | return false; |
| 5091 | } |
| 5092 | |
| 5093 | return mViewServer != null && mViewServer.isRunning(); |
| 5094 | } |
| 5095 | |
| 5096 | /** |
| 5097 | * Lists all availble windows in the system. The listing is written in the |
| 5098 | * specified Socket's output stream with the following syntax: |
| 5099 | * windowHashCodeInHexadecimal windowName |
| 5100 | * Each line of the ouput represents a different window. |
| 5101 | * |
| 5102 | * @param client The remote client to send the listing to. |
| 5103 | * @return False if an error occured, true otherwise. |
| 5104 | */ |
| 5105 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5106 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | return false; |
| 5108 | } |
| 5109 | |
| 5110 | boolean result = true; |
| 5111 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5112 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5113 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5115 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | BufferedWriter out = null; |
| 5119 | |
| 5120 | // Any uncaught exception will crash the system process |
| 5121 | try { |
| 5122 | OutputStream clientStream = client.getOutputStream(); |
| 5123 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5124 | |
| 5125 | final int count = windows.length; |
| 5126 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5127 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5128 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5129 | out.write(' '); |
| 5130 | out.append(w.mAttrs.getTitle()); |
| 5131 | out.write('\n'); |
| 5132 | } |
| 5133 | |
| 5134 | out.write("DONE.\n"); |
| 5135 | out.flush(); |
| 5136 | } catch (Exception e) { |
| 5137 | result = false; |
| 5138 | } finally { |
| 5139 | if (out != null) { |
| 5140 | try { |
| 5141 | out.close(); |
| 5142 | } catch (IOException e) { |
| 5143 | result = false; |
| 5144 | } |
| 5145 | } |
| 5146 | } |
| 5147 | |
| 5148 | return result; |
| 5149 | } |
| 5150 | |
| 5151 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5152 | * Returns the focused window in the following format: |
| 5153 | * windowHashCodeInHexadecimal windowName |
| 5154 | * |
| 5155 | * @param client The remote client to send the listing to. |
| 5156 | * @return False if an error occurred, true otherwise. |
| 5157 | */ |
| 5158 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5159 | if (isSystemSecure()) { |
| 5160 | return false; |
| 5161 | } |
| 5162 | |
| 5163 | boolean result = true; |
| 5164 | |
| 5165 | WindowState focusedWindow = getFocusedWindow(); |
| 5166 | |
| 5167 | BufferedWriter out = null; |
| 5168 | |
| 5169 | // Any uncaught exception will crash the system process |
| 5170 | try { |
| 5171 | OutputStream clientStream = client.getOutputStream(); |
| 5172 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5173 | |
| 5174 | if(focusedWindow != null) { |
| 5175 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5176 | out.write(' '); |
| 5177 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5178 | } |
| 5179 | out.write('\n'); |
| 5180 | out.flush(); |
| 5181 | } catch (Exception e) { |
| 5182 | result = false; |
| 5183 | } finally { |
| 5184 | if (out != null) { |
| 5185 | try { |
| 5186 | out.close(); |
| 5187 | } catch (IOException e) { |
| 5188 | result = false; |
| 5189 | } |
| 5190 | } |
| 5191 | } |
| 5192 | |
| 5193 | return result; |
| 5194 | } |
| 5195 | |
| 5196 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5197 | * Sends a command to a target window. The result of the command, if any, will be |
| 5198 | * written in the output stream of the specified socket. |
| 5199 | * |
| 5200 | * The parameters must follow this syntax: |
| 5201 | * windowHashcode extra |
| 5202 | * |
| 5203 | * Where XX is the length in characeters of the windowTitle. |
| 5204 | * |
| 5205 | * The first parameter is the target window. The window with the specified hashcode |
| 5206 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5207 | * will be delivered to the target window and as parameters to the command itself. |
| 5208 | * |
| 5209 | * @param client The remote client to sent the result, if any, to. |
| 5210 | * @param command The command to execute. |
| 5211 | * @param parameters The command parameters. |
| 5212 | * |
| 5213 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5214 | * not indicate whether the command itself was successful. |
| 5215 | */ |
| 5216 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5217 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | return false; |
| 5219 | } |
| 5220 | |
| 5221 | boolean success = true; |
| 5222 | Parcel data = null; |
| 5223 | Parcel reply = null; |
| 5224 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5225 | BufferedWriter out = null; |
| 5226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5227 | // Any uncaught exception will crash the system process |
| 5228 | try { |
| 5229 | // Find the hashcode of the window |
| 5230 | int index = parameters.indexOf(' '); |
| 5231 | if (index == -1) { |
| 5232 | index = parameters.length(); |
| 5233 | } |
| 5234 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5235 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5236 | |
| 5237 | // Extract the command's parameter after the window description |
| 5238 | if (index < parameters.length()) { |
| 5239 | parameters = parameters.substring(index + 1); |
| 5240 | } else { |
| 5241 | parameters = ""; |
| 5242 | } |
| 5243 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 5244 | final WindowState window = findWindow(hashCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5245 | if (window == null) { |
| 5246 | return false; |
| 5247 | } |
| 5248 | |
| 5249 | data = Parcel.obtain(); |
| 5250 | data.writeInterfaceToken("android.view.IWindow"); |
| 5251 | data.writeString(command); |
| 5252 | data.writeString(parameters); |
| 5253 | data.writeInt(1); |
| 5254 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5255 | |
| 5256 | reply = Parcel.obtain(); |
| 5257 | |
| 5258 | final IBinder binder = window.mClient.asBinder(); |
| 5259 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5260 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5261 | |
| 5262 | reply.readException(); |
| 5263 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5264 | if (!client.isOutputShutdown()) { |
| 5265 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5266 | out.write("DONE\n"); |
| 5267 | out.flush(); |
| 5268 | } |
| 5269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5270 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5271 | Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5272 | success = false; |
| 5273 | } finally { |
| 5274 | if (data != null) { |
| 5275 | data.recycle(); |
| 5276 | } |
| 5277 | if (reply != null) { |
| 5278 | reply.recycle(); |
| 5279 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5280 | if (out != null) { |
| 5281 | try { |
| 5282 | out.close(); |
| 5283 | } catch (IOException e) { |
| 5284 | |
| 5285 | } |
| 5286 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | return success; |
| 5290 | } |
| 5291 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5292 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5293 | synchronized(mWindowMap) { |
| 5294 | mWindowChangeListeners.add(listener); |
| 5295 | } |
| 5296 | } |
| 5297 | |
| 5298 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5299 | synchronized(mWindowMap) { |
| 5300 | mWindowChangeListeners.remove(listener); |
| 5301 | } |
| 5302 | } |
| 5303 | |
| 5304 | private void notifyWindowsChanged() { |
| 5305 | WindowChangeListener[] windowChangeListeners; |
| 5306 | synchronized(mWindowMap) { |
| 5307 | if(mWindowChangeListeners.isEmpty()) { |
| 5308 | return; |
| 5309 | } |
| 5310 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5311 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5312 | } |
| 5313 | int N = windowChangeListeners.length; |
| 5314 | for(int i = 0; i < N; i++) { |
| 5315 | windowChangeListeners[i].windowsChanged(); |
| 5316 | } |
| 5317 | } |
| 5318 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5319 | private void notifyFocusChanged() { |
| 5320 | WindowChangeListener[] windowChangeListeners; |
| 5321 | synchronized(mWindowMap) { |
| 5322 | if(mWindowChangeListeners.isEmpty()) { |
| 5323 | return; |
| 5324 | } |
| 5325 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5326 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5327 | } |
| 5328 | int N = windowChangeListeners.length; |
| 5329 | for(int i = 0; i < N; i++) { |
| 5330 | windowChangeListeners[i].focusChanged(); |
| 5331 | } |
| 5332 | } |
| 5333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5334 | private WindowState findWindow(int hashCode) { |
| 5335 | if (hashCode == -1) { |
| 5336 | return getFocusedWindow(); |
| 5337 | } |
| 5338 | |
| 5339 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5340 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5341 | final int count = windows.size(); |
| 5342 | |
| 5343 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5344 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5345 | if (System.identityHashCode(w) == hashCode) { |
| 5346 | return w; |
| 5347 | } |
| 5348 | } |
| 5349 | } |
| 5350 | |
| 5351 | return null; |
| 5352 | } |
| 5353 | |
| 5354 | /* |
| 5355 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5356 | * that to config-changed listeners if appropriate. |
| 5357 | */ |
| 5358 | void sendNewConfiguration() { |
| 5359 | try { |
| 5360 | mActivityManager.updateConfiguration(null); |
| 5361 | } catch (RemoteException e) { |
| 5362 | } |
| 5363 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5365 | public Configuration computeNewConfiguration() { |
| 5366 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5367 | Configuration config = computeNewConfigurationLocked(); |
| 5368 | if (config == null && mWaitingForConfig) { |
| 5369 | // Nothing changed but we are waiting for something... stop that! |
| 5370 | mWaitingForConfig = false; |
| 5371 | performLayoutAndPlaceSurfacesLocked(); |
| 5372 | } |
| 5373 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5374 | } |
| 5375 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5376 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5377 | Configuration computeNewConfigurationLocked() { |
| 5378 | Configuration config = new Configuration(); |
| 5379 | if (!computeNewConfigurationLocked(config)) { |
| 5380 | return null; |
| 5381 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5382 | return config; |
| 5383 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5384 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5385 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5386 | if (mDisplay == null) { |
| 5387 | return false; |
| 5388 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5389 | |
| 5390 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5391 | |
| 5392 | // Use the effective "visual" dimensions based on current rotation |
| 5393 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5394 | || mRotation == Surface.ROTATION_270); |
| 5395 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5396 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5397 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5398 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5399 | if (dw < dh) { |
| 5400 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5401 | } else if (dw > dh) { |
| 5402 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5403 | } |
| 5404 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5405 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5406 | DisplayMetrics dm = new DisplayMetrics(); |
| 5407 | mDisplay.getMetrics(dm); |
| 5408 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5409 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5410 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5411 | // Note we only do this once because at this point we don't |
| 5412 | // expect the screen to change in this way at runtime, and want |
| 5413 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5414 | int longSize = dw; |
| 5415 | int shortSize = dh; |
| 5416 | if (longSize < shortSize) { |
| 5417 | int tmp = longSize; |
| 5418 | longSize = shortSize; |
| 5419 | shortSize = tmp; |
| 5420 | } |
| 5421 | longSize = (int)(longSize/dm.density); |
| 5422 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5423 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5424 | // These semi-magic numbers define our compatibility modes for |
| 5425 | // applications with different screens. Don't change unless you |
| 5426 | // make sure to test lots and lots of apps! |
| 5427 | if (longSize < 470) { |
| 5428 | // This is shorter than an HVGA normal density screen (which |
| 5429 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5430 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5431 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5432 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5433 | // What size is this screen screen? |
| 5434 | if (longSize >= 800 && shortSize >= 600) { |
| 5435 | // SVGA or larger screens at medium density are the point |
| 5436 | // at which we consider it to be an extra large screen. |
| 5437 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5438 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5439 | // SVGA or larger screens at high density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5440 | // at which we consider it to be a large screen. |
| 5441 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5442 | } else { |
| 5443 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Dianne Hackborn | e97a12e | 2011-01-29 13:22:02 -0800 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | // If this screen is wider than normal HVGA, or taller |
| 5447 | // than FWVGA, then for old apps we want to run in size |
| 5448 | // compatibility mode. |
| 5449 | if (shortSize > 321 || longSize > 570) { |
| 5450 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5451 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5452 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5453 | // Is this a long screen? |
| 5454 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5455 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5456 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5457 | } else { |
| 5458 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5459 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5460 | } |
| 5461 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5462 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5463 | |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5464 | // Determine whether a hard keyboard is available and enabled. |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5465 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 5466 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 5467 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 5468 | mHardKeyboardEnabled = hardKeyboardAvailable; |
| 5469 | |
| 5470 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5471 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5472 | } |
| 5473 | if (!mHardKeyboardEnabled) { |
| 5474 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5475 | } |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5476 | |
| 5477 | // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden |
| 5478 | // based on whether a hard or soft keyboard is present, whether navigation keys |
| 5479 | // are present and the lid switch state. |
| 5480 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5481 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5482 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
| 5483 | mPolicy.adjustConfigurationLw(config); |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5484 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5485 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5486 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5487 | public boolean isHardKeyboardAvailable() { |
| 5488 | synchronized (mWindowMap) { |
| 5489 | return mHardKeyboardAvailable; |
| 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | public boolean isHardKeyboardEnabled() { |
| 5494 | synchronized (mWindowMap) { |
| 5495 | return mHardKeyboardEnabled; |
| 5496 | } |
| 5497 | } |
| 5498 | |
| 5499 | public void setHardKeyboardEnabled(boolean enabled) { |
| 5500 | synchronized (mWindowMap) { |
| 5501 | if (mHardKeyboardEnabled != enabled) { |
| 5502 | mHardKeyboardEnabled = enabled; |
| 5503 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5504 | } |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | public void setOnHardKeyboardStatusChangeListener( |
| 5509 | OnHardKeyboardStatusChangeListener listener) { |
| 5510 | synchronized (mWindowMap) { |
| 5511 | mHardKeyboardStatusChangeListener = listener; |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | void notifyHardKeyboardStatusChange() { |
| 5516 | final boolean available, enabled; |
| 5517 | final OnHardKeyboardStatusChangeListener listener; |
| 5518 | synchronized (mWindowMap) { |
| 5519 | listener = mHardKeyboardStatusChangeListener; |
| 5520 | available = mHardKeyboardAvailable; |
| 5521 | enabled = mHardKeyboardEnabled; |
| 5522 | } |
| 5523 | if (listener != null) { |
| 5524 | listener.onHardKeyboardStatusChange(available, enabled); |
| 5525 | } |
| 5526 | } |
| 5527 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5528 | // ------------------------------------------------------------- |
| 5529 | // Drag and drop |
| 5530 | // ------------------------------------------------------------- |
| 5531 | |
| 5532 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5533 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5534 | if (DEBUG_DRAG) { |
| 5535 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5536 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5537 | + " asbinder=" + window.asBinder()); |
| 5538 | } |
| 5539 | |
| 5540 | final int callerPid = Binder.getCallingPid(); |
| 5541 | final long origId = Binder.clearCallingIdentity(); |
| 5542 | IBinder token = null; |
| 5543 | |
| 5544 | try { |
| 5545 | synchronized (mWindowMap) { |
| 5546 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5547 | if (mDragState == null) { |
| 5548 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5549 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 5550 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 5551 | + surface + ": CREATE"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5552 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5553 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5554 | token = new Binder(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 5555 | mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5556 | mDragState.mSurface = surface; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5557 | token = mDragState.mToken = new Binder(); |
| 5558 | |
| 5559 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5560 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5561 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5562 | mH.sendMessageDelayed(msg, 5000); |
| 5563 | } else { |
| 5564 | Slog.w(TAG, "Drag already in progress"); |
| 5565 | } |
| 5566 | } catch (Surface.OutOfResourcesException e) { |
| 5567 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5568 | if (mDragState != null) { |
| 5569 | mDragState.reset(); |
| 5570 | mDragState = null; |
| 5571 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5572 | } |
| 5573 | } |
| 5574 | } finally { |
| 5575 | Binder.restoreCallingIdentity(origId); |
| 5576 | } |
| 5577 | |
| 5578 | return token; |
| 5579 | } |
| 5580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5581 | // ------------------------------------------------------------- |
| 5582 | // Input Events and Focus Management |
| 5583 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5584 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 5585 | final InputMonitor mInputMonitor = new InputMonitor(this); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5587 | public void pauseKeyDispatching(IBinder _token) { |
| 5588 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5589 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5590 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | synchronized (mWindowMap) { |
| 5594 | WindowToken token = mTokenMap.get(_token); |
| 5595 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5596 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5597 | } |
| 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | public void resumeKeyDispatching(IBinder _token) { |
| 5602 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5603 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5604 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | synchronized (mWindowMap) { |
| 5608 | WindowToken token = mTokenMap.get(_token); |
| 5609 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5610 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5611 | } |
| 5612 | } |
| 5613 | } |
| 5614 | |
| 5615 | public void setEventDispatching(boolean enabled) { |
| 5616 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5617 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5618 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5622 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5623 | } |
| 5624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | /** |
| 5627 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5628 | * Even when sync is false, this method may block while waiting for current |
| 5629 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5630 | * |
| 5631 | * @param ev A motion event describing the keystroke action. (Be sure to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5633 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5634 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5635 | */ |
| 5636 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5637 | long downTime = ev.getDownTime(); |
| 5638 | long eventTime = ev.getEventTime(); |
| 5639 | |
| 5640 | int action = ev.getAction(); |
| 5641 | int code = ev.getKeyCode(); |
| 5642 | int repeatCount = ev.getRepeatCount(); |
| 5643 | int metaState = ev.getMetaState(); |
| 5644 | int deviceId = ev.getDeviceId(); |
| 5645 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5646 | int source = ev.getSource(); |
Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 5647 | int flags = ev.getFlags(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5648 | |
| 5649 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5650 | source = InputDevice.SOURCE_KEYBOARD; |
| 5651 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5652 | |
| 5653 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5654 | if (downTime == 0) downTime = eventTime; |
| 5655 | |
| 5656 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 5657 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5659 | final int pid = Binder.getCallingPid(); |
| 5660 | final int uid = Binder.getCallingUid(); |
| 5661 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5662 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5663 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5664 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5665 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5666 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5667 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5668 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5669 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | } |
| 5671 | |
| 5672 | /** |
| 5673 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5674 | * Even when sync is false, this method may block while waiting for current |
| 5675 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5676 | * |
| 5677 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5678 | * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5679 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5680 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5681 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5682 | */ |
| 5683 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5684 | final int pid = Binder.getCallingPid(); |
| 5685 | final int uid = Binder.getCallingUid(); |
| 5686 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5687 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5688 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5689 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5690 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5691 | } |
| 5692 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5693 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5694 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5695 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5696 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5697 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5698 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5699 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5702 | /** |
| 5703 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5704 | * Even when sync is false, this method may block while waiting for current |
| 5705 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5706 | * |
| 5707 | * @param ev A motion event describing the trackball action. (As noted in |
| 5708 | * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5710 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5711 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5712 | */ |
| 5713 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5714 | final int pid = Binder.getCallingPid(); |
| 5715 | final int uid = Binder.getCallingUid(); |
| 5716 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5717 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5718 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5719 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5720 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5721 | } |
| 5722 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5723 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5724 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5725 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5726 | INJECTION_TIMEOUT_MILLIS); |
| 5727 | |
| 5728 | Binder.restoreCallingIdentity(ident); |
| 5729 | return reportInjectionResult(result); |
| 5730 | } |
| 5731 | |
| 5732 | /** |
| 5733 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5734 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5735 | * block any longer than it takes to enqueue the input event. |
| 5736 | * |
| 5737 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5738 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5739 | */ |
| 5740 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5741 | final int pid = Binder.getCallingPid(); |
| 5742 | final int uid = Binder.getCallingUid(); |
| 5743 | final long ident = Binder.clearCallingIdentity(); |
| 5744 | |
| 5745 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5746 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5747 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5748 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5749 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5750 | return reportInjectionResult(result); |
| 5751 | } |
| 5752 | |
| 5753 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5754 | switch (result) { |
| 5755 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5756 | Slog.w(TAG, "Input event injection permission denied."); |
| 5757 | throw new SecurityException( |
| 5758 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5759 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5760 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5761 | return true; |
| 5762 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5763 | Slog.w(TAG, "Input event injection timed out."); |
| 5764 | return false; |
| 5765 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5766 | default: |
| 5767 | Slog.w(TAG, "Input event injection failed."); |
| 5768 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5769 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5770 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5772 | private WindowState getFocusedWindow() { |
| 5773 | synchronized (mWindowMap) { |
| 5774 | return getFocusedWindowLocked(); |
| 5775 | } |
| 5776 | } |
| 5777 | |
| 5778 | private WindowState getFocusedWindowLocked() { |
| 5779 | return mCurrentFocus; |
| 5780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5782 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5783 | if (!mInputMonitor.waitForInputDevicesReady( |
| 5784 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 5785 | Slog.w(TAG, "Devices still not ready after waiting " |
| 5786 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 5787 | + " milliseconds before attempting to detect safe mode."); |
| 5788 | } |
| 5789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5790 | mSafeMode = mPolicy.detectSafeMode(); |
| 5791 | return mSafeMode; |
| 5792 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5795 | synchronized(mWindowMap) { |
| 5796 | if (mDisplay != null) { |
| 5797 | throw new IllegalStateException("Display already initialized"); |
| 5798 | } |
| 5799 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 5800 | mDisplay = wm.getDefaultDisplay(); |
| 5801 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 5802 | mInitialDisplayHeight = mDisplay.getHeight(); |
Dianne Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 5803 | mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth), |
| 5804 | Display.unmapDisplaySize(mInitialDisplayHeight)); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | try { |
| 5808 | mActivityManager.updateConfiguration(null); |
| 5809 | } catch (RemoteException e) { |
| 5810 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 5811 | |
| 5812 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5813 | } |
| 5814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5815 | // This is an animation that does nothing: it just immediately finishes |
| 5816 | // itself every time it is called. It is used as a stub animation in cases |
| 5817 | // where we want to synchronize multiple things that may be animating. |
| 5818 | static final class DummyAnimation extends Animation { |
| 5819 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 5820 | return false; |
| 5821 | } |
| 5822 | } |
| 5823 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | // ------------------------------------------------------------- |
| 5826 | // Async Handler |
| 5827 | // ------------------------------------------------------------- |
| 5828 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 5829 | final class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 5831 | public static final int REPORT_LOSING_FOCUS = 3; |
| 5832 | public static final int ANIMATE = 4; |
| 5833 | public static final int ADD_STARTING = 5; |
| 5834 | public static final int REMOVE_STARTING = 6; |
| 5835 | public static final int FINISHED_STARTING = 7; |
| 5836 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 5838 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 5839 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 5840 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 5841 | public static final int FORCE_GC = 15; |
| 5842 | public static final int ENABLE_SCREEN = 16; |
| 5843 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5844 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5845 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5846 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5847 | public static final int DRAG_END_TIMEOUT = 21; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5848 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5850 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5852 | public H() { |
| 5853 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | @Override |
| 5856 | public void handleMessage(Message msg) { |
| 5857 | switch (msg.what) { |
| 5858 | case REPORT_FOCUS_CHANGE: { |
| 5859 | WindowState lastFocus; |
| 5860 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5862 | synchronized(mWindowMap) { |
| 5863 | lastFocus = mLastFocus; |
| 5864 | newFocus = mCurrentFocus; |
| 5865 | if (lastFocus == newFocus) { |
| 5866 | // Focus is not changing, so nothing to do. |
| 5867 | return; |
| 5868 | } |
| 5869 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5870 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | // + " to " + newFocus); |
| 5872 | if (newFocus != null && lastFocus != null |
| 5873 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5874 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5875 | mLosingFocus.add(lastFocus); |
| 5876 | lastFocus = null; |
| 5877 | } |
| 5878 | } |
| 5879 | |
| 5880 | if (lastFocus != newFocus) { |
| 5881 | //System.out.println("Changing focus from " + lastFocus |
| 5882 | // + " to " + newFocus); |
| 5883 | if (newFocus != null) { |
| 5884 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5885 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5886 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 5887 | } catch (RemoteException e) { |
| 5888 | // Ignore if process has died. |
| 5889 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 5890 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | if (lastFocus != null) { |
| 5894 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5895 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5896 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 5897 | } catch (RemoteException e) { |
| 5898 | // Ignore if process has died. |
| 5899 | } |
| 5900 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5901 | |
| 5902 | mPolicy.focusChanged(lastFocus, newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5903 | } |
| 5904 | } break; |
| 5905 | |
| 5906 | case REPORT_LOSING_FOCUS: { |
| 5907 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5909 | synchronized(mWindowMap) { |
| 5910 | losers = mLosingFocus; |
| 5911 | mLosingFocus = new ArrayList<WindowState>(); |
| 5912 | } |
| 5913 | |
| 5914 | final int N = losers.size(); |
| 5915 | for (int i=0; i<N; i++) { |
| 5916 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5917 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5918 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 5919 | } catch (RemoteException e) { |
| 5920 | // Ignore if process has died. |
| 5921 | } |
| 5922 | } |
| 5923 | } break; |
| 5924 | |
| 5925 | case ANIMATE: { |
| 5926 | synchronized(mWindowMap) { |
| 5927 | mAnimationPending = false; |
| 5928 | performLayoutAndPlaceSurfacesLocked(); |
| 5929 | } |
| 5930 | } break; |
| 5931 | |
| 5932 | case ADD_STARTING: { |
| 5933 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 5934 | final StartingData sd = wtoken.startingData; |
| 5935 | |
| 5936 | if (sd == null) { |
| 5937 | // Animation has been canceled... do nothing. |
| 5938 | return; |
| 5939 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5940 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5941 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5942 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5944 | View view = null; |
| 5945 | try { |
| 5946 | view = mPolicy.addStartingWindow( |
| 5947 | wtoken.token, sd.pkg, |
| 5948 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 5949 | sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5950 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5951 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | if (view != null) { |
| 5955 | boolean abort = false; |
| 5956 | |
| 5957 | synchronized(mWindowMap) { |
| 5958 | if (wtoken.removed || wtoken.startingData == null) { |
| 5959 | // If the window was successfully added, then |
| 5960 | // we need to remove it. |
| 5961 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5962 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5963 | "Aborted starting " + wtoken |
| 5964 | + ": removed=" + wtoken.removed |
| 5965 | + " startingData=" + wtoken.startingData); |
| 5966 | wtoken.startingWindow = null; |
| 5967 | wtoken.startingData = null; |
| 5968 | abort = true; |
| 5969 | } |
| 5970 | } else { |
| 5971 | wtoken.startingView = view; |
| 5972 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5973 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5974 | "Added starting " + wtoken |
| 5975 | + ": startingWindow=" |
| 5976 | + wtoken.startingWindow + " startingView=" |
| 5977 | + wtoken.startingView); |
| 5978 | } |
| 5979 | |
| 5980 | if (abort) { |
| 5981 | try { |
| 5982 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 5983 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5984 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5985 | } |
| 5986 | } |
| 5987 | } |
| 5988 | } break; |
| 5989 | |
| 5990 | case REMOVE_STARTING: { |
| 5991 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 5992 | IBinder token = null; |
| 5993 | View view = null; |
| 5994 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5995 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5996 | + wtoken + ": startingWindow=" |
| 5997 | + wtoken.startingWindow + " startingView=" |
| 5998 | + wtoken.startingView); |
| 5999 | if (wtoken.startingWindow != null) { |
| 6000 | view = wtoken.startingView; |
| 6001 | token = wtoken.token; |
| 6002 | wtoken.startingData = null; |
| 6003 | wtoken.startingView = null; |
| 6004 | wtoken.startingWindow = null; |
| 6005 | } |
| 6006 | } |
| 6007 | if (view != null) { |
| 6008 | try { |
| 6009 | mPolicy.removeStartingWindow(token, view); |
| 6010 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6011 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6012 | } |
| 6013 | } |
| 6014 | } break; |
| 6015 | |
| 6016 | case FINISHED_STARTING: { |
| 6017 | IBinder token = null; |
| 6018 | View view = null; |
| 6019 | while (true) { |
| 6020 | synchronized (mWindowMap) { |
| 6021 | final int N = mFinishedStarting.size(); |
| 6022 | if (N <= 0) { |
| 6023 | break; |
| 6024 | } |
| 6025 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 6026 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6027 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | "Finished starting " + wtoken |
| 6029 | + ": startingWindow=" + wtoken.startingWindow |
| 6030 | + " startingView=" + wtoken.startingView); |
| 6031 | |
| 6032 | if (wtoken.startingWindow == null) { |
| 6033 | continue; |
| 6034 | } |
| 6035 | |
| 6036 | view = wtoken.startingView; |
| 6037 | token = wtoken.token; |
| 6038 | wtoken.startingData = null; |
| 6039 | wtoken.startingView = null; |
| 6040 | wtoken.startingWindow = null; |
| 6041 | } |
| 6042 | |
| 6043 | try { |
| 6044 | mPolicy.removeStartingWindow(token, view); |
| 6045 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6046 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6047 | } |
| 6048 | } |
| 6049 | } break; |
| 6050 | |
| 6051 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 6052 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 6053 | |
| 6054 | boolean nowVisible = msg.arg1 != 0; |
| 6055 | boolean nowGone = msg.arg2 != 0; |
| 6056 | |
| 6057 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6058 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | TAG, "Reporting visible in " + wtoken |
| 6060 | + " visible=" + nowVisible |
| 6061 | + " gone=" + nowGone); |
| 6062 | if (nowVisible) { |
| 6063 | wtoken.appToken.windowsVisible(); |
| 6064 | } else { |
| 6065 | wtoken.appToken.windowsGone(); |
| 6066 | } |
| 6067 | } catch (RemoteException ex) { |
| 6068 | } |
| 6069 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6071 | case WINDOW_FREEZE_TIMEOUT: { |
| 6072 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6073 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6074 | int i = mWindows.size(); |
| 6075 | while (i > 0) { |
| 6076 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6077 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | if (w.mOrientationChanging) { |
| 6079 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6080 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6081 | } |
| 6082 | } |
| 6083 | performLayoutAndPlaceSurfacesLocked(); |
| 6084 | } |
| 6085 | break; |
| 6086 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6087 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6088 | case HOLD_SCREEN_CHANGED: { |
| 6089 | Session oldHold; |
| 6090 | Session newHold; |
| 6091 | synchronized (mWindowMap) { |
| 6092 | oldHold = mLastReportedHold; |
| 6093 | newHold = (Session)msg.obj; |
| 6094 | mLastReportedHold = newHold; |
| 6095 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6097 | if (oldHold != newHold) { |
| 6098 | try { |
| 6099 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6100 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | "window", |
| 6102 | BatteryStats.WAKE_TYPE_WINDOW); |
| 6103 | } |
| 6104 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6105 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6106 | "window", |
| 6107 | BatteryStats.WAKE_TYPE_WINDOW); |
| 6108 | } |
| 6109 | } catch (RemoteException e) { |
| 6110 | } |
| 6111 | } |
| 6112 | break; |
| 6113 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6115 | case APP_TRANSITION_TIMEOUT: { |
| 6116 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6117 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6118 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6119 | "*** APP TRANSITION TIMEOUT"); |
| 6120 | mAppTransitionReady = true; |
| 6121 | mAppTransitionTimeout = true; |
| 6122 | performLayoutAndPlaceSurfacesLocked(); |
| 6123 | } |
| 6124 | } |
| 6125 | break; |
| 6126 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6128 | case PERSIST_ANIMATION_SCALE: { |
| 6129 | Settings.System.putFloat(mContext.getContentResolver(), |
| 6130 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 6131 | Settings.System.putFloat(mContext.getContentResolver(), |
| 6132 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 6133 | break; |
| 6134 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6136 | case FORCE_GC: { |
| 6137 | synchronized(mWindowMap) { |
| 6138 | if (mAnimationPending) { |
| 6139 | // If we are animating, don't do the gc now but |
| 6140 | // delay a bit so we don't interrupt the animation. |
| 6141 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 6142 | 2000); |
| 6143 | return; |
| 6144 | } |
| 6145 | // If we are currently rotating the display, it will |
| 6146 | // schedule a new message when done. |
| 6147 | if (mDisplayFrozen) { |
| 6148 | return; |
| 6149 | } |
| 6150 | mFreezeGcPending = 0; |
| 6151 | } |
| 6152 | Runtime.getRuntime().gc(); |
| 6153 | break; |
| 6154 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | case ENABLE_SCREEN: { |
| 6157 | performEnableScreen(); |
| 6158 | break; |
| 6159 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6161 | case APP_FREEZE_TIMEOUT: { |
| 6162 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6163 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | int i = mAppTokens.size(); |
| 6165 | while (i > 0) { |
| 6166 | i--; |
| 6167 | AppWindowToken tok = mAppTokens.get(i); |
| 6168 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6169 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | unsetAppFreezingScreenLocked(tok, true, true); |
| 6171 | } |
| 6172 | } |
| 6173 | } |
| 6174 | break; |
| 6175 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6176 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6177 | case SEND_NEW_CONFIGURATION: { |
| 6178 | removeMessages(SEND_NEW_CONFIGURATION); |
| 6179 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6180 | break; |
| 6181 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6182 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6183 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6184 | if (mWindowsChanged) { |
| 6185 | synchronized (mWindowMap) { |
| 6186 | mWindowsChanged = false; |
| 6187 | } |
| 6188 | notifyWindowsChanged(); |
| 6189 | } |
| 6190 | break; |
| 6191 | } |
| 6192 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6193 | case DRAG_START_TIMEOUT: { |
| 6194 | IBinder win = (IBinder)msg.obj; |
| 6195 | if (DEBUG_DRAG) { |
| 6196 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 6197 | } |
| 6198 | synchronized (mWindowMap) { |
| 6199 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 6200 | if (mDragState != null) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6201 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6202 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6203 | mDragState.reset(); |
| 6204 | mDragState = null; |
| 6205 | } |
| 6206 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6207 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6208 | } |
| 6209 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6210 | case DRAG_END_TIMEOUT: { |
| 6211 | IBinder win = (IBinder)msg.obj; |
| 6212 | if (DEBUG_DRAG) { |
| 6213 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 6214 | } |
| 6215 | synchronized (mWindowMap) { |
| 6216 | // !!! TODO: ANR the drag-receiving app |
| 6217 | mDragState.mDragResult = false; |
| 6218 | mDragState.endDragLw(); |
| 6219 | } |
| 6220 | break; |
| 6221 | } |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6222 | |
| 6223 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 6224 | notifyHardKeyboardStatusChange(); |
| 6225 | break; |
| 6226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6227 | } |
| 6228 | } |
| 6229 | } |
| 6230 | |
| 6231 | // ------------------------------------------------------------- |
| 6232 | // IWindowManager API |
| 6233 | // ------------------------------------------------------------- |
| 6234 | |
| 6235 | public IWindowSession openSession(IInputMethodClient client, |
| 6236 | IInputContext inputContext) { |
| 6237 | if (client == null) throw new IllegalArgumentException("null client"); |
| 6238 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame^] | 6239 | Session session = new Session(this, client, inputContext); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6240 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6241 | } |
| 6242 | |
| 6243 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 6244 | synchronized (mWindowMap) { |
| 6245 | // The focus for the client is the window immediately below |
| 6246 | // where we would place the input method window. |
| 6247 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 6248 | WindowState imFocus; |
| 6249 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6250 | imFocus = mWindows.get(idx-1); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6251 | //Log.i(TAG, "Desired input method target: " + imFocus); |
| 6252 | //Log.i(TAG, "Current focus: " + this.mCurrentFocus); |
| 6253 | //Log.i(TAG, "Last focus: " + this.mLastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | if (imFocus != null) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6255 | // This may be a starting window, in which case we still want |
| 6256 | // to count it as okay. |
| 6257 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 6258 | && imFocus.mAppToken != null) { |
| 6259 | // The client has definitely started, so it really should |
| 6260 | // have a window in this app token. Let's look for it. |
| 6261 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 6262 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 6263 | if (w != imFocus) { |
| 6264 | //Log.i(TAG, "Switching to real app window: " + w); |
| 6265 | imFocus = w; |
| 6266 | break; |
| 6267 | } |
| 6268 | } |
| 6269 | } |
| 6270 | //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 6271 | //if (imFocus.mSession.mClient != null) { |
| 6272 | // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder()); |
| 6273 | // Log.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 6274 | //} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6275 | if (imFocus.mSession.mClient != null && |
| 6276 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 6277 | return true; |
| 6278 | } |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6279 | |
| 6280 | // Okay, how about this... what is the current focus? |
| 6281 | // It seems in some cases we may not have moved the IM |
| 6282 | // target window, such as when it was in a pop-up window, |
| 6283 | // so let's also look at the current focus. (An example: |
| 6284 | // go to Gmail, start searching so the keyboard goes up, |
| 6285 | // press home. Sometimes the IME won't go down.) |
| 6286 | // Would be nice to fix this more correctly, but it's |
| 6287 | // way at the end of a release, and this should be good enough. |
| 6288 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null && |
| 6289 | mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 6290 | return true; |
| 6291 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | } |
| 6293 | } |
| 6294 | } |
| 6295 | return false; |
| 6296 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6298 | // ------------------------------------------------------------- |
| 6299 | // Internals |
| 6300 | // ------------------------------------------------------------- |
| 6301 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6302 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 6303 | boolean throwOnError) { |
| 6304 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6305 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6306 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6307 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 6308 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6309 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6310 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | TAG, "Looking up client " + client + ": " + win); |
| 6312 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6313 | RuntimeException ex = new IllegalArgumentException( |
| 6314 | "Requested window " + client + " does not exist"); |
| 6315 | if (throwOnError) { |
| 6316 | throw ex; |
| 6317 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6318 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6319 | return null; |
| 6320 | } |
| 6321 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6322 | RuntimeException ex = new IllegalArgumentException( |
| 6323 | "Requested window " + client + " is in session " + |
| 6324 | win.mSession + ", not " + session); |
| 6325 | if (throwOnError) { |
| 6326 | throw ex; |
| 6327 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6328 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | return null; |
| 6330 | } |
| 6331 | |
| 6332 | return win; |
| 6333 | } |
| 6334 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6335 | final void rebuildAppWindowListLocked() { |
| 6336 | int NW = mWindows.size(); |
| 6337 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6338 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6339 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6340 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6341 | if (mRebuildTmp.length < NW) { |
| 6342 | mRebuildTmp = new WindowState[NW+10]; |
| 6343 | } |
| 6344 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6345 | // First remove all existing app windows. |
| 6346 | i=0; |
| 6347 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6348 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6349 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6350 | WindowState win = mWindows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6351 | win.mRebuilding = true; |
| 6352 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6353 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6354 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6355 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6356 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6357 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6358 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6359 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 6360 | && lastWallpaper == i-1) { |
| 6361 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6362 | } |
| 6363 | i++; |
| 6364 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6365 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6366 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 6367 | // so skip them before adding app tokens. |
| 6368 | lastWallpaper++; |
| 6369 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6370 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6371 | // First add all of the exiting app tokens... these are no longer |
| 6372 | // in the main app list, but still have windows shown. We put them |
| 6373 | // in the back because now that the animation is over we no longer |
| 6374 | // will care about them. |
| 6375 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6376 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6377 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 6378 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6379 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6380 | // And add in the still active app tokens in Z order. |
| 6381 | NT = mAppTokens.size(); |
| 6382 | for (int j=0; j<NT; j++) { |
| 6383 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6384 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6385 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6386 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6387 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6388 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6389 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6390 | for (i=0; i<numRemoved; i++) { |
| 6391 | WindowState ws = mRebuildTmp[i]; |
| 6392 | if (ws.mRebuilding) { |
| 6393 | StringWriter sw = new StringWriter(); |
| 6394 | PrintWriter pw = new PrintWriter(sw); |
| 6395 | ws.dump(pw, ""); |
| 6396 | pw.flush(); |
| 6397 | Slog.w(TAG, "This window was lost: " + ws); |
| 6398 | Slog.w(TAG, sw.toString()); |
| 6399 | } |
| 6400 | } |
| 6401 | Slog.w(TAG, "Current app token list:"); |
| 6402 | dumpAppTokensLocked(); |
| 6403 | Slog.w(TAG, "Final window list:"); |
| 6404 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6405 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6406 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | private final void assignLayersLocked() { |
| 6409 | int N = mWindows.size(); |
| 6410 | int curBaseLayer = 0; |
| 6411 | int curLayer = 0; |
| 6412 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6413 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6414 | if (DEBUG_LAYERS) { |
| 6415 | RuntimeException here = new RuntimeException("here"); |
| 6416 | here.fillInStackTrace(); |
| 6417 | Log.v(TAG, "Assigning layers", here); |
| 6418 | } |
| 6419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6421 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6422 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 6423 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6424 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 6425 | w.mLayer = curLayer; |
| 6426 | } else { |
| 6427 | curBaseLayer = curLayer = w.mBaseLayer; |
| 6428 | w.mLayer = curLayer; |
| 6429 | } |
| 6430 | if (w.mTargetAppToken != null) { |
| 6431 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 6432 | } else if (w.mAppToken != null) { |
| 6433 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 6434 | } else { |
| 6435 | w.mAnimLayer = w.mLayer; |
| 6436 | } |
| 6437 | if (w.mIsImWindow) { |
| 6438 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6439 | } else if (w.mIsWallpaper) { |
| 6440 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6441 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6442 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6443 | + w.mAnimLayer); |
| 6444 | //System.out.println( |
| 6445 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | private boolean mInLayout = false; |
| 6450 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 6451 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6452 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | throw new RuntimeException("Recursive call!"); |
| 6454 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6455 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | return; |
| 6457 | } |
| 6458 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6459 | if (mWaitingForConfig) { |
| 6460 | // Our configuration has changed (most likely rotation), but we |
| 6461 | // don't yet have the complete configuration to report to |
| 6462 | // applications. Don't do any window layout until we have it. |
| 6463 | return; |
| 6464 | } |
| 6465 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6466 | if (mDisplay == null) { |
| 6467 | // Not yet initialized, nothing to do. |
| 6468 | return; |
| 6469 | } |
| 6470 | |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6471 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6473 | |
| 6474 | try { |
| 6475 | if (mForceRemoves != null) { |
| 6476 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6477 | // Wait a little bit for things to settle down, and off we go. |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6478 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 6479 | WindowState ws = mForceRemoves.get(i); |
| 6480 | Slog.i(TAG, "Force removing: " + ws); |
| 6481 | removeWindowInnerLocked(ws.mSession, ws); |
| 6482 | } |
| 6483 | mForceRemoves = null; |
| 6484 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 6485 | Object tmp = new Object(); |
| 6486 | synchronized (tmp) { |
| 6487 | try { |
| 6488 | tmp.wait(250); |
| 6489 | } catch (InterruptedException e) { |
| 6490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6491 | } |
| 6492 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6493 | } catch (RuntimeException e) { |
| 6494 | Slog.e(TAG, "Unhandled exception while force removing for memory", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6495 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | try { |
| 6498 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6499 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6500 | int N = mPendingRemove.size(); |
| 6501 | if (N > 0) { |
| 6502 | if (mPendingRemoveTmp.length < N) { |
| 6503 | mPendingRemoveTmp = new WindowState[N+10]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6505 | mPendingRemove.toArray(mPendingRemoveTmp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6506 | mPendingRemove.clear(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6507 | for (int i=0; i<N; i++) { |
| 6508 | WindowState w = mPendingRemoveTmp[i]; |
| 6509 | removeWindowInnerLocked(w.mSession, w); |
| 6510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6511 | |
| 6512 | mInLayout = false; |
| 6513 | assignLayersLocked(); |
| 6514 | mLayoutNeeded = true; |
| 6515 | performLayoutAndPlaceSurfacesLocked(); |
| 6516 | |
| 6517 | } else { |
| 6518 | mInLayout = false; |
| 6519 | if (mLayoutNeeded) { |
| 6520 | requestAnimationLocked(0); |
| 6521 | } |
| 6522 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6523 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6524 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 6525 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6527 | } catch (RuntimeException e) { |
| 6528 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6529 | Slog.e(TAG, "Unhandled exception while layout out windows", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6530 | } |
| 6531 | } |
| 6532 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6533 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6534 | if (!mLayoutNeeded) { |
| 6535 | return 0; |
| 6536 | } |
| 6537 | |
| 6538 | mLayoutNeeded = false; |
| 6539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6540 | final int dw = mDisplay.getWidth(); |
| 6541 | final int dh = mDisplay.getHeight(); |
| 6542 | |
| 6543 | final int N = mWindows.size(); |
| 6544 | int i; |
| 6545 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6546 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 6547 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 6548 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6549 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6550 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6551 | int seq = mLayoutSeq+1; |
| 6552 | if (seq < 0) seq = 0; |
| 6553 | mLayoutSeq = seq; |
| 6554 | |
| 6555 | // First perform layout of any root windows (not attached |
| 6556 | // to another window). |
| 6557 | int topAttached = -1; |
| 6558 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6559 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6560 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6561 | // Don't do layout of a window if it is not visible, or |
| 6562 | // soon won't be visible, to avoid wasting time and funky |
| 6563 | // changes while a window is animating away. |
| 6564 | final AppWindowToken atoken = win.mAppToken; |
| 6565 | final boolean gone = win.mViewVisibility == View.GONE |
| 6566 | || !win.mRelayoutCalled |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 6567 | || (atoken == null && win.mRootToken.hidden) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6568 | || (atoken != null && atoken.hiddenRequested) |
| 6569 | || win.mAttachedHidden |
| 6570 | || win.mExiting || win.mDestroying; |
| 6571 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6572 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 6573 | Slog.v(TAG, "First pass " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6574 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 6575 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6576 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6577 | + win.mViewVisibility + " mRelayoutCalled=" |
| 6578 | + win.mRelayoutCalled + " hidden=" |
| 6579 | + win.mRootToken.hidden + " hiddenRequested=" |
| 6580 | + (atoken != null && atoken.hiddenRequested) |
| 6581 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 6582 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6583 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6584 | // If this view is GONE, then skip it -- keep the current |
| 6585 | // frame, and let the caller know so they can ignore it |
| 6586 | // if they want. (We do the normal layout for INVISIBLE |
| 6587 | // windows, since that means "perform layout as normal, |
| 6588 | // just don't display"). |
| 6589 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6590 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6591 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 6592 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6593 | win.mContentChanged = false; |
| 6594 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6595 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 6596 | win.mLayoutSeq = seq; |
| 6597 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 6598 | + win.mFrame + " mContainingFrame=" |
| 6599 | + win.mContainingFrame + " mDisplayFrame=" |
| 6600 | + win.mDisplayFrame); |
| 6601 | } else { |
| 6602 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6603 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 6604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6605 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6606 | |
| 6607 | // Now perform layout of attached windows, which usually |
| 6608 | // depend on the position of the window they are attached to. |
| 6609 | // XXX does not deal with windows that are attached to windows |
| 6610 | // that are themselves attached. |
| 6611 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6612 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6613 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6614 | if (win.mLayoutAttached) { |
| 6615 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 6616 | + " mHaveFrame=" + win.mHaveFrame |
| 6617 | + " mViewVisibility=" + win.mViewVisibility |
| 6618 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6619 | // If this view is GONE, then skip it -- keep the current |
| 6620 | // frame, and let the caller know so they can ignore it |
| 6621 | // if they want. (We do the normal layout for INVISIBLE |
| 6622 | // windows, since that means "perform layout as normal, |
| 6623 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6624 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 6625 | || !win.mHaveFrame) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6626 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 6627 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6628 | win.mContentChanged = false; |
| 6629 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6630 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 6631 | win.mLayoutSeq = seq; |
| 6632 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 6633 | + win.mFrame + " mContainingFrame=" |
| 6634 | + win.mContainingFrame + " mDisplayFrame=" |
| 6635 | + win.mDisplayFrame); |
| 6636 | } |
| 6637 | } |
| 6638 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6639 | |
| 6640 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6641 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 6642 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6643 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6644 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6645 | |
| 6646 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6648 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 6649 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6650 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 6651 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 6652 | if (mDisplay == null) { |
| 6653 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 6654 | return; |
| 6655 | } |
| 6656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | final long currentTime = SystemClock.uptimeMillis(); |
| 6658 | final int dw = mDisplay.getWidth(); |
| 6659 | final int dh = mDisplay.getHeight(); |
| 6660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6661 | int i; |
| 6662 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6663 | if (mFocusMayChange) { |
| 6664 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6665 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 6666 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6667 | } |
| 6668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6669 | // Initialize state of exiting tokens. |
| 6670 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 6671 | mExitingTokens.get(i).hasVisible = false; |
| 6672 | } |
| 6673 | |
| 6674 | // Initialize state of exiting applications. |
| 6675 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 6676 | mExitingAppTokens.get(i).hasVisible = false; |
| 6677 | } |
| 6678 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | boolean orientationChangeComplete = true; |
| 6680 | Session holdScreen = null; |
| 6681 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 6682 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6683 | boolean focusDisplayed = false; |
| 6684 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6685 | boolean createWatermark = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 6686 | boolean updateRotation = false; |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 6687 | boolean screenRotationFinished = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6688 | |
| 6689 | if (mFxSession == null) { |
| 6690 | mFxSession = new SurfaceSession(); |
| 6691 | createWatermark = true; |
| 6692 | } |
| 6693 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6694 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6695 | |
| 6696 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6697 | |
| 6698 | if (createWatermark) { |
| 6699 | createWatermark(); |
| 6700 | } |
| 6701 | if (mWatermark != null) { |
| 6702 | mWatermark.positionSurface(dw, dh); |
| 6703 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 6704 | if (mStrictModeFlash != null) { |
| 6705 | mStrictModeFlash.positionSurface(dw, dh); |
| 6706 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6709 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6710 | int repeats = 0; |
| 6711 | int changes = 0; |
| 6712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6713 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6714 | repeats++; |
| 6715 | if (repeats > 6) { |
| 6716 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 6717 | mLayoutNeeded = false; |
| 6718 | break; |
| 6719 | } |
| 6720 | |
| 6721 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 6722 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 6723 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 6724 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 6725 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 6726 | assignLayersLocked(); |
| 6727 | mLayoutNeeded = true; |
| 6728 | } |
| 6729 | } |
| 6730 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 6731 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6732 | if (updateOrientationFromAppTokensLocked(true)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6733 | mLayoutNeeded = true; |
| 6734 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 6735 | } |
| 6736 | } |
| 6737 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 6738 | mLayoutNeeded = true; |
| 6739 | } |
| 6740 | } |
| 6741 | |
| 6742 | // FIRST LOOP: Perform a layout, if needed. |
| 6743 | if (repeats < 4) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6744 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6745 | if (changes != 0) { |
| 6746 | continue; |
| 6747 | } |
| 6748 | } else { |
| 6749 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 6750 | changes = 0; |
| 6751 | } |
| 6752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | final int transactionSequence = ++mTransactionSequence; |
| 6754 | |
| 6755 | // Update animations of all applications, including those |
| 6756 | // associated with exiting/removed apps |
| 6757 | boolean tokensAnimating = false; |
| 6758 | final int NAT = mAppTokens.size(); |
| 6759 | for (i=0; i<NAT; i++) { |
| 6760 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 6761 | tokensAnimating = true; |
| 6762 | } |
| 6763 | } |
| 6764 | final int NEAT = mExitingAppTokens.size(); |
| 6765 | for (i=0; i<NEAT; i++) { |
| 6766 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 6767 | tokensAnimating = true; |
| 6768 | } |
| 6769 | } |
| 6770 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6771 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 6772 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6773 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6774 | + transactionSequence + " tokensAnimating=" |
| 6775 | + tokensAnimating); |
| 6776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6778 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 6779 | if (mScreenRotationAnimation != null) { |
| 6780 | if (mScreenRotationAnimation.isAnimating()) { |
| 6781 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 6782 | animating = true; |
| 6783 | } else { |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 6784 | screenRotationFinished = true; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 6785 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 6786 | } |
| 6787 | } |
| 6788 | } |
| 6789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6790 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6791 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6792 | boolean forceHiding = false; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6793 | WindowState windowDetachedWallpaper = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6794 | |
| 6795 | mPolicy.beginAnimationLw(dw, dh); |
| 6796 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6797 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6799 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6800 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6801 | |
| 6802 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 6803 | |
| 6804 | if (w.mSurface != null) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6805 | // Take care of the window being ready to display. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6806 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 6807 | if ((w.mAttrs.flags |
| 6808 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6809 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6810 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6811 | wallpaperMayChange = true; |
| 6812 | } |
| 6813 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6814 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6815 | final boolean wasAnimating = w.mAnimating; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6816 | |
| 6817 | int animDw = dw; |
| 6818 | int animDh = dh; |
| 6819 | |
| 6820 | // If the window has moved due to its containing |
| 6821 | // content frame changing, then we'd like to animate |
| 6822 | // it. The checks here are ordered by what is least |
Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 6823 | // likely to be true first. |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6824 | if (w.shouldAnimateMove()) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6825 | // Frame has moved, containing content frame |
| 6826 | // has also moved, and we're not currently animating... |
| 6827 | // let's do something. |
| 6828 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 6829 | com.android.internal.R.anim.window_move_from_decor); |
| 6830 | w.setAnimation(a); |
| 6831 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 6832 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 6833 | } |
| 6834 | |
| 6835 | // Execute animation. |
| 6836 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 6837 | animDw, animDh); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6838 | |
| 6839 | // If this window is animating, make a note that we have |
| 6840 | // an animating window and take care of a request to run |
| 6841 | // a detached wallpaper animation. |
| 6842 | if (nowAnimating) { |
| 6843 | if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) { |
| 6844 | windowDetachedWallpaper = w; |
| 6845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6846 | animating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6847 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6848 | |
| 6849 | // If this window's app token is running a detached wallpaper |
| 6850 | // animation, make a note so we can ensure the wallpaper is |
| 6851 | // displayed behind it. |
| 6852 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 6853 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 6854 | windowDetachedWallpaper = w; |
| 6855 | } |
| 6856 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6857 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 6858 | wallpaperMayChange = true; |
| 6859 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6860 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6861 | if (mPolicy.doesForceHide(w, attrs)) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6862 | if (!wasAnimating && nowAnimating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6863 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6864 | "Animation started that could impact force hide: " |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6865 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6866 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6867 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6868 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 6869 | forceHiding = true; |
| 6870 | } |
| 6871 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 6872 | boolean changed; |
| 6873 | if (forceHiding) { |
| 6874 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6875 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 6876 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6877 | } else { |
| 6878 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6879 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 6880 | "Now policy shown: " + w); |
| 6881 | if (changed) { |
| 6882 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6883 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6884 | // Assume we will need to animate. If |
| 6885 | // we don't (because the wallpaper will |
| 6886 | // stay with the lock screen), then we will |
| 6887 | // clean up later. |
| 6888 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 6889 | if (a != null) { |
| 6890 | w.setAnimation(a); |
| 6891 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6892 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6893 | if (mCurrentFocus == null || |
| 6894 | mCurrentFocus.mLayer < w.mLayer) { |
| 6895 | // We are showing on to of the current |
| 6896 | // focus, so re-evaluate focus to make |
| 6897 | // sure it is correct. |
| 6898 | mFocusMayChange = true; |
| 6899 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6900 | } |
| 6901 | } |
| 6902 | if (changed && (attrs.flags |
| 6903 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 6904 | wallpaperMayChange = true; |
| 6905 | } |
| 6906 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | mPolicy.animatingWindowLw(w, attrs); |
| 6909 | } |
| 6910 | |
| 6911 | final AppWindowToken atoken = w.mAppToken; |
| 6912 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 6913 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 6914 | atoken.lastTransactionSequence = transactionSequence; |
| 6915 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 6916 | atoken.startingDisplayed = false; |
| 6917 | } |
| 6918 | if ((w.isOnScreen() || w.mAttrs.type |
| 6919 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 6920 | && !w.mExiting && !w.mDestroying) { |
| 6921 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6922 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6923 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6924 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6925 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6926 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6927 | + " pv=" + w.mPolicyVisibility |
| 6928 | + " dp=" + w.mDrawPending |
| 6929 | + " cdp=" + w.mCommitDrawPending |
| 6930 | + " ah=" + w.mAttachedHidden |
| 6931 | + " th=" + atoken.hiddenRequested |
| 6932 | + " a=" + w.mAnimating); |
| 6933 | } |
| 6934 | } |
| 6935 | if (w != atoken.startingWindow) { |
| 6936 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 6937 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6938 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6940 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | "tokenMayBeDrawn: " + atoken |
| 6942 | + " freezingScreen=" + atoken.freezingScreen |
| 6943 | + " mAppFreezing=" + w.mAppFreezing); |
| 6944 | tokenMayBeDrawn = true; |
| 6945 | } |
| 6946 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6947 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | atoken.startingDisplayed = true; |
| 6949 | } |
| 6950 | } |
| 6951 | } else if (w.mReadyToShow) { |
| 6952 | w.performShowLocked(); |
| 6953 | } |
| 6954 | } |
| 6955 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6956 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6957 | |
| 6958 | if (tokenMayBeDrawn) { |
| 6959 | // See if any windows have been drawn, so they (and others |
| 6960 | // associated with them) can now be shown. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6961 | final int NT = mAppTokens.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | for (i=0; i<NT; i++) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6963 | AppWindowToken wtoken = mAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | if (wtoken.freezingScreen) { |
| 6965 | int numInteresting = wtoken.numInterestingWindows; |
| 6966 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6967 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6968 | "allDrawn: " + wtoken |
| 6969 | + " interesting=" + numInteresting |
| 6970 | + " drawn=" + wtoken.numDrawnWindows); |
| 6971 | wtoken.showAllWindowsLocked(); |
| 6972 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 6973 | orientationChangeComplete = true; |
| 6974 | } |
| 6975 | } else if (!wtoken.allDrawn) { |
| 6976 | int numInteresting = wtoken.numInterestingWindows; |
| 6977 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6978 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6979 | "allDrawn: " + wtoken |
| 6980 | + " interesting=" + numInteresting |
| 6981 | + " drawn=" + wtoken.numDrawnWindows); |
| 6982 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6983 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6984 | |
| 6985 | // We can now show all of the drawn windows! |
| 6986 | if (!mOpeningApps.contains(wtoken)) { |
| 6987 | wtoken.showAllWindowsLocked(); |
| 6988 | } |
| 6989 | } |
| 6990 | } |
| 6991 | } |
| 6992 | } |
| 6993 | |
| 6994 | // If we are ready to perform an app transition, check through |
| 6995 | // all of the app tokens to be shown and see if they are ready |
| 6996 | // to go. |
| 6997 | if (mAppTransitionReady) { |
| 6998 | int NN = mOpeningApps.size(); |
| 6999 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7000 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | "Checking " + NN + " opening apps (frozen=" |
| 7002 | + mDisplayFrozen + " timeout=" |
| 7003 | + mAppTransitionTimeout + ")..."); |
| 7004 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 7005 | // If the display isn't frozen, wait to do anything until |
| 7006 | // all of the apps are ready. Otherwise just go because |
| 7007 | // we'll unfreeze the display when everyone is ready. |
| 7008 | for (i=0; i<NN && goodToGo; i++) { |
| 7009 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7010 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7011 | "Check opening app" + wtoken + ": allDrawn=" |
| 7012 | + wtoken.allDrawn + " startingDisplayed=" |
| 7013 | + wtoken.startingDisplayed); |
| 7014 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 7015 | && !wtoken.startingMoved) { |
| 7016 | goodToGo = false; |
| 7017 | } |
| 7018 | } |
| 7019 | } |
| 7020 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7021 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7022 | int transit = mNextAppTransition; |
| 7023 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7024 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7025 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7026 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7027 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7028 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7029 | mAppTransitionTimeout = false; |
| 7030 | mStartingIconInTransition = false; |
| 7031 | mSkipAppTransitionAnimation = false; |
| 7032 | |
| 7033 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 7034 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7035 | // If there are applications waiting to come to the |
| 7036 | // top of the stack, now is the time to move their windows. |
| 7037 | // (Note that we don't do apps going to the bottom |
| 7038 | // here -- we want to keep their windows in the old |
| 7039 | // Z-order until the animation completes.) |
| 7040 | if (mToTopApps.size() > 0) { |
| 7041 | NN = mAppTokens.size(); |
| 7042 | for (i=0; i<NN; i++) { |
| 7043 | AppWindowToken wtoken = mAppTokens.get(i); |
| 7044 | if (wtoken.sendingToTop) { |
| 7045 | wtoken.sendingToTop = false; |
| 7046 | moveAppWindowsLocked(wtoken, NN, false); |
| 7047 | } |
| 7048 | } |
| 7049 | mToTopApps.clear(); |
| 7050 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7051 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7052 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7053 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7054 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7055 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7056 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7057 | // The top-most window will supply the layout params, |
| 7058 | // and we will determine it below. |
| 7059 | LayoutParams animLp = null; |
| 7060 | int bestAnimLayer = -1; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7061 | boolean fullscreenAnim = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7062 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7063 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7064 | "New wallpaper target=" + mWallpaperTarget |
| 7065 | + ", lower target=" + mLowerWallpaperTarget |
| 7066 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7067 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7068 | // Do a first pass through the tokens for two |
| 7069 | // things: |
| 7070 | // (1) Determine if both the closing and opening |
| 7071 | // app token sets are wallpaper targets, in which |
| 7072 | // case special animations are needed |
| 7073 | // (since the wallpaper needs to stay static |
| 7074 | // behind them). |
| 7075 | // (2) Find the layout params of the top-most |
| 7076 | // application window in the tokens, which is |
| 7077 | // what will control the animation theme. |
| 7078 | final int NC = mClosingApps.size(); |
| 7079 | NN = NC + mOpeningApps.size(); |
| 7080 | for (i=0; i<NN; i++) { |
| 7081 | AppWindowToken wtoken; |
| 7082 | int mode; |
| 7083 | if (i < NC) { |
| 7084 | wtoken = mClosingApps.get(i); |
| 7085 | mode = 1; |
| 7086 | } else { |
| 7087 | wtoken = mOpeningApps.get(i-NC); |
| 7088 | mode = 2; |
| 7089 | } |
| 7090 | if (mLowerWallpaperTarget != null) { |
| 7091 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 7092 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 7093 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7094 | } |
| 7095 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7096 | if (wtoken.appFullscreen) { |
| 7097 | WindowState ws = wtoken.findMainWindow(); |
| 7098 | if (ws != null) { |
| 7099 | // If this is a compatibility mode |
| 7100 | // window, we will always use its anim. |
| 7101 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7102 | animLp = ws.mAttrs; |
| 7103 | bestAnimLayer = Integer.MAX_VALUE; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7104 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7105 | animLp = ws.mAttrs; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7106 | bestAnimLayer = ws.mLayer; |
| 7107 | } |
| 7108 | fullscreenAnim = true; |
| 7109 | } |
| 7110 | } else if (!fullscreenAnim) { |
| 7111 | WindowState ws = wtoken.findMainWindow(); |
| 7112 | if (ws != null) { |
| 7113 | if (ws.mLayer > bestAnimLayer) { |
| 7114 | animLp = ws.mAttrs; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7115 | bestAnimLayer = ws.mLayer; |
| 7116 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7117 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7118 | } |
| 7119 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7120 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7121 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7122 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7123 | "Wallpaper animation!"); |
| 7124 | switch (transit) { |
| 7125 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 7126 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 7127 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 7128 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 7129 | break; |
| 7130 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 7131 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 7132 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 7133 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 7134 | break; |
| 7135 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7136 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7137 | "New transit: " + transit); |
| 7138 | } else if (oldWallpaper != null) { |
| 7139 | // We are transitioning from an activity with |
| 7140 | // a wallpaper to one without. |
| 7141 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7142 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7143 | "New transit away from wallpaper: " + transit); |
| 7144 | } else if (mWallpaperTarget != null) { |
| 7145 | // We are transitioning from an activity without |
| 7146 | // a wallpaper to now showing the wallpaper |
| 7147 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7148 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7149 | "New transit into wallpaper: " + transit); |
| 7150 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7151 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7152 | // If all closing windows are obscured, then there is |
| 7153 | // no need to do an animation. This is the case, for |
| 7154 | // example, when this transition is being done behind |
| 7155 | // the lock screen. |
| 7156 | if (!mPolicy.allowAppAnimationsLw()) { |
| 7157 | animLp = null; |
| 7158 | } |
| 7159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7160 | NN = mOpeningApps.size(); |
| 7161 | for (i=0; i<NN; i++) { |
| 7162 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7163 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7164 | "Now opening app" + wtoken); |
| 7165 | wtoken.reportedVisible = false; |
| 7166 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 7167 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7168 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7169 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7170 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7171 | wtoken.showAllWindowsLocked(); |
| 7172 | } |
| 7173 | NN = mClosingApps.size(); |
| 7174 | for (i=0; i<NN; i++) { |
| 7175 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7176 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7177 | "Now closing app" + wtoken); |
| 7178 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 7179 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7180 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7181 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7182 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7183 | // Force the allDrawn flag, because we want to start |
| 7184 | // this guy's animations regardless of whether it's |
| 7185 | // gotten drawn. |
| 7186 | wtoken.allDrawn = true; |
| 7187 | } |
| 7188 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 7189 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | mOpeningApps.clear(); |
| 7192 | mClosingApps.clear(); |
| 7193 | |
| 7194 | // This has changed the visibility of windows, so perform |
| 7195 | // a new layout to get them all up-to-date. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7196 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 7197 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7198 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 7199 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 7200 | assignLayersLocked(); |
| 7201 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 7202 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 7203 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7204 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | } |
| 7206 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7207 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7208 | int adjResult = 0; |
| 7209 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7210 | if (!animating && mAppTransitionRunning) { |
| 7211 | // We have finished the animation of an app transition. To do |
| 7212 | // this, we have delayed a lot of operations like showing and |
| 7213 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 7214 | // reflects the correct Z-order, but the window list may now |
| 7215 | // be out of sync with it. So here we will just rebuild the |
| 7216 | // entire app window list. Fun! |
| 7217 | mAppTransitionRunning = false; |
| 7218 | // Clear information about apps that were moving. |
| 7219 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7220 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7221 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7222 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7223 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7224 | moveInputMethodWindowsIfNeededLocked(false); |
| 7225 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 7226 | // Since the window list has been rebuilt, focus might |
| 7227 | // have to be recomputed since the actual order of windows |
| 7228 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7229 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7230 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7231 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7232 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7233 | // At this point, there was a window with a wallpaper that |
| 7234 | // was force hiding other windows behind it, but now it |
| 7235 | // is going away. This may be simple -- just animate |
| 7236 | // away the wallpaper and its window -- or it may be |
| 7237 | // hard -- the wallpaper now needs to be shown behind |
| 7238 | // something that was hidden. |
| 7239 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7240 | if (mLowerWallpaperTarget != null |
| 7241 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7242 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7243 | "wallpaperForceHiding changed with lower=" |
| 7244 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7245 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7246 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 7247 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 7248 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 7249 | // The lower target has become hidden before we |
| 7250 | // actually started the animation... let's completely |
| 7251 | // re-evaluate everything. |
| 7252 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7253 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7254 | } |
| 7255 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7256 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7257 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7258 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7259 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7260 | + " NEW: " + mWallpaperTarget |
| 7261 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7262 | if (mLowerWallpaperTarget == null) { |
| 7263 | // Whoops, we don't need a special wallpaper animation. |
| 7264 | // Clear them out. |
| 7265 | forceHiding = false; |
| 7266 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7267 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7268 | if (w.mSurface != null) { |
| 7269 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 7270 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7271 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7272 | forceHiding = true; |
| 7273 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 7274 | if (!w.mAnimating) { |
| 7275 | // We set the animation above so it |
| 7276 | // is not yet running. |
| 7277 | w.clearAnimation(); |
| 7278 | } |
| 7279 | } |
| 7280 | } |
| 7281 | } |
| 7282 | } |
| 7283 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7284 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7285 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 7286 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 7287 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 7288 | + windowDetachedWallpaper); |
| 7289 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 7290 | wallpaperMayChange = true; |
| 7291 | } |
| 7292 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7293 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7294 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7295 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7296 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7297 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7298 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7299 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7300 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7301 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7302 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7303 | assignLayersLocked(); |
| 7304 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7305 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7306 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7307 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7308 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7309 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7310 | if (mFocusMayChange) { |
| 7311 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 7312 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 7313 | false /*updateInputWindows*/)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7314 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7315 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7316 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7317 | } |
| 7318 | |
| 7319 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7320 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7321 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7322 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7323 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 7324 | + Integer.toHexString(changes)); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7325 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | |
| 7327 | // THIRD LOOP: Update the surfaces of all windows. |
| 7328 | |
| 7329 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 7330 | |
| 7331 | boolean obscured = false; |
| 7332 | boolean blurring = false; |
| 7333 | boolean dimming = false; |
| 7334 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7335 | boolean syswin = false; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7336 | boolean backgroundFillerWasShown = mBackgroundFillerTarget != null; |
| 7337 | mBackgroundFillerTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7338 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7339 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7341 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7342 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7343 | |
| 7344 | boolean displayed = false; |
| 7345 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 7346 | final int attrFlags = attrs.flags; |
| 7347 | |
| 7348 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7349 | // XXX NOTE: The logic here could be improved. We have |
| 7350 | // the decision about whether to resize a window separated |
| 7351 | // from whether to hide the surface. This can cause us to |
| 7352 | // resize a surface even if we are going to hide it. You |
| 7353 | // can see this by (1) holding device in landscape mode on |
| 7354 | // home screen; (2) tapping browser icon (device will rotate |
| 7355 | // to landscape; (3) tap home. The wallpaper will be resized |
| 7356 | // in step 2 but then immediately hidden, causing us to |
| 7357 | // have to resize and then redraw it again in step 3. It |
| 7358 | // would be nice to figure out how to avoid this, but it is |
| 7359 | // difficult because we do need to resize surfaces in some |
| 7360 | // cases while they are hidden such as when first showing a |
| 7361 | // window. |
| 7362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7363 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7364 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 7366 | + ": new=" + w.mShownFrame + ", old=" |
| 7367 | + w.mLastShownFrame); |
| 7368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7369 | int width, height; |
| 7370 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | // for a scaled surface, we just want to use |
| 7372 | // the requested size. |
| 7373 | width = w.mRequestedWidth; |
| 7374 | height = w.mRequestedHeight; |
| 7375 | w.mLastRequestedWidth = width; |
| 7376 | w.mLastRequestedHeight = height; |
| 7377 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7378 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | width = w.mShownFrame.width(); |
| 7380 | height = w.mShownFrame.height(); |
| 7381 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7382 | } |
| 7383 | |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7384 | if (w.mSurface != null) { |
| 7385 | if (w.mSurfaceX != w.mShownFrame.left |
| 7386 | || w.mSurfaceY != w.mShownFrame.top) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7388 | if (SHOW_TRANSACTIONS) logSurface(w, |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7389 | "POS " + w.mShownFrame.left |
| 7390 | + ", " + w.mShownFrame.top, null); |
| 7391 | w.mSurfaceX = w.mShownFrame.left; |
| 7392 | w.mSurfaceY = w.mShownFrame.top; |
| 7393 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 7394 | } catch (RuntimeException e) { |
| 7395 | Slog.w(TAG, "Error positioning surface of " + w |
| 7396 | + " pos=(" + w.mShownFrame.left |
| 7397 | + "," + w.mShownFrame.top + ")", e); |
| 7398 | if (!recoveringMemory) { |
| 7399 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 7400 | } |
| 7401 | } |
| 7402 | } |
| 7403 | |
| 7404 | if (width < 1) { |
| 7405 | width = 1; |
| 7406 | } |
| 7407 | if (height < 1) { |
| 7408 | height = 1; |
| 7409 | } |
| 7410 | |
| 7411 | if (w.mSurfaceW != width || w.mSurfaceH != height) { |
| 7412 | try { |
| 7413 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7414 | "SIZE " + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7415 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7416 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7417 | w.mSurfaceW = width; |
| 7418 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | w.mSurface.setSize(width, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7420 | } catch (RuntimeException e) { |
| 7421 | // If something goes wrong with the surface (such |
| 7422 | // as running out of memory), don't take down the |
| 7423 | // entire system. |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7424 | Slog.e(TAG, "Error resizing surface of " + w |
| 7425 | + " size=(" + width + "x" + height + ")", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7426 | if (!recoveringMemory) { |
| 7427 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 7428 | } |
| 7429 | } |
| 7430 | } |
| 7431 | } |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7432 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7433 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7434 | w.mContentInsetsChanged = |
| 7435 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 7436 | w.mVisibleInsetsChanged = |
| 7437 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7438 | boolean configChanged = |
| 7439 | w.mConfiguration != mCurConfiguration |
| 7440 | && (w.mConfiguration == null |
| 7441 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7442 | if (DEBUG_CONFIGURATION && configChanged) { |
| 7443 | Slog.v(TAG, "Win " + w + " config changed: " |
| 7444 | + mCurConfiguration); |
| 7445 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7446 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7447 | + ": configChanged=" + configChanged |
| 7448 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7449 | boolean frameChanged = !w.mLastFrame.equals(w.mFrame); |
| 7450 | if (frameChanged |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7451 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7452 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7453 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7454 | || configChanged) { |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7455 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 7456 | Slog.v(TAG, "Resize reasons: " |
| 7457 | + "frameChanged=" + frameChanged |
| 7458 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 7459 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
| 7460 | + " surfaceResized=" + w.mSurfaceResized |
| 7461 | + " configChanged=" + configChanged); |
| 7462 | } |
| 7463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | w.mLastFrame.set(w.mFrame); |
| 7465 | w.mLastContentInsets.set(w.mContentInsets); |
| 7466 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7467 | // If the screen is currently frozen, then keep |
| 7468 | // it frozen until this window draws at its new |
| 7469 | // orientation. |
| 7470 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7471 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7472 | "Resizing while display frozen: " + w); |
| 7473 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7474 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7475 | mWindowsFreezingScreen = true; |
| 7476 | // XXX should probably keep timeout from |
| 7477 | // when we first froze the display. |
| 7478 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 7479 | mH.sendMessageDelayed(mH.obtainMessage( |
| 7480 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 7481 | } |
| 7482 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | // If the orientation is changing, then we need to |
| 7484 | // hold off on unfreezing the display until this |
| 7485 | // window has been redrawn; to do that, we need |
| 7486 | // to go through the process of getting informed |
| 7487 | // by the application when it has finished drawing. |
| 7488 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7489 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7490 | "Orientation start waiting for draw in " |
| 7491 | + w + ", surface " + w.mSurface); |
| 7492 | w.mDrawPending = true; |
| 7493 | w.mCommitDrawPending = false; |
| 7494 | w.mReadyToShow = false; |
| 7495 | if (w.mAppToken != null) { |
| 7496 | w.mAppToken.allDrawn = false; |
| 7497 | } |
| 7498 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7499 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7500 | "Resizing window " + w + " to " + w.mFrame); |
| 7501 | mResizingWindows.add(w); |
| 7502 | } else if (w.mOrientationChanging) { |
| 7503 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7504 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7505 | "Orientation not waiting for draw in " |
| 7506 | + w + ", surface " + w.mSurface); |
| 7507 | w.mOrientationChanging = false; |
| 7508 | } |
| 7509 | } |
| 7510 | } |
| 7511 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7512 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7513 | if (!w.mLastHidden) { |
| 7514 | //dump(); |
| 7515 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7516 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7517 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7519 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7520 | try { |
| 7521 | w.mSurface.hide(); |
| 7522 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7523 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7524 | } |
| 7525 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | } |
| 7527 | // If we are waiting for this window to handle an |
| 7528 | // orientation change, well, it is hidden, so |
| 7529 | // doesn't really matter. Note that this does |
| 7530 | // introduce a potential glitch if the window |
| 7531 | // becomes unhidden before it has drawn for the |
| 7532 | // new orientation. |
| 7533 | if (w.mOrientationChanging) { |
| 7534 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7535 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7536 | "Orientation change skips hidden " + w); |
| 7537 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7538 | } else if (w.mLastLayer != w.mAnimLayer |
| 7539 | || w.mLastAlpha != w.mShownAlpha |
| 7540 | || w.mLastDsDx != w.mDsDx |
| 7541 | || w.mLastDtDx != w.mDtDx |
| 7542 | || w.mLastDsDy != w.mDsDy |
| 7543 | || w.mLastDtDy != w.mDtDy |
| 7544 | || w.mLastHScale != w.mHScale |
| 7545 | || w.mLastVScale != w.mVScale |
| 7546 | || w.mLastHidden) { |
| 7547 | displayed = true; |
| 7548 | w.mLastAlpha = w.mShownAlpha; |
| 7549 | w.mLastLayer = w.mAnimLayer; |
| 7550 | w.mLastDsDx = w.mDsDx; |
| 7551 | w.mLastDtDx = w.mDtDx; |
| 7552 | w.mLastDsDy = w.mDsDy; |
| 7553 | w.mLastDtDy = w.mDtDy; |
| 7554 | w.mLastHScale = w.mHScale; |
| 7555 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7556 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7557 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7558 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 7559 | + "," + (w.mDtDx*w.mVScale) |
| 7560 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7561 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | if (w.mSurface != null) { |
| 7563 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7564 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7566 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | w.mSurface.setLayer(w.mAnimLayer); |
| 7568 | w.mSurface.setMatrix( |
| 7569 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 7570 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 7571 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7572 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7573 | if (!recoveringMemory) { |
| 7574 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 7575 | } |
| 7576 | } |
| 7577 | } |
| 7578 | |
| 7579 | if (w.mLastHidden && !w.mDrawPending |
| 7580 | && !w.mCommitDrawPending |
| 7581 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7582 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7583 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7584 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7585 | + " during relayout"); |
| 7586 | if (showSurfaceRobustlyLocked(w)) { |
| 7587 | w.mHasDrawn = true; |
| 7588 | w.mLastHidden = false; |
| 7589 | } else { |
| 7590 | w.mOrientationChanging = false; |
| 7591 | } |
| 7592 | } |
| 7593 | if (w.mSurface != null) { |
| 7594 | w.mToken.hasVisible = true; |
| 7595 | } |
| 7596 | } else { |
| 7597 | displayed = true; |
| 7598 | } |
| 7599 | |
| 7600 | if (displayed) { |
| 7601 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7602 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 7603 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7604 | covered = true; |
| 7605 | } |
| 7606 | } |
| 7607 | if (w.mOrientationChanging) { |
| 7608 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 7609 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7610 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | "Orientation continue waiting for draw in " + w); |
| 7612 | } else { |
| 7613 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7614 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7615 | "Orientation change complete in " + w); |
| 7616 | } |
| 7617 | } |
| 7618 | w.mToken.hasVisible = true; |
| 7619 | } |
| 7620 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7621 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | "Orientation change skips hidden " + w); |
| 7623 | w.mOrientationChanging = false; |
| 7624 | } |
| 7625 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7626 | if (w.mContentChanged) { |
| 7627 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 7628 | w.mContentChanged = false; |
| 7629 | } |
| 7630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7631 | final boolean canBeSeen = w.isDisplayedLw(); |
| 7632 | |
| 7633 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 7634 | focusDisplayed = true; |
| 7635 | } |
| 7636 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7637 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7638 | |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7639 | if (mBackgroundFillerTarget != null) { |
| 7640 | if (w.isAnimating()) { |
| 7641 | // Background filler is below all other windows that |
| 7642 | // are animating. |
| 7643 | mBackgroundFillerTarget = w; |
| 7644 | } else if (w.mIsWallpaper) { |
| 7645 | mBackgroundFillerTarget = w; |
| 7646 | } |
| 7647 | } |
| 7648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7650 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7651 | if (w.mSurface != null) { |
| 7652 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 7653 | holdScreen = w.mSession; |
| 7654 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7655 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 7656 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7657 | screenBrightness = w.mAttrs.screenBrightness; |
| 7658 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 7659 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 7660 | && buttonBrightness < 0) { |
| 7661 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 7662 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 7663 | if (canBeSeen |
| 7664 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 7665 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 7666 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7667 | syswin = true; |
| 7668 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7669 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7670 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7671 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 7672 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7673 | // This window completely covers everything behind it, |
| 7674 | // so we want to leave all of them as unblurred (for |
| 7675 | // performance reasons). |
| 7676 | obscured = true; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7677 | } else if (w.needsBackgroundFiller(dw, dh) && (canBeSeen || w.isAnimating())) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7678 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7679 | obscured = true; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7680 | mBackgroundFillerTarget = w; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7681 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7682 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7683 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7684 | + ": blurring=" + blurring |
| 7685 | + " obscured=" + obscured |
| 7686 | + " displayed=" + displayed); |
| 7687 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 7688 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7689 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7691 | if (mDimAnimator == null) { |
| 7692 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7693 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7694 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7695 | mDimAnimator.updateParameters(mContext.getResources(), |
| 7696 | w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | } |
| 7699 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 7700 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7701 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7702 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | if (mBlurSurface == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7704 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7705 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7706 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7707 | -1, 16, 16, |
| 7708 | PixelFormat.OPAQUE, |
| 7709 | Surface.FX_SURFACE_BLUR); |
| 7710 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7711 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | } |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7713 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7714 | + mBlurSurface + ": CREATE"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7716 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7717 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7718 | + mBlurSurface + ": pos=(0,0) (" + |
| 7719 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7720 | mBlurSurface.setPosition(0, 0); |
| 7721 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7722 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 7723 | if (!mBlurShown) { |
| 7724 | try { |
| 7725 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7726 | + mBlurSurface + ": SHOW"); |
| 7727 | mBlurSurface.show(); |
| 7728 | } catch (RuntimeException e) { |
| 7729 | Slog.w(TAG, "Failure showing blur surface", e); |
| 7730 | } |
| 7731 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | } |
| 7733 | } |
| 7734 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | } |
| 7736 | } |
| 7737 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7738 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7739 | if (obscuredChanged && mWallpaperTarget == w) { |
| 7740 | // This is the wallpaper target and its obscured state |
| 7741 | // changed... make sure the current wallaper's visibility |
| 7742 | // has been updated accordingly. |
| 7743 | updateWallpaperVisibilityLocked(); |
| 7744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7745 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7746 | |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7747 | if (mBackgroundFillerTarget != null) { |
| 7748 | if (mBackgroundFillerSurface == null) { |
| 7749 | try { |
| 7750 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 7751 | "BackGroundFiller", |
| 7752 | 0, dw, dh, |
| 7753 | PixelFormat.OPAQUE, |
| 7754 | Surface.FX_SURFACE_NORMAL); |
| 7755 | } catch (Exception e) { |
| 7756 | Slog.e(TAG, "Exception creating filler surface", e); |
| 7757 | } |
| 7758 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7759 | + mBackgroundFillerSurface + ": CREATE"); |
| 7760 | } |
| 7761 | try { |
| 7762 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7763 | + mBackgroundFillerSurface + " SHOW: pos=(0,0) (" |
| 7764 | + dw + "x" + dh + ") layer=" |
| 7765 | + (mBackgroundFillerTarget.mLayer - 1)); |
| 7766 | mBackgroundFillerSurface.setPosition(0, 0); |
| 7767 | mBackgroundFillerSurface.setSize(dw, dh); |
| 7768 | // Using the same layer as Dim because they will never be shown at the |
| 7769 | // same time. NOTE: we do NOT use mAnimLayer, because we don't |
| 7770 | // want this surface dragged up in front of stuff that is animating. |
| 7771 | mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer - 1); |
| 7772 | mBackgroundFillerSurface.show(); |
| 7773 | } catch (RuntimeException e) { |
| 7774 | Slog.e(TAG, "Exception showing filler surface"); |
| 7775 | } |
| 7776 | } else if (backgroundFillerWasShown) { |
| 7777 | mBackgroundFillerTarget = null; |
| 7778 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7779 | + mBackgroundFillerSurface + " HIDE"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7780 | try { |
| 7781 | mBackgroundFillerSurface.hide(); |
| 7782 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7783 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7784 | } |
| 7785 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7787 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7788 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 7789 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7792 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7793 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7794 | + ": HIDE"); |
| 7795 | try { |
| 7796 | mBlurSurface.hide(); |
| 7797 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7798 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7799 | } |
| 7800 | mBlurShown = false; |
| 7801 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7802 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7803 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | } |
| 7805 | |
| 7806 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7807 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7808 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 7809 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 7810 | if (mWatermark != null) { |
| 7811 | mWatermark.drawIfNeeded(); |
| 7812 | } |
| 7813 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7814 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7815 | "With display frozen, orientationChangeComplete=" |
| 7816 | + orientationChangeComplete); |
| 7817 | if (orientationChangeComplete) { |
| 7818 | if (mWindowsFreezingScreen) { |
| 7819 | mWindowsFreezingScreen = false; |
| 7820 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 7821 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7822 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7823 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7825 | i = mResizingWindows.size(); |
| 7826 | if (i > 0) { |
| 7827 | do { |
| 7828 | i--; |
| 7829 | WindowState win = mResizingWindows.get(i); |
| 7830 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7831 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 7832 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7833 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7834 | boolean configChanged = |
| 7835 | win.mConfiguration != mCurConfiguration |
| 7836 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7837 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 7838 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 7839 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7840 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7841 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7842 | + " / " + mCurConfiguration + " / 0x" |
| 7843 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7844 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7845 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7846 | win.mClient.resized(win.mFrame.width(), |
| 7847 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7848 | win.mLastVisibleInsets, win.mDrawPending, |
| 7849 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7850 | win.mContentInsetsChanged = false; |
| 7851 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7852 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7853 | } catch (RemoteException e) { |
| 7854 | win.mOrientationChanging = false; |
| 7855 | } |
| 7856 | } while (i > 0); |
| 7857 | mResizingWindows.clear(); |
| 7858 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7860 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7861 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7862 | i = mDestroySurface.size(); |
| 7863 | if (i > 0) { |
| 7864 | do { |
| 7865 | i--; |
| 7866 | WindowState win = mDestroySurface.get(i); |
| 7867 | win.mDestroying = false; |
| 7868 | if (mInputMethodWindow == win) { |
| 7869 | mInputMethodWindow = null; |
| 7870 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7871 | if (win == mWallpaperTarget) { |
| 7872 | wallpaperDestroyed = true; |
| 7873 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7874 | win.destroySurfaceLocked(); |
| 7875 | } while (i > 0); |
| 7876 | mDestroySurface.clear(); |
| 7877 | } |
| 7878 | |
| 7879 | // Time to remove any exiting tokens? |
| 7880 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 7881 | WindowToken token = mExitingTokens.get(i); |
| 7882 | if (!token.hasVisible) { |
| 7883 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7884 | if (token.windowType == TYPE_WALLPAPER) { |
| 7885 | mWallpaperTokens.remove(token); |
| 7886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7887 | } |
| 7888 | } |
| 7889 | |
| 7890 | // Time to remove any exiting applications? |
| 7891 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 7892 | AppWindowToken token = mExitingAppTokens.get(i); |
| 7893 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7894 | // Make sure there is no animation running on this token, |
| 7895 | // so any windows associated with it will be removed as |
| 7896 | // soon as their animations are complete |
| 7897 | token.animation = null; |
| 7898 | token.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7899 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 7900 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7901 | mAppTokens.remove(token); |
| 7902 | mExitingAppTokens.remove(i); |
| 7903 | } |
| 7904 | } |
| 7905 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7906 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7907 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7908 | if (!animating && mAppTransitionRunning) { |
| 7909 | // We have finished the animation of an app transition. To do |
| 7910 | // this, we have delayed a lot of operations like showing and |
| 7911 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 7912 | // reflects the correct Z-order, but the window list may now |
| 7913 | // be out of sync with it. So here we will just rebuild the |
| 7914 | // entire app window list. Fun! |
| 7915 | mAppTransitionRunning = false; |
| 7916 | needRelayout = true; |
| 7917 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7918 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7919 | // Clear information about apps that were moving. |
| 7920 | mToBottomApps.clear(); |
| 7921 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | if (focusDisplayed) { |
| 7924 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 7925 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7926 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7927 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7928 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7929 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7930 | requestAnimationLocked(0); |
| 7931 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7932 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 7933 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 7934 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 7935 | // Finally update all input windows now that the window changes have stabilized. |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 7936 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 7937 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 7938 | setHoldScreenLocked(holdScreen != null); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 7939 | if (!mDisplayFrozen) { |
| 7940 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 7941 | mPowerManager.setScreenBrightnessOverride(-1); |
| 7942 | } else { |
| 7943 | mPowerManager.setScreenBrightnessOverride((int) |
| 7944 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 7945 | } |
| 7946 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 7947 | mPowerManager.setButtonBrightnessOverride(-1); |
| 7948 | } else { |
| 7949 | mPowerManager.setButtonBrightnessOverride((int) |
| 7950 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 7951 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 7952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | if (holdScreen != mHoldingScreenOn) { |
| 7954 | mHoldingScreenOn = holdScreen; |
| 7955 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 7956 | mH.sendMessage(m); |
| 7957 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7958 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7959 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7960 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7961 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 7962 | LocalPowerManager.BUTTON_EVENT, true); |
| 7963 | mTurnOnScreen = false; |
| 7964 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7965 | |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 7966 | if (screenRotationFinished && mScreenRotationAnimation != null) { |
| 7967 | mScreenRotationAnimation.kill(); |
| 7968 | mScreenRotationAnimation = null; |
| 7969 | } |
| 7970 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 7971 | if (updateRotation) { |
| 7972 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 7973 | boolean changed = setRotationUncheckedLocked( |
| 7974 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 7975 | if (changed) { |
Dianne Hackborn | 3e4f9d0 | 2011-02-04 14:05:55 -0800 | [diff] [blame] | 7976 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 7977 | } |
| 7978 | } |
| 7979 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7980 | // Check to see if we are now in a state where the screen should |
| 7981 | // be enabled, because the window obscured flags have changed. |
| 7982 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7983 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7984 | |
| 7985 | /** |
| 7986 | * Must be called with the main window manager lock held. |
| 7987 | */ |
| 7988 | void setHoldScreenLocked(boolean holding) { |
| 7989 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 7990 | if (holding != state) { |
| 7991 | if (holding) { |
| 7992 | mHoldingScreenWakeLock.acquire(); |
| 7993 | } else { |
| 7994 | mPolicy.screenOnStoppedLw(); |
| 7995 | mHoldingScreenWakeLock.release(); |
| 7996 | } |
| 7997 | } |
| 7998 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7999 | |
| 8000 | void requestAnimationLocked(long delay) { |
| 8001 | if (!mAnimationPending) { |
| 8002 | mAnimationPending = true; |
| 8003 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 8004 | } |
| 8005 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8007 | /** |
| 8008 | * Have the surface flinger show a surface, robustly dealing with |
| 8009 | * error conditions. In particular, if there is not enough memory |
| 8010 | * to show the surface, then we will try to get rid of other surfaces |
| 8011 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8012 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8013 | * @return Returns true if the surface was successfully shown. |
| 8014 | */ |
| 8015 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 8016 | try { |
| 8017 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8018 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8019 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8020 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8021 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8022 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8023 | win.mTurnOnScreen = false; |
| 8024 | mTurnOnScreen = true; |
| 8025 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8026 | } |
| 8027 | return true; |
| 8028 | } catch (RuntimeException e) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8029 | Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8030 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8032 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8034 | return false; |
| 8035 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8037 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 8038 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8039 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8040 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8042 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8043 | if (mForceRemoves == null) { |
| 8044 | mForceRemoves = new ArrayList<WindowState>(); |
| 8045 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8047 | long callingIdentity = Binder.clearCallingIdentity(); |
| 8048 | try { |
| 8049 | // There was some problem... first, do a sanity check of the |
| 8050 | // window list to make sure we haven't left any dangling surfaces |
| 8051 | // around. |
| 8052 | int N = mWindows.size(); |
| 8053 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8054 | Slog.i(TAG, "Out of memory for surface! Looking for leaks..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8056 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8057 | if (ws.mSurface != null) { |
| 8058 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8059 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8060 | + ws + " surface=" + ws.mSurface |
| 8061 | + " token=" + win.mToken |
| 8062 | + " pid=" + ws.mSession.mPid |
| 8063 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8064 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8065 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8066 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8067 | ws.mSurface = null; |
| 8068 | mForceRemoves.add(ws); |
| 8069 | i--; |
| 8070 | N--; |
| 8071 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8072 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8073 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8074 | + ws + " surface=" + ws.mSurface |
| 8075 | + " token=" + win.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8076 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8077 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8078 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8079 | ws.mSurface = null; |
| 8080 | leakedSurface = true; |
| 8081 | } |
| 8082 | } |
| 8083 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8085 | boolean killedApps = false; |
| 8086 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8087 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8088 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 8089 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8090 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | if (ws.mSurface != null) { |
| 8092 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 8093 | } |
| 8094 | } |
| 8095 | if (pidCandidates.size() > 0) { |
| 8096 | int[] pids = new int[pidCandidates.size()]; |
| 8097 | for (int i=0; i<pids.length; i++) { |
| 8098 | pids[i] = pidCandidates.keyAt(i); |
| 8099 | } |
| 8100 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 8101 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8102 | killedApps = true; |
| 8103 | } |
| 8104 | } catch (RemoteException e) { |
| 8105 | } |
| 8106 | } |
| 8107 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8109 | if (leakedSurface || killedApps) { |
| 8110 | // We managed to reclaim some memory, so get rid of the trouble |
| 8111 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8112 | Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8113 | if (surface != null) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8114 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8115 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8116 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8117 | win.mSurface = null; |
| 8118 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8120 | try { |
| 8121 | win.mClient.dispatchGetNewSurface(); |
| 8122 | } catch (RemoteException e) { |
| 8123 | } |
| 8124 | } |
| 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(callingIdentity); |
| 8127 | } |
| 8128 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8129 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8130 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8131 | WindowState newFocus = computeFocusedWindowLocked(); |
| 8132 | if (mCurrentFocus != newFocus) { |
| 8133 | // This check makes sure that we don't already have the focus |
| 8134 | // change message pending. |
| 8135 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 8136 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8137 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8138 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 8139 | final WindowState oldFocus = mCurrentFocus; |
| 8140 | mCurrentFocus = newFocus; |
| 8141 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8143 | final WindowState imWindow = mInputMethodWindow; |
| 8144 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8145 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8146 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8147 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 8148 | mLayoutNeeded = true; |
| 8149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8150 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8151 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8152 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 8153 | // Client will do the layout, but we need to assign layers |
| 8154 | // for handleNewWindowLocked() below. |
| 8155 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8156 | } |
| 8157 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8158 | |
| 8159 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 8160 | // If we defer assigning layers, then the caller is responsible for |
| 8161 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8162 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8163 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | return true; |
| 8165 | } |
| 8166 | return false; |
| 8167 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8168 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8169 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 8170 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8171 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8172 | |
| 8173 | private WindowState computeFocusedWindowLocked() { |
| 8174 | WindowState result = null; |
| 8175 | WindowState win; |
| 8176 | |
| 8177 | int i = mWindows.size() - 1; |
| 8178 | int nextAppIndex = mAppTokens.size()-1; |
| 8179 | WindowToken nextApp = nextAppIndex >= 0 |
| 8180 | ? mAppTokens.get(nextAppIndex) : null; |
| 8181 | |
| 8182 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8183 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8185 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8186 | TAG, "Looking for focus: " + i |
| 8187 | + " = " + win |
| 8188 | + ", flags=" + win.mAttrs.flags |
| 8189 | + ", canReceive=" + win.canReceiveKeys()); |
| 8190 | |
| 8191 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8193 | // If this window's application has been removed, just skip it. |
| 8194 | if (thisApp != null && thisApp.removed) { |
| 8195 | i--; |
| 8196 | continue; |
| 8197 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8199 | // If there is a focused app, don't allow focus to go to any |
| 8200 | // windows below it. If this is an application window, step |
| 8201 | // through the app tokens until we find its app. |
| 8202 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 8203 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 8204 | int origAppIndex = nextAppIndex; |
| 8205 | while (nextAppIndex > 0) { |
| 8206 | if (nextApp == mFocusedApp) { |
| 8207 | // Whoops, we are below the focused app... no focus |
| 8208 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8209 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8210 | TAG, "Reached focused app: " + mFocusedApp); |
| 8211 | return null; |
| 8212 | } |
| 8213 | nextAppIndex--; |
| 8214 | nextApp = mAppTokens.get(nextAppIndex); |
| 8215 | if (nextApp == thisApp) { |
| 8216 | break; |
| 8217 | } |
| 8218 | } |
| 8219 | if (thisApp != nextApp) { |
| 8220 | // Uh oh, the app token doesn't exist! This shouldn't |
| 8221 | // happen, but if it does we can get totally hosed... |
| 8222 | // so restart at the original app. |
| 8223 | nextAppIndex = origAppIndex; |
| 8224 | nextApp = mAppTokens.get(nextAppIndex); |
| 8225 | } |
| 8226 | } |
| 8227 | |
| 8228 | // Dispatch to this window if it is wants key events. |
| 8229 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8230 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8231 | TAG, "Found focus @ " + i + " = " + win); |
| 8232 | result = win; |
| 8233 | break; |
| 8234 | } |
| 8235 | |
| 8236 | i--; |
| 8237 | } |
| 8238 | |
| 8239 | return result; |
| 8240 | } |
| 8241 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8242 | private void startFreezingDisplayLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8243 | if (mDisplayFrozen) { |
| 8244 | return; |
| 8245 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8247 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8249 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8250 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8251 | if (mFreezeGcPending != 0) { |
| 8252 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8253 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8254 | mH.removeMessages(H.FORCE_GC); |
| 8255 | Runtime.getRuntime().gc(); |
| 8256 | mFreezeGcPending = now; |
| 8257 | } |
| 8258 | } else { |
| 8259 | mFreezeGcPending = now; |
| 8260 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8263 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8264 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8265 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8266 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 8267 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8268 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8269 | mAppTransitionReady = true; |
| 8270 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8272 | if (PROFILE_ORIENTATION) { |
| 8273 | File file = new File("/data/system/frozen"); |
| 8274 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 8275 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8276 | |
| 8277 | if (CUSTOM_SCREEN_ROTATION) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8278 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 8279 | mScreenRotationAnimation.kill(); |
| 8280 | mScreenRotationAnimation = null; |
| 8281 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8282 | if (mScreenRotationAnimation == null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8283 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8284 | mDisplay, mFxSession, inTransaction); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8285 | } |
| 8286 | } else { |
| 8287 | Surface.freezeDisplay(0); |
| 8288 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8289 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8291 | private void stopFreezingDisplayLocked() { |
| 8292 | if (!mDisplayFrozen) { |
| 8293 | return; |
| 8294 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8295 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8296 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 8297 | return; |
| 8298 | } |
| 8299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8300 | mDisplayFrozen = false; |
| 8301 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 8302 | if (PROFILE_ORIENTATION) { |
| 8303 | Debug.stopMethodTracing(); |
| 8304 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8305 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8306 | boolean updateRotation = false; |
| 8307 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8308 | if (CUSTOM_SCREEN_ROTATION) { |
| 8309 | if (mScreenRotationAnimation != null) { |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 8310 | if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION, |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8311 | mTransitionAnimationScale)) { |
| 8312 | requestAnimationLocked(0); |
| 8313 | } else { |
| 8314 | mScreenRotationAnimation = null; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8315 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8316 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8317 | } |
| 8318 | } else { |
| 8319 | Surface.unfreezeDisplay(0); |
| 8320 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8321 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8322 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8323 | |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8324 | boolean configChanged; |
| 8325 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 8326 | // While the display is frozen we don't re-compute the orientation |
| 8327 | // to avoid inconsistent states. However, something interesting |
| 8328 | // could have actually changed during that time so re-evaluate it |
| 8329 | // now to catch that. |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8330 | configChanged = updateOrientationFromAppTokensLocked(false); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 8331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | // A little kludge: a lot could have happened while the |
| 8333 | // display was frozen, so now that we are coming back we |
| 8334 | // do a gc so that any remote references the system |
| 8335 | // processes holds on others can be released if they are |
| 8336 | // no longer needed. |
| 8337 | mH.removeMessages(H.FORCE_GC); |
| 8338 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8339 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8341 | mScreenFrozenLock.release(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8342 | |
| 8343 | if (updateRotation) { |
| 8344 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8345 | configChanged |= setRotationUncheckedLocked( |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8346 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8347 | } |
| 8348 | |
| 8349 | if (configChanged) { |
| 8350 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8352 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8353 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8354 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 8355 | DisplayMetrics dm) { |
| 8356 | if (index < tokens.length) { |
| 8357 | String str = tokens[index]; |
| 8358 | if (str != null && str.length() > 0) { |
| 8359 | try { |
| 8360 | int val = Integer.parseInt(str); |
| 8361 | return val; |
| 8362 | } catch (Exception e) { |
| 8363 | } |
| 8364 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8365 | } |
| 8366 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 8367 | return defDps; |
| 8368 | } |
| 8369 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 8370 | return val; |
| 8371 | } |
| 8372 | |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8373 | void createWatermark() { |
| 8374 | if (mWatermark != null) { |
| 8375 | return; |
| 8376 | } |
| 8377 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8378 | File file = new File("/system/etc/setup.conf"); |
| 8379 | FileInputStream in = null; |
| 8380 | try { |
| 8381 | in = new FileInputStream(file); |
| 8382 | DataInputStream ind = new DataInputStream(in); |
| 8383 | String line = ind.readLine(); |
| 8384 | if (line != null) { |
| 8385 | String[] toks = line.split("%"); |
| 8386 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 8387 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8388 | } |
| 8389 | } |
| 8390 | } catch (FileNotFoundException e) { |
| 8391 | } catch (IOException e) { |
| 8392 | } finally { |
| 8393 | if (in != null) { |
| 8394 | try { |
| 8395 | in.close(); |
| 8396 | } catch (IOException e) { |
| 8397 | } |
| 8398 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8399 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8400 | } |
| 8401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8402 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8403 | public void statusBarVisibilityChanged(int visibility) { |
| 8404 | synchronized (mWindowMap) { |
| 8405 | final int N = mWindows.size(); |
| 8406 | for (int i = 0; i < N; i++) { |
| 8407 | WindowState ws = mWindows.get(i); |
| 8408 | try { |
| 8409 | if (ws.getAttrs().hasSystemUiListeners) { |
| 8410 | ws.mClient.dispatchSystemUiVisibilityChanged(visibility); |
| 8411 | } |
| 8412 | } catch (RemoteException e) { |
| 8413 | // so sorry |
| 8414 | } |
| 8415 | } |
| 8416 | } |
| 8417 | } |
| 8418 | |
| 8419 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8420 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 8421 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 8422 | != PackageManager.PERMISSION_GRANTED) { |
| 8423 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 8424 | + Binder.getCallingPid() |
| 8425 | + ", uid=" + Binder.getCallingUid()); |
| 8426 | return; |
| 8427 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8428 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8429 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 8430 | pw.println(" "); |
| 8431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | synchronized(mWindowMap) { |
| 8433 | pw.println("Current Window Manager state:"); |
| 8434 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8435 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8436 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 8437 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8438 | w.dump(pw, " "); |
| 8439 | } |
| 8440 | if (mInputMethodDialogs.size() > 0) { |
| 8441 | pw.println(" "); |
| 8442 | pw.println(" Input method dialogs:"); |
| 8443 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 8444 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8445 | pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8446 | } |
| 8447 | } |
| 8448 | if (mPendingRemove.size() > 0) { |
| 8449 | pw.println(" "); |
| 8450 | pw.println(" Remove pending for:"); |
| 8451 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 8452 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8453 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 8454 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8455 | w.dump(pw, " "); |
| 8456 | } |
| 8457 | } |
| 8458 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 8459 | pw.println(" "); |
| 8460 | pw.println(" Windows force removing:"); |
| 8461 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 8462 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8463 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 8464 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8465 | w.dump(pw, " "); |
| 8466 | } |
| 8467 | } |
| 8468 | if (mDestroySurface.size() > 0) { |
| 8469 | pw.println(" "); |
| 8470 | pw.println(" Windows waiting to destroy their surface:"); |
| 8471 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 8472 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8473 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 8474 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8475 | w.dump(pw, " "); |
| 8476 | } |
| 8477 | } |
| 8478 | if (mLosingFocus.size() > 0) { |
| 8479 | pw.println(" "); |
| 8480 | pw.println(" Windows losing focus:"); |
| 8481 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 8482 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8483 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 8484 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8485 | w.dump(pw, " "); |
| 8486 | } |
| 8487 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8488 | if (mResizingWindows.size() > 0) { |
| 8489 | pw.println(" "); |
| 8490 | pw.println(" Windows waiting to resize:"); |
| 8491 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 8492 | WindowState w = mResizingWindows.get(i); |
| 8493 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 8494 | pw.print(w); pw.println(":"); |
| 8495 | w.dump(pw, " "); |
| 8496 | } |
| 8497 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8498 | if (mSessions.size() > 0) { |
| 8499 | pw.println(" "); |
| 8500 | pw.println(" All active sessions:"); |
| 8501 | Iterator<Session> it = mSessions.iterator(); |
| 8502 | while (it.hasNext()) { |
| 8503 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8504 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8505 | s.dump(pw, " "); |
| 8506 | } |
| 8507 | } |
| 8508 | if (mTokenMap.size() > 0) { |
| 8509 | pw.println(" "); |
| 8510 | pw.println(" All tokens:"); |
| 8511 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 8512 | while (it.hasNext()) { |
| 8513 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8514 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8515 | token.dump(pw, " "); |
| 8516 | } |
| 8517 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8518 | if (mWallpaperTokens.size() > 0) { |
| 8519 | pw.println(" "); |
| 8520 | pw.println(" Wallpaper tokens:"); |
| 8521 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 8522 | WindowToken token = mWallpaperTokens.get(i); |
| 8523 | pw.print(" Wallpaper #"); pw.print(i); |
| 8524 | pw.print(' '); pw.print(token); pw.println(':'); |
| 8525 | token.dump(pw, " "); |
| 8526 | } |
| 8527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8528 | if (mAppTokens.size() > 0) { |
| 8529 | pw.println(" "); |
| 8530 | pw.println(" Application tokens in Z order:"); |
| 8531 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8532 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 8533 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8534 | } |
| 8535 | } |
| 8536 | if (mFinishedStarting.size() > 0) { |
| 8537 | pw.println(" "); |
| 8538 | pw.println(" Finishing start of application tokens:"); |
| 8539 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 8540 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8541 | pw.print(" Finished Starting #"); pw.print(i); |
| 8542 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8543 | token.dump(pw, " "); |
| 8544 | } |
| 8545 | } |
| 8546 | if (mExitingTokens.size() > 0) { |
| 8547 | pw.println(" "); |
| 8548 | pw.println(" Exiting tokens:"); |
| 8549 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 8550 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8551 | pw.print(" Exiting #"); pw.print(i); |
| 8552 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8553 | token.dump(pw, " "); |
| 8554 | } |
| 8555 | } |
| 8556 | if (mExitingAppTokens.size() > 0) { |
| 8557 | pw.println(" "); |
| 8558 | pw.println(" Exiting application tokens:"); |
| 8559 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8560 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8561 | pw.print(" Exiting App #"); pw.print(i); |
| 8562 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8563 | token.dump(pw, " "); |
| 8564 | } |
| 8565 | } |
| 8566 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8567 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 8568 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 8569 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 8570 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 8571 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 8572 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 8573 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 8574 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 8575 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 8576 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 8577 | if (mWindowDetachedWallpaper != null) { |
| 8578 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 8579 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8580 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 8581 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 8582 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8583 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 8584 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 8585 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 8586 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8587 | if (mDimAnimator != null) { |
| 8588 | mDimAnimator.printTo(pw); |
| 8589 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 8590 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8591 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8592 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8593 | pw.print(mInputMethodAnimLayerAdjustment); |
| 8594 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 8595 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 8596 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 8597 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8598 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 8599 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8600 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 8601 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8602 | pw.print(" mRotation="); pw.print(mRotation); |
| 8603 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 8604 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8605 | pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); |
| 8606 | pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8607 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 8608 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 8609 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 8610 | pw.print(" mNextAppTransition=0x"); |
| 8611 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 8612 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8613 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8614 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8615 | if (mNextAppTransitionPackage != null) { |
| 8616 | pw.print(" mNextAppTransitionPackage="); |
| 8617 | pw.print(mNextAppTransitionPackage); |
| 8618 | pw.print(", mNextAppTransitionEnter=0x"); |
| 8619 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 8620 | pw.print(", mNextAppTransitionExit=0x"); |
| 8621 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 8622 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8623 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 8624 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 8625 | if (mOpeningApps.size() > 0) { |
| 8626 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 8627 | } |
| 8628 | if (mClosingApps.size() > 0) { |
| 8629 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 8630 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8631 | if (mToTopApps.size() > 0) { |
| 8632 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 8633 | } |
| 8634 | if (mToBottomApps.size() > 0) { |
| 8635 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 8636 | } |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 8637 | if (mDisplay != null) { |
| 8638 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 8639 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 8640 | } else { |
| 8641 | pw.println(" NO DISPLAY"); |
| 8642 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8643 | pw.println(" Policy:"); |
| 8644 | mPolicy.dump(" ", fd, pw, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | } |
| 8646 | } |
| 8647 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8648 | // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8649 | public void monitor() { |
| 8650 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 8651 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 8652 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8653 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 8654 | public interface OnHardKeyboardStatusChangeListener { |
| 8655 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 8656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8657 | } |