| 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 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import static android.os.LocalPowerManager.CHEEK_EVENT; |
| 20 | import static android.os.LocalPowerManager.OTHER_EVENT; |
| 21 | import static android.os.LocalPowerManager.TOUCH_EVENT; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 22 | import static android.os.LocalPowerManager.LONG_TOUCH_EVENT; |
| 23 | import static android.os.LocalPowerManager.TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 25 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 26 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 32 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 33 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 36 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 38 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 39 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 40 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 41 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
| 44 | import com.android.internal.app.IBatteryStats; |
| 45 | import com.android.internal.policy.PolicyManager; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 46 | import com.android.internal.policy.impl.PhoneWindowManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import com.android.internal.view.IInputContext; |
| 48 | import com.android.internal.view.IInputMethodClient; |
| 49 | import com.android.internal.view.IInputMethodManager; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 50 | import com.android.internal.view.WindowManagerPolicyThread; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import com.android.server.KeyInputQueue.QueuedEvent; |
| 52 | import com.android.server.am.BatteryStatsService; |
| 53 | |
| 54 | import android.Manifest; |
| 55 | import android.app.ActivityManagerNative; |
| 56 | import android.app.IActivityManager; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 57 | import android.app.admin.DevicePolicyManager; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 58 | import android.content.BroadcastReceiver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.Context; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 60 | import android.content.Intent; |
| 61 | import android.content.IntentFilter; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.content.pm.ActivityInfo; |
| 63 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 64 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.content.res.Configuration; |
| 66 | import android.graphics.Matrix; |
| 67 | import android.graphics.PixelFormat; |
| 68 | import android.graphics.Rect; |
| 69 | import android.graphics.Region; |
| 70 | import android.os.BatteryStats; |
| 71 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 72 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.Debug; |
| 74 | import android.os.Handler; |
| 75 | import android.os.IBinder; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 76 | import android.os.LatencyTimer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.os.LocalPowerManager; |
| 78 | import android.os.Looper; |
| 79 | import android.os.Message; |
| 80 | import android.os.Parcel; |
| 81 | import android.os.ParcelFileDescriptor; |
| 82 | import android.os.Power; |
| 83 | import android.os.PowerManager; |
| 84 | import android.os.Process; |
| 85 | import android.os.RemoteException; |
| 86 | import android.os.ServiceManager; |
| 87 | import android.os.SystemClock; |
| 88 | import android.os.SystemProperties; |
| 89 | import android.os.TokenWatcher; |
| 90 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 91 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.util.EventLog; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 93 | import android.util.Log; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 94 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.util.SparseIntArray; |
| 96 | import android.view.Display; |
| 97 | import android.view.Gravity; |
| 98 | import android.view.IApplicationToken; |
| 99 | import android.view.IOnKeyguardExitResult; |
| 100 | import android.view.IRotationWatcher; |
| 101 | import android.view.IWindow; |
| 102 | import android.view.IWindowManager; |
| 103 | import android.view.IWindowSession; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 104 | import android.view.InputChannel; |
| 105 | import android.view.InputQueue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.KeyEvent; |
| 107 | import android.view.MotionEvent; |
| 108 | import android.view.RawInputEvent; |
| 109 | import android.view.Surface; |
| 110 | import android.view.SurfaceSession; |
| 111 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 112 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.ViewTreeObserver; |
| 114 | import android.view.WindowManager; |
| 115 | import android.view.WindowManagerImpl; |
| 116 | import android.view.WindowManagerPolicy; |
| 117 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 118 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | import android.view.animation.Animation; |
| 120 | import android.view.animation.AnimationUtils; |
| 121 | import android.view.animation.Transformation; |
| 122 | |
| 123 | import java.io.BufferedWriter; |
| 124 | import java.io.File; |
| 125 | import java.io.FileDescriptor; |
| 126 | import java.io.IOException; |
| 127 | import java.io.OutputStream; |
| 128 | import java.io.OutputStreamWriter; |
| 129 | import java.io.PrintWriter; |
| 130 | import java.io.StringWriter; |
| 131 | import java.net.Socket; |
| 132 | import java.util.ArrayList; |
| 133 | import java.util.HashMap; |
| 134 | import java.util.HashSet; |
| 135 | import java.util.Iterator; |
| 136 | import java.util.List; |
| 137 | |
| 138 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 139 | public class WindowManagerService extends IWindowManager.Stub |
| 140 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | static final String TAG = "WindowManager"; |
| 142 | static final boolean DEBUG = false; |
| 143 | static final boolean DEBUG_FOCUS = false; |
| 144 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 146 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_LAYERS = false; |
| 148 | static final boolean DEBUG_INPUT = false; |
| 149 | static final boolean DEBUG_INPUT_METHOD = false; |
| 150 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 151 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 153 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 155 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 156 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 157 | static final boolean DEBUG_WALLPAPER = false; |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 158 | static final boolean DEBUG_FREEZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 160 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 161 | static final boolean MEASURE_LATENCY = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 162 | static final boolean ENABLE_NATIVE_INPUT_DISPATCH = |
| 163 | WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 164 | static private LatencyTimer lt; |
| 165 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | static final boolean PROFILE_ORIENTATION = false; |
| 167 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 168 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 169 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 171 | static final int KEY_REPEAT_DELAY = 50; |
| 172 | |
| 173 | /** How much to multiply the policy's type layer, to reserve room |
| 174 | * for multiple windows of the same type and Z-ordering adjustment |
| 175 | * with TYPE_LAYER_OFFSET. */ |
| 176 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| 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 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 179 | * or below others in the same layer. */ |
| 180 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 181 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** How much to increment the layer for each window, to reserve room |
| 183 | * for effect surfaces between them. |
| 184 | */ |
| 185 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | /** The maximum length we will accept for a loaded animation duration: |
| 188 | * this is 10 seconds. |
| 189 | */ |
| 190 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 191 | |
| 192 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 193 | * value to another, when no window animation is driving it. |
| 194 | */ |
| 195 | static final int DEFAULT_DIM_DURATION = 200; |
| 196 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 197 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 198 | * compatible windows. |
| 199 | */ |
| 200 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 201 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 203 | */ |
| 204 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 205 | |
| 206 | // Maximum number of milliseconds to wait for input event injection. |
| 207 | // FIXME is this value reasonable? |
| 208 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 209 | |
| 210 | // Default input dispatching timeout in nanoseconds. |
| 211 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 212 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 213 | static final int INJECT_FAILED = 0; |
| 214 | static final int INJECT_SUCCEEDED = 1; |
| 215 | static final int INJECT_NO_PERMISSION = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 216 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 218 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 219 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 220 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 222 | /** The minimum time between dispatching touch events. */ |
| 223 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 224 | |
| 225 | // Last touch event time |
| 226 | long mLastTouchEventTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 227 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 228 | // Last touch event type |
| 229 | int mLastTouchEventType = OTHER_EVENT; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 230 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 231 | // Time to wait before calling useractivity again. This saves CPU usage |
| 232 | // when we get a flood of touch events. |
| 233 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 234 | |
| 235 | // Last time we call user activity |
| 236 | long mLastUserActivityCallTime = 0; |
| 237 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 238 | // Last time we updated battery stats |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 239 | long mLastBatteryStatsCallTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 242 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 246 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 247 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 248 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 250 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 252 | private static final int ALLOW_DISABLE_YES = 1; |
| 253 | private static final int ALLOW_DISABLE_NO = 0; |
| 254 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 255 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 256 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 257 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 258 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 260 | if (shouldAllowDisableKeyguard()) { |
| 261 | mPolicy.enableKeyguard(false); |
| 262 | mKeyguardDisabled = true; |
| 263 | } else { |
| 264 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 265 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | } |
| 267 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 268 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 269 | synchronized (mKeyguardTokenWatcher) { |
| 270 | mKeyguardDisabled = false; |
| 271 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | }; |
| 275 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 276 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 277 | @Override |
| 278 | public void onReceive(Context context, Intent intent) { |
| 279 | mPolicy.enableKeyguard(true); |
| 280 | synchronized(mKeyguardTokenWatcher) { |
| 281 | // lazily evaluate this next time we're asked to disable keyguard |
| 282 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 283 | mKeyguardDisabled = false; |
| 284 | } |
| 285 | } |
| 286 | }; |
| 287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | final Context mContext; |
| 289 | |
| 290 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 295 | |
| 296 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 297 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | /** |
| 301 | * All currently active sessions with clients. |
| 302 | */ |
| 303 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 304 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | /** |
| 306 | * Mapping from an IWindow IBinder to the server's Window object. |
| 307 | * This is also used as the lock for all of our state. |
| 308 | */ |
| 309 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 310 | |
| 311 | /** |
| 312 | * Mapping from a token IBinder to a WindowToken object. |
| 313 | */ |
| 314 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 315 | new HashMap<IBinder, WindowToken>(); |
| 316 | |
| 317 | /** |
| 318 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 319 | * over them. |
| 320 | */ |
| 321 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 322 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | /** |
| 324 | * Window tokens that are in the process of exiting, but still |
| 325 | * on screen for animations. |
| 326 | */ |
| 327 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 328 | |
| 329 | /** |
| 330 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 331 | * controlling the ordering of windows in different applications. This |
| 332 | * contains WindowToken objects. |
| 333 | */ |
| 334 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 335 | |
| 336 | /** |
| 337 | * Application tokens that are in the process of exiting, but still |
| 338 | * on screen for animations. |
| 339 | */ |
| 340 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 341 | |
| 342 | /** |
| 343 | * List of window tokens that have finished starting their application, |
| 344 | * and now need to have the policy remove their windows. |
| 345 | */ |
| 346 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 347 | |
| 348 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 349 | * This was the app token that was used to retrieve the last enter |
| 350 | * animation. It will be used for the next exit animation. |
| 351 | */ |
| 352 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 353 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 354 | /** |
| 355 | * These were the layout params used to retrieve the last enter animation. |
| 356 | * They will be used for the next exit animation. |
| 357 | */ |
| 358 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 359 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 360 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | * Z-ordered (bottom-most first) list of all Window objects. |
| 362 | */ |
| 363 | final ArrayList mWindows = new ArrayList(); |
| 364 | |
| 365 | /** |
| 366 | * Windows that are being resized. Used so we can tell the client about |
| 367 | * the resize after closing the transaction in which we resized the |
| 368 | * underlying surface. |
| 369 | */ |
| 370 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 371 | |
| 372 | /** |
| 373 | * Windows whose animations have ended and now must be removed. |
| 374 | */ |
| 375 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 376 | |
| 377 | /** |
| 378 | * Windows whose surface should be destroyed. |
| 379 | */ |
| 380 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 381 | |
| 382 | /** |
| 383 | * Windows that have lost input focus and are waiting for the new |
| 384 | * focus window to be displayed before they are told about this. |
| 385 | */ |
| 386 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 387 | |
| 388 | /** |
| 389 | * This is set when we have run out of memory, and will either be an empty |
| 390 | * list or contain windows that need to be force removed. |
| 391 | */ |
| 392 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | IInputMethodManager mInputMethodManager; |
| 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 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 397 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | Surface mBlurSurface; |
| 399 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | final float[] mTmpFloats = new float[9]; |
| 404 | |
| 405 | boolean mSafeMode; |
| 406 | boolean mDisplayEnabled = false; |
| 407 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 408 | int mInitialDisplayWidth = 0; |
| 409 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | int mRotation = 0; |
| 411 | int mRequestedRotation = 0; |
| 412 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 413 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | ArrayList<IRotationWatcher> mRotationWatchers |
| 415 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | boolean mLayoutNeeded = true; |
| 418 | boolean mAnimationPending = false; |
| 419 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 420 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | boolean mWindowsFreezingScreen = false; |
| 422 | long mFreezeGcPending = 0; |
| 423 | int mAppsFreezingScreen = 0; |
| 424 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 425 | int mLayoutSeq = 0; |
| 426 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 427 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 428 | boolean mFocusMayChange; |
| 429 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 430 | Configuration mCurConfiguration = new Configuration(); |
| 431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | // This is held as long as we have the screen frozen, to give us time to |
| 433 | // perform a rotation animation when turning off shows the lock screen which |
| 434 | // changes the orientation. |
| 435 | PowerManager.WakeLock mScreenFrozenLock; |
| 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 | // State management of app transitions. When we are preparing for a |
| 438 | // transition, mNextAppTransition will be the kind of transition to |
| 439 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 440 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 441 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 442 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 443 | String mNextAppTransitionPackage; |
| 444 | int mNextAppTransitionEnter; |
| 445 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 447 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | boolean mAppTransitionTimeout = false; |
| 449 | boolean mStartingIconInTransition = false; |
| 450 | boolean mSkipAppTransitionAnimation = false; |
| 451 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 452 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 453 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 454 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 457 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | H mH = new H(); |
| 459 | |
| 460 | WindowState mCurrentFocus = null; |
| 461 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | // This just indicates the window the input method is on top of, not |
| 464 | // necessarily the window its input is going to. |
| 465 | WindowState mInputMethodTarget = null; |
| 466 | WindowState mUpcomingInputMethodTarget = null; |
| 467 | boolean mInputMethodTargetWaitingAnim; |
| 468 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 469 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | WindowState mInputMethodWindow = null; |
| 471 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 472 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 473 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 474 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 475 | // If non-null, this is the currently visible window that is associated |
| 476 | // with the wallpaper. |
| 477 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 478 | // If non-null, we are in the middle of animating from one wallpaper target |
| 479 | // to another, and this is the lower one in Z-order. |
| 480 | WindowState mLowerWallpaperTarget = null; |
| 481 | // If non-null, we are in the middle of animating from one wallpaper target |
| 482 | // to another, and this is the higher one in Z-order. |
| 483 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 484 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 485 | float mLastWallpaperX = -1; |
| 486 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 487 | float mLastWallpaperXStep = -1; |
| 488 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 489 | boolean mSendingPointersToWallpaper = false; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 490 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 491 | // changing its scroll position. |
| 492 | WindowState mWaitingOnWallpaper; |
| 493 | // The last time we had a timeout when waiting for a wallpaper. |
| 494 | long mLastWallpaperTimeoutTime; |
| 495 | // We give a wallpaper up to 150ms to finish scrolling. |
| 496 | static final long WALLPAPER_TIMEOUT = 150; |
| 497 | // Time we wait after a timeout before trying to wait again. |
| 498 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 499 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | AppWindowToken mFocusedApp = null; |
| 501 | |
| 502 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | float mWindowAnimationScale = 1.0f; |
| 505 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 508 | final KeyQ mQueue; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 509 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | final InputDispatcherThread mInputThread; |
| 511 | |
| 512 | // Who is holding the screen on. |
| 513 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 514 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 515 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 516 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 517 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | /** |
| 519 | * Whether the UI is currently running in touch mode (not showing |
| 520 | * navigational focus because the user is directly pressing the screen). |
| 521 | */ |
| 522 | boolean mInTouchMode = false; |
| 523 | |
| 524 | private ViewServer mViewServer; |
| 525 | |
| 526 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 527 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 528 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 529 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 530 | |
| 531 | // The frame use to limit the size of the app running in compatibility mode. |
| 532 | Rect mCompatibleScreenFrame = new Rect(); |
| 533 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 534 | Surface mBackgroundFillerSurface = null; |
| 535 | boolean mBackgroundFillerShown = false; |
| 536 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | public static WindowManagerService main(Context context, |
| 538 | PowerManagerService pm, boolean haveInputMethods) { |
| 539 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 540 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 541 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | synchronized (thr) { |
| 543 | while (thr.mService == null) { |
| 544 | try { |
| 545 | thr.wait(); |
| 546 | } catch (InterruptedException e) { |
| 547 | } |
| 548 | } |
| 549 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 550 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | return thr.mService; |
| 552 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | static class WMThread extends Thread { |
| 555 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | private final Context mContext; |
| 558 | private final PowerManagerService mPM; |
| 559 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | public WMThread(Context context, PowerManagerService pm, |
| 562 | boolean haveInputMethods) { |
| 563 | super("WindowManager"); |
| 564 | mContext = context; |
| 565 | mPM = pm; |
| 566 | mHaveInputMethods = haveInputMethods; |
| 567 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 568 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | public void run() { |
| 570 | Looper.prepare(); |
| 571 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 572 | mHaveInputMethods); |
| 573 | android.os.Process.setThreadPriority( |
| 574 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame^] | 575 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 576 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | synchronized (this) { |
| 578 | mService = s; |
| 579 | notifyAll(); |
| 580 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 581 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | Looper.loop(); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | static class PolicyThread extends Thread { |
| 587 | private final WindowManagerPolicy mPolicy; |
| 588 | private final WindowManagerService mService; |
| 589 | private final Context mContext; |
| 590 | private final PowerManagerService mPM; |
| 591 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 592 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | public PolicyThread(WindowManagerPolicy policy, |
| 594 | WindowManagerService service, Context context, |
| 595 | PowerManagerService pm) { |
| 596 | super("WindowManagerPolicy"); |
| 597 | mPolicy = policy; |
| 598 | mService = service; |
| 599 | mContext = context; |
| 600 | mPM = pm; |
| 601 | } |
| 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 | public void run() { |
| 604 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 605 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 608 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | android.os.Process.setThreadPriority( |
| 610 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame^] | 611 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 613 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | synchronized (this) { |
| 615 | mRunning = true; |
| 616 | notifyAll(); |
| 617 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 618 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | Looper.loop(); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | private WindowManagerService(Context context, PowerManagerService pm, |
| 624 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 625 | if (MEASURE_LATENCY) { |
| 626 | lt = new LatencyTimer(100, 1000); |
| 627 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | mContext = context; |
| 630 | mHaveInputMethods = haveInputMethods; |
| 631 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 632 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 633 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | mPowerManager = pm; |
| 635 | mPowerManager.setPolicy(mPolicy); |
| 636 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 637 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 638 | "SCREEN_FROZEN"); |
| 639 | mScreenFrozenLock.setReferenceCounted(false); |
| 640 | |
| 641 | mActivityManager = ActivityManagerNative.getDefault(); |
| 642 | mBatteryStats = BatteryStatsService.getService(); |
| 643 | |
| 644 | // Get persisted window scale setting |
| 645 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 646 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 647 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 648 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 649 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 650 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 651 | IntentFilter filter = new IntentFilter(); |
| 652 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 653 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 654 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 655 | int max_events_per_sec = 35; |
| 656 | try { |
| 657 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 658 | .get("windowsmgr.max_events_per_sec")); |
| 659 | if (max_events_per_sec < 1) { |
| 660 | max_events_per_sec = 35; |
| 661 | } |
| 662 | } catch (NumberFormatException e) { |
| 663 | } |
| 664 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 665 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 666 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 667 | "KEEP_SCREEN_ON_FLAG"); |
| 668 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 670 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 671 | mInputManager = new InputManager(context, this, mPolicy, pmc, mPowerManager); |
| 672 | } else { |
| 673 | mInputManager = null; |
| 674 | } |
| 675 | mQueue = new KeyQ(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | mInputThread = new InputDispatcherThread(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 677 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 679 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | synchronized (thr) { |
| 682 | while (!thr.mRunning) { |
| 683 | try { |
| 684 | thr.wait(); |
| 685 | } catch (InterruptedException e) { |
| 686 | } |
| 687 | } |
| 688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 689 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 690 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 691 | mInputManager.start(); |
| 692 | } else { |
| 693 | mInputThread.start(); |
| 694 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 695 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | // Add ourself to the Watchdog monitors. |
| 697 | Watchdog.getInstance().addMonitor(this); |
| 698 | } |
| 699 | |
| 700 | @Override |
| 701 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 702 | throws RemoteException { |
| 703 | try { |
| 704 | return super.onTransact(code, data, reply, flags); |
| 705 | } catch (RuntimeException e) { |
| 706 | // The window manager only throws security exceptions, so let's |
| 707 | // log all others. |
| 708 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 709 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | } |
| 711 | throw e; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | private void placeWindowAfter(Object pos, WindowState window) { |
| 716 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 717 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | TAG, "Adding window " + window + " at " |
| 719 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 720 | mWindows.add(i+1, window); |
| 721 | } |
| 722 | |
| 723 | private void placeWindowBefore(Object pos, WindowState window) { |
| 724 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 725 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | TAG, "Adding window " + window + " at " |
| 727 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 728 | mWindows.add(i, window); |
| 729 | } |
| 730 | |
| 731 | //This method finds out the index of a window that has the same app token as |
| 732 | //win. used for z ordering the windows in mWindows |
| 733 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 734 | //use a local variable to cache mWindows |
| 735 | ArrayList localmWindows = mWindows; |
| 736 | int jmax = localmWindows.size(); |
| 737 | if(jmax == 0) { |
| 738 | return -1; |
| 739 | } |
| 740 | for(int j = (jmax-1); j >= 0; j--) { |
| 741 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 742 | if(wentry.mAppToken == win.mAppToken) { |
| 743 | return j; |
| 744 | } |
| 745 | } |
| 746 | return -1; |
| 747 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 750 | final IWindow client = win.mClient; |
| 751 | final WindowToken token = win.mToken; |
| 752 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 753 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | final int N = localmWindows.size(); |
| 755 | final WindowState attached = win.mAttachedWindow; |
| 756 | int i; |
| 757 | if (attached == null) { |
| 758 | int tokenWindowsPos = token.windows.size(); |
| 759 | if (token.appWindowToken != null) { |
| 760 | int index = tokenWindowsPos-1; |
| 761 | if (index >= 0) { |
| 762 | // If this application has existing windows, we |
| 763 | // simply place the new window on top of them... but |
| 764 | // keep the starting window on top. |
| 765 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 766 | // Base windows go behind everything else. |
| 767 | placeWindowBefore(token.windows.get(0), win); |
| 768 | tokenWindowsPos = 0; |
| 769 | } else { |
| 770 | AppWindowToken atoken = win.mAppToken; |
| 771 | if (atoken != null && |
| 772 | token.windows.get(index) == atoken.startingWindow) { |
| 773 | placeWindowBefore(token.windows.get(index), win); |
| 774 | tokenWindowsPos--; |
| 775 | } else { |
| 776 | int newIdx = findIdxBasedOnAppTokens(win); |
| 777 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 778 | //there is a window above this one associated with the same |
| 779 | //apptoken note that the window could be a floating window |
| 780 | //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] | 781 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 782 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 783 | TAG, "Adding window " + win + " at " |
| 784 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | localmWindows.add(newIdx+1, win); |
| 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 | } |
| 788 | } |
| 789 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 790 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | TAG, "Figuring out where to add app window " |
| 792 | + client.asBinder() + " (token=" + token + ")"); |
| 793 | // Figure out where the window should go, based on the |
| 794 | // order of applications. |
| 795 | final int NA = mAppTokens.size(); |
| 796 | Object pos = null; |
| 797 | for (i=NA-1; i>=0; i--) { |
| 798 | AppWindowToken t = mAppTokens.get(i); |
| 799 | if (t == token) { |
| 800 | i--; |
| 801 | break; |
| 802 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 803 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 804 | // We haven't reached the token yet; if this token |
| 805 | // is not going to the bottom and has windows, we can |
| 806 | // use it as an anchor for when we do reach the token. |
| 807 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | pos = t.windows.get(0); |
| 809 | } |
| 810 | } |
| 811 | // We now know the index into the apps. If we found |
| 812 | // an app window above, that gives us the position; else |
| 813 | // we need to look some more. |
| 814 | if (pos != null) { |
| 815 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 816 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 818 | if (atoken != null) { |
| 819 | final int NC = atoken.windows.size(); |
| 820 | if (NC > 0) { |
| 821 | WindowState bottom = atoken.windows.get(0); |
| 822 | if (bottom.mSubLayer < 0) { |
| 823 | pos = bottom; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | placeWindowBefore(pos, win); |
| 828 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 829 | // Continue looking down until we find the first |
| 830 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | while (i >= 0) { |
| 832 | AppWindowToken t = mAppTokens.get(i); |
| 833 | final int NW = t.windows.size(); |
| 834 | if (NW > 0) { |
| 835 | pos = t.windows.get(NW-1); |
| 836 | break; |
| 837 | } |
| 838 | i--; |
| 839 | } |
| 840 | if (pos != null) { |
| 841 | // Move in front of any windows attached to this |
| 842 | // one. |
| 843 | WindowToken atoken = |
| 844 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 845 | if (atoken != null) { |
| 846 | final int NC = atoken.windows.size(); |
| 847 | if (NC > 0) { |
| 848 | WindowState top = atoken.windows.get(NC-1); |
| 849 | if (top.mSubLayer >= 0) { |
| 850 | pos = top; |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | placeWindowAfter(pos, win); |
| 855 | } else { |
| 856 | // Just search for the start of this layer. |
| 857 | final int myLayer = win.mBaseLayer; |
| 858 | for (i=0; i<N; i++) { |
| 859 | WindowState w = (WindowState)localmWindows.get(i); |
| 860 | if (w.mBaseLayer > myLayer) { |
| 861 | break; |
| 862 | } |
| 863 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 864 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 865 | TAG, "Adding window " + win + " at " |
| 866 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | localmWindows.add(i, win); |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | } else { |
| 872 | // Figure out where window should go, based on layer. |
| 873 | final int myLayer = win.mBaseLayer; |
| 874 | for (i=N-1; i>=0; i--) { |
| 875 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 876 | i++; |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 881 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 882 | TAG, "Adding window " + win + " at " |
| 883 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | localmWindows.add(i, win); |
| 885 | } |
| 886 | if (addToToken) { |
| 887 | token.windows.add(tokenWindowsPos, win); |
| 888 | } |
| 889 | |
| 890 | } else { |
| 891 | // Figure out this window's ordering relative to the window |
| 892 | // it is attached to. |
| 893 | final int NA = token.windows.size(); |
| 894 | final int sublayer = win.mSubLayer; |
| 895 | int largestSublayer = Integer.MIN_VALUE; |
| 896 | WindowState windowWithLargestSublayer = null; |
| 897 | for (i=0; i<NA; i++) { |
| 898 | WindowState w = token.windows.get(i); |
| 899 | final int wSublayer = w.mSubLayer; |
| 900 | if (wSublayer >= largestSublayer) { |
| 901 | largestSublayer = wSublayer; |
| 902 | windowWithLargestSublayer = w; |
| 903 | } |
| 904 | if (sublayer < 0) { |
| 905 | // For negative sublayers, we go below all windows |
| 906 | // in the same sublayer. |
| 907 | if (wSublayer >= sublayer) { |
| 908 | if (addToToken) { |
| 909 | token.windows.add(i, win); |
| 910 | } |
| 911 | placeWindowBefore( |
| 912 | wSublayer >= 0 ? attached : w, win); |
| 913 | break; |
| 914 | } |
| 915 | } else { |
| 916 | // For positive sublayers, we go above all windows |
| 917 | // in the same sublayer. |
| 918 | if (wSublayer > sublayer) { |
| 919 | if (addToToken) { |
| 920 | token.windows.add(i, win); |
| 921 | } |
| 922 | placeWindowBefore(w, win); |
| 923 | break; |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | if (i >= NA) { |
| 928 | if (addToToken) { |
| 929 | token.windows.add(win); |
| 930 | } |
| 931 | if (sublayer < 0) { |
| 932 | placeWindowBefore(attached, win); |
| 933 | } else { |
| 934 | placeWindowAfter(largestSublayer >= 0 |
| 935 | ? windowWithLargestSublayer |
| 936 | : attached, |
| 937 | win); |
| 938 | } |
| 939 | } |
| 940 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | if (win.mAppToken != null && addToToken) { |
| 943 | win.mAppToken.allAppWindows.add(win); |
| 944 | } |
| 945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | static boolean canBeImeTarget(WindowState w) { |
| 948 | final int fl = w.mAttrs.flags |
| 949 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 950 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 951 | return w.isVisibleOrAdding(); |
| 952 | } |
| 953 | return false; |
| 954 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 955 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 957 | final ArrayList localmWindows = mWindows; |
| 958 | final int N = localmWindows.size(); |
| 959 | WindowState w = null; |
| 960 | int i = N; |
| 961 | while (i > 0) { |
| 962 | i--; |
| 963 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 964 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 965 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | // + Integer.toHexString(w.mAttrs.flags)); |
| 967 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 968 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 969 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | // Yet more tricksyness! If this window is a "starting" |
| 971 | // window, we do actually want to be on top of it, but |
| 972 | // it is not -really- where input will go. So if the caller |
| 973 | // is not actually looking to move the IME, look down below |
| 974 | // for a real window to target... |
| 975 | if (!willMove |
| 976 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 977 | && i > 0) { |
| 978 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 979 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 980 | i--; |
| 981 | w = wb; |
| 982 | } |
| 983 | } |
| 984 | break; |
| 985 | } |
| 986 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 987 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 989 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 990 | 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] | 991 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | if (willMove && w != null) { |
| 994 | final WindowState curTarget = mInputMethodTarget; |
| 995 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | // Now some fun for dealing with window animations that |
| 998 | // modify the Z order. We need to look at all windows below |
| 999 | // the current target that are in this app, finding the highest |
| 1000 | // visible one in layering. |
| 1001 | AppWindowToken token = curTarget.mAppToken; |
| 1002 | WindowState highestTarget = null; |
| 1003 | int highestPos = 0; |
| 1004 | if (token.animating || token.animation != null) { |
| 1005 | int pos = 0; |
| 1006 | pos = localmWindows.indexOf(curTarget); |
| 1007 | while (pos >= 0) { |
| 1008 | WindowState win = (WindowState)localmWindows.get(pos); |
| 1009 | if (win.mAppToken != token) { |
| 1010 | break; |
| 1011 | } |
| 1012 | if (!win.mRemoved) { |
| 1013 | if (highestTarget == null || win.mAnimLayer > |
| 1014 | highestTarget.mAnimLayer) { |
| 1015 | highestTarget = win; |
| 1016 | highestPos = pos; |
| 1017 | } |
| 1018 | } |
| 1019 | pos--; |
| 1020 | } |
| 1021 | } |
| 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 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1024 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | + mNextAppTransition + " " + highestTarget |
| 1026 | + " animating=" + highestTarget.isAnimating() |
| 1027 | + " layer=" + highestTarget.mAnimLayer |
| 1028 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1029 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1030 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | // If we are currently setting up for an animation, |
| 1032 | // hold everything until we can find out what will happen. |
| 1033 | mInputMethodTargetWaitingAnim = true; |
| 1034 | mInputMethodTarget = highestTarget; |
| 1035 | return highestPos + 1; |
| 1036 | } else if (highestTarget.isAnimating() && |
| 1037 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1038 | // If the window we are currently targeting is involved |
| 1039 | // with an animation, and it is on top of the next target |
| 1040 | // we will be over, then hold off on moving until |
| 1041 | // that is done. |
| 1042 | mInputMethodTarget = highestTarget; |
| 1043 | return highestPos + 1; |
| 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1048 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1049 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | if (w != null) { |
| 1051 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1052 | if (DEBUG_INPUT_METHOD) { |
| 1053 | RuntimeException e = null; |
| 1054 | if (!HIDE_STACK_CRAWLS) { |
| 1055 | e = new RuntimeException(); |
| 1056 | e.fillInStackTrace(); |
| 1057 | } |
| 1058 | Slog.w(TAG, "Moving IM target from " |
| 1059 | + mInputMethodTarget + " to " + w, e); |
| 1060 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | mInputMethodTarget = w; |
| 1062 | if (w.mAppToken != null) { |
| 1063 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1064 | } else { |
| 1065 | setInputMethodAnimLayerAdjustment(0); |
| 1066 | } |
| 1067 | } |
| 1068 | return i+1; |
| 1069 | } |
| 1070 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1071 | if (DEBUG_INPUT_METHOD) { |
| 1072 | RuntimeException e = null; |
| 1073 | if (!HIDE_STACK_CRAWLS) { |
| 1074 | e = new RuntimeException(); |
| 1075 | e.fillInStackTrace(); |
| 1076 | } |
| 1077 | Slog.w(TAG, "Moving IM target from " |
| 1078 | + mInputMethodTarget + " to null", e); |
| 1079 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | mInputMethodTarget = null; |
| 1081 | setInputMethodAnimLayerAdjustment(0); |
| 1082 | } |
| 1083 | return -1; |
| 1084 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1085 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1087 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1088 | if (pos >= 0) { |
| 1089 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1090 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1091 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | mWindows.add(pos, win); |
| 1093 | moveInputMethodDialogsLocked(pos+1); |
| 1094 | return; |
| 1095 | } |
| 1096 | win.mTargetAppToken = null; |
| 1097 | addWindowToListInOrderLocked(win, true); |
| 1098 | moveInputMethodDialogsLocked(pos); |
| 1099 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1102 | 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] | 1103 | mInputMethodAnimLayerAdjustment = adj; |
| 1104 | WindowState imw = mInputMethodWindow; |
| 1105 | if (imw != null) { |
| 1106 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1107 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | + " anim layer: " + imw.mAnimLayer); |
| 1109 | int wi = imw.mChildWindows.size(); |
| 1110 | while (wi > 0) { |
| 1111 | wi--; |
| 1112 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1113 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1114 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | + " anim layer: " + cw.mAnimLayer); |
| 1116 | } |
| 1117 | } |
| 1118 | int di = mInputMethodDialogs.size(); |
| 1119 | while (di > 0) { |
| 1120 | di --; |
| 1121 | imw = mInputMethodDialogs.get(di); |
| 1122 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1123 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | + " anim layer: " + imw.mAnimLayer); |
| 1125 | } |
| 1126 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1129 | int wpos = mWindows.indexOf(win); |
| 1130 | if (wpos >= 0) { |
| 1131 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1132 | 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] | 1133 | mWindows.remove(wpos); |
| 1134 | int NC = win.mChildWindows.size(); |
| 1135 | while (NC > 0) { |
| 1136 | NC--; |
| 1137 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1138 | int cpos = mWindows.indexOf(cw); |
| 1139 | if (cpos >= 0) { |
| 1140 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1141 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1142 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | mWindows.remove(cpos); |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | return interestingPos; |
| 1148 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1149 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1151 | addWindowToListInOrderLocked(win, false); |
| 1152 | // This is a hack to get all of the child windows added as well |
| 1153 | // at the right position. Child windows should be rare and |
| 1154 | // this case should be rare, so it shouldn't be that big a deal. |
| 1155 | int wpos = mWindows.indexOf(win); |
| 1156 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1157 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1158 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | mWindows.remove(wpos); |
| 1160 | reAddWindowLocked(wpos, win); |
| 1161 | } |
| 1162 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | void logWindowList(String prefix) { |
| 1165 | int N = mWindows.size(); |
| 1166 | while (N > 0) { |
| 1167 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1168 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | } |
| 1170 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | void moveInputMethodDialogsLocked(int pos) { |
| 1173 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1176 | 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] | 1177 | for (int i=0; i<N; i++) { |
| 1178 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1179 | } |
| 1180 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1181 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | logWindowList(" "); |
| 1183 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | if (pos >= 0) { |
| 1186 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1187 | if (pos < mWindows.size()) { |
| 1188 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1189 | if (wp == mInputMethodWindow) { |
| 1190 | pos++; |
| 1191 | } |
| 1192 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1193 | 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] | 1194 | for (int i=0; i<N; i++) { |
| 1195 | WindowState win = dialogs.get(i); |
| 1196 | win.mTargetAppToken = targetAppToken; |
| 1197 | pos = reAddWindowLocked(pos, win); |
| 1198 | } |
| 1199 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1200 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | logWindowList(" "); |
| 1202 | } |
| 1203 | return; |
| 1204 | } |
| 1205 | for (int i=0; i<N; i++) { |
| 1206 | WindowState win = dialogs.get(i); |
| 1207 | win.mTargetAppToken = null; |
| 1208 | reAddWindowToListInOrderLocked(win); |
| 1209 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1210 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | logWindowList(" "); |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1217 | final WindowState imWin = mInputMethodWindow; |
| 1218 | final int DN = mInputMethodDialogs.size(); |
| 1219 | if (imWin == null && DN == 0) { |
| 1220 | return false; |
| 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 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1224 | if (imPos >= 0) { |
| 1225 | // In this case, the input method windows are to be placed |
| 1226 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | // First check to see if the input method windows are already |
| 1229 | // located here, and contiguous. |
| 1230 | final int N = mWindows.size(); |
| 1231 | WindowState firstImWin = imPos < N |
| 1232 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | // Figure out the actual input method window that should be |
| 1235 | // at the bottom of their stack. |
| 1236 | WindowState baseImWin = imWin != null |
| 1237 | ? imWin : mInputMethodDialogs.get(0); |
| 1238 | if (baseImWin.mChildWindows.size() > 0) { |
| 1239 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1240 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1241 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | if (firstImWin == baseImWin) { |
| 1244 | // The windows haven't moved... but are they still contiguous? |
| 1245 | // First find the top IM window. |
| 1246 | int pos = imPos+1; |
| 1247 | while (pos < N) { |
| 1248 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1249 | break; |
| 1250 | } |
| 1251 | pos++; |
| 1252 | } |
| 1253 | pos++; |
| 1254 | // Now there should be no more input method windows above. |
| 1255 | while (pos < N) { |
| 1256 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1257 | break; |
| 1258 | } |
| 1259 | pos++; |
| 1260 | } |
| 1261 | if (pos >= N) { |
| 1262 | // All is good! |
| 1263 | return false; |
| 1264 | } |
| 1265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | if (imWin != null) { |
| 1268 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1269 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | logWindowList(" "); |
| 1271 | } |
| 1272 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1273 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1274 | Slog.v(TAG, "List after moving with new pos " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | logWindowList(" "); |
| 1276 | } |
| 1277 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1278 | reAddWindowLocked(imPos, imWin); |
| 1279 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1280 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1281 | logWindowList(" "); |
| 1282 | } |
| 1283 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1284 | } else { |
| 1285 | moveInputMethodDialogsLocked(imPos); |
| 1286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | } else { |
| 1289 | // In this case, the input method windows go in a fixed layer, |
| 1290 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1293 | 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] | 1294 | tmpRemoveWindowLocked(0, imWin); |
| 1295 | imWin.mTargetAppToken = null; |
| 1296 | reAddWindowToListInOrderLocked(imWin); |
| 1297 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1298 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | logWindowList(" "); |
| 1300 | } |
| 1301 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1302 | } else { |
| 1303 | moveInputMethodDialogsLocked(-1);; |
| 1304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | } |
| 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 | if (needAssignLayers) { |
| 1309 | assignLayersLocked(); |
| 1310 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | return true; |
| 1313 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1314 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | void adjustInputMethodDialogsLocked() { |
| 1316 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1317 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1318 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1319 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1320 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1321 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1322 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1323 | ? wallpaperTarget.mAppToken.animation : null) |
| 1324 | + " upper=" + mUpperWallpaperTarget |
| 1325 | + " lower=" + mLowerWallpaperTarget); |
| 1326 | return (wallpaperTarget != null |
| 1327 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1328 | && wallpaperTarget.mAppToken.animation != null))) |
| 1329 | || mUpperWallpaperTarget != null |
| 1330 | || mLowerWallpaperTarget != null; |
| 1331 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1332 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1333 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1334 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1335 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1336 | int adjustWallpaperWindowsLocked() { |
| 1337 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1338 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1339 | final int dw = mDisplay.getWidth(); |
| 1340 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1341 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1342 | // First find top-most window that has asked to be on top of the |
| 1343 | // wallpaper; all wallpapers go behind it. |
| 1344 | final ArrayList localmWindows = mWindows; |
| 1345 | int N = localmWindows.size(); |
| 1346 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1347 | WindowState foundW = null; |
| 1348 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1349 | WindowState topCurW = null; |
| 1350 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1351 | int i = N; |
| 1352 | while (i > 0) { |
| 1353 | i--; |
| 1354 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1355 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1356 | if (topCurW == null) { |
| 1357 | topCurW = w; |
| 1358 | topCurI = i; |
| 1359 | } |
| 1360 | continue; |
| 1361 | } |
| 1362 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1363 | if (w.mAppToken != null) { |
| 1364 | // If this window's app token is hidden and not animating, |
| 1365 | // it is of no interest to us. |
| 1366 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1367 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1368 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1369 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1370 | continue; |
| 1371 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1372 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1373 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1374 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1375 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1376 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1377 | && (mWallpaperTarget == w |
| 1378 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1379 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1380 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1381 | foundW = w; |
| 1382 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1383 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1384 | && w.mAppToken.animation != null) |
| 1385 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1386 | // The current wallpaper target is animating, so we'll |
| 1387 | // look behind it for another possible target and figure |
| 1388 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1389 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1390 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1391 | continue; |
| 1392 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | } |
| 1395 | } |
| 1396 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1397 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1398 | // If we are currently waiting for an app transition, and either |
| 1399 | // the current target or the next target are involved with it, |
| 1400 | // then hold off on doing anything with the wallpaper. |
| 1401 | // Note that we are checking here for just whether the target |
| 1402 | // is part of an app token... which is potentially overly aggressive |
| 1403 | // (the app token may not be involved in the transition), but good |
| 1404 | // enough (we'll just wait until whatever transition is pending |
| 1405 | // executes). |
| 1406 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1407 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1408 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1409 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1410 | } |
| 1411 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1412 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1413 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1414 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1415 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1416 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1417 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1418 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1419 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1420 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1421 | + " oldTarget: " + mWallpaperTarget); |
| 1422 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1423 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1424 | mLowerWallpaperTarget = null; |
| 1425 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1426 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1427 | WindowState oldW = mWallpaperTarget; |
| 1428 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1429 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1430 | // Now what is happening... if the current and new targets are |
| 1431 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1432 | if (foundW != null && oldW != null) { |
| 1433 | boolean oldAnim = oldW.mAnimation != null |
| 1434 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1435 | boolean foundAnim = foundW.mAnimation != null |
| 1436 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1437 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1438 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1439 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1440 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1441 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1442 | int oldI = localmWindows.indexOf(oldW); |
| 1443 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1444 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1445 | } |
| 1446 | if (oldI >= 0) { |
| 1447 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1448 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1449 | + "=" + oldW + "; new#" + foundI |
| 1450 | + "=" + foundW); |
| 1451 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1452 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1453 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1454 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1455 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1456 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1457 | } |
| 1458 | mWallpaperTarget = oldW; |
| 1459 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1460 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1461 | // Now set the upper and lower wallpaper targets |
| 1462 | // correctly, and make sure that we are positioning |
| 1463 | // the wallpaper below the lower. |
| 1464 | if (foundI > oldI) { |
| 1465 | // The new target is on top of the old one. |
| 1466 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1467 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1468 | } |
| 1469 | mUpperWallpaperTarget = foundW; |
| 1470 | mLowerWallpaperTarget = oldW; |
| 1471 | foundW = oldW; |
| 1472 | foundI = oldI; |
| 1473 | } else { |
| 1474 | // The new target is below the old one. |
| 1475 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1476 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1477 | } |
| 1478 | mUpperWallpaperTarget = oldW; |
| 1479 | mLowerWallpaperTarget = foundW; |
| 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1484 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1485 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1486 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1487 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1488 | || (mLowerWallpaperTarget.mAppToken != null |
| 1489 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1490 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1491 | || (mUpperWallpaperTarget.mAppToken != null |
| 1492 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1493 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1494 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1495 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1496 | } |
| 1497 | mLowerWallpaperTarget = null; |
| 1498 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1499 | } |
| 1500 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1501 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1502 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1503 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1504 | // The window is visible to the compositor... but is it visible |
| 1505 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1506 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1507 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1508 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1509 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1510 | // its layer adjustment. Only do this if we are not transfering |
| 1511 | // between two wallpaper targets. |
| 1512 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1513 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1514 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1515 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1516 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1517 | * TYPE_LAYER_MULTIPLIER |
| 1518 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1519 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1520 | // Now w is the window we are supposed to be behind... but we |
| 1521 | // 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] | 1522 | // AND any starting window associated with it, AND below the |
| 1523 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1524 | while (foundI > 0) { |
| 1525 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1526 | if (wb.mBaseLayer < maxLayer && |
| 1527 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1528 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1529 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1530 | // This window is not related to the previous one in any |
| 1531 | // interesting way, so stop here. |
| 1532 | break; |
| 1533 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1534 | foundW = wb; |
| 1535 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1536 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1537 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1538 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1539 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1540 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1541 | if (foundW == null && topCurW != null) { |
| 1542 | // There is no wallpaper target, so it goes at the bottom. |
| 1543 | // We will assume it is the same place as last time, if known. |
| 1544 | foundW = topCurW; |
| 1545 | foundI = topCurI+1; |
| 1546 | } else { |
| 1547 | // Okay i is the position immediately above the wallpaper. Look at |
| 1548 | // what is below it for later. |
| 1549 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1550 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1551 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1552 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1553 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1554 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1555 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1556 | } |
| 1557 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1558 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1559 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1560 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1561 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1562 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1563 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1564 | // are correctly placed. |
| 1565 | int curTokenIndex = mWallpaperTokens.size(); |
| 1566 | while (curTokenIndex > 0) { |
| 1567 | curTokenIndex--; |
| 1568 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1569 | if (token.hidden == visible) { |
| 1570 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1571 | token.hidden = !visible; |
| 1572 | // Need to do a layout to ensure the wallpaper now has the |
| 1573 | // correct size. |
| 1574 | mLayoutNeeded = true; |
| 1575 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1576 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1577 | int curWallpaperIndex = token.windows.size(); |
| 1578 | while (curWallpaperIndex > 0) { |
| 1579 | curWallpaperIndex--; |
| 1580 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1581 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1582 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1583 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1584 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1585 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1586 | // First, make sure the client has the current visibility |
| 1587 | // state. |
| 1588 | if (wallpaper.mWallpaperVisible != visible) { |
| 1589 | wallpaper.mWallpaperVisible = visible; |
| 1590 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1591 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1592 | "Setting visibility of wallpaper " + wallpaper |
| 1593 | + ": " + visible); |
| 1594 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1595 | } catch (RemoteException e) { |
| 1596 | } |
| 1597 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1598 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1599 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1600 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1601 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| 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 | // First, if this window is at the current index, then all |
| 1604 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1605 | if (wallpaper == foundW) { |
| 1606 | foundI--; |
| 1607 | foundW = foundI > 0 |
| 1608 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1609 | continue; |
| 1610 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1611 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1612 | // The window didn't match... the current wallpaper window, |
| 1613 | // wherever it is, is in the wrong place, so make sure it is |
| 1614 | // not in the list. |
| 1615 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1616 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1617 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1618 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1619 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1620 | if (oldIndex < foundI) { |
| 1621 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1622 | } |
| 1623 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1624 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1625 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1626 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1627 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1628 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1629 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1630 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1631 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1632 | } |
| 1633 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1634 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1635 | return changed; |
| 1636 | } |
| 1637 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1638 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1639 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1640 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1641 | mWallpaperAnimLayerAdjustment = adj; |
| 1642 | int curTokenIndex = mWallpaperTokens.size(); |
| 1643 | while (curTokenIndex > 0) { |
| 1644 | curTokenIndex--; |
| 1645 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1646 | int curWallpaperIndex = token.windows.size(); |
| 1647 | while (curWallpaperIndex > 0) { |
| 1648 | curWallpaperIndex--; |
| 1649 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1650 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1651 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1652 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | } |
| 1656 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1657 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1658 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1659 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1660 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1661 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1662 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1663 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1664 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1665 | changed = wallpaperWin.mXOffset != offset; |
| 1666 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1667 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1668 | + wallpaperWin + " x: " + offset); |
| 1669 | wallpaperWin.mXOffset = offset; |
| 1670 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1671 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1672 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1673 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1674 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1675 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1676 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1677 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1678 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1679 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1680 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1681 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1682 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1683 | + wallpaperWin + " y: " + offset); |
| 1684 | changed = true; |
| 1685 | wallpaperWin.mYOffset = offset; |
| 1686 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1687 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1688 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1689 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1690 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1691 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1692 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1693 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1694 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1695 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1696 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1697 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1698 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1699 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1700 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1701 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1702 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1703 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1704 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1705 | if (mWaitingOnWallpaper != null) { |
| 1706 | long start = SystemClock.uptimeMillis(); |
| 1707 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1708 | < start) { |
| 1709 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1710 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1711 | "Waiting for offset complete..."); |
| 1712 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1713 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1714 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1715 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1716 | if ((start+WALLPAPER_TIMEOUT) |
| 1717 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1718 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1719 | + wallpaperWin); |
| 1720 | mLastWallpaperTimeoutTime = start; |
| 1721 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1722 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1723 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1724 | } |
| 1725 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1726 | } catch (RemoteException e) { |
| 1727 | } |
| 1728 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1729 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1730 | return changed; |
| 1731 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1732 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1733 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1734 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1735 | if (mWaitingOnWallpaper != null && |
| 1736 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1737 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1738 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1742 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1743 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1744 | final int dw = mDisplay.getWidth(); |
| 1745 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1746 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1747 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1748 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1749 | WindowState target = mWallpaperTarget; |
| 1750 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1751 | if (target.mWallpaperX >= 0) { |
| 1752 | mLastWallpaperX = target.mWallpaperX; |
| 1753 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1754 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1755 | } |
| 1756 | if (target.mWallpaperY >= 0) { |
| 1757 | mLastWallpaperY = target.mWallpaperY; |
| 1758 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1759 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1760 | } |
| 1761 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1762 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1763 | int curTokenIndex = mWallpaperTokens.size(); |
| 1764 | while (curTokenIndex > 0) { |
| 1765 | curTokenIndex--; |
| 1766 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1767 | int curWallpaperIndex = token.windows.size(); |
| 1768 | while (curWallpaperIndex > 0) { |
| 1769 | curWallpaperIndex--; |
| 1770 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1771 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1772 | wallpaper.computeShownFrameLocked(); |
| 1773 | changed = true; |
| 1774 | // We only want to be synchronous with one wallpaper. |
| 1775 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1779 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1780 | return changed; |
| 1781 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1782 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1783 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1784 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1785 | final int dw = mDisplay.getWidth(); |
| 1786 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1787 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1788 | int curTokenIndex = mWallpaperTokens.size(); |
| 1789 | while (curTokenIndex > 0) { |
| 1790 | curTokenIndex--; |
| 1791 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1792 | if (token.hidden == visible) { |
| 1793 | token.hidden = !visible; |
| 1794 | // Need to do a layout to ensure the wallpaper now has the |
| 1795 | // correct size. |
| 1796 | mLayoutNeeded = true; |
| 1797 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1798 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1799 | int curWallpaperIndex = token.windows.size(); |
| 1800 | while (curWallpaperIndex > 0) { |
| 1801 | curWallpaperIndex--; |
| 1802 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1803 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1804 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1805 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1806 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1807 | if (wallpaper.mWallpaperVisible != visible) { |
| 1808 | wallpaper.mWallpaperVisible = visible; |
| 1809 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1810 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1811 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1812 | + ": " + visible); |
| 1813 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1814 | } catch (RemoteException e) { |
| 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | } |
| 1819 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1820 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1821 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1822 | MotionEvent pointer, long eventTime) { |
| 1823 | int curTokenIndex = mWallpaperTokens.size(); |
| 1824 | while (curTokenIndex > 0) { |
| 1825 | curTokenIndex--; |
| 1826 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1827 | int curWallpaperIndex = token.windows.size(); |
| 1828 | while (curWallpaperIndex > 0) { |
| 1829 | curWallpaperIndex--; |
| 1830 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1831 | if ((wallpaper.mAttrs.flags & |
| 1832 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1833 | continue; |
| 1834 | } |
| 1835 | try { |
| 1836 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1837 | if (srcWin != null) { |
| 1838 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1839 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1840 | } else { |
| 1841 | ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top); |
| 1842 | } |
| 1843 | switch (pointer.getAction()) { |
| 1844 | case MotionEvent.ACTION_DOWN: |
| 1845 | mSendingPointersToWallpaper = true; |
| 1846 | break; |
| 1847 | case MotionEvent.ACTION_UP: |
| 1848 | mSendingPointersToWallpaper = false; |
| 1849 | break; |
| 1850 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1851 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1852 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1853 | Slog.w(TAG, "Failure sending pointer to wallpaper", e); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1858 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1859 | void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin, |
| 1860 | MotionEvent pointer, long eventTime, boolean skipped) { |
| 1861 | if (relWin != null) { |
| 1862 | mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top); |
| 1863 | } else { |
| 1864 | mPolicy.dispatchedPointerEventLw(pointer, 0, 0); |
| 1865 | } |
| 1866 | |
| 1867 | // If we sent an initial down to the wallpaper, then continue |
| 1868 | // sending events until the final up. |
| 1869 | if (mSendingPointersToWallpaper) { |
| 1870 | if (skipped) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1871 | Slog.i(TAG, "Sending skipped pointer to wallpaper!"); |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1872 | } |
| 1873 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1874 | |
| 1875 | // If we are on top of the wallpaper, then the wallpaper also |
| 1876 | // gets to see this movement. |
| 1877 | } else if (srcWin != null |
| 1878 | && pointer.getAction() == MotionEvent.ACTION_DOWN |
| 1879 | && mWallpaperTarget == srcWin |
| 1880 | && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 1881 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1882 | } |
| 1883 | } |
| 1884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | public int addWindow(Session session, IWindow client, |
| 1886 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1887 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | int res = mPolicy.checkAddPermission(attrs); |
| 1889 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1890 | return res; |
| 1891 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | boolean reportNewConfig = false; |
| 1894 | WindowState attachedWindow = null; |
| 1895 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | synchronized(mWindowMap) { |
| 1898 | // Instantiating a Display requires talking with the simulator, |
| 1899 | // so don't do it until we know the system is mostly up and |
| 1900 | // running. |
| 1901 | if (mDisplay == null) { |
| 1902 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1903 | mDisplay = wm.getDefaultDisplay(); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1904 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1905 | mInitialDisplayHeight = mDisplay.getHeight(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1906 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 1907 | mInputManager.setDisplaySize(0, |
| 1908 | mInitialDisplayWidth, mInitialDisplayHeight); |
| 1909 | } else { |
| 1910 | mQueue.setDisplay(mDisplay); |
| 1911 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | reportNewConfig = true; |
| 1913 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1916 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1918 | } |
| 1919 | |
| 1920 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1921 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1923 | 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] | 1924 | + attrs.token + ". Aborting."); |
| 1925 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1926 | } |
| 1927 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1928 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1929 | 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] | 1930 | + attrs.token + ". Aborting."); |
| 1931 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | boolean addToken = false; |
| 1936 | WindowToken token = mTokenMap.get(attrs.token); |
| 1937 | if (token == null) { |
| 1938 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1939 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1940 | 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] | 1941 | + attrs.token + ". Aborting."); |
| 1942 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1943 | } |
| 1944 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1945 | 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] | 1946 | + attrs.token + ". Aborting."); |
| 1947 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1948 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1949 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1950 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1951 | + attrs.token + ". Aborting."); |
| 1952 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1953 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1954 | token = new WindowToken(attrs.token, -1, false); |
| 1955 | addToken = true; |
| 1956 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1957 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1958 | AppWindowToken atoken = token.appWindowToken; |
| 1959 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1960 | 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] | 1961 | + token + ". Aborting."); |
| 1962 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1963 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1964 | 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] | 1965 | + token + ". Aborting."); |
| 1966 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1967 | } |
| 1968 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1969 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1970 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1972 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1973 | } |
| 1974 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1975 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1976 | 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] | 1977 | + attrs.token + ". Aborting."); |
| 1978 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1979 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1980 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1981 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1982 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1983 | + attrs.token + ". Aborting."); |
| 1984 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1985 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | win = new WindowState(session, client, token, |
| 1989 | attachedWindow, attrs, viewVisibility); |
| 1990 | if (win.mDeathRecipient == null) { |
| 1991 | // Client has apparently died, so there is no reason to |
| 1992 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1993 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1994 | + " that is dead, aborting."); |
| 1995 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1996 | } |
| 1997 | |
| 1998 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1999 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2000 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2001 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2002 | return res; |
| 2003 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2004 | |
| 2005 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 2006 | if (outInputChannel != null) { |
| 2007 | String name = win.makeInputChannelName(); |
| 2008 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2009 | win.mInputChannel = inputChannels[0]; |
| 2010 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2011 | |
| 2012 | mInputManager.registerInputChannel(win.mInputChannel); |
| 2013 | } |
| 2014 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | |
| 2016 | // From now on, no exceptions or errors allowed! |
| 2017 | |
| 2018 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2020 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2021 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | if (addToken) { |
| 2023 | mTokenMap.put(attrs.token, token); |
| 2024 | mTokenList.add(token); |
| 2025 | } |
| 2026 | win.attach(); |
| 2027 | mWindowMap.put(client.asBinder(), win); |
| 2028 | |
| 2029 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2030 | token.appWindowToken != null) { |
| 2031 | token.appWindowToken.startingWindow = win; |
| 2032 | } |
| 2033 | |
| 2034 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2035 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2037 | mInputMethodWindow = win; |
| 2038 | addInputMethodWindowToListLocked(win); |
| 2039 | imMayMove = false; |
| 2040 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2041 | mInputMethodDialogs.add(win); |
| 2042 | addWindowToListInOrderLocked(win, true); |
| 2043 | adjustInputMethodDialogsLocked(); |
| 2044 | imMayMove = false; |
| 2045 | } else { |
| 2046 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2047 | if (attrs.type == TYPE_WALLPAPER) { |
| 2048 | mLastWallpaperTimeoutTime = 0; |
| 2049 | adjustWallpaperWindowsLocked(); |
| 2050 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2051 | adjustWallpaperWindowsLocked(); |
| 2052 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2053 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2054 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2055 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2058 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2059 | if (mInTouchMode) { |
| 2060 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2061 | } |
| 2062 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2063 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2064 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2065 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2066 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | if (win.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2068 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2069 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2070 | imMayMove = false; |
| 2071 | } |
| 2072 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2073 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2075 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2076 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2077 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | assignLayersLocked(); |
| 2079 | // Don't do layout here, the window must call |
| 2080 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | //dump(); |
| 2083 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2084 | if (focusChanged) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2085 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2086 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2087 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2088 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | TAG, "New client " + client.asBinder() |
| 2090 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2091 | |
| 2092 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2093 | reportNewConfig = true; |
| 2094 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 2098 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 2099 | // identity anyway, so it's safe to just clear & restore around this whole |
| 2100 | // block. |
| 2101 | final long origId = Binder.clearCallingIdentity(); |
| 2102 | if (reportNewConfig) { |
| 2103 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2104 | } |
| 2105 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | return res; |
| 2108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | public void removeWindow(Session session, IWindow client) { |
| 2111 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2112 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | if (win == null) { |
| 2114 | return; |
| 2115 | } |
| 2116 | removeWindowLocked(session, win); |
| 2117 | } |
| 2118 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2119 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | public void removeWindowLocked(Session session, WindowState win) { |
| 2121 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2122 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2123 | TAG, "Remove " + win + " client=" |
| 2124 | + Integer.toHexString(System.identityHashCode( |
| 2125 | win.mClient.asBinder())) |
| 2126 | + ", surface=" + win.mSurface); |
| 2127 | |
| 2128 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2129 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2130 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2132 | + " mExiting=" + win.mExiting |
| 2133 | + " isAnimating=" + win.isAnimating() |
| 2134 | + " app-animation=" |
| 2135 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2136 | + " inPendingTransaction=" |
| 2137 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2138 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2139 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2140 | boolean wasVisible = false; |
| 2141 | // First, see if we need to run an animation. If we do, we have |
| 2142 | // to hold off on removing the window until the animation is done. |
| 2143 | // If the display is frozen, just remove immediately, since the |
| 2144 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2145 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | // If we are not currently running the exit animation, we |
| 2147 | // need to see about starting one. |
| 2148 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2149 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2151 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2152 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2153 | } |
| 2154 | // Try starting an animation. |
| 2155 | if (applyAnimationLocked(win, transit, false)) { |
| 2156 | win.mExiting = true; |
| 2157 | } |
| 2158 | } |
| 2159 | if (win.mExiting || win.isAnimating()) { |
| 2160 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2161 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | win.mExiting = true; |
| 2163 | win.mRemoveOnExit = true; |
| 2164 | mLayoutNeeded = true; |
| 2165 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2166 | performLayoutAndPlaceSurfacesLocked(); |
| 2167 | if (win.mAppToken != null) { |
| 2168 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2169 | } |
| 2170 | //dump(); |
| 2171 | Binder.restoreCallingIdentity(origId); |
| 2172 | return; |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | removeWindowInnerLocked(session, win); |
| 2177 | // Removing a visible window will effect the computed orientation |
| 2178 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2179 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2180 | != mForcedAppOrientation |
| 2181 | && updateOrientationFromAppTokensLocked()) { |
| 2182 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | } |
| 2184 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2185 | Binder.restoreCallingIdentity(origId); |
| 2186 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2189 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 2190 | mInputMonitor.windowIsBeingRemovedLw(win); |
| 2191 | } else { |
| 2192 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2193 | KeyWaiter.RETURN_NOTHING); |
| 2194 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2195 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| 2196 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2200 | if (mInputMethodTarget == win) { |
| 2201 | moveInputMethodWindowsIfNeededLocked(false); |
| 2202 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2203 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2204 | if (false) { |
| 2205 | RuntimeException e = new RuntimeException("here"); |
| 2206 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2207 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2208 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2210 | mPolicy.removeWindowLw(win); |
| 2211 | win.removeLocked(); |
| 2212 | |
| 2213 | mWindowMap.remove(win.mClient.asBinder()); |
| 2214 | mWindows.remove(win); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2215 | 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] | 2216 | |
| 2217 | if (mInputMethodWindow == win) { |
| 2218 | mInputMethodWindow = null; |
| 2219 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2220 | mInputMethodDialogs.remove(win); |
| 2221 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2222 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | final WindowToken token = win.mToken; |
| 2224 | final AppWindowToken atoken = win.mAppToken; |
| 2225 | token.windows.remove(win); |
| 2226 | if (atoken != null) { |
| 2227 | atoken.allAppWindows.remove(win); |
| 2228 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2229 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2230 | TAG, "**** Removing window " + win + ": count=" |
| 2231 | + token.windows.size()); |
| 2232 | if (token.windows.size() == 0) { |
| 2233 | if (!token.explicit) { |
| 2234 | mTokenMap.remove(token.token); |
| 2235 | mTokenList.remove(token); |
| 2236 | } else if (atoken != null) { |
| 2237 | atoken.firstWindowDrawn = false; |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | if (atoken != null) { |
| 2242 | if (atoken.startingWindow == win) { |
| 2243 | atoken.startingWindow = null; |
| 2244 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2245 | // If this is the last window and we had requested a starting |
| 2246 | // transition window, well there is no point now. |
| 2247 | atoken.startingData = null; |
| 2248 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2249 | // If this is the last window except for a starting transition |
| 2250 | // window, we need to get rid of the starting transition. |
| 2251 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2252 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | + ": no more real windows"); |
| 2254 | } |
| 2255 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2256 | mH.sendMessage(m); |
| 2257 | } |
| 2258 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2259 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2260 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2261 | mLastWallpaperTimeoutTime = 0; |
| 2262 | adjustWallpaperWindowsLocked(); |
| 2263 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2264 | adjustWallpaperWindowsLocked(); |
| 2265 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | if (!mInLayout) { |
| 2268 | assignLayersLocked(); |
| 2269 | mLayoutNeeded = true; |
| 2270 | performLayoutAndPlaceSurfacesLocked(); |
| 2271 | if (win.mAppToken != null) { |
| 2272 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2273 | } |
| 2274 | } |
| 2275 | } |
| 2276 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2277 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2278 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2279 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2280 | if (where != null) { |
| 2281 | Slog.i(TAG, str, where); |
| 2282 | } else { |
| 2283 | Slog.i(TAG, str); |
| 2284 | } |
| 2285 | } |
| 2286 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2288 | long origId = Binder.clearCallingIdentity(); |
| 2289 | try { |
| 2290 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2291 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2293 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | Surface.openTransaction(); |
| 2295 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2296 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2297 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2298 | w.mSurface.setTransparentRegionHint(region); |
| 2299 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2300 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2301 | Surface.closeTransaction(); |
| 2302 | } |
| 2303 | } |
| 2304 | } |
| 2305 | } finally { |
| 2306 | Binder.restoreCallingIdentity(origId); |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2311 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2312 | Rect visibleInsets) { |
| 2313 | long origId = Binder.clearCallingIdentity(); |
| 2314 | try { |
| 2315 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2316 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | if (w != null) { |
| 2318 | w.mGivenInsetsPending = false; |
| 2319 | w.mGivenContentInsets.set(contentInsets); |
| 2320 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2321 | w.mTouchableInsets = touchableInsets; |
| 2322 | mLayoutNeeded = true; |
| 2323 | performLayoutAndPlaceSurfacesLocked(); |
| 2324 | } |
| 2325 | } |
| 2326 | } finally { |
| 2327 | Binder.restoreCallingIdentity(origId); |
| 2328 | } |
| 2329 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2331 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2332 | Rect outDisplayFrame) { |
| 2333 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2334 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | if (win == null) { |
| 2336 | outDisplayFrame.setEmpty(); |
| 2337 | return; |
| 2338 | } |
| 2339 | outDisplayFrame.set(win.mDisplayFrame); |
| 2340 | } |
| 2341 | } |
| 2342 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2343 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2344 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2345 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2346 | window.mWallpaperX = x; |
| 2347 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2348 | window.mWallpaperXStep = xStep; |
| 2349 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2350 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2351 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2352 | } |
| 2353 | } |
| 2354 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2355 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2356 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2357 | synchronized (mWindowMap) { |
| 2358 | if (mWaitingOnWallpaper != null && |
| 2359 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2360 | mWaitingOnWallpaper = null; |
| 2361 | mWindowMap.notifyAll(); |
| 2362 | } |
| 2363 | } |
| 2364 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2365 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2366 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2367 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2368 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2369 | || window == mUpperWallpaperTarget) { |
| 2370 | boolean doWait = sync; |
| 2371 | int curTokenIndex = mWallpaperTokens.size(); |
| 2372 | while (curTokenIndex > 0) { |
| 2373 | curTokenIndex--; |
| 2374 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2375 | int curWallpaperIndex = token.windows.size(); |
| 2376 | while (curWallpaperIndex > 0) { |
| 2377 | curWallpaperIndex--; |
| 2378 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2379 | try { |
| 2380 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2381 | x, y, z, extras, sync); |
| 2382 | // We only want to be synchronous with one wallpaper. |
| 2383 | sync = false; |
| 2384 | } catch (RemoteException e) { |
| 2385 | } |
| 2386 | } |
| 2387 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2388 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2389 | if (doWait) { |
| 2390 | // XXX Need to wait for result. |
| 2391 | } |
| 2392 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2393 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2394 | return null; |
| 2395 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | public int relayoutWindow(Session session, IWindow client, |
| 2398 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2399 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2400 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2401 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | boolean displayed = false; |
| 2403 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2404 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2405 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2406 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2408 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | if (win == null) { |
| 2410 | return 0; |
| 2411 | } |
| 2412 | win.mRequestedWidth = requestedWidth; |
| 2413 | win.mRequestedHeight = requestedHeight; |
| 2414 | |
| 2415 | if (attrs != null) { |
| 2416 | mPolicy.adjustWindowParamsLw(attrs); |
| 2417 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2418 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2419 | int attrChanges = 0; |
| 2420 | int flagChanges = 0; |
| 2421 | if (attrs != null) { |
| 2422 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2423 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2424 | } |
| 2425 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2426 | 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] | 2427 | |
| 2428 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2429 | win.mAlpha = attrs.alpha; |
| 2430 | } |
| 2431 | |
| 2432 | final boolean scaledWindow = |
| 2433 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2434 | |
| 2435 | if (scaledWindow) { |
| 2436 | // requested{Width|Height} Surface's physical size |
| 2437 | // attrs.{width|height} Size on screen |
| 2438 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2439 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2440 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2441 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2442 | } else { |
| 2443 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | boolean imMayMove = (flagChanges&( |
| 2447 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2448 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2451 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2452 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2453 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2454 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2455 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2456 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | win.mRelayoutCalled = true; |
| 2458 | final int oldVisibility = win.mViewVisibility; |
| 2459 | win.mViewVisibility = viewVisibility; |
| 2460 | if (viewVisibility == View.VISIBLE && |
| 2461 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2462 | displayed = !win.isVisibleLw(); |
| 2463 | if (win.mExiting) { |
| 2464 | win.mExiting = false; |
| 2465 | win.mAnimation = null; |
| 2466 | } |
| 2467 | if (win.mDestroying) { |
| 2468 | win.mDestroying = false; |
| 2469 | mDestroySurface.remove(win); |
| 2470 | } |
| 2471 | if (oldVisibility == View.GONE) { |
| 2472 | win.mEnterAnimationPending = true; |
| 2473 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2474 | if (displayed) { |
| 2475 | if (win.mSurface != null && !win.mDrawPending |
| 2476 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2477 | && mPolicy.isScreenOn()) { |
| 2478 | applyEnterAnimationLocked(win); |
| 2479 | } |
| 2480 | if ((win.mAttrs.flags |
| 2481 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2482 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2483 | "Relayout window turning screen on: " + win); |
| 2484 | win.mTurnOnScreen = true; |
| 2485 | } |
| 2486 | int diff = 0; |
| 2487 | if (win.mConfiguration != mCurConfiguration |
| 2488 | && (win.mConfiguration == null |
| 2489 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2490 | win.mConfiguration = mCurConfiguration; |
| 2491 | if (DEBUG_CONFIGURATION) { |
| 2492 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2493 | + win.mConfiguration + " / 0x" |
| 2494 | + Integer.toHexString(diff)); |
| 2495 | } |
| 2496 | outConfig.setTo(mCurConfiguration); |
| 2497 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2498 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2500 | // To change the format, we need to re-build the surface. |
| 2501 | win.destroySurfaceLocked(); |
| 2502 | displayed = true; |
| 2503 | } |
| 2504 | try { |
| 2505 | Surface surface = win.createSurfaceLocked(); |
| 2506 | if (surface != null) { |
| 2507 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2508 | win.mReportDestroySurface = false; |
| 2509 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2510 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2511 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2513 | // For some reason there isn't a surface. Clear the |
| 2514 | // caller's object so they see the same state. |
| 2515 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | } |
| 2517 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2518 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2519 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2520 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2521 | Binder.restoreCallingIdentity(origId); |
| 2522 | return 0; |
| 2523 | } |
| 2524 | if (displayed) { |
| 2525 | focusMayChange = true; |
| 2526 | } |
| 2527 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2528 | && mInputMethodWindow == null) { |
| 2529 | mInputMethodWindow = win; |
| 2530 | imMayMove = true; |
| 2531 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2532 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2533 | && win.mAppToken != null |
| 2534 | && win.mAppToken.startingWindow != null) { |
| 2535 | // Special handling of starting window over the base |
| 2536 | // window of the app: propagate lock screen flags to it, |
| 2537 | // to provide the correct semantics while starting. |
| 2538 | final int mask = |
| 2539 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2540 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2541 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2542 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2543 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2544 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | } else { |
| 2546 | win.mEnterAnimationPending = false; |
| 2547 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2548 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2549 | + ": mExiting=" + win.mExiting |
| 2550 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | // If we are not currently running the exit animation, we |
| 2552 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2553 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | // Try starting an animation; if there isn't one, we |
| 2555 | // can destroy the surface right away. |
| 2556 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2557 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2558 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2559 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2560 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2561 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2562 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2563 | win.mExiting = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2564 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 2565 | mInputMonitor.windowIsBecomingInvisibleLw(win); |
| 2566 | } else { |
| 2567 | mKeyWaiter.finishedKey(session, client, true, |
| 2568 | KeyWaiter.RETURN_NOTHING); |
| 2569 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2570 | } else if (win.isAnimating()) { |
| 2571 | // Currently in a hide animation... turn this into |
| 2572 | // an exit. |
| 2573 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2574 | } else if (win == mWallpaperTarget) { |
| 2575 | // If the wallpaper is currently behind this |
| 2576 | // window, we need to change both of them inside |
| 2577 | // of a transaction to avoid artifacts. |
| 2578 | win.mExiting = true; |
| 2579 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2580 | } else { |
| 2581 | if (mInputMethodWindow == win) { |
| 2582 | mInputMethodWindow = null; |
| 2583 | } |
| 2584 | win.destroySurfaceLocked(); |
| 2585 | } |
| 2586 | } |
| 2587 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2588 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2589 | if (win.mSurface == null || (win.getAttrs().flags |
| 2590 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2591 | || win.mSurfacePendingDestroy) { |
| 2592 | // We are being called from a local process, which |
| 2593 | // means outSurface holds its current surface. Ensure the |
| 2594 | // surface object is cleared, but we don't want it actually |
| 2595 | // destroyed at this point. |
| 2596 | win.mSurfacePendingDestroy = false; |
| 2597 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2598 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2599 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2600 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2601 | "Keeping surface, will report destroy: " + win); |
| 2602 | win.mReportDestroySurface = true; |
| 2603 | outSurface.copyFrom(win.mSurface); |
| 2604 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | } |
| 2606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | if (focusMayChange) { |
| 2608 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2609 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | imMayMove = false; |
| 2611 | } |
| 2612 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2614 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2615 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2616 | // reassign them at this point if the IM window state gets shuffled |
| 2617 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2618 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2619 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2620 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2621 | // Little hack here -- we -should- be able to rely on the |
| 2622 | // function to return true if the IME has moved and needs |
| 2623 | // its layer recomputed. However, if the IME was hidden |
| 2624 | // and isn't actually moved in the list, its layer may be |
| 2625 | // 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] | 2626 | assignLayers = true; |
| 2627 | } |
| 2628 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2629 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2630 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2631 | assignLayers = true; |
| 2632 | } |
| 2633 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2634 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | mLayoutNeeded = true; |
| 2636 | win.mGivenInsetsPending = insetsPending; |
| 2637 | if (assignLayers) { |
| 2638 | assignLayersLocked(); |
| 2639 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2640 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2642 | if (displayed && win.mIsWallpaper) { |
| 2643 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2644 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2645 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2646 | if (win.mAppToken != null) { |
| 2647 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2648 | } |
| 2649 | outFrame.set(win.mFrame); |
| 2650 | outContentInsets.set(win.mContentInsets); |
| 2651 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2652 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2654 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | + ", requestedHeight=" + requestedHeight |
| 2656 | + ", viewVisibility=" + viewVisibility |
| 2657 | + "\nRelayout returning frame=" + outFrame |
| 2658 | + ", surface=" + outSurface); |
| 2659 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2660 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2662 | |
| 2663 | inTouchMode = mInTouchMode; |
| 2664 | } |
| 2665 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2666 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | sendNewConfiguration(); |
| 2668 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2669 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2671 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2673 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2674 | } |
| 2675 | |
| 2676 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2677 | final long origId = Binder.clearCallingIdentity(); |
| 2678 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2679 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2680 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2681 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2682 | adjustWallpaperWindowsLocked(); |
| 2683 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2684 | mLayoutNeeded = true; |
| 2685 | performLayoutAndPlaceSurfacesLocked(); |
| 2686 | } |
| 2687 | } |
| 2688 | Binder.restoreCallingIdentity(origId); |
| 2689 | } |
| 2690 | |
| 2691 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2692 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2693 | + (lp != null ? lp.packageName : null) |
| 2694 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2695 | if (lp != null && lp.windowAnimations != 0) { |
| 2696 | // If this is a system resource, don't try to load it from the |
| 2697 | // application resources. It is nice to avoid loading application |
| 2698 | // resources if we can. |
| 2699 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2700 | int resId = lp.windowAnimations; |
| 2701 | if ((resId&0xFF000000) == 0x01000000) { |
| 2702 | packageName = "android"; |
| 2703 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2704 | 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] | 2705 | + packageName); |
| 2706 | return AttributeCache.instance().get(packageName, resId, |
| 2707 | com.android.internal.R.styleable.WindowAnimation); |
| 2708 | } |
| 2709 | return null; |
| 2710 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2711 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2712 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2713 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2714 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2715 | if (packageName != null) { |
| 2716 | if ((resId&0xFF000000) == 0x01000000) { |
| 2717 | packageName = "android"; |
| 2718 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2719 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2720 | + packageName); |
| 2721 | return AttributeCache.instance().get(packageName, resId, |
| 2722 | com.android.internal.R.styleable.WindowAnimation); |
| 2723 | } |
| 2724 | return null; |
| 2725 | } |
| 2726 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | private void applyEnterAnimationLocked(WindowState win) { |
| 2728 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2729 | if (win.mEnterAnimationPending) { |
| 2730 | win.mEnterAnimationPending = false; |
| 2731 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2732 | } |
| 2733 | |
| 2734 | applyAnimationLocked(win, transit, true); |
| 2735 | } |
| 2736 | |
| 2737 | private boolean applyAnimationLocked(WindowState win, |
| 2738 | int transit, boolean isEntrance) { |
| 2739 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2740 | // If we are trying to apply an animation, but already running |
| 2741 | // an animation of the same type, then just leave that one alone. |
| 2742 | return true; |
| 2743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2745 | // Only apply an animation if the display isn't frozen. If it is |
| 2746 | // frozen, there is no reason to animate and it can cause strange |
| 2747 | // artifacts when we unfreeze the display if some different animation |
| 2748 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2749 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2751 | int attr = -1; |
| 2752 | Animation a = null; |
| 2753 | if (anim != 0) { |
| 2754 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2755 | } else { |
| 2756 | switch (transit) { |
| 2757 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2758 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2759 | break; |
| 2760 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2761 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2762 | break; |
| 2763 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2764 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2765 | break; |
| 2766 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2767 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2768 | break; |
| 2769 | } |
| 2770 | if (attr >= 0) { |
| 2771 | a = loadAnimation(win.mAttrs, attr); |
| 2772 | } |
| 2773 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2774 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2776 | + " mAnimation=" + win.mAnimation |
| 2777 | + " isEntrance=" + isEntrance); |
| 2778 | if (a != null) { |
| 2779 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2780 | RuntimeException e = null; |
| 2781 | if (!HIDE_STACK_CRAWLS) { |
| 2782 | e = new RuntimeException(); |
| 2783 | e.fillInStackTrace(); |
| 2784 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2785 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | } |
| 2787 | win.setAnimation(a); |
| 2788 | win.mAnimationIsEntrance = isEntrance; |
| 2789 | } |
| 2790 | } else { |
| 2791 | win.clearAnimation(); |
| 2792 | } |
| 2793 | |
| 2794 | return win.mAnimation != null; |
| 2795 | } |
| 2796 | |
| 2797 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2798 | int anim = 0; |
| 2799 | Context context = mContext; |
| 2800 | if (animAttr >= 0) { |
| 2801 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2802 | if (ent != null) { |
| 2803 | context = ent.context; |
| 2804 | anim = ent.array.getResourceId(animAttr, 0); |
| 2805 | } |
| 2806 | } |
| 2807 | if (anim != 0) { |
| 2808 | return AnimationUtils.loadAnimation(context, anim); |
| 2809 | } |
| 2810 | return null; |
| 2811 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2812 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2813 | private Animation loadAnimation(String packageName, int resId) { |
| 2814 | int anim = 0; |
| 2815 | Context context = mContext; |
| 2816 | if (resId >= 0) { |
| 2817 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2818 | if (ent != null) { |
| 2819 | context = ent.context; |
| 2820 | anim = resId; |
| 2821 | } |
| 2822 | } |
| 2823 | if (anim != 0) { |
| 2824 | return AnimationUtils.loadAnimation(context, anim); |
| 2825 | } |
| 2826 | return null; |
| 2827 | } |
| 2828 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2830 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2831 | // Only apply an animation if the display isn't frozen. If it is |
| 2832 | // frozen, there is no reason to animate and it can cause strange |
| 2833 | // artifacts when we unfreeze the display if some different animation |
| 2834 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2835 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2836 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2837 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2838 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2839 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2840 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2841 | } else if (mNextAppTransitionPackage != null) { |
| 2842 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2843 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2844 | } else { |
| 2845 | int animAttr = 0; |
| 2846 | switch (transit) { |
| 2847 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2848 | animAttr = enter |
| 2849 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2850 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2851 | break; |
| 2852 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2853 | animAttr = enter |
| 2854 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2855 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2856 | break; |
| 2857 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2858 | animAttr = enter |
| 2859 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2860 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2861 | break; |
| 2862 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2863 | animAttr = enter |
| 2864 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2865 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2866 | break; |
| 2867 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2868 | animAttr = enter |
| 2869 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2870 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2871 | break; |
| 2872 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2873 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2874 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2875 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2876 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2877 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2878 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2879 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2880 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2881 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2882 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2883 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2884 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2885 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2886 | break; |
| 2887 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2888 | animAttr = enter |
| 2889 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2890 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2891 | break; |
| 2892 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2893 | animAttr = enter |
| 2894 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2895 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2896 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2897 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2898 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2899 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2900 | + " anim=" + a |
| 2901 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2902 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2904 | if (a != null) { |
| 2905 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2906 | RuntimeException e = null; |
| 2907 | if (!HIDE_STACK_CRAWLS) { |
| 2908 | e = new RuntimeException(); |
| 2909 | e.fillInStackTrace(); |
| 2910 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2911 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | } |
| 2913 | wtoken.setAnimation(a); |
| 2914 | } |
| 2915 | } else { |
| 2916 | wtoken.clearAnimation(); |
| 2917 | } |
| 2918 | |
| 2919 | return wtoken.animation != null; |
| 2920 | } |
| 2921 | |
| 2922 | // ------------------------------------------------------------- |
| 2923 | // Application Window Tokens |
| 2924 | // ------------------------------------------------------------- |
| 2925 | |
| 2926 | public void validateAppTokens(List tokens) { |
| 2927 | int v = tokens.size()-1; |
| 2928 | int m = mAppTokens.size()-1; |
| 2929 | while (v >= 0 && m >= 0) { |
| 2930 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2931 | if (wtoken.removed) { |
| 2932 | m--; |
| 2933 | continue; |
| 2934 | } |
| 2935 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2936 | 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] | 2937 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2938 | } |
| 2939 | v--; |
| 2940 | m--; |
| 2941 | } |
| 2942 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2943 | 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] | 2944 | v--; |
| 2945 | } |
| 2946 | while (m >= 0) { |
| 2947 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2948 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2949 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2950 | } |
| 2951 | m--; |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | boolean checkCallingPermission(String permission, String func) { |
| 2956 | // Quick check: if the calling permission is me, it's all okay. |
| 2957 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2958 | return true; |
| 2959 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2960 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | if (mContext.checkCallingPermission(permission) |
| 2962 | == PackageManager.PERMISSION_GRANTED) { |
| 2963 | return true; |
| 2964 | } |
| 2965 | String msg = "Permission Denial: " + func + " from pid=" |
| 2966 | + Binder.getCallingPid() |
| 2967 | + ", uid=" + Binder.getCallingUid() |
| 2968 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2969 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | return false; |
| 2971 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2974 | WindowToken wtoken = mTokenMap.get(token); |
| 2975 | if (wtoken == null) { |
| 2976 | return null; |
| 2977 | } |
| 2978 | return wtoken.appWindowToken; |
| 2979 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2980 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | public void addWindowToken(IBinder token, int type) { |
| 2982 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2983 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2984 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2986 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | synchronized(mWindowMap) { |
| 2988 | WindowToken wtoken = mTokenMap.get(token); |
| 2989 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2990 | 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] | 2991 | return; |
| 2992 | } |
| 2993 | wtoken = new WindowToken(token, type, true); |
| 2994 | mTokenMap.put(token, wtoken); |
| 2995 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2996 | if (type == TYPE_WALLPAPER) { |
| 2997 | mWallpaperTokens.add(wtoken); |
| 2998 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2999 | } |
| 3000 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | public void removeWindowToken(IBinder token) { |
| 3003 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3004 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3005 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | final long origId = Binder.clearCallingIdentity(); |
| 3009 | synchronized(mWindowMap) { |
| 3010 | WindowToken wtoken = mTokenMap.remove(token); |
| 3011 | mTokenList.remove(wtoken); |
| 3012 | if (wtoken != null) { |
| 3013 | boolean delayed = false; |
| 3014 | if (!wtoken.hidden) { |
| 3015 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3016 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3017 | final int N = wtoken.windows.size(); |
| 3018 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3020 | for (int i=0; i<N; i++) { |
| 3021 | WindowState win = wtoken.windows.get(i); |
| 3022 | |
| 3023 | if (win.isAnimating()) { |
| 3024 | delayed = true; |
| 3025 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3026 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | if (win.isVisibleNow()) { |
| 3028 | applyAnimationLocked(win, |
| 3029 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3030 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 3031 | mInputMonitor.windowIsBeingRemovedLw(win); |
| 3032 | } else { |
| 3033 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3034 | KeyWaiter.RETURN_NOTHING); |
| 3035 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | changed = true; |
| 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | if (changed) { |
| 3041 | mLayoutNeeded = true; |
| 3042 | performLayoutAndPlaceSurfacesLocked(); |
| 3043 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3044 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3046 | if (delayed) { |
| 3047 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3048 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3049 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | } |
| 3051 | } |
| 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 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3054 | 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] | 3055 | } |
| 3056 | } |
| 3057 | Binder.restoreCallingIdentity(origId); |
| 3058 | } |
| 3059 | |
| 3060 | public void addAppToken(int addPos, IApplicationToken token, |
| 3061 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3062 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3063 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3064 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3066 | |
| 3067 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3068 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3069 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3070 | // here we would run the chance of introducing a deadlock between the window manager |
| 3071 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3072 | // (which holds locks while querying the application token). |
| 3073 | long inputDispatchingTimeoutNanos; |
| 3074 | try { |
| 3075 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3076 | } catch (RemoteException ex) { |
| 3077 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3078 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3079 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3080 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | synchronized(mWindowMap) { |
| 3082 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3083 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3084 | 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] | 3085 | return; |
| 3086 | } |
| 3087 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3088 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | wtoken.groupId = groupId; |
| 3090 | wtoken.appFullscreen = fullscreen; |
| 3091 | wtoken.requestedOrientation = requestedOrientation; |
| 3092 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3093 | if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3094 | mTokenMap.put(token.asBinder(), wtoken); |
| 3095 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3096 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | // Application tokens start out hidden. |
| 3098 | wtoken.hidden = true; |
| 3099 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3101 | //dump(); |
| 3102 | } |
| 3103 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3104 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | public void setAppGroupId(IBinder token, int groupId) { |
| 3106 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3107 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3108 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | synchronized(mWindowMap) { |
| 3112 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3113 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3114 | 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] | 3115 | return; |
| 3116 | } |
| 3117 | wtoken.groupId = groupId; |
| 3118 | } |
| 3119 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | public int getOrientationFromWindowsLocked() { |
| 3122 | int pos = mWindows.size() - 1; |
| 3123 | while (pos >= 0) { |
| 3124 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 3125 | pos--; |
| 3126 | if (wtoken.mAppToken != null) { |
| 3127 | // We hit an application window. so the orientation will be determined by the |
| 3128 | // app window. No point in continuing further. |
| 3129 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3130 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3131 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | continue; |
| 3133 | } |
| 3134 | int req = wtoken.mAttrs.screenOrientation; |
| 3135 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3136 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3137 | continue; |
| 3138 | } else { |
| 3139 | return req; |
| 3140 | } |
| 3141 | } |
| 3142 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3143 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3144 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3146 | int pos = mAppTokens.size() - 1; |
| 3147 | int curGroup = 0; |
| 3148 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3149 | boolean findingBehind = false; |
| 3150 | boolean haveGroup = false; |
| 3151 | boolean lastFullscreen = false; |
| 3152 | while (pos >= 0) { |
| 3153 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3154 | pos--; |
| 3155 | // if we're about to tear down this window and not seek for |
| 3156 | // the behind activity, don't use it for orientation |
| 3157 | if (!findingBehind |
| 3158 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3159 | continue; |
| 3160 | } |
| 3161 | |
| 3162 | if (!haveGroup) { |
| 3163 | // We ignore any hidden applications on the top. |
| 3164 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3165 | continue; |
| 3166 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3167 | haveGroup = true; |
| 3168 | curGroup = wtoken.groupId; |
| 3169 | lastOrientation = wtoken.requestedOrientation; |
| 3170 | } else if (curGroup != wtoken.groupId) { |
| 3171 | // If we have hit a new application group, and the bottom |
| 3172 | // of the previous group didn't explicitly say to use |
| 3173 | // the orientation behind it, and the last app was |
| 3174 | // full screen, then we'll stick with the |
| 3175 | // user's orientation. |
| 3176 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3177 | && lastFullscreen) { |
| 3178 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3179 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3181 | int or = wtoken.requestedOrientation; |
| 3182 | // If this application is fullscreen, and didn't explicitly say |
| 3183 | // to use the orientation behind it, then just take whatever |
| 3184 | // orientation it has and ignores whatever is under it. |
| 3185 | lastFullscreen = wtoken.appFullscreen; |
| 3186 | if (lastFullscreen |
| 3187 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3188 | return or; |
| 3189 | } |
| 3190 | // If this application has requested an explicit orientation, |
| 3191 | // then use it. |
| 3192 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3193 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3194 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3195 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3196 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3197 | return or; |
| 3198 | } |
| 3199 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3200 | } |
| 3201 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3203 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3205 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3206 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3207 | "updateOrientationFromAppTokens()")) { |
| 3208 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3209 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3210 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3211 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3212 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3213 | |
| 3214 | synchronized(mWindowMap) { |
| 3215 | if (updateOrientationFromAppTokensLocked()) { |
| 3216 | if (freezeThisOneIfNeeded != null) { |
| 3217 | AppWindowToken wtoken = findAppWindowToken( |
| 3218 | freezeThisOneIfNeeded); |
| 3219 | if (wtoken != null) { |
| 3220 | startAppFreezingScreenLocked(wtoken, |
| 3221 | ActivityInfo.CONFIG_ORIENTATION); |
| 3222 | } |
| 3223 | } |
| 3224 | config = computeNewConfigurationLocked(); |
| 3225 | |
| 3226 | } else if (currentConfig != null) { |
| 3227 | // No obvious action we need to take, but if our current |
| 3228 | // state mismatches the activity maanager's, update it |
| 3229 | mTempConfiguration.setToDefaults(); |
| 3230 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3231 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3232 | mWaitingForConfig = true; |
| 3233 | mLayoutNeeded = true; |
| 3234 | startFreezingDisplayLocked(); |
| 3235 | config = new Configuration(mTempConfiguration); |
| 3236 | } |
| 3237 | } |
| 3238 | } |
| 3239 | } |
| 3240 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3241 | Binder.restoreCallingIdentity(ident); |
| 3242 | return config; |
| 3243 | } |
| 3244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3246 | * Determine the new desired orientation of the display, returning |
| 3247 | * a non-null new Configuration if it has changed from the current |
| 3248 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3249 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3250 | * SCREEN. This will typically be done for you if you call |
| 3251 | * sendNewConfiguration(). |
| 3252 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | * The orientation is computed from non-application windows first. If none of |
| 3254 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3255 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3257 | * android.os.IBinder) |
| 3258 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3259 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3260 | if (mDisplayFrozen) { |
| 3261 | // If the display is frozen, some activities may be in the middle |
| 3262 | // of restarting, and thus have removed their old window. If the |
| 3263 | // window has the flag to hide the lock screen, then the lock screen |
| 3264 | // can re-appear and inflict its own orientation on us. Keep the |
| 3265 | // orientation stable until this all settles down. |
| 3266 | return false; |
| 3267 | } |
| 3268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3270 | long ident = Binder.clearCallingIdentity(); |
| 3271 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3272 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3275 | mForcedAppOrientation = req; |
| 3276 | //send a message to Policy indicating orientation change to take |
| 3277 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3278 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3279 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3280 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3281 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3282 | } |
| 3283 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3284 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3285 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | } finally { |
| 3287 | Binder.restoreCallingIdentity(ident); |
| 3288 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3289 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3290 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3291 | int computeForcedAppOrientationLocked() { |
| 3292 | int req = getOrientationFromWindowsLocked(); |
| 3293 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3294 | req = getOrientationFromAppTokensLocked(); |
| 3295 | } |
| 3296 | return req; |
| 3297 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3298 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3299 | public void setNewConfiguration(Configuration config) { |
| 3300 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3301 | "setNewConfiguration()")) { |
| 3302 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3303 | } |
| 3304 | |
| 3305 | synchronized(mWindowMap) { |
| 3306 | mCurConfiguration = new Configuration(config); |
| 3307 | mWaitingForConfig = false; |
| 3308 | performLayoutAndPlaceSurfacesLocked(); |
| 3309 | } |
| 3310 | } |
| 3311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3313 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3314 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3315 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | synchronized(mWindowMap) { |
| 3319 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3320 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3321 | 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] | 3322 | return; |
| 3323 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | wtoken.requestedOrientation = requestedOrientation; |
| 3326 | } |
| 3327 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3329 | public int getAppOrientation(IApplicationToken token) { |
| 3330 | synchronized(mWindowMap) { |
| 3331 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3332 | if (wtoken == null) { |
| 3333 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3334 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | return wtoken.requestedOrientation; |
| 3337 | } |
| 3338 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3341 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3342 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3343 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | synchronized(mWindowMap) { |
| 3347 | boolean changed = false; |
| 3348 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3349 | 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] | 3350 | changed = mFocusedApp != null; |
| 3351 | mFocusedApp = null; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3352 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 3353 | if (changed) { |
| 3354 | mInputMonitor.setFocusedAppLw(null); |
| 3355 | } |
| 3356 | } else { |
| 3357 | mKeyWaiter.tickle(); |
| 3358 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | } else { |
| 3360 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3361 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3362 | 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] | 3363 | return; |
| 3364 | } |
| 3365 | changed = mFocusedApp != newFocus; |
| 3366 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3367 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3368 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 3369 | if (changed) { |
| 3370 | mInputMonitor.setFocusedAppLw(newFocus); |
| 3371 | } |
| 3372 | } else { |
| 3373 | mKeyWaiter.tickle(); |
| 3374 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | if (moveFocusNow && changed) { |
| 3378 | final long origId = Binder.clearCallingIdentity(); |
| 3379 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3380 | Binder.restoreCallingIdentity(origId); |
| 3381 | } |
| 3382 | } |
| 3383 | } |
| 3384 | |
| 3385 | public void prepareAppTransition(int transit) { |
| 3386 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3387 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3388 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3391 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3392 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3393 | TAG, "Prepare app transition: transit=" + transit |
| 3394 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3395 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3396 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3397 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3398 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3399 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3400 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3401 | // Opening a new task always supersedes a close for the anim. |
| 3402 | mNextAppTransition = transit; |
| 3403 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3404 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3405 | // Opening a new activity always supersedes a close for the anim. |
| 3406 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3407 | } |
| 3408 | mAppTransitionReady = false; |
| 3409 | mAppTransitionTimeout = false; |
| 3410 | mStartingIconInTransition = false; |
| 3411 | mSkipAppTransitionAnimation = false; |
| 3412 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3413 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3414 | 5000); |
| 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | public int getPendingAppTransition() { |
| 3420 | return mNextAppTransition; |
| 3421 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3422 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3423 | public void overridePendingAppTransition(String packageName, |
| 3424 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3425 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3426 | mNextAppTransitionPackage = packageName; |
| 3427 | mNextAppTransitionEnter = enterAnim; |
| 3428 | mNextAppTransitionExit = exitAnim; |
| 3429 | } |
| 3430 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3432 | public void executeAppTransition() { |
| 3433 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3434 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3435 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3436 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3439 | if (DEBUG_APP_TRANSITIONS) { |
| 3440 | RuntimeException e = new RuntimeException("here"); |
| 3441 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3442 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3443 | + mNextAppTransition, e); |
| 3444 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3445 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | mAppTransitionReady = true; |
| 3447 | final long origId = Binder.clearCallingIdentity(); |
| 3448 | performLayoutAndPlaceSurfacesLocked(); |
| 3449 | Binder.restoreCallingIdentity(origId); |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3455 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3456 | IBinder transferFrom, boolean createIfNeeded) { |
| 3457 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3458 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3459 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3463 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3464 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3465 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3466 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3468 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3469 | 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] | 3470 | return; |
| 3471 | } |
| 3472 | |
| 3473 | // If the display is frozen, we won't do anything until the |
| 3474 | // actual window is displayed so there is no reason to put in |
| 3475 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3476 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | return; |
| 3478 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | if (wtoken.startingData != null) { |
| 3481 | return; |
| 3482 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | if (transferFrom != null) { |
| 3485 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3486 | if (ttoken != null) { |
| 3487 | WindowState startingWindow = ttoken.startingWindow; |
| 3488 | if (startingWindow != null) { |
| 3489 | if (mStartingIconInTransition) { |
| 3490 | // In this case, the starting icon has already |
| 3491 | // been displayed, so start letting windows get |
| 3492 | // shown immediately without any more transitions. |
| 3493 | mSkipAppTransitionAnimation = true; |
| 3494 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3495 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | "Moving existing starting from " + ttoken |
| 3497 | + " to " + wtoken); |
| 3498 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3499 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | // Transfer the starting window over to the new |
| 3501 | // token. |
| 3502 | wtoken.startingData = ttoken.startingData; |
| 3503 | wtoken.startingView = ttoken.startingView; |
| 3504 | wtoken.startingWindow = startingWindow; |
| 3505 | ttoken.startingData = null; |
| 3506 | ttoken.startingView = null; |
| 3507 | ttoken.startingWindow = null; |
| 3508 | ttoken.startingMoved = true; |
| 3509 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3510 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3511 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3512 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3513 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | mWindows.remove(startingWindow); |
| 3515 | ttoken.windows.remove(startingWindow); |
| 3516 | ttoken.allAppWindows.remove(startingWindow); |
| 3517 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | // Propagate other interesting state between the |
| 3520 | // tokens. If the old token is displayed, we should |
| 3521 | // immediately force the new one to be displayed. If |
| 3522 | // it is animating, we need to move that animation to |
| 3523 | // the new one. |
| 3524 | if (ttoken.allDrawn) { |
| 3525 | wtoken.allDrawn = true; |
| 3526 | } |
| 3527 | if (ttoken.firstWindowDrawn) { |
| 3528 | wtoken.firstWindowDrawn = true; |
| 3529 | } |
| 3530 | if (!ttoken.hidden) { |
| 3531 | wtoken.hidden = false; |
| 3532 | wtoken.hiddenRequested = false; |
| 3533 | wtoken.willBeHidden = false; |
| 3534 | } |
| 3535 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3536 | wtoken.clientHidden = ttoken.clientHidden; |
| 3537 | wtoken.sendAppVisibilityToClients(); |
| 3538 | } |
| 3539 | if (ttoken.animation != null) { |
| 3540 | wtoken.animation = ttoken.animation; |
| 3541 | wtoken.animating = ttoken.animating; |
| 3542 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3543 | ttoken.animation = null; |
| 3544 | ttoken.animLayerAdjustment = 0; |
| 3545 | wtoken.updateLayers(); |
| 3546 | ttoken.updateLayers(); |
| 3547 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | mLayoutNeeded = true; |
| 3551 | performLayoutAndPlaceSurfacesLocked(); |
| 3552 | Binder.restoreCallingIdentity(origId); |
| 3553 | return; |
| 3554 | } else if (ttoken.startingData != null) { |
| 3555 | // The previous app was getting ready to show a |
| 3556 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3557 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | "Moving pending starting from " + ttoken |
| 3559 | + " to " + wtoken); |
| 3560 | wtoken.startingData = ttoken.startingData; |
| 3561 | ttoken.startingData = null; |
| 3562 | ttoken.startingMoved = true; |
| 3563 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3564 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3565 | // want to process the message ASAP, before any other queued |
| 3566 | // messages. |
| 3567 | mH.sendMessageAtFrontOfQueue(m); |
| 3568 | return; |
| 3569 | } |
| 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | // There is no existing starting window, and the caller doesn't |
| 3574 | // want us to create one, so that's it! |
| 3575 | if (!createIfNeeded) { |
| 3576 | return; |
| 3577 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3578 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3579 | // If this is a translucent or wallpaper window, then don't |
| 3580 | // show a starting window -- the current effect (a full-screen |
| 3581 | // opaque starting window that fades away to the real contents |
| 3582 | // when it is ready) does not work for this. |
| 3583 | if (theme != 0) { |
| 3584 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3585 | com.android.internal.R.styleable.Window); |
| 3586 | if (ent.array.getBoolean( |
| 3587 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3588 | return; |
| 3589 | } |
| 3590 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3591 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3592 | return; |
| 3593 | } |
| 3594 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3595 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3596 | return; |
| 3597 | } |
| 3598 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3599 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | mStartingIconInTransition = true; |
| 3601 | wtoken.startingData = new StartingData( |
| 3602 | pkg, theme, nonLocalizedLabel, |
| 3603 | labelRes, icon); |
| 3604 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3605 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3606 | // want to process the message ASAP, before any other queued |
| 3607 | // messages. |
| 3608 | mH.sendMessageAtFrontOfQueue(m); |
| 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | public void setAppWillBeHidden(IBinder token) { |
| 3613 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3614 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3615 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | AppWindowToken wtoken; |
| 3619 | |
| 3620 | synchronized(mWindowMap) { |
| 3621 | wtoken = findAppWindowToken(token); |
| 3622 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3623 | 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] | 3624 | return; |
| 3625 | } |
| 3626 | wtoken.willBeHidden = true; |
| 3627 | } |
| 3628 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3629 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3631 | boolean visible, int transit, boolean performLayout) { |
| 3632 | boolean delayed = false; |
| 3633 | |
| 3634 | if (wtoken.clientHidden == visible) { |
| 3635 | wtoken.clientHidden = !visible; |
| 3636 | wtoken.sendAppVisibilityToClients(); |
| 3637 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3638 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | wtoken.willBeHidden = false; |
| 3640 | if (wtoken.hidden == visible) { |
| 3641 | final int N = wtoken.allAppWindows.size(); |
| 3642 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3643 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3644 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3645 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3646 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3648 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3649 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | if (wtoken.animation == sDummyAnimation) { |
| 3651 | wtoken.animation = null; |
| 3652 | } |
| 3653 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3654 | changed = true; |
| 3655 | if (wtoken.animation != null) { |
| 3656 | delayed = runningAppAnimation = true; |
| 3657 | } |
| 3658 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | for (int i=0; i<N; i++) { |
| 3661 | WindowState win = wtoken.allAppWindows.get(i); |
| 3662 | if (win == wtoken.startingWindow) { |
| 3663 | continue; |
| 3664 | } |
| 3665 | |
| 3666 | if (win.isAnimating()) { |
| 3667 | delayed = true; |
| 3668 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3669 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3670 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | //win.dump(" "); |
| 3672 | if (visible) { |
| 3673 | if (!win.isVisibleNow()) { |
| 3674 | if (!runningAppAnimation) { |
| 3675 | applyAnimationLocked(win, |
| 3676 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3677 | } |
| 3678 | changed = true; |
| 3679 | } |
| 3680 | } else if (win.isVisibleNow()) { |
| 3681 | if (!runningAppAnimation) { |
| 3682 | applyAnimationLocked(win, |
| 3683 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3684 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3685 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 3686 | mInputMonitor.windowIsBecomingInvisibleLw(win); |
| 3687 | } else { |
| 3688 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3689 | KeyWaiter.RETURN_NOTHING); |
| 3690 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | changed = true; |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3696 | if (!visible) { |
| 3697 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3698 | } else { |
| 3699 | // If we are being set visible, and the starting window is |
| 3700 | // not yet displayed, then make sure it doesn't get displayed. |
| 3701 | WindowState swin = wtoken.startingWindow; |
| 3702 | if (swin != null && (swin.mDrawPending |
| 3703 | || swin.mCommitDrawPending)) { |
| 3704 | swin.mPolicyVisibility = false; |
| 3705 | swin.mPolicyVisibilityAfterAnim = false; |
| 3706 | } |
| 3707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3708 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3709 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3711 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3712 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3713 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3715 | if (performLayout) { |
| 3716 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3717 | performLayoutAndPlaceSurfacesLocked(); |
| 3718 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | } |
| 3720 | } |
| 3721 | |
| 3722 | if (wtoken.animation != null) { |
| 3723 | delayed = true; |
| 3724 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3725 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | return delayed; |
| 3727 | } |
| 3728 | |
| 3729 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3730 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3731 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3732 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | AppWindowToken wtoken; |
| 3736 | |
| 3737 | synchronized(mWindowMap) { |
| 3738 | wtoken = findAppWindowToken(token); |
| 3739 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3740 | 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] | 3741 | return; |
| 3742 | } |
| 3743 | |
| 3744 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3745 | RuntimeException e = null; |
| 3746 | if (!HIDE_STACK_CRAWLS) { |
| 3747 | e = new RuntimeException(); |
| 3748 | e.fillInStackTrace(); |
| 3749 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3750 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | + "): mNextAppTransition=" + mNextAppTransition |
| 3752 | + " hidden=" + wtoken.hidden |
| 3753 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3754 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3755 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3756 | // If we are preparing an app transition, then delay changing |
| 3757 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3758 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3759 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3760 | // Already in requested state, don't do anything more. |
| 3761 | if (wtoken.hiddenRequested != visible) { |
| 3762 | return; |
| 3763 | } |
| 3764 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3765 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3766 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | TAG, "Setting dummy animation on: " + wtoken); |
| 3768 | wtoken.setDummyAnimation(); |
| 3769 | mOpeningApps.remove(wtoken); |
| 3770 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3771 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | wtoken.inPendingTransaction = true; |
| 3773 | if (visible) { |
| 3774 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3775 | wtoken.startingDisplayed = false; |
| 3776 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3777 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3778 | // If the token is currently hidden (should be the |
| 3779 | // common case), then we need to set up to wait for |
| 3780 | // its windows to be ready. |
| 3781 | if (wtoken.hidden) { |
| 3782 | wtoken.allDrawn = false; |
| 3783 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3784 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3785 | if (wtoken.clientHidden) { |
| 3786 | // In the case where we are making an app visible |
| 3787 | // but holding off for a transition, we still need |
| 3788 | // to tell the client to make its windows visible so |
| 3789 | // they get drawn. Otherwise, we will wait on |
| 3790 | // performing the transition until all windows have |
| 3791 | // been drawn, they never will be, and we are sad. |
| 3792 | wtoken.clientHidden = false; |
| 3793 | wtoken.sendAppVisibilityToClients(); |
| 3794 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3795 | } |
| 3796 | } else { |
| 3797 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3798 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3799 | // If the token is currently visible (should be the |
| 3800 | // common case), then set up to wait for it to be hidden. |
| 3801 | if (!wtoken.hidden) { |
| 3802 | wtoken.waitingToHide = true; |
| 3803 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | } |
| 3805 | return; |
| 3806 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3807 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3808 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3809 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | wtoken.updateReportedVisibilityLocked(); |
| 3811 | Binder.restoreCallingIdentity(origId); |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3816 | boolean unfreezeSurfaceNow, boolean force) { |
| 3817 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3818 | 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] | 3819 | + " force=" + force); |
| 3820 | final int N = wtoken.allAppWindows.size(); |
| 3821 | boolean unfrozeWindows = false; |
| 3822 | for (int i=0; i<N; i++) { |
| 3823 | WindowState w = wtoken.allAppWindows.get(i); |
| 3824 | if (w.mAppFreezing) { |
| 3825 | w.mAppFreezing = false; |
| 3826 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3827 | w.mOrientationChanging = true; |
| 3828 | } |
| 3829 | unfrozeWindows = true; |
| 3830 | } |
| 3831 | } |
| 3832 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3833 | 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] | 3834 | wtoken.freezingScreen = false; |
| 3835 | mAppsFreezingScreen--; |
| 3836 | } |
| 3837 | if (unfreezeSurfaceNow) { |
| 3838 | if (unfrozeWindows) { |
| 3839 | mLayoutNeeded = true; |
| 3840 | performLayoutAndPlaceSurfacesLocked(); |
| 3841 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3842 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3846 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3848 | int configChanges) { |
| 3849 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3850 | RuntimeException e = null; |
| 3851 | if (!HIDE_STACK_CRAWLS) { |
| 3852 | e = new RuntimeException(); |
| 3853 | e.fillInStackTrace(); |
| 3854 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3855 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3856 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3857 | + wtoken.freezingScreen, e); |
| 3858 | } |
| 3859 | if (!wtoken.hiddenRequested) { |
| 3860 | if (!wtoken.freezingScreen) { |
| 3861 | wtoken.freezingScreen = true; |
| 3862 | mAppsFreezingScreen++; |
| 3863 | if (mAppsFreezingScreen == 1) { |
| 3864 | startFreezingDisplayLocked(); |
| 3865 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3866 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3867 | 5000); |
| 3868 | } |
| 3869 | } |
| 3870 | final int N = wtoken.allAppWindows.size(); |
| 3871 | for (int i=0; i<N; i++) { |
| 3872 | WindowState w = wtoken.allAppWindows.get(i); |
| 3873 | w.mAppFreezing = true; |
| 3874 | } |
| 3875 | } |
| 3876 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3877 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3879 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3880 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3881 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3885 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3886 | 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] | 3887 | return; |
| 3888 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3889 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3891 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3892 | 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] | 3893 | return; |
| 3894 | } |
| 3895 | final long origId = Binder.clearCallingIdentity(); |
| 3896 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3897 | Binder.restoreCallingIdentity(origId); |
| 3898 | } |
| 3899 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3900 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3902 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3903 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3904 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | synchronized(mWindowMap) { |
| 3908 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3909 | if (wtoken == null || wtoken.appToken == null) { |
| 3910 | return; |
| 3911 | } |
| 3912 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3913 | 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] | 3914 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3915 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3916 | Binder.restoreCallingIdentity(origId); |
| 3917 | } |
| 3918 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3920 | public void removeAppToken(IBinder token) { |
| 3921 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3922 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3923 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | AppWindowToken wtoken = null; |
| 3927 | AppWindowToken startingToken = null; |
| 3928 | boolean delayed = false; |
| 3929 | |
| 3930 | final long origId = Binder.clearCallingIdentity(); |
| 3931 | synchronized(mWindowMap) { |
| 3932 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3933 | mTokenList.remove(basewtoken); |
| 3934 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3935 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3936 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | wtoken.inPendingTransaction = false; |
| 3938 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3939 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3940 | if (mClosingApps.contains(wtoken)) { |
| 3941 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3942 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3944 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | delayed = true; |
| 3946 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3947 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3949 | + " animation=" + wtoken.animation |
| 3950 | + " animating=" + wtoken.animating); |
| 3951 | if (delayed) { |
| 3952 | // set the token aside because it has an active animation to be finished |
| 3953 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3954 | } else { |
| 3955 | // Make sure there is no animation running on this token, |
| 3956 | // so any windows associated with it will be removed as |
| 3957 | // soon as their animations are complete |
| 3958 | wtoken.animation = null; |
| 3959 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | } |
| 3961 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3962 | if (mLastEnterAnimToken == wtoken) { |
| 3963 | mLastEnterAnimToken = null; |
| 3964 | mLastEnterAnimParams = null; |
| 3965 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3966 | wtoken.removed = true; |
| 3967 | if (wtoken.startingData != null) { |
| 3968 | startingToken = wtoken; |
| 3969 | } |
| 3970 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3971 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3972 | 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] | 3973 | mFocusedApp = null; |
| 3974 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3975 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 3976 | mInputMonitor.setFocusedAppLw(null); |
| 3977 | } else { |
| 3978 | mKeyWaiter.tickle(); |
| 3979 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | } |
| 3981 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3982 | 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] | 3983 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3984 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3985 | if (!delayed && wtoken != null) { |
| 3986 | wtoken.updateReportedVisibilityLocked(); |
| 3987 | } |
| 3988 | } |
| 3989 | Binder.restoreCallingIdentity(origId); |
| 3990 | |
| 3991 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3992 | 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] | 3993 | + startingToken + ": app token removed"); |
| 3994 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3995 | mH.sendMessage(m); |
| 3996 | } |
| 3997 | } |
| 3998 | |
| 3999 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4000 | final int NW = token.windows.size(); |
| 4001 | for (int i=0; i<NW; i++) { |
| 4002 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4003 | 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] | 4004 | mWindows.remove(win); |
| 4005 | int j = win.mChildWindows.size(); |
| 4006 | while (j > 0) { |
| 4007 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4008 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4009 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4010 | "Tmp removing child window " + cwin); |
| 4011 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | } |
| 4013 | } |
| 4014 | return NW > 0; |
| 4015 | } |
| 4016 | |
| 4017 | void dumpAppTokensLocked() { |
| 4018 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4019 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | } |
| 4021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4022 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | void dumpWindowsLocked() { |
| 4024 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4025 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4026 | } |
| 4027 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4029 | private int findWindowOffsetLocked(int tokenPos) { |
| 4030 | final int NW = mWindows.size(); |
| 4031 | |
| 4032 | if (tokenPos >= mAppTokens.size()) { |
| 4033 | int i = NW; |
| 4034 | while (i > 0) { |
| 4035 | i--; |
| 4036 | WindowState win = (WindowState)mWindows.get(i); |
| 4037 | if (win.getAppToken() != null) { |
| 4038 | return i+1; |
| 4039 | } |
| 4040 | } |
| 4041 | } |
| 4042 | |
| 4043 | while (tokenPos > 0) { |
| 4044 | // Find the first app token below the new position that has |
| 4045 | // a window displayed. |
| 4046 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4047 | 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] | 4048 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4049 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4050 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4051 | "Skipping token -- currently sending to bottom"); |
| 4052 | tokenPos--; |
| 4053 | continue; |
| 4054 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | int i = wtoken.windows.size(); |
| 4056 | while (i > 0) { |
| 4057 | i--; |
| 4058 | WindowState win = wtoken.windows.get(i); |
| 4059 | int j = win.mChildWindows.size(); |
| 4060 | while (j > 0) { |
| 4061 | j--; |
| 4062 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4063 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4064 | for (int pos=NW-1; pos>=0; pos--) { |
| 4065 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4066 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | "Found child win @" + (pos+1)); |
| 4068 | return pos+1; |
| 4069 | } |
| 4070 | } |
| 4071 | } |
| 4072 | } |
| 4073 | for (int pos=NW-1; pos>=0; pos--) { |
| 4074 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4075 | 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] | 4076 | return pos+1; |
| 4077 | } |
| 4078 | } |
| 4079 | } |
| 4080 | tokenPos--; |
| 4081 | } |
| 4082 | |
| 4083 | return 0; |
| 4084 | } |
| 4085 | |
| 4086 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4087 | final int NCW = win.mChildWindows.size(); |
| 4088 | boolean added = false; |
| 4089 | for (int j=0; j<NCW; j++) { |
| 4090 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 4091 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4092 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4093 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | mWindows.add(index, win); |
| 4095 | index++; |
| 4096 | added = true; |
| 4097 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4098 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4099 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4100 | mWindows.add(index, cwin); |
| 4101 | index++; |
| 4102 | } |
| 4103 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4104 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4105 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4106 | mWindows.add(index, win); |
| 4107 | index++; |
| 4108 | } |
| 4109 | return index; |
| 4110 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4113 | final int NW = token.windows.size(); |
| 4114 | for (int i=0; i<NW; i++) { |
| 4115 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4116 | } |
| 4117 | return index; |
| 4118 | } |
| 4119 | |
| 4120 | public void moveAppToken(int index, IBinder token) { |
| 4121 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4122 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4123 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4127 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4128 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4129 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4130 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4131 | 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] | 4132 | + token + " (" + wtoken + ")"); |
| 4133 | return; |
| 4134 | } |
| 4135 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4136 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4138 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4139 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4140 | 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] | 4141 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4142 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4143 | 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] | 4144 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4145 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4146 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4147 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4148 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | mLayoutNeeded = true; |
| 4150 | performLayoutAndPlaceSurfacesLocked(); |
| 4151 | } |
| 4152 | Binder.restoreCallingIdentity(origId); |
| 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4157 | // XXX This should be done more efficiently! |
| 4158 | // (take advantage of the fact that both lists should be |
| 4159 | // ordered in the same way.) |
| 4160 | int N = tokens.size(); |
| 4161 | for (int i=0; i<N; i++) { |
| 4162 | IBinder token = tokens.get(i); |
| 4163 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4164 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4165 | 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] | 4166 | + token + " (" + wtoken + ")"); |
| 4167 | i--; |
| 4168 | N--; |
| 4169 | } |
| 4170 | } |
| 4171 | } |
| 4172 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4173 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4174 | boolean updateFocusAndLayout) { |
| 4175 | // First remove all of the windows from the list. |
| 4176 | tmpRemoveAppWindowsLocked(wtoken); |
| 4177 | |
| 4178 | // Where to start adding? |
| 4179 | int pos = findWindowOffsetLocked(tokenPos); |
| 4180 | |
| 4181 | // And now add them back at the correct place. |
| 4182 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4183 | |
| 4184 | if (updateFocusAndLayout) { |
| 4185 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4186 | assignLayersLocked(); |
| 4187 | } |
| 4188 | mLayoutNeeded = true; |
| 4189 | performLayoutAndPlaceSurfacesLocked(); |
| 4190 | } |
| 4191 | } |
| 4192 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4194 | // First remove all of the windows from the list. |
| 4195 | final int N = tokens.size(); |
| 4196 | int i; |
| 4197 | for (i=0; i<N; i++) { |
| 4198 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4199 | if (token != null) { |
| 4200 | tmpRemoveAppWindowsLocked(token); |
| 4201 | } |
| 4202 | } |
| 4203 | |
| 4204 | // Where to start adding? |
| 4205 | int pos = findWindowOffsetLocked(tokenPos); |
| 4206 | |
| 4207 | // And now add them back at the correct place. |
| 4208 | for (i=0; i<N; i++) { |
| 4209 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4210 | if (token != null) { |
| 4211 | pos = reAddAppWindowsLocked(pos, token); |
| 4212 | } |
| 4213 | } |
| 4214 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4215 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4216 | assignLayersLocked(); |
| 4217 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4218 | mLayoutNeeded = true; |
| 4219 | performLayoutAndPlaceSurfacesLocked(); |
| 4220 | |
| 4221 | //dump(); |
| 4222 | } |
| 4223 | |
| 4224 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4225 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4226 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4227 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | final long origId = Binder.clearCallingIdentity(); |
| 4231 | synchronized(mWindowMap) { |
| 4232 | removeAppTokensLocked(tokens); |
| 4233 | final int N = tokens.size(); |
| 4234 | for (int i=0; i<N; i++) { |
| 4235 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4236 | if (wt != null) { |
| 4237 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4238 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4239 | mToTopApps.remove(wt); |
| 4240 | mToBottomApps.remove(wt); |
| 4241 | mToTopApps.add(wt); |
| 4242 | wt.sendingToBottom = false; |
| 4243 | wt.sendingToTop = true; |
| 4244 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4245 | } |
| 4246 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4247 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4248 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4249 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4250 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | } |
| 4252 | Binder.restoreCallingIdentity(origId); |
| 4253 | } |
| 4254 | |
| 4255 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4256 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4257 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4258 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | final long origId = Binder.clearCallingIdentity(); |
| 4262 | synchronized(mWindowMap) { |
| 4263 | removeAppTokensLocked(tokens); |
| 4264 | final int N = tokens.size(); |
| 4265 | int pos = 0; |
| 4266 | for (int i=0; i<N; i++) { |
| 4267 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4268 | if (wt != null) { |
| 4269 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4270 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4271 | mToTopApps.remove(wt); |
| 4272 | mToBottomApps.remove(wt); |
| 4273 | mToBottomApps.add(i, wt); |
| 4274 | wt.sendingToTop = false; |
| 4275 | wt.sendingToBottom = true; |
| 4276 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4277 | pos++; |
| 4278 | } |
| 4279 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4280 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4281 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4282 | moveAppWindowsLocked(tokens, 0); |
| 4283 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | } |
| 4285 | Binder.restoreCallingIdentity(origId); |
| 4286 | } |
| 4287 | |
| 4288 | // ------------------------------------------------------------- |
| 4289 | // Misc IWindowSession methods |
| 4290 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4291 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4292 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4293 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4294 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4295 | // called before DevicePolicyManagerService has started. |
| 4296 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4297 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4298 | Context.DEVICE_POLICY_SERVICE); |
| 4299 | if (dpm != null) { |
| 4300 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4301 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4302 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4303 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4304 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4305 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4309 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | != PackageManager.PERMISSION_GRANTED) { |
| 4311 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4312 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4313 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4314 | synchronized (mKeyguardTokenWatcher) { |
| 4315 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4316 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4320 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4321 | != PackageManager.PERMISSION_GRANTED) { |
| 4322 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4323 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4325 | synchronized (mKeyguardTokenWatcher) { |
| 4326 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4327 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4328 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4329 | // If we are the last one to reenable the keyguard wait until |
| 4330 | // we have actually finished reenabling until returning. |
| 4331 | // It is possible that reenableKeyguard() can be called before |
| 4332 | // the previous disableKeyguard() is handled, in which case |
| 4333 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4334 | // be called. In that case mKeyguardDisabled will be false here |
| 4335 | // and we have nothing to wait for. |
| 4336 | while (mKeyguardDisabled) { |
| 4337 | try { |
| 4338 | mKeyguardTokenWatcher.wait(); |
| 4339 | } catch (InterruptedException e) { |
| 4340 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | /** |
| 4348 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4349 | */ |
| 4350 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4351 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | != PackageManager.PERMISSION_GRANTED) { |
| 4353 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4354 | } |
| 4355 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4356 | public void onKeyguardExitResult(boolean success) { |
| 4357 | try { |
| 4358 | callback.onKeyguardExitResult(success); |
| 4359 | } catch (RemoteException e) { |
| 4360 | // Client has died, we don't care. |
| 4361 | } |
| 4362 | } |
| 4363 | }); |
| 4364 | } |
| 4365 | |
| 4366 | public boolean inKeyguardRestrictedInputMode() { |
| 4367 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4368 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4369 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4370 | public void closeSystemDialogs(String reason) { |
| 4371 | synchronized(mWindowMap) { |
| 4372 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4373 | WindowState w = (WindowState)mWindows.get(i); |
| 4374 | if (w.mSurface != null) { |
| 4375 | try { |
| 4376 | w.mClient.closeSystemDialogs(reason); |
| 4377 | } catch (RemoteException e) { |
| 4378 | } |
| 4379 | } |
| 4380 | } |
| 4381 | } |
| 4382 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | static float fixScale(float scale) { |
| 4385 | if (scale < 0) scale = 0; |
| 4386 | else if (scale > 20) scale = 20; |
| 4387 | return Math.abs(scale); |
| 4388 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | public void setAnimationScale(int which, float scale) { |
| 4391 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4392 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4393 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | if (scale < 0) scale = 0; |
| 4397 | else if (scale > 20) scale = 20; |
| 4398 | scale = Math.abs(scale); |
| 4399 | switch (which) { |
| 4400 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4401 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4402 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4404 | // Persist setting |
| 4405 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4406 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | public void setAnimationScales(float[] scales) { |
| 4409 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4410 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4411 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | if (scales != null) { |
| 4415 | if (scales.length >= 1) { |
| 4416 | mWindowAnimationScale = fixScale(scales[0]); |
| 4417 | } |
| 4418 | if (scales.length >= 2) { |
| 4419 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4420 | } |
| 4421 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4422 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | // Persist setting |
| 4424 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4425 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4426 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4427 | public float getAnimationScale(int which) { |
| 4428 | switch (which) { |
| 4429 | case 0: return mWindowAnimationScale; |
| 4430 | case 1: return mTransitionAnimationScale; |
| 4431 | } |
| 4432 | return 0; |
| 4433 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | public float[] getAnimationScales() { |
| 4436 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4437 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | public int getSwitchState(int sw) { |
| 4440 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4441 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4442 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4444 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4445 | return mInputManager.getSwitchState(sw); |
| 4446 | } else { |
| 4447 | return KeyInputQueue.getSwitchState(sw); |
| 4448 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 int getSwitchStateForDevice(int devid, int sw) { |
| 4452 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4453 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4454 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4456 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4457 | return mInputManager.getSwitchState(devid, sw); |
| 4458 | } else { |
| 4459 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4460 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | public int getScancodeState(int sw) { |
| 4464 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4465 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4466 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4468 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4469 | return mInputManager.getScancodeState(sw); |
| 4470 | } else { |
| 4471 | return mQueue.getScancodeState(sw); |
| 4472 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4474 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4476 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4477 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4478 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4479 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4480 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4481 | return mInputManager.getScancodeState(devid, sw); |
| 4482 | } else { |
| 4483 | return mQueue.getScancodeState(devid, sw); |
| 4484 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4486 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4487 | public int getTrackballScancodeState(int sw) { |
| 4488 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4489 | "getTrackballScancodeState()")) { |
| 4490 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4491 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4492 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4493 | return mInputManager.getTrackballScancodeState(sw); |
| 4494 | } else { |
| 4495 | return mQueue.getTrackballScancodeState(sw); |
| 4496 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | public int getDPadScancodeState(int sw) { |
| 4500 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4501 | "getDPadScancodeState()")) { |
| 4502 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4503 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4504 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4505 | return mInputManager.getDPadScancodeState(sw); |
| 4506 | } else { |
| 4507 | return mQueue.getDPadScancodeState(sw); |
| 4508 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4509 | } |
| 4510 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | public int getKeycodeState(int sw) { |
| 4512 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4513 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4514 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4516 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4517 | return mInputManager.getKeycodeState(sw); |
| 4518 | } else { |
| 4519 | return mQueue.getKeycodeState(sw); |
| 4520 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4523 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4524 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4525 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4526 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4528 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4529 | return mInputManager.getKeycodeState(devid, sw); |
| 4530 | } else { |
| 4531 | return mQueue.getKeycodeState(devid, sw); |
| 4532 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4534 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4535 | public int getTrackballKeycodeState(int sw) { |
| 4536 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4537 | "getTrackballKeycodeState()")) { |
| 4538 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4539 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4540 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4541 | return mInputManager.getTrackballKeycodeState(sw); |
| 4542 | } else { |
| 4543 | return mQueue.getTrackballKeycodeState(sw); |
| 4544 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | public int getDPadKeycodeState(int sw) { |
| 4548 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4549 | "getDPadKeycodeState()")) { |
| 4550 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4551 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4552 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4553 | return mInputManager.getDPadKeycodeState(sw); |
| 4554 | } else { |
| 4555 | return mQueue.getDPadKeycodeState(sw); |
| 4556 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4557 | } |
| 4558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4559 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4560 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4561 | return mInputManager.hasKeys(keycodes, keyExists); |
| 4562 | } else { |
| 4563 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4564 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4565 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4566 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | public void enableScreenAfterBoot() { |
| 4568 | synchronized(mWindowMap) { |
| 4569 | if (mSystemBooted) { |
| 4570 | return; |
| 4571 | } |
| 4572 | mSystemBooted = true; |
| 4573 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4575 | performEnableScreen(); |
| 4576 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | public void enableScreenIfNeededLocked() { |
| 4579 | if (mDisplayEnabled) { |
| 4580 | return; |
| 4581 | } |
| 4582 | if (!mSystemBooted) { |
| 4583 | return; |
| 4584 | } |
| 4585 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4586 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4587 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4588 | public void performEnableScreen() { |
| 4589 | synchronized(mWindowMap) { |
| 4590 | if (mDisplayEnabled) { |
| 4591 | return; |
| 4592 | } |
| 4593 | if (!mSystemBooted) { |
| 4594 | return; |
| 4595 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | // Don't enable the screen until all existing windows |
| 4598 | // have been drawn. |
| 4599 | final int N = mWindows.size(); |
| 4600 | for (int i=0; i<N; i++) { |
| 4601 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 4602 | if (w.isVisibleLw() && !w.mObscured |
| 4603 | && (w.mOrientationChanging || !w.isDrawnLw())) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4604 | return; |
| 4605 | } |
| 4606 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4608 | mDisplayEnabled = true; |
| 4609 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4610 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | StringWriter sw = new StringWriter(); |
| 4612 | PrintWriter pw = new PrintWriter(sw); |
| 4613 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4614 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4615 | } |
| 4616 | try { |
| 4617 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4618 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4619 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | Parcel data = Parcel.obtain(); |
| 4621 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4622 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4623 | data, null, 0); |
| 4624 | data.recycle(); |
| 4625 | } |
| 4626 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4627 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4628 | } |
| 4629 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4633 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4634 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4635 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4636 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4637 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4638 | public void setInTouchMode(boolean mode) { |
| 4639 | synchronized(mWindowMap) { |
| 4640 | mInTouchMode = mode; |
| 4641 | } |
| 4642 | } |
| 4643 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4644 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4645 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4647 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4648 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4649 | } |
| 4650 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4651 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4653 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4654 | public void setRotationUnchecked(int rotation, |
| 4655 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4656 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4658 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | long origId = Binder.clearCallingIdentity(); |
| 4660 | boolean changed; |
| 4661 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4662 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4663 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4664 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4665 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | sendNewConfiguration(); |
| 4667 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4668 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | Binder.restoreCallingIdentity(origId); |
| 4670 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4671 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4672 | /** |
| 4673 | * Apply a new rotation to the screen, respecting the requests of |
| 4674 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4675 | * re-evaluate the desired rotation. |
| 4676 | * |
| 4677 | * Returns null if the rotation has been changed. In this case YOU |
| 4678 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4679 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4680 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | boolean changed; |
| 4682 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4683 | rotation = mRequestedRotation; |
| 4684 | } else { |
| 4685 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4686 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4688 | 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] | 4689 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4691 | 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] | 4692 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4693 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4695 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | "Rotation changed to " + rotation |
| 4697 | + " from " + mRotation |
| 4698 | + " (forceApp=" + mForcedAppOrientation |
| 4699 | + ", req=" + mRequestedRotation + ")"); |
| 4700 | mRotation = rotation; |
| 4701 | mWindowsFreezingScreen = true; |
| 4702 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4703 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4704 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4705 | mWaitingForConfig = true; |
| 4706 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4707 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4708 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4709 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4710 | mInputManager.setDisplayOrientation(0, rotation); |
| 4711 | } else { |
| 4712 | mQueue.setOrientation(rotation); |
| 4713 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4715 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4716 | } |
| 4717 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4718 | WindowState w = (WindowState)mWindows.get(i); |
| 4719 | if (w.mSurface != null) { |
| 4720 | w.mOrientationChanging = true; |
| 4721 | } |
| 4722 | } |
| 4723 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4724 | try { |
| 4725 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4726 | } catch (RemoteException e) { |
| 4727 | } |
| 4728 | } |
| 4729 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4730 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4731 | return changed; |
| 4732 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4733 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | public int getRotation() { |
| 4735 | return mRotation; |
| 4736 | } |
| 4737 | |
| 4738 | public int watchRotation(IRotationWatcher watcher) { |
| 4739 | final IBinder watcherBinder = watcher.asBinder(); |
| 4740 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4741 | public void binderDied() { |
| 4742 | synchronized (mWindowMap) { |
| 4743 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4744 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4745 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4746 | if (removed != null) { |
| 4747 | removed.asBinder().unlinkToDeath(this, 0); |
| 4748 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | i--; |
| 4750 | } |
| 4751 | } |
| 4752 | } |
| 4753 | } |
| 4754 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4755 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4756 | synchronized (mWindowMap) { |
| 4757 | try { |
| 4758 | watcher.asBinder().linkToDeath(dr, 0); |
| 4759 | mRotationWatchers.add(watcher); |
| 4760 | } catch (RemoteException e) { |
| 4761 | // Client died, no cleanup needed. |
| 4762 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4763 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4764 | return mRotation; |
| 4765 | } |
| 4766 | } |
| 4767 | |
| 4768 | /** |
| 4769 | * Starts the view server on the specified port. |
| 4770 | * |
| 4771 | * @param port The port to listener to. |
| 4772 | * |
| 4773 | * @return True if the server was successfully started, false otherwise. |
| 4774 | * |
| 4775 | * @see com.android.server.ViewServer |
| 4776 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4777 | */ |
| 4778 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4779 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4780 | return false; |
| 4781 | } |
| 4782 | |
| 4783 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4784 | return false; |
| 4785 | } |
| 4786 | |
| 4787 | if (port < 1024) { |
| 4788 | return false; |
| 4789 | } |
| 4790 | |
| 4791 | if (mViewServer != null) { |
| 4792 | if (!mViewServer.isRunning()) { |
| 4793 | try { |
| 4794 | return mViewServer.start(); |
| 4795 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4796 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | return false; |
| 4800 | } |
| 4801 | |
| 4802 | try { |
| 4803 | mViewServer = new ViewServer(this, port); |
| 4804 | return mViewServer.start(); |
| 4805 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4806 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4807 | } |
| 4808 | return false; |
| 4809 | } |
| 4810 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4811 | private boolean isSystemSecure() { |
| 4812 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4813 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4814 | } |
| 4815 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4816 | /** |
| 4817 | * Stops the view server if it exists. |
| 4818 | * |
| 4819 | * @return True if the server stopped, false if it wasn't started or |
| 4820 | * couldn't be stopped. |
| 4821 | * |
| 4822 | * @see com.android.server.ViewServer |
| 4823 | */ |
| 4824 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4825 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | return false; |
| 4827 | } |
| 4828 | |
| 4829 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4830 | return false; |
| 4831 | } |
| 4832 | |
| 4833 | if (mViewServer != null) { |
| 4834 | return mViewServer.stop(); |
| 4835 | } |
| 4836 | return false; |
| 4837 | } |
| 4838 | |
| 4839 | /** |
| 4840 | * Indicates whether the view server is running. |
| 4841 | * |
| 4842 | * @return True if the server is running, false otherwise. |
| 4843 | * |
| 4844 | * @see com.android.server.ViewServer |
| 4845 | */ |
| 4846 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4847 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | return false; |
| 4849 | } |
| 4850 | |
| 4851 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4852 | return false; |
| 4853 | } |
| 4854 | |
| 4855 | return mViewServer != null && mViewServer.isRunning(); |
| 4856 | } |
| 4857 | |
| 4858 | /** |
| 4859 | * Lists all availble windows in the system. The listing is written in the |
| 4860 | * specified Socket's output stream with the following syntax: |
| 4861 | * windowHashCodeInHexadecimal windowName |
| 4862 | * Each line of the ouput represents a different window. |
| 4863 | * |
| 4864 | * @param client The remote client to send the listing to. |
| 4865 | * @return False if an error occured, true otherwise. |
| 4866 | */ |
| 4867 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4868 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4869 | return false; |
| 4870 | } |
| 4871 | |
| 4872 | boolean result = true; |
| 4873 | |
| 4874 | Object[] windows; |
| 4875 | synchronized (mWindowMap) { |
| 4876 | windows = new Object[mWindows.size()]; |
| 4877 | //noinspection unchecked |
| 4878 | windows = mWindows.toArray(windows); |
| 4879 | } |
| 4880 | |
| 4881 | BufferedWriter out = null; |
| 4882 | |
| 4883 | // Any uncaught exception will crash the system process |
| 4884 | try { |
| 4885 | OutputStream clientStream = client.getOutputStream(); |
| 4886 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4887 | |
| 4888 | final int count = windows.length; |
| 4889 | for (int i = 0; i < count; i++) { |
| 4890 | final WindowState w = (WindowState) windows[i]; |
| 4891 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4892 | out.write(' '); |
| 4893 | out.append(w.mAttrs.getTitle()); |
| 4894 | out.write('\n'); |
| 4895 | } |
| 4896 | |
| 4897 | out.write("DONE.\n"); |
| 4898 | out.flush(); |
| 4899 | } catch (Exception e) { |
| 4900 | result = false; |
| 4901 | } finally { |
| 4902 | if (out != null) { |
| 4903 | try { |
| 4904 | out.close(); |
| 4905 | } catch (IOException e) { |
| 4906 | result = false; |
| 4907 | } |
| 4908 | } |
| 4909 | } |
| 4910 | |
| 4911 | return result; |
| 4912 | } |
| 4913 | |
| 4914 | /** |
| 4915 | * Sends a command to a target window. The result of the command, if any, will be |
| 4916 | * written in the output stream of the specified socket. |
| 4917 | * |
| 4918 | * The parameters must follow this syntax: |
| 4919 | * windowHashcode extra |
| 4920 | * |
| 4921 | * Where XX is the length in characeters of the windowTitle. |
| 4922 | * |
| 4923 | * The first parameter is the target window. The window with the specified hashcode |
| 4924 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4925 | * will be delivered to the target window and as parameters to the command itself. |
| 4926 | * |
| 4927 | * @param client The remote client to sent the result, if any, to. |
| 4928 | * @param command The command to execute. |
| 4929 | * @param parameters The command parameters. |
| 4930 | * |
| 4931 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4932 | * not indicate whether the command itself was successful. |
| 4933 | */ |
| 4934 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4935 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | return false; |
| 4937 | } |
| 4938 | |
| 4939 | boolean success = true; |
| 4940 | Parcel data = null; |
| 4941 | Parcel reply = null; |
| 4942 | |
| 4943 | // Any uncaught exception will crash the system process |
| 4944 | try { |
| 4945 | // Find the hashcode of the window |
| 4946 | int index = parameters.indexOf(' '); |
| 4947 | if (index == -1) { |
| 4948 | index = parameters.length(); |
| 4949 | } |
| 4950 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4951 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | |
| 4953 | // Extract the command's parameter after the window description |
| 4954 | if (index < parameters.length()) { |
| 4955 | parameters = parameters.substring(index + 1); |
| 4956 | } else { |
| 4957 | parameters = ""; |
| 4958 | } |
| 4959 | |
| 4960 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4961 | if (window == null) { |
| 4962 | return false; |
| 4963 | } |
| 4964 | |
| 4965 | data = Parcel.obtain(); |
| 4966 | data.writeInterfaceToken("android.view.IWindow"); |
| 4967 | data.writeString(command); |
| 4968 | data.writeString(parameters); |
| 4969 | data.writeInt(1); |
| 4970 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4971 | |
| 4972 | reply = Parcel.obtain(); |
| 4973 | |
| 4974 | final IBinder binder = window.mClient.asBinder(); |
| 4975 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4976 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4977 | |
| 4978 | reply.readException(); |
| 4979 | |
| 4980 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4981 | 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] | 4982 | success = false; |
| 4983 | } finally { |
| 4984 | if (data != null) { |
| 4985 | data.recycle(); |
| 4986 | } |
| 4987 | if (reply != null) { |
| 4988 | reply.recycle(); |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | return success; |
| 4993 | } |
| 4994 | |
| 4995 | private WindowState findWindow(int hashCode) { |
| 4996 | if (hashCode == -1) { |
| 4997 | return getFocusedWindow(); |
| 4998 | } |
| 4999 | |
| 5000 | synchronized (mWindowMap) { |
| 5001 | final ArrayList windows = mWindows; |
| 5002 | final int count = windows.size(); |
| 5003 | |
| 5004 | for (int i = 0; i < count; i++) { |
| 5005 | WindowState w = (WindowState) windows.get(i); |
| 5006 | if (System.identityHashCode(w) == hashCode) { |
| 5007 | return w; |
| 5008 | } |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | return null; |
| 5013 | } |
| 5014 | |
| 5015 | /* |
| 5016 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5017 | * that to config-changed listeners if appropriate. |
| 5018 | */ |
| 5019 | void sendNewConfiguration() { |
| 5020 | try { |
| 5021 | mActivityManager.updateConfiguration(null); |
| 5022 | } catch (RemoteException e) { |
| 5023 | } |
| 5024 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5025 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5026 | public Configuration computeNewConfiguration() { |
| 5027 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5028 | return computeNewConfigurationLocked(); |
| 5029 | } |
| 5030 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5031 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5032 | Configuration computeNewConfigurationLocked() { |
| 5033 | Configuration config = new Configuration(); |
| 5034 | if (!computeNewConfigurationLocked(config)) { |
| 5035 | return null; |
| 5036 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5037 | return config; |
| 5038 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5039 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5040 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5041 | if (mDisplay == null) { |
| 5042 | return false; |
| 5043 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5044 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 5045 | mInputManager.getInputConfiguration(config); |
| 5046 | } else { |
| 5047 | mQueue.getInputConfiguration(config); |
| 5048 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5049 | |
| 5050 | // Use the effective "visual" dimensions based on current rotation |
| 5051 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5052 | || mRotation == Surface.ROTATION_270); |
| 5053 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5054 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5055 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5056 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5057 | if (dw < dh) { |
| 5058 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5059 | } else if (dw > dh) { |
| 5060 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5061 | } |
| 5062 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5063 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5064 | DisplayMetrics dm = new DisplayMetrics(); |
| 5065 | mDisplay.getMetrics(dm); |
| 5066 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5067 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5068 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5069 | // Note we only do this once because at this point we don't |
| 5070 | // expect the screen to change in this way at runtime, and want |
| 5071 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5072 | int longSize = dw; |
| 5073 | int shortSize = dh; |
| 5074 | if (longSize < shortSize) { |
| 5075 | int tmp = longSize; |
| 5076 | longSize = shortSize; |
| 5077 | shortSize = tmp; |
| 5078 | } |
| 5079 | longSize = (int)(longSize/dm.density); |
| 5080 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5081 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5082 | // These semi-magic numbers define our compatibility modes for |
| 5083 | // applications with different screens. Don't change unless you |
| 5084 | // make sure to test lots and lots of apps! |
| 5085 | if (longSize < 470) { |
| 5086 | // This is shorter than an HVGA normal density screen (which |
| 5087 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5088 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5089 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5090 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5091 | // What size is this screen screen? |
| 5092 | if (longSize >= 800 && shortSize >= 600) { |
| 5093 | // SVGA or larger screens at medium density are the point |
| 5094 | // at which we consider it to be an extra large screen. |
| 5095 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5096 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5097 | // VGA or larger screens at medium density are the point |
| 5098 | // at which we consider it to be a large screen. |
| 5099 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5100 | } else { |
| 5101 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5102 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5103 | // If this screen is wider than normal HVGA, or taller |
| 5104 | // than FWVGA, then for old apps we want to run in size |
| 5105 | // compatibility mode. |
| 5106 | if (shortSize > 321 || longSize > 570) { |
| 5107 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5108 | } |
| 5109 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5110 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5111 | // Is this a long screen? |
| 5112 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5113 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5114 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5115 | } else { |
| 5116 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5117 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5118 | } |
| 5119 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5120 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5121 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5122 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5123 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5124 | mPolicy.adjustConfigurationLw(config); |
| 5125 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5126 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5128 | // ------------------------------------------------------------- |
| 5129 | // Input Events and Focus Management |
| 5130 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5131 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5132 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5133 | |
| 5134 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5135 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5136 | * other relevant Window Manager state transitions. */ |
| 5137 | final class InputMonitor { |
| 5138 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5139 | private WindowState mInputFocus; |
| 5140 | |
| 5141 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5142 | private boolean mInputDispatchFrozen; |
| 5143 | |
| 5144 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5145 | private boolean mInputDispatchEnabled = true; |
| 5146 | |
| 5147 | // Temporary list of windows information to provide to the input dispatcher. |
| 5148 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5149 | |
| 5150 | // Temporary input application object to provide to the input dispatcher. |
| 5151 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5152 | |
| 5153 | /* Notifies the window manager about a broken input channel. |
| 5154 | * |
| 5155 | * Called by the InputManager. |
| 5156 | */ |
| 5157 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5158 | synchronized (mWindowMap) { |
| 5159 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5160 | if (windowState == null) { |
| 5161 | return; // irrelevant |
| 5162 | } |
| 5163 | |
| 5164 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5165 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5166 | } |
| 5167 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5168 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5169 | /* Notifies the window manager about an input channel that is not responding. |
| 5170 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5171 | * return a new timeout in nanoseconds. |
| 5172 | * |
| 5173 | * Called by the InputManager. |
| 5174 | */ |
| 5175 | public long notifyInputChannelANR(InputChannel inputChannel) { |
| 5176 | AppWindowToken token; |
| 5177 | synchronized (mWindowMap) { |
| 5178 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5179 | if (windowState == null) { |
| 5180 | return -2; // irrelevant, abort dispatching (-2) |
| 5181 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5182 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5183 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5184 | + windowState.mAttrs.getTitle()); |
| 5185 | token = windowState.mAppToken; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5188 | return notifyANRInternal(token); |
| 5189 | } |
| 5190 | |
| 5191 | /* Notifies the window manager about an input channel spontaneously recovering from ANR |
| 5192 | * by successfully delivering the event that originally timed out. |
| 5193 | * |
| 5194 | * Called by the InputManager. |
| 5195 | */ |
| 5196 | public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) { |
| 5197 | // Nothing to do just now. |
| 5198 | // Just wait for the user to dismiss the ANR dialog. |
| 5199 | } |
| 5200 | |
| 5201 | /* Notifies the window manager about an application that is not responding |
| 5202 | * in general rather than with respect to a particular input channel. |
| 5203 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5204 | * return a new timeout in nanoseconds. |
| 5205 | * |
| 5206 | * Called by the InputManager. |
| 5207 | */ |
| 5208 | public long notifyANR(Object token) { |
| 5209 | AppWindowToken appWindowToken = (AppWindowToken) token; |
| 5210 | |
| 5211 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5212 | + appWindowToken.stringName); |
| 5213 | return notifyANRInternal(appWindowToken); |
| 5214 | } |
| 5215 | |
| 5216 | private long notifyANRInternal(AppWindowToken token) { |
| 5217 | if (token != null && token.appToken != null) { |
| 5218 | try { |
| 5219 | // Notify the activity manager about the timeout and let it decide whether |
| 5220 | // to abort dispatching or keep waiting. |
| 5221 | boolean abort = token.appToken.keyDispatchingTimedOut(); |
| 5222 | if (! abort) { |
| 5223 | // The activity manager declined to abort dispatching. |
| 5224 | // Wait a bit longer and timeout again later. |
| 5225 | return token.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5226 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5227 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5228 | } |
| 5229 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5230 | return -2; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5233 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5234 | synchronized (mWindowMap) { |
| 5235 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5240 | int windowCount = mWindows.size(); |
| 5241 | for (int i = 0; i < windowCount; i++) { |
| 5242 | WindowState windowState = (WindowState) mWindows.get(i); |
| 5243 | if (windowState.mInputChannel == inputChannel) { |
| 5244 | return windowState; |
| 5245 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5248 | return null; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5249 | } |
| 5250 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5251 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5252 | public void updateInputWindowsLw() { |
| 5253 | // Populate the input window list with information about all of the windows that |
| 5254 | // could potentially receive input. |
| 5255 | // As an optimization, we could try to prune the list of windows but this turns |
| 5256 | // out to be difficult because only the native code knows for sure which window |
| 5257 | // currently has touch focus. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5258 | final ArrayList windows = mWindows; |
| 5259 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5260 | for (int i = N - 1; i >= 0; i--) { |
| 5261 | final WindowState child = (WindowState) windows.get(i); |
| 5262 | if (child.mInputChannel == null) { |
| 5263 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5264 | continue; |
| 5265 | } |
| 5266 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5267 | final int flags = child.mAttrs.flags; |
| 5268 | final int type = child.mAttrs.type; |
| 5269 | |
| 5270 | final boolean hasFocus = (child == mInputFocus); |
| 5271 | final boolean isVisible = child.isVisibleLw(); |
| 5272 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5273 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| 5274 | |
| 5275 | // Add a window to our list of input windows. |
| 5276 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5277 | inputWindow.inputChannel = child.mInputChannel; |
| 5278 | inputWindow.layoutParamsFlags = flags; |
| 5279 | inputWindow.layoutParamsType = type; |
| 5280 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5281 | inputWindow.visible = isVisible; |
| 5282 | inputWindow.hasFocus = hasFocus; |
| 5283 | inputWindow.hasWallpaper = hasWallpaper; |
| 5284 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 5285 | inputWindow.ownerPid = child.mSession.mPid; |
| 5286 | inputWindow.ownerUid = child.mSession.mUid; |
| 5287 | |
| 5288 | final Rect frame = child.mFrame; |
| 5289 | inputWindow.frameLeft = frame.left; |
| 5290 | inputWindow.frameTop = frame.top; |
| 5291 | |
| 5292 | switch (child.mTouchableInsets) { |
| 5293 | default: |
| 5294 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5295 | inputWindow.touchableAreaLeft = frame.left; |
| 5296 | inputWindow.touchableAreaTop = frame.top; |
| 5297 | inputWindow.touchableAreaRight = frame.right; |
| 5298 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5299 | break; |
| 5300 | |
| 5301 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5302 | Rect inset = child.mGivenContentInsets; |
| 5303 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5304 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5305 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5306 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5307 | break; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5308 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5309 | |
| 5310 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5311 | Rect inset = child.mGivenVisibleInsets; |
| 5312 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5313 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5314 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5315 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5316 | break; |
| 5317 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5318 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5319 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5320 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5321 | // Send windows to native code. |
| 5322 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5323 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5324 | // Clear the list in preparation for the next round. |
| 5325 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5326 | mTempInputWindows.clear(); |
| 5327 | } |
| 5328 | |
| 5329 | /* Notifies that an app switch key (BACK / HOME) has just been pressed. |
| 5330 | * This essentially starts a .5 second timeout for the application to process |
| 5331 | * subsequent input events while waiting for the app switch to occur. If it takes longer |
| 5332 | * than this, the pending events will be dropped. |
| 5333 | */ |
| 5334 | public void notifyAppSwitchComing() { |
| 5335 | // TODO Not implemented yet. Should go in the native side. |
| 5336 | } |
| 5337 | |
| 5338 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5339 | * processing as soon as the key has been read from the device. */ |
| 5340 | public int interceptKeyBeforeQueueing(int deviceId, int type, int scanCode, |
| 5341 | int keyCode, int policyFlags, int value, long whenNanos, boolean isScreenOn) { |
| 5342 | RawInputEvent event = new RawInputEvent(); |
| 5343 | event.deviceId = deviceId; |
| 5344 | event.type = type; |
| 5345 | event.scancode = scanCode; |
| 5346 | event.keycode = keyCode; |
| 5347 | event.flags = policyFlags; |
| 5348 | event.value = value; |
| 5349 | event.when = whenNanos / 1000000; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5350 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5351 | return mPolicy.interceptKeyTq(event, isScreenOn); |
| 5352 | } |
| 5353 | |
| 5354 | /* Provides an opportunity for the window manager policy to process a key before |
| 5355 | * ordinary dispatch. */ |
| 5356 | public boolean interceptKeyBeforeDispatching(InputChannel focus, int keyCode, |
| 5357 | int metaState, boolean down, int repeatCount, int policyFlags) { |
| 5358 | WindowState windowState = getWindowStateForInputChannel(focus); |
| 5359 | return mPolicy.interceptKeyTi(windowState, keyCode, metaState, down, repeatCount, |
| 5360 | policyFlags); |
| 5361 | } |
| 5362 | |
| 5363 | /* Called when the current input focus changes. |
| 5364 | * Layer assignment is assumed to be complete by the time this is called. |
| 5365 | */ |
| 5366 | public void setInputFocusLw(WindowState newWindow) { |
| 5367 | if (DEBUG_INPUT) { |
| 5368 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5369 | } |
| 5370 | |
| 5371 | if (newWindow != mInputFocus) { |
| 5372 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 5373 | // If the new input focus is an error window or appears above the current |
| 5374 | // input focus, preempt any pending synchronous dispatch so that we can |
| 5375 | // start delivering events to the new input focus as soon as possible. |
| 5376 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5377 | if (DEBUG_INPUT) { |
| 5378 | Slog.v(TAG, "New SYSTEM_ERROR window; resetting state"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5379 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5380 | preemptInputDispatchLw(); |
| 5381 | } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) { |
| 5382 | if (DEBUG_INPUT) { |
| 5383 | Slog.v(TAG, "Transferring focus to new window at higher layer: " |
| 5384 | + "old win layer=" + mInputFocus.mLayer |
| 5385 | + ", new win layer=" + newWindow.mLayer); |
| 5386 | } |
| 5387 | preemptInputDispatchLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5388 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5389 | |
| 5390 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5391 | // This is to protect against bugs if someone pauses dispatching but |
| 5392 | // forgets to resume. |
| 5393 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5394 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5395 | |
| 5396 | mInputFocus = newWindow; |
| 5397 | updateInputWindowsLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5398 | } |
| 5399 | } |
| 5400 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5401 | public void windowIsBecomingInvisibleLw(WindowState window) { |
| 5402 | // The window is becoming invisible. Preempt input dispatch in progress |
| 5403 | // so that the next window below can receive focus. |
| 5404 | if (window == mInputFocus) { |
| 5405 | mInputFocus = null; |
| 5406 | preemptInputDispatchLw(); |
| 5407 | } |
| 5408 | |
| 5409 | updateInputWindowsLw(); |
| 5410 | } |
| 5411 | |
| 5412 | /* Tells the dispatcher to stop waiting for its current synchronous event targets. |
| 5413 | * Essentially, just makes those dispatches asynchronous so a new dispatch cycle |
| 5414 | * can begin. |
| 5415 | */ |
| 5416 | private void preemptInputDispatchLw() { |
| 5417 | mInputManager.preemptInputDispatch(); |
| 5418 | } |
| 5419 | |
| 5420 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5421 | // Focused app has changed. |
| 5422 | if (newApp == null) { |
| 5423 | mInputManager.setFocusedApplication(null); |
| 5424 | } else { |
| 5425 | mTempInputApplication.name = newApp.toString(); |
| 5426 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5427 | newApp.inputDispatchingTimeoutNanos; |
| 5428 | mTempInputApplication.token = newApp; |
| 5429 | |
| 5430 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | public void windowIsBeingRemovedLw(WindowState window) { |
| 5435 | // Window is being removed. |
| 5436 | updateInputWindowsLw(); |
| 5437 | } |
| 5438 | |
| 5439 | public void pauseDispatchingLw(WindowToken window) { |
| 5440 | if (! window.paused) { |
| 5441 | if (DEBUG_INPUT) { |
| 5442 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5443 | } |
| 5444 | |
| 5445 | window.paused = true; |
| 5446 | updateInputWindowsLw(); |
| 5447 | } |
| 5448 | } |
| 5449 | |
| 5450 | public void resumeDispatchingLw(WindowToken window) { |
| 5451 | if (window.paused) { |
| 5452 | if (DEBUG_INPUT) { |
| 5453 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5454 | } |
| 5455 | |
| 5456 | window.paused = false; |
| 5457 | updateInputWindowsLw(); |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | public void freezeInputDispatchingLw() { |
| 5462 | if (! mInputDispatchFrozen) { |
| 5463 | if (DEBUG_INPUT) { |
| 5464 | Slog.v(TAG, "Freezing input dispatching"); |
| 5465 | } |
| 5466 | |
| 5467 | mInputDispatchFrozen = true; |
| 5468 | updateInputDispatchModeLw(); |
| 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | public void thawInputDispatchingLw() { |
| 5473 | if (mInputDispatchFrozen) { |
| 5474 | if (DEBUG_INPUT) { |
| 5475 | Slog.v(TAG, "Thawing input dispatching"); |
| 5476 | } |
| 5477 | |
| 5478 | mInputDispatchFrozen = false; |
| 5479 | updateInputDispatchModeLw(); |
| 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | public void setEventDispatchingLw(boolean enabled) { |
| 5484 | if (mInputDispatchEnabled != enabled) { |
| 5485 | if (DEBUG_INPUT) { |
| 5486 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5487 | } |
| 5488 | |
| 5489 | mInputDispatchEnabled = enabled; |
| 5490 | updateInputDispatchModeLw(); |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | private void updateInputDispatchModeLw() { |
| 5495 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5496 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5497 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5498 | |
| 5499 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5500 | long curTime = SystemClock.uptimeMillis(); |
| 5501 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 5502 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5503 | if (mLastTouchEventType == eventType && |
| 5504 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 5505 | return; |
| 5506 | } |
| 5507 | mLastUserActivityCallTime = curTime; |
| 5508 | mLastTouchEventType = eventType; |
| 5509 | } |
| 5510 | |
| 5511 | if (targetWin == null |
| 5512 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 5513 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | // tells if it's a cheek event or not -- this function is stateful |
| 5518 | private static final int EVENT_NONE = 0; |
| 5519 | private static final int EVENT_UNKNOWN = 0; |
| 5520 | private static final int EVENT_CHEEK = 0; |
| 5521 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 5522 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 5523 | private int mEventState = EVENT_NONE; |
| 5524 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5526 | private int eventType(MotionEvent ev) { |
| 5527 | float size = ev.getSize(); |
| 5528 | switch (ev.getAction()) { |
| 5529 | case MotionEvent.ACTION_DOWN: |
| 5530 | mEventSize = size; |
| 5531 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 5532 | case MotionEvent.ACTION_UP: |
| 5533 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5534 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5535 | case MotionEvent.ACTION_MOVE: |
| 5536 | final int N = ev.getHistorySize(); |
| 5537 | if (size > mEventSize) mEventSize = size; |
| 5538 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 5539 | for (int i=0; i<N; i++) { |
| 5540 | size = ev.getHistoricalSize(i); |
| 5541 | if (size > mEventSize) mEventSize = size; |
| 5542 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 5543 | } |
| 5544 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 5545 | return TOUCH_EVENT; |
| 5546 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5547 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5548 | } |
| 5549 | default: |
| 5550 | // not good |
| 5551 | return OTHER_EVENT; |
| 5552 | } |
| 5553 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5554 | |
| 5555 | private boolean mFatTouch; // remove me together with dispatchPointer |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | |
| 5557 | /** |
| 5558 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5559 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5560 | private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5561 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | "dispatchPointer " + ev); |
| 5563 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5564 | if (MEASURE_LATENCY) { |
| 5565 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 5566 | } |
| 5567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5569 | ev, true, false, pid, uid); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5570 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5571 | if (MEASURE_LATENCY) { |
| 5572 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 5573 | } |
| 5574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5576 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5577 | if (action == MotionEvent.ACTION_UP) { |
| 5578 | // let go of our target |
| 5579 | mKeyWaiter.mMotionTarget = null; |
| 5580 | mPowerManager.logPointerUpEvent(); |
| 5581 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 5582 | mPowerManager.logPointerDownEvent(); |
| 5583 | } |
| 5584 | |
| 5585 | if (targetObj == null) { |
| 5586 | // In this case we are either dropping the event, or have received |
| 5587 | // a move or up without a down. It is common to receive move |
| 5588 | // events in such a way, since this means the user is moving the |
| 5589 | // pointer without actually pressing down. All other cases should |
| 5590 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5591 | if (action != MotionEvent.ACTION_MOVE) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5592 | Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5593 | } |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5594 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5595 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5596 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5597 | if (qev != null) { |
| 5598 | mQueue.recycleEvent(qev); |
| 5599 | } |
| 5600 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5601 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5602 | } |
| 5603 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5604 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5605 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5606 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5607 | if (qev != null) { |
| 5608 | mQueue.recycleEvent(qev); |
| 5609 | } |
| 5610 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5611 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5612 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5613 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5614 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5615 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5616 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5617 | final long eventTimeNano = ev.getEventTimeNano(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5618 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5619 | //Slog.i(TAG, "Sending " + ev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5620 | |
| 5621 | if (uid != 0 && uid != target.mSession.mUid) { |
| 5622 | if (mContext.checkPermission( |
| 5623 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5624 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5625 | Slog.w(TAG, "Permission denied: injecting pointer event from pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | + pid + " uid " + uid + " to window " + target |
| 5627 | + " owned by uid " + target.mSession.mUid); |
| 5628 | if (qev != null) { |
| 5629 | mQueue.recycleEvent(qev); |
| 5630 | } |
| 5631 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5632 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | } |
| 5634 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5635 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5636 | if (MEASURE_LATENCY) { |
| 5637 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5638 | } |
| 5639 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5640 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 5642 | //target wants to ignore fat touch events |
| 5643 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 5644 | //explicit flag to return without processing event further |
| 5645 | boolean returnFlag = false; |
| 5646 | if((action == MotionEvent.ACTION_DOWN)) { |
| 5647 | mFatTouch = false; |
| 5648 | if(cheekPress) { |
| 5649 | mFatTouch = true; |
| 5650 | returnFlag = true; |
| 5651 | } |
| 5652 | } else { |
| 5653 | if(action == MotionEvent.ACTION_UP) { |
| 5654 | if(mFatTouch) { |
| 5655 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 5656 | mFatTouch = false; |
| 5657 | returnFlag = true; |
| 5658 | } else if(cheekPress) { |
| 5659 | //cancel the earlier event |
| 5660 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5661 | action = MotionEvent.ACTION_CANCEL; |
| 5662 | } |
| 5663 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 5664 | if(mFatTouch) { |
| 5665 | //two cases here |
| 5666 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5667 | //a valid down, invalid move, more moves. want to ignore till up |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5668 | returnFlag = true; |
| 5669 | } else if(cheekPress) { |
| 5670 | //valid down followed by invalid moves |
| 5671 | //an invalid move have to cancel earlier action |
| 5672 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5673 | action = MotionEvent.ACTION_CANCEL; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5674 | if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5675 | //note that the subsequent invalid moves will not get here |
| 5676 | mFatTouch = true; |
| 5677 | } |
| 5678 | } |
| 5679 | } //else if action |
| 5680 | if(returnFlag) { |
| 5681 | //recycle que, ev |
| 5682 | if (qev != null) { |
| 5683 | mQueue.recycleEvent(qev); |
| 5684 | } |
| 5685 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5686 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5687 | } |
| 5688 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5689 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 5690 | // Enable this for testing the "right" value |
| 5691 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5692 | int max_events_per_sec = 35; |
| 5693 | try { |
| 5694 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5695 | .get("windowsmgr.max_events_per_sec")); |
| 5696 | if (max_events_per_sec < 1) { |
| 5697 | max_events_per_sec = 35; |
| 5698 | } |
| 5699 | } catch (NumberFormatException e) { |
| 5700 | } |
| 5701 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5702 | } |
| 5703 | |
| 5704 | /* |
| 5705 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5706 | * e.g. constant contact with the screen |
| 5707 | */ |
| 5708 | if (action == MotionEvent.ACTION_MOVE) { |
| 5709 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5710 | long now = SystemClock.uptimeMillis(); |
| 5711 | if (now < nextEventTime) { |
| 5712 | try { |
| 5713 | Thread.sleep(nextEventTime - now); |
| 5714 | } catch (InterruptedException e) { |
| 5715 | } |
| 5716 | mLastTouchEventTime = nextEventTime; |
| 5717 | } else { |
| 5718 | mLastTouchEventTime = now; |
| 5719 | } |
| 5720 | } |
| 5721 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5722 | if (MEASURE_LATENCY) { |
| 5723 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5724 | } |
| 5725 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | synchronized(mWindowMap) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5727 | if (!target.isVisibleLw()) { |
| 5728 | // During this motion dispatch, the target window has become |
| 5729 | // invisible. |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5730 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5731 | if (qev != null) { |
| 5732 | mQueue.recycleEvent(qev); |
| 5733 | } |
| 5734 | ev.recycle(); |
| 5735 | return INJECT_SUCCEEDED; |
| 5736 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5739 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5740 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5741 | ev = null; |
| 5742 | } else { |
| 5743 | if (action == MotionEvent.ACTION_DOWN) { |
| 5744 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5745 | if (out != null) { |
| 5746 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5747 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5748 | do { |
| 5749 | final Rect frame = out.mFrame; |
| 5750 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5751 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5752 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5754 | Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5755 | } |
| 5756 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5757 | out = out.mNextOutsideTouch; |
| 5758 | } while (out != null); |
| 5759 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5760 | } |
| 5761 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5762 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5763 | dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5764 | |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5765 | final Rect frame = target.mFrame; |
| 5766 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5767 | mKeyWaiter.bindTargetWindowLocked(target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5768 | } |
| 5769 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5770 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | // finally offset the event to the target's coordinate system and |
| 5772 | // dispatch the event. |
| 5773 | try { |
| 5774 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5775 | Slog.v(TAG, "Delivering pointer " + qev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5776 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5777 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5778 | if (MEASURE_LATENCY) { |
| 5779 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5780 | } |
| 5781 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5782 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5783 | |
| 5784 | if (MEASURE_LATENCY) { |
| 5785 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5786 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5787 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5788 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5789 | Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5790 | mKeyWaiter.mMotionTarget = null; |
| 5791 | try { |
| 5792 | removeWindow(target.mSession, target.mClient); |
| 5793 | } catch (java.util.NoSuchElementException ex) { |
| 5794 | // This will happen if the window has already been |
| 5795 | // removed. |
| 5796 | } |
| 5797 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5798 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5800 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | /** |
| 5802 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5803 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5804 | private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5805 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5807 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5808 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5809 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5811 | Slog.w(TAG, "No focus window, dropping trackball: " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5812 | if (qev != null) { |
| 5813 | mQueue.recycleEvent(qev); |
| 5814 | } |
| 5815 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5816 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | } |
| 5818 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5819 | if (qev != null) { |
| 5820 | mQueue.recycleEvent(qev); |
| 5821 | } |
| 5822 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5823 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5824 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5827 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5829 | if (mContext.checkPermission( |
| 5830 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5831 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5832 | Slog.w(TAG, "Permission denied: injecting key event from pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5833 | + pid + " uid " + uid + " to window " + focus |
| 5834 | + " owned by uid " + focus.mSession.mUid); |
| 5835 | if (qev != null) { |
| 5836 | mQueue.recycleEvent(qev); |
| 5837 | } |
| 5838 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5839 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5840 | } |
| 5841 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5843 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5844 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5845 | synchronized(mWindowMap) { |
| 5846 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5847 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5848 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5849 | // We don't deliver movement events to the client, we hold |
| 5850 | // them and wait for them to call back. |
| 5851 | ev = null; |
| 5852 | } else { |
| 5853 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5854 | } |
| 5855 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5856 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5858 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5859 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5861 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5862 | try { |
| 5863 | removeWindow(focus.mSession, focus.mClient); |
| 5864 | } catch (java.util.NoSuchElementException ex) { |
| 5865 | // This will happen if the window has already been |
| 5866 | // removed. |
| 5867 | } |
| 5868 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5869 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5870 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5872 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5873 | /** |
| 5874 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5875 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5876 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5877 | if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5878 | |
| 5879 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5880 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5881 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5882 | Slog.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5883 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5884 | } |
| 5885 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5886 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5888 | |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5889 | // Okay we have finished waiting for the last event to be processed. |
| 5890 | // First off, if this is a repeat event, check to see if there is |
| 5891 | // a corresponding up event in the queue. If there is, we will |
| 5892 | // just drop the repeat, because it makes no sense to repeat after |
| 5893 | // the user has released a key. (This is especially important for |
| 5894 | // long presses.) |
| 5895 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5896 | return INJECT_SUCCEEDED; |
| 5897 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5898 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5900 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5901 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | TAG, "Dispatching to " + focus + ": " + event); |
| 5903 | |
| 5904 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5905 | if (mContext.checkPermission( |
| 5906 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5907 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5908 | Slog.w(TAG, "Permission denied: injecting key event from pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5909 | + pid + " uid " + uid + " to window " + focus |
| 5910 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5911 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5912 | } |
| 5913 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5915 | synchronized(mWindowMap) { |
| 5916 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5917 | } |
| 5918 | |
| 5919 | // NOSHIP extra state logging |
| 5920 | mKeyWaiter.recordDispatchState(event, focus); |
| 5921 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5923 | try { |
| 5924 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5925 | Slog.v(TAG, "Delivering key " + event.getKeyCode() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5926 | + " to " + focus); |
| 5927 | } |
| 5928 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5929 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5930 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5931 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | try { |
| 5933 | removeWindow(focus.mSession, focus.mClient); |
| 5934 | } catch (java.util.NoSuchElementException ex) { |
| 5935 | // This will happen if the window has already been |
| 5936 | // removed. |
| 5937 | } |
| 5938 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5939 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5940 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5941 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5943 | public void pauseKeyDispatching(IBinder _token) { |
| 5944 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5945 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5946 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | synchronized (mWindowMap) { |
| 5950 | WindowToken token = mTokenMap.get(_token); |
| 5951 | if (token != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5952 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 5953 | mInputMonitor.pauseDispatchingLw(token); |
| 5954 | } else { |
| 5955 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5956 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5957 | } |
| 5958 | } |
| 5959 | } |
| 5960 | |
| 5961 | public void resumeKeyDispatching(IBinder _token) { |
| 5962 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5963 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5964 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | synchronized (mWindowMap) { |
| 5968 | WindowToken token = mTokenMap.get(_token); |
| 5969 | if (token != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5970 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 5971 | mInputMonitor.resumeDispatchingLw(token); |
| 5972 | } else { |
| 5973 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5974 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5975 | } |
| 5976 | } |
| 5977 | } |
| 5978 | |
| 5979 | public void setEventDispatching(boolean enabled) { |
| 5980 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5981 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5982 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | synchronized (mWindowMap) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5986 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 5987 | mInputMonitor.setEventDispatchingLw(enabled); |
| 5988 | } else { |
| 5989 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5990 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5991 | } |
| 5992 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5994 | /** |
| 5995 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5996 | * |
| 5997 | * @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] | 5998 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5999 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6000 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6001 | */ |
| 6002 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6003 | long downTime = ev.getDownTime(); |
| 6004 | long eventTime = ev.getEventTime(); |
| 6005 | |
| 6006 | int action = ev.getAction(); |
| 6007 | int code = ev.getKeyCode(); |
| 6008 | int repeatCount = ev.getRepeatCount(); |
| 6009 | int metaState = ev.getMetaState(); |
| 6010 | int deviceId = ev.getDeviceId(); |
| 6011 | int scancode = ev.getScanCode(); |
| 6012 | |
| 6013 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6014 | if (downTime == 0) downTime = eventTime; |
| 6015 | |
| 6016 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6017 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6018 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6019 | final int pid = Binder.getCallingPid(); |
| 6020 | final int uid = Binder.getCallingUid(); |
| 6021 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6022 | |
| 6023 | final int result; |
| 6024 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6025 | result = mInputManager.injectKeyEvent(newEvent, InputQueue.INPUT_EVENT_NATURE_KEY, |
| 6026 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6027 | } else { |
| 6028 | result = dispatchKey(newEvent, pid, uid); |
| 6029 | if (sync) { |
| 6030 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| 6031 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6032 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6033 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6034 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6035 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | } |
| 6037 | |
| 6038 | /** |
| 6039 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6040 | * |
| 6041 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6042 | * {@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] | 6043 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6044 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6045 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6046 | */ |
| 6047 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6048 | final int pid = Binder.getCallingPid(); |
| 6049 | final int uid = Binder.getCallingUid(); |
| 6050 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6051 | |
| 6052 | final int result; |
| 6053 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6054 | result = mInputManager.injectMotionEvent(ev, InputQueue.INPUT_EVENT_NATURE_TOUCH, |
| 6055 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6056 | } else { |
| 6057 | result = dispatchPointer(null, ev, pid, uid); |
| 6058 | if (sync) { |
| 6059 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| 6060 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6061 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6062 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6063 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6064 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6065 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6066 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | /** |
| 6068 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6069 | * |
| 6070 | * @param ev A motion event describing the trackball action. (As noted in |
| 6071 | * {@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] | 6072 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6073 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6074 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6075 | */ |
| 6076 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6077 | final int pid = Binder.getCallingPid(); |
| 6078 | final int uid = Binder.getCallingUid(); |
| 6079 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6080 | |
| 6081 | final int result; |
| 6082 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6083 | result = mInputManager.injectMotionEvent(ev, InputQueue.INPUT_EVENT_NATURE_TRACKBALL, |
| 6084 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6085 | } else { |
| 6086 | result = dispatchTrackball(null, ev, pid, uid); |
| 6087 | if (sync) { |
| 6088 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| 6089 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6090 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6091 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6092 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6093 | return reportInjectionResult(result); |
| 6094 | } |
| 6095 | |
| 6096 | private boolean reportInjectionResult(int result) { |
| 6097 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 6098 | switch (result) { |
| 6099 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6100 | Slog.w(TAG, "Input event injection permission denied."); |
| 6101 | throw new SecurityException( |
| 6102 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6103 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| 6104 | Slog.v(TAG, "Input event injection succeeded."); |
| 6105 | return true; |
| 6106 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6107 | Slog.w(TAG, "Input event injection timed out."); |
| 6108 | return false; |
| 6109 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6110 | default: |
| 6111 | Slog.w(TAG, "Input event injection failed."); |
| 6112 | return false; |
| 6113 | } |
| 6114 | } else { |
| 6115 | switch (result) { |
| 6116 | case INJECT_NO_PERMISSION: |
| 6117 | throw new SecurityException( |
| 6118 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6119 | case INJECT_SUCCEEDED: |
| 6120 | return true; |
| 6121 | } |
| 6122 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6123 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6125 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6126 | private WindowState getFocusedWindow() { |
| 6127 | synchronized (mWindowMap) { |
| 6128 | return getFocusedWindowLocked(); |
| 6129 | } |
| 6130 | } |
| 6131 | |
| 6132 | private WindowState getFocusedWindowLocked() { |
| 6133 | return mCurrentFocus; |
| 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 | /** |
| 6137 | * This class holds the state for dispatching key events. This state |
| 6138 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 6139 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 6140 | * but not the other way around. |
| 6141 | */ |
| 6142 | final class KeyWaiter { |
| 6143 | // NOSHIP debugging |
| 6144 | public class DispatchState { |
| 6145 | private KeyEvent event; |
| 6146 | private WindowState focus; |
| 6147 | private long time; |
| 6148 | private WindowState lastWin; |
| 6149 | private IBinder lastBinder; |
| 6150 | private boolean finished; |
| 6151 | private boolean gotFirstWindow; |
| 6152 | private boolean eventDispatching; |
| 6153 | private long timeToSwitch; |
| 6154 | private boolean wasFrozen; |
| 6155 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6156 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6157 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 6159 | focus = theFocus; |
| 6160 | event = theEvent; |
| 6161 | time = System.currentTimeMillis(); |
| 6162 | // snapshot KeyWaiter state |
| 6163 | lastWin = mLastWin; |
| 6164 | lastBinder = mLastBinder; |
| 6165 | finished = mFinished; |
| 6166 | gotFirstWindow = mGotFirstWindow; |
| 6167 | eventDispatching = mEventDispatching; |
| 6168 | timeToSwitch = mTimeToSwitch; |
| 6169 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6170 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6171 | // cache the paused state at ctor time as well |
| 6172 | if (theFocus == null || theFocus.mToken == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6173 | focusPaused = false; |
| 6174 | } else { |
| 6175 | focusPaused = theFocus.mToken.paused; |
| 6176 | } |
| 6177 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6179 | public String toString() { |
| 6180 | return "{{" + event + " to " + focus + " @ " + time |
| 6181 | + " lw=" + lastWin + " lb=" + lastBinder |
| 6182 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 6183 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6184 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| Christopher Tate | 46d4525 | 2010-02-09 15:48:57 -0800 | [diff] [blame] | 6185 | + " mcf=" + curFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | } |
| 6187 | }; |
| 6188 | private DispatchState mDispatchState = null; |
| 6189 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 6190 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 6191 | } |
| 6192 | // END NOSHIP |
| 6193 | |
| 6194 | public static final int RETURN_NOTHING = 0; |
| 6195 | public static final int RETURN_PENDING_POINTER = 1; |
| 6196 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6198 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 6199 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6200 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6201 | private WindowState mLastWin = null; |
| 6202 | private IBinder mLastBinder = null; |
| 6203 | private boolean mFinished = true; |
| 6204 | private boolean mGotFirstWindow = false; |
| 6205 | private boolean mEventDispatching = true; |
| 6206 | private long mTimeToSwitch = 0; |
| 6207 | /* package */ boolean mWasFrozen = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6208 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | // Target of Motion events |
| 6210 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6212 | // Windows above the target who would like to receive an "outside" |
| 6213 | // touch event for any down events outside of them. |
| 6214 | WindowState mOutsideTouchTargets; |
| 6215 | |
| 6216 | /** |
| 6217 | * Wait for the last event dispatch to complete, then find the next |
| 6218 | * target that should receive the given event and wait for that one |
| 6219 | * to be ready to receive it. |
| 6220 | */ |
| 6221 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 6222 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6223 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | long startTime = SystemClock.uptimeMillis(); |
| 6225 | long keyDispatchingTimeout = 5 * 1000; |
| 6226 | long waitedFor = 0; |
| 6227 | |
| 6228 | while (true) { |
| 6229 | // Figure out which window we care about. It is either the |
| 6230 | // last window we are waiting to have process the event or, |
| 6231 | // if none, then the next window we think the event should go |
| 6232 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 6233 | // it may change before we lock. Thus we must check it again. |
| 6234 | WindowState targetWin = mLastWin; |
| 6235 | boolean targetIsNew = targetWin == null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6236 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6237 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 6238 | ", mLastWin=" + mLastWin); |
| 6239 | if (targetIsNew) { |
| 6240 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6241 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6242 | if (target == SKIP_TARGET_TOKEN) { |
| 6243 | // The user has pressed a special key, and we are |
| 6244 | // dropping all pending events before it. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6245 | if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6246 | + " " + nextMotion); |
| 6247 | return null; |
| 6248 | } |
| 6249 | if (target == CONSUMED_EVENT_TOKEN) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6250 | if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | + " " + nextMotion); |
| 6252 | return target; |
| 6253 | } |
| 6254 | targetWin = (WindowState)target; |
| 6255 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6258 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | // Now: is it okay to send the next event to this window? |
| 6260 | synchronized (this) { |
| 6261 | // First: did we come here based on the last window not |
| 6262 | // being null, but it changed by the time we got here? |
| 6263 | // If so, try again. |
| 6264 | if (!targetIsNew && mLastWin == null) { |
| 6265 | continue; |
| 6266 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | // We never dispatch events if not finished with the |
| 6269 | // last one, or the display is frozen. |
| 6270 | if (mFinished && !mDisplayFrozen) { |
| 6271 | // If event dispatching is disabled, then we |
| 6272 | // just consume the events. |
| 6273 | if (!mEventDispatching) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6274 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6275 | "Skipping event; dispatching disabled: " |
| 6276 | + nextKey + " " + nextMotion); |
| 6277 | return null; |
| 6278 | } |
| 6279 | if (targetWin != null) { |
| 6280 | // If this is a new target, and that target is not |
| 6281 | // paused or unresponsive, then all looks good to |
| 6282 | // handle the event. |
| 6283 | if (targetIsNew && !targetWin.mToken.paused) { |
| 6284 | return targetWin; |
| 6285 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6286 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6287 | // If we didn't find a target window, and there is no |
| 6288 | // focused app window, then just eat the events. |
| 6289 | } else if (mFocusedApp == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6290 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6291 | "Skipping event; no focused app: " |
| 6292 | + nextKey + " " + nextMotion); |
| 6293 | return null; |
| 6294 | } |
| 6295 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6296 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6297 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6298 | TAG, "Waiting for last key in " + mLastBinder |
| 6299 | + " target=" + targetWin |
| 6300 | + " mFinished=" + mFinished |
| 6301 | + " mDisplayFrozen=" + mDisplayFrozen |
| 6302 | + " targetIsNew=" + targetIsNew |
| 6303 | + " paused=" |
| 6304 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6305 | + " mFocusedApp=" + mFocusedApp |
| 6306 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | targetApp = targetWin != null |
| 6309 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6310 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | long curTimeout = keyDispatchingTimeout; |
| 6312 | if (mTimeToSwitch != 0) { |
| 6313 | long now = SystemClock.uptimeMillis(); |
| 6314 | if (mTimeToSwitch <= now) { |
| 6315 | // If an app switch key has been pressed, and we have |
| 6316 | // waited too long for the current app to finish |
| 6317 | // processing keys, then wait no more! |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6318 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6319 | continue; |
| 6320 | } |
| 6321 | long switchTimeout = mTimeToSwitch - now; |
| 6322 | if (curTimeout > switchTimeout) { |
| 6323 | curTimeout = switchTimeout; |
| 6324 | } |
| 6325 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | try { |
| 6328 | // after that continue |
| 6329 | // processing keys, so we don't get stuck. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6330 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 6332 | wait(curTimeout); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6333 | if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6334 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6335 | + startTime + " switchTime=" + mTimeToSwitch |
| 6336 | + " target=" + targetWin + " mLW=" + mLastWin |
| 6337 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 6338 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6339 | } catch (InterruptedException e) { |
| 6340 | } |
| 6341 | } |
| 6342 | |
| 6343 | // If we were frozen during configuration change, restart the |
| 6344 | // timeout checks from now; otherwise look at whether we timed |
| 6345 | // out before awakening. |
| 6346 | if (mWasFrozen) { |
| 6347 | waitedFor = 0; |
| 6348 | mWasFrozen = false; |
| 6349 | } else { |
| 6350 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 6351 | } |
| 6352 | |
| 6353 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 6354 | IApplicationToken at = null; |
| 6355 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6356 | Slog.w(TAG, "Key dispatching timed out sending to " + |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6357 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 6358 | : "<null>: no window ready for key dispatch")); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | // NOSHIP debugging |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6360 | Slog.w(TAG, "Previous dispatch state: " + mDispatchState); |
| 6361 | Slog.w(TAG, "Current dispatch state: " + |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 6362 | new DispatchState(nextKey, targetWin)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6363 | // END NOSHIP |
| 6364 | //dump(); |
| 6365 | if (targetWin != null) { |
| 6366 | at = targetWin.getAppToken(); |
| 6367 | } else if (targetApp != null) { |
| 6368 | at = targetApp.appToken; |
| 6369 | } |
| 6370 | } |
| 6371 | |
| 6372 | boolean abort = true; |
| 6373 | if (at != null) { |
| 6374 | try { |
| 6375 | long timeout = at.getKeyDispatchingTimeout(); |
| 6376 | if (timeout > waitedFor) { |
| 6377 | // we did not wait the proper amount of time for this application. |
| 6378 | // set the timeout to be the real timeout and wait again. |
| 6379 | keyDispatchingTimeout = timeout - waitedFor; |
| 6380 | continue; |
| 6381 | } else { |
| 6382 | abort = at.keyDispatchingTimedOut(); |
| 6383 | } |
| 6384 | } catch (RemoteException ex) { |
| 6385 | } |
| 6386 | } |
| 6387 | |
| 6388 | synchronized (this) { |
| 6389 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 6390 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6391 | if (mLastWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6392 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6393 | "Window " + mLastWin + |
| 6394 | " timed out on key input"); |
| 6395 | if (mLastWin.mToken.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6396 | Slog.w(TAG, "Un-pausing dispatching to this window"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6397 | mLastWin.mToken.paused = false; |
| 6398 | } |
| 6399 | } |
| 6400 | if (mMotionTarget == targetWin) { |
| 6401 | mMotionTarget = null; |
| 6402 | } |
| 6403 | mLastWin = null; |
| 6404 | mLastBinder = null; |
| 6405 | if (failIfTimeout || targetWin == null) { |
| 6406 | return null; |
| 6407 | } |
| 6408 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6409 | Slog.w(TAG, "Continuing to wait for key to be dispatched"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6410 | startTime = SystemClock.uptimeMillis(); |
| 6411 | } |
| 6412 | } |
| 6413 | } |
| 6414 | } |
| 6415 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6417 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6418 | MotionEvent nextMotion, boolean isPointerEvent, |
| 6419 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6421 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6422 | if (nextKey != null) { |
| 6423 | // Find the target window for a normal key event. |
| 6424 | final int keycode = nextKey.getKeyCode(); |
| 6425 | final int repeatCount = nextKey.getRepeatCount(); |
| 6426 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 6427 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6429 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6430 | if (callingUid == 0 || |
| 6431 | mContext.checkPermission( |
| 6432 | android.Manifest.permission.INJECT_EVENTS, |
| 6433 | callingPid, callingUid) |
| 6434 | == PackageManager.PERMISSION_GRANTED) { |
| 6435 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6436 | nextKey.getMetaState(), down, repeatCount, |
| 6437 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6438 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6439 | Slog.w(TAG, "Event timeout during app switch: dropping " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6440 | + nextKey); |
| 6441 | return SKIP_TARGET_TOKEN; |
| 6442 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6443 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | WindowState focus = null; |
| 6447 | synchronized(mWindowMap) { |
| 6448 | focus = getFocusedWindowLocked(); |
| 6449 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6451 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6452 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6453 | if (callingUid == 0 || |
| 6454 | (focus != null && callingUid == focus.mSession.mUid) || |
| 6455 | mContext.checkPermission( |
| 6456 | android.Manifest.permission.INJECT_EVENTS, |
| 6457 | callingPid, callingUid) |
| 6458 | == PackageManager.PERMISSION_GRANTED) { |
| 6459 | if (mPolicy.interceptKeyTi(focus, |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6460 | keycode, nextKey.getMetaState(), down, repeatCount, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6461 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6462 | return CONSUMED_EVENT_TOKEN; |
| 6463 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | return focus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6468 | } else if (!isPointerEvent) { |
| 6469 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 6470 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6471 | Slog.w(TAG, "Event timeout during app switch: dropping trackball " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | + nextMotion); |
| 6473 | return SKIP_TARGET_TOKEN; |
| 6474 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6475 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6476 | WindowState focus = null; |
| 6477 | synchronized(mWindowMap) { |
| 6478 | focus = getFocusedWindowLocked(); |
| 6479 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6480 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 6482 | return focus; |
| 6483 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6485 | if (nextMotion == null) { |
| 6486 | return SKIP_TARGET_TOKEN; |
| 6487 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6489 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 6490 | KeyEvent.KEYCODE_UNKNOWN); |
| 6491 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6492 | Slog.w(TAG, "Event timeout during app switch: dropping pointer " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | + nextMotion); |
| 6494 | return SKIP_TARGET_TOKEN; |
| 6495 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | // Find the target window for a pointer event. |
| 6498 | int action = nextMotion.getAction(); |
| 6499 | final float xf = nextMotion.getX(); |
| 6500 | final float yf = nextMotion.getY(); |
| 6501 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6503 | final boolean screenWasOff = qev != null |
| 6504 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6506 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | synchronized(mWindowMap) { |
| 6509 | synchronized (this) { |
| 6510 | if (action == MotionEvent.ACTION_DOWN) { |
| 6511 | if (mMotionTarget != null) { |
| 6512 | // this is weird, we got a pen down, but we thought it was |
| 6513 | // already down! |
| 6514 | // XXX: We should probably send an ACTION_UP to the current |
| 6515 | // target. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6516 | Slog.w(TAG, "Pointer down received while already down in: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | + mMotionTarget); |
| 6518 | mMotionTarget = null; |
| 6519 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6520 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | // ACTION_DOWN is special, because we need to lock next events to |
| 6522 | // the window we'll land onto. |
| 6523 | final int x = (int)xf; |
| 6524 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6526 | final ArrayList windows = mWindows; |
| 6527 | final int N = windows.size(); |
| 6528 | WindowState topErrWindow = null; |
| 6529 | final Rect tmpRect = mTempRect; |
| 6530 | for (int i=N-1; i>=0; i--) { |
| 6531 | WindowState child = (WindowState)windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6532 | //Slog.i(TAG, "Checking dispatch to: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | final int flags = child.mAttrs.flags; |
| 6534 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 6535 | if (topErrWindow == null) { |
| 6536 | topErrWindow = child; |
| 6537 | } |
| 6538 | } |
| 6539 | if (!child.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6540 | //Slog.i(TAG, "Not visible!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6541 | continue; |
| 6542 | } |
| 6543 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6544 | //Slog.i(TAG, "Not touchable!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6545 | if ((flags & WindowManager.LayoutParams |
| 6546 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 6547 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 6548 | mOutsideTouchTargets = child; |
| 6549 | } |
| 6550 | continue; |
| 6551 | } |
| 6552 | tmpRect.set(child.mFrame); |
| 6553 | if (child.mTouchableInsets == ViewTreeObserver |
| 6554 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 6555 | // The touch is inside of the window if it is |
| 6556 | // inside the frame, AND the content part of that |
| 6557 | // frame that was given by the application. |
| 6558 | tmpRect.left += child.mGivenContentInsets.left; |
| 6559 | tmpRect.top += child.mGivenContentInsets.top; |
| 6560 | tmpRect.right -= child.mGivenContentInsets.right; |
| 6561 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 6562 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 6563 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 6564 | // The touch is inside of the window if it is |
| 6565 | // inside the frame, AND the visible part of that |
| 6566 | // frame that was given by the application. |
| 6567 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 6568 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 6569 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 6570 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 6571 | } |
| 6572 | final int touchFlags = flags & |
| 6573 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 6574 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 6575 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6576 | //Slog.i(TAG, "Using this target!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | if (!screenWasOff || (flags & |
| 6578 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 6579 | mMotionTarget = child; |
| 6580 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6581 | //Slog.i(TAG, "Waking, skip!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6582 | mMotionTarget = null; |
| 6583 | } |
| 6584 | break; |
| 6585 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6586 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6587 | if ((flags & WindowManager.LayoutParams |
| 6588 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 6589 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 6590 | mOutsideTouchTargets = child; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6591 | //Slog.i(TAG, "Adding to outside target list: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6592 | } |
| 6593 | } |
| 6594 | |
| 6595 | // if there's an error window but it's not accepting |
| 6596 | // focus (typically because it is not yet visible) just |
| 6597 | // wait for it -- any other focused window may in fact |
| 6598 | // be in ANR state. |
| 6599 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 6600 | mMotionTarget = null; |
| 6601 | } |
| 6602 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6604 | target = mMotionTarget; |
| 6605 | } |
| 6606 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6609 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | // Pointer events are a little different -- if there isn't a |
| 6611 | // target found for any event, then just drop it. |
| 6612 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 6613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | boolean checkShouldDispatchKey(int keycode) { |
| 6616 | synchronized (this) { |
| 6617 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 6618 | mTimeToSwitch = 0; |
| 6619 | return true; |
| 6620 | } |
| 6621 | if (mTimeToSwitch != 0 |
| 6622 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 6623 | return false; |
| 6624 | } |
| 6625 | return true; |
| 6626 | } |
| 6627 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6629 | void bindTargetWindowLocked(WindowState win, |
| 6630 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6631 | synchronized (this) { |
| 6632 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 6633 | } |
| 6634 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6635 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6636 | void bindTargetWindowLocked(WindowState win) { |
| 6637 | synchronized (this) { |
| 6638 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 6639 | } |
| 6640 | } |
| 6641 | |
| 6642 | void bindTargetWindowLockedLocked(WindowState win, |
| 6643 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6644 | mLastWin = win; |
| 6645 | mLastBinder = win.mClient.asBinder(); |
| 6646 | mFinished = false; |
| 6647 | if (pendingMotion != null) { |
| 6648 | final Session s = win.mSession; |
| 6649 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 6650 | releasePendingPointerLocked(s); |
| 6651 | s.mPendingPointerMove = pendingMotion; |
| 6652 | s.mPendingPointerWindow = win; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6653 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 6655 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 6656 | releasePendingTrackballLocked(s); |
| 6657 | s.mPendingTrackballMove = pendingMotion; |
| 6658 | s.mPendingTrackballWindow = win; |
| 6659 | } |
| 6660 | } |
| 6661 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6662 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6663 | void releasePendingPointerLocked(Session s) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6664 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6665 | "releasePendingPointer " + s.mPendingPointerMove); |
| 6666 | if (s.mPendingPointerMove != null) { |
| 6667 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 6668 | s.mPendingPointerMove = null; |
| 6669 | } |
| 6670 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6671 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6672 | void releasePendingTrackballLocked(Session s) { |
| 6673 | if (s.mPendingTrackballMove != null) { |
| 6674 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 6675 | s.mPendingTrackballMove = null; |
| 6676 | } |
| 6677 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6678 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 6680 | int returnWhat) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6681 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6682 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 6683 | |
| 6684 | if (client == null) { |
| 6685 | return null; |
| 6686 | } |
| 6687 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6688 | MotionEvent res = null; |
| 6689 | QueuedEvent qev = null; |
| 6690 | WindowState win = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6691 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6692 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6693 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | TAG, "finishedKey: client=" + client.asBinder() |
| 6695 | + ", force=" + force + ", last=" + mLastBinder |
| 6696 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 6697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6698 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 6699 | qev = session.mPendingPointerMove; |
| 6700 | win = session.mPendingPointerWindow; |
| 6701 | session.mPendingPointerMove = null; |
| 6702 | session.mPendingPointerWindow = null; |
| 6703 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 6704 | qev = session.mPendingTrackballMove; |
| 6705 | win = session.mPendingTrackballWindow; |
| 6706 | session.mPendingTrackballMove = null; |
| 6707 | session.mPendingTrackballWindow = null; |
| 6708 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6709 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6710 | if (mLastBinder == client.asBinder()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6711 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | TAG, "finishedKey: last paused=" |
| 6713 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 6714 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 6715 | || !mEventDispatching)) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6716 | doFinishedKeyLocked(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | } else { |
| 6718 | // Make sure to wake up anyone currently waiting to |
| 6719 | // dispatch a key, so they can re-evaluate their |
| 6720 | // current situation. |
| 6721 | mFinished = true; |
| 6722 | notifyAll(); |
| 6723 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6724 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6725 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6726 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6727 | res = (MotionEvent)qev.event; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6728 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6729 | "Returning pending motion: " + res); |
| 6730 | mQueue.recycleEvent(qev); |
| 6731 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6732 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6733 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | } |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6735 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6736 | |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6737 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6738 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 6739 | dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6740 | } |
| 6741 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6742 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6743 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | void tickle() { |
| 6747 | synchronized (this) { |
| 6748 | notifyAll(); |
| 6749 | } |
| 6750 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6752 | void handleNewWindowLocked(WindowState newWindow) { |
| 6753 | if (!newWindow.canReceiveKeys()) { |
| 6754 | return; |
| 6755 | } |
| 6756 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6757 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6758 | TAG, "New key dispatch window: win=" |
| 6759 | + newWindow.mClient.asBinder() |
| 6760 | + ", last=" + mLastBinder |
| 6761 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6762 | + "), finished=" + mFinished + ", paused=" |
| 6763 | + newWindow.mToken.paused); |
| 6764 | |
| 6765 | // Displaying a window implicitly causes dispatching to |
| 6766 | // be unpaused. (This is to protect against bugs if someone |
| 6767 | // pauses dispatching but forgets to resume.) |
| 6768 | newWindow.mToken.paused = false; |
| 6769 | |
| 6770 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | |
| 6772 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6773 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6774 | "New SYSTEM_ERROR window; resetting state"); |
| 6775 | mLastWin = null; |
| 6776 | mLastBinder = null; |
| 6777 | mMotionTarget = null; |
| 6778 | mFinished = true; |
| 6779 | } else if (mLastWin != null) { |
| 6780 | // If the new window is above the window we are |
| 6781 | // waiting on, then stop waiting and let key dispatching |
| 6782 | // start on the new guy. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6783 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6785 | + ", new win layer=" + newWindow.mLayer); |
| 6786 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6787 | // The new window is above the old; finish pending input to the last |
| 6788 | // window and start directing it to the new one. |
| 6789 | mLastWin.mToken.paused = false; |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6790 | doFinishedKeyLocked(false); // does a notifyAll() |
| 6791 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6792 | } |
| 6793 | } |
| 6794 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6795 | // Now that we've put a new window state in place, make the event waiter |
| 6796 | // take notice and retarget its attentions. |
| 6797 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | void pauseDispatchingLocked(WindowToken token) { |
| 6802 | synchronized (this) |
| 6803 | { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6804 | if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6805 | token.paused = true; |
| 6806 | |
| 6807 | /* |
| 6808 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6809 | mPaused = true; |
| 6810 | } else { |
| 6811 | if (mLastWin == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6812 | Slog.i(TAG, "Key dispatching not paused: no last window."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6813 | } else if (mFinished) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6814 | Slog.i(TAG, "Key dispatching not paused: finished last key."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6816 | Slog.i(TAG, "Key dispatching not paused: window in higher layer."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6817 | } |
| 6818 | } |
| 6819 | */ |
| 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | void resumeDispatchingLocked(WindowToken token) { |
| 6824 | synchronized (this) { |
| 6825 | if (token.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6826 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | TAG, "Resuming WindowToken " + token |
| 6828 | + ", last=" + mLastBinder |
| 6829 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6830 | + "), finished=" + mFinished + ", paused=" |
| 6831 | + token.paused); |
| 6832 | token.paused = false; |
| 6833 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6834 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6835 | } else { |
| 6836 | notifyAll(); |
| 6837 | } |
| 6838 | } |
| 6839 | } |
| 6840 | } |
| 6841 | |
| 6842 | void setEventDispatchingLocked(boolean enabled) { |
| 6843 | synchronized (this) { |
| 6844 | mEventDispatching = enabled; |
| 6845 | notifyAll(); |
| 6846 | } |
| 6847 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6848 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6849 | void appSwitchComing() { |
| 6850 | synchronized (this) { |
| 6851 | // Don't wait for more than .5 seconds for app to finish |
| 6852 | // processing the pending events. |
| 6853 | long now = SystemClock.uptimeMillis() + 500; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6854 | if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6855 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6856 | mTimeToSwitch = now; |
| 6857 | } |
| 6858 | notifyAll(); |
| 6859 | } |
| 6860 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6861 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6862 | private final void doFinishedKeyLocked(boolean force) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6863 | if (mLastWin != null) { |
| 6864 | releasePendingPointerLocked(mLastWin.mSession); |
| 6865 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6866 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6867 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6868 | if (force || mLastWin == null || !mLastWin.mToken.paused |
| 6869 | || !mLastWin.isVisibleLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | // If the current window has been paused, we aren't -really- |
| 6871 | // finished... so let the waiters still wait. |
| 6872 | mLastWin = null; |
| 6873 | mLastBinder = null; |
| 6874 | } |
| 6875 | mFinished = true; |
| 6876 | notifyAll(); |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | private class KeyQ extends KeyInputQueue |
| 6881 | implements KeyInputQueue.FilterCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6882 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6883 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | @Override |
| 6887 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6888 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6889 | return true; |
| 6890 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6891 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6892 | switch (event.type) { |
| 6893 | case RawInputEvent.EV_KEY: { |
| 6894 | // XXX begin hack |
| 6895 | if (DEBUG) { |
| 6896 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6897 | if (event.value != 0) { |
| 6898 | // G down |
| 6899 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6900 | } |
| 6901 | return false; |
| 6902 | } |
| 6903 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6904 | if (event.value != 0) { |
| 6905 | //dump(); |
| 6906 | } |
| 6907 | return false; |
| 6908 | } |
| 6909 | } |
| 6910 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6911 | |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6912 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6913 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6914 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6916 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6917 | mPowerManager.goToSleep(event.when); |
| 6918 | } |
| 6919 | |
| 6920 | if (screenIsOff) { |
| 6921 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6922 | } |
| 6923 | if (screenIsDim) { |
| 6924 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6925 | } |
| 6926 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6927 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6928 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6929 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6930 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6932 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6933 | filterQueue(this); |
| 6934 | mKeyWaiter.appSwitchComing(); |
| 6935 | } |
| 6936 | return true; |
| 6937 | } else { |
| 6938 | return false; |
| 6939 | } |
| 6940 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6942 | case RawInputEvent.EV_REL: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6943 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6944 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | if (screenIsOff) { |
| 6946 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6947 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6948 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6949 | return false; |
| 6950 | } |
| 6951 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6952 | } |
| 6953 | if (screenIsDim) { |
| 6954 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6955 | } |
| 6956 | return true; |
| 6957 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6958 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6959 | case RawInputEvent.EV_ABS: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6960 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6961 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | if (screenIsOff) { |
| 6963 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6964 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6965 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6966 | return false; |
| 6967 | } |
| 6968 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6969 | } |
| 6970 | if (screenIsDim) { |
| 6971 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6972 | } |
| 6973 | return true; |
| 6974 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6976 | default: |
| 6977 | return true; |
| 6978 | } |
| 6979 | } |
| 6980 | |
| 6981 | public int filterEvent(QueuedEvent ev) { |
| 6982 | switch (ev.classType) { |
| 6983 | case RawInputEvent.CLASS_KEYBOARD: |
| 6984 | KeyEvent ke = (KeyEvent)ev.event; |
| 6985 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6986 | Slog.w(TAG, "Dropping movement key during app switch: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6988 | return FILTER_REMOVE; |
| 6989 | } |
| 6990 | return FILTER_ABORT; |
| 6991 | default: |
| 6992 | return FILTER_KEEP; |
| 6993 | } |
| 6994 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6995 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6996 | |
| 6997 | public boolean detectSafeMode() { |
| 6998 | mSafeMode = mPolicy.detectSafeMode(); |
| 6999 | return mSafeMode; |
| 7000 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7002 | public void systemReady() { |
| 7003 | mPolicy.systemReady(); |
| 7004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7006 | private final class InputDispatcherThread extends Thread { |
| 7007 | // Time to wait when there is nothing to do: 9999 seconds. |
| 7008 | static final int LONG_WAIT=9999*1000; |
| 7009 | |
| 7010 | public InputDispatcherThread() { |
| 7011 | super("InputDispatcher"); |
| 7012 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7013 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | @Override |
| 7015 | public void run() { |
| 7016 | while (true) { |
| 7017 | try { |
| 7018 | process(); |
| 7019 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7020 | Slog.e(TAG, "Exception in input dispatcher", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7021 | } |
| 7022 | } |
| 7023 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7024 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7025 | private void process() { |
| 7026 | android.os.Process.setThreadPriority( |
| 7027 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7029 | // The last key event we saw |
| 7030 | KeyEvent lastKey = null; |
| 7031 | |
| 7032 | // Last keydown time for auto-repeating keys |
| 7033 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 7034 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7035 | long downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7037 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7038 | int keyRepeatCount = 0; |
| 7039 | |
| 7040 | // Need to report that configuration has changed? |
| 7041 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7042 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7043 | while (true) { |
| 7044 | long curTime = SystemClock.uptimeMillis(); |
| 7045 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7046 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | TAG, "Waiting for next key: now=" + curTime |
| 7048 | + ", repeat @ " + nextKeyTime); |
| 7049 | |
| 7050 | // Retrieve next event, waiting only as long as the next |
| 7051 | // repeat timeout. If the configuration has changed, then |
| 7052 | // don't wait at all -- we'll report the change as soon as |
| 7053 | // we have processed all events. |
| 7054 | QueuedEvent ev = mQueue.getEvent( |
| 7055 | (int)((!configChanged && curTime < nextKeyTime) |
| 7056 | ? (nextKeyTime-curTime) : 0)); |
| 7057 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7058 | if (DEBUG_INPUT && ev != null) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7059 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 7060 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7061 | if (MEASURE_LATENCY) { |
| 7062 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 7063 | } |
| 7064 | |
| Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 7065 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 7066 | // cancel key repeat at the request of the policy. |
| 7067 | lastKey = null; |
| 7068 | downTime = 0; |
| 7069 | lastKeyTime = curTime; |
| 7070 | nextKeyTime = curTime + LONG_WAIT; |
| 7071 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7072 | try { |
| 7073 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7074 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | int eventType; |
| 7076 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 7077 | eventType = eventType((MotionEvent)ev.event); |
| 7078 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 7079 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 7080 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 7081 | } else { |
| 7082 | eventType = LocalPowerManager.OTHER_EVENT; |
| 7083 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7084 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7085 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 7086 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7087 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 7088 | mBatteryStats.noteInputEvent(); |
| 7089 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7090 | } catch (RemoteException e) { |
| 7091 | // Ignore |
| 7092 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 7093 | |
| Mike Lockwood | 5db4240 | 2009-11-30 14:51:51 -0500 | [diff] [blame] | 7094 | if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) { |
| 7095 | // do not wake screen in this case |
| 7096 | } else if (eventType != TOUCH_EVENT |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 7097 | && eventType != LONG_TOUCH_EVENT |
| 7098 | && eventType != CHEEK_EVENT) { |
| 7099 | mPowerManager.userActivity(curTime, false, |
| 7100 | eventType, false); |
| 7101 | } else if (mLastTouchEventType != eventType |
| 7102 | || (curTime - mLastUserActivityCallTime) |
| 7103 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 7104 | mLastUserActivityCallTime = curTime; |
| 7105 | mLastTouchEventType = eventType; |
| 7106 | mPowerManager.userActivity(curTime, false, |
| 7107 | eventType, false); |
| 7108 | } |
| 7109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7110 | switch (ev.classType) { |
| 7111 | case RawInputEvent.CLASS_KEYBOARD: |
| 7112 | KeyEvent ke = (KeyEvent)ev.event; |
| 7113 | if (ke.isDown()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7114 | lastKeyTime = curTime; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7115 | if (lastKey != null && |
| 7116 | ke.getKeyCode() == lastKey.getKeyCode()) { |
| 7117 | keyRepeatCount++; |
| 7118 | // Arbitrary long timeout to block |
| 7119 | // repeating here since we know that |
| 7120 | // the device driver takes care of it. |
| 7121 | nextKeyTime = lastKeyTime + LONG_WAIT; |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 7122 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7123 | TAG, "Received repeated key down"); |
| 7124 | } else { |
| 7125 | downTime = curTime; |
| 7126 | keyRepeatCount = 0; |
| 7127 | nextKeyTime = lastKeyTime |
| 7128 | + ViewConfiguration.getLongPressTimeout(); |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 7129 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7130 | TAG, "Received key down: first repeat @ " |
| 7131 | + nextKeyTime); |
| 7132 | } |
| 7133 | lastKey = ke; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | } else { |
| 7135 | lastKey = null; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7136 | downTime = 0; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7137 | keyRepeatCount = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | // Arbitrary long timeout. |
| 7139 | lastKeyTime = curTime; |
| 7140 | nextKeyTime = curTime + LONG_WAIT; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7141 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7142 | TAG, "Received key up: ignore repeat @ " |
| 7143 | + nextKeyTime); |
| 7144 | } |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7145 | if (keyRepeatCount > 0) { |
| 7146 | dispatchKey(KeyEvent.changeTimeRepeat(ke, |
| 7147 | ke.getEventTime(), keyRepeatCount), 0, 0); |
| 7148 | } else { |
| 7149 | dispatchKey(ke, 0, 0); |
| 7150 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7151 | mQueue.recycleEvent(ev); |
| 7152 | break; |
| 7153 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7154 | //Slog.i(TAG, "Read next event " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7155 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 7156 | break; |
| 7157 | case RawInputEvent.CLASS_TRACKBALL: |
| 7158 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 7159 | break; |
| 7160 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 7161 | configChanged = true; |
| 7162 | break; |
| 7163 | default: |
| 7164 | mQueue.recycleEvent(ev); |
| 7165 | break; |
| 7166 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7168 | } else if (configChanged) { |
| 7169 | configChanged = false; |
| 7170 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | } else if (lastKey != null) { |
| 7173 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7175 | // Timeout occurred while key was down. If it is at or |
| 7176 | // past the key repeat time, dispatch the repeat. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7177 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7178 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 7179 | + ", now=" + curTime); |
| 7180 | if (curTime < nextKeyTime) { |
| 7181 | continue; |
| 7182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7184 | lastKeyTime = nextKeyTime; |
| 7185 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 7186 | keyRepeatCount++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7187 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7188 | TAG, "Key repeat: count=" + keyRepeatCount |
| 7189 | + ", next @ " + nextKeyTime); |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7190 | KeyEvent newEvent; |
| 7191 | if (downTime != 0 && (downTime |
| 7192 | + ViewConfiguration.getLongPressTimeout()) |
| 7193 | <= curTime) { |
| 7194 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 7195 | curTime, keyRepeatCount, |
| 7196 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 7197 | downTime = 0; |
| 7198 | } else { |
| 7199 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 7200 | curTime, keyRepeatCount); |
| 7201 | } |
| 7202 | dispatchKey(newEvent, 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7203 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7204 | } else { |
| 7205 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7207 | lastKeyTime = curTime; |
| 7208 | nextKeyTime = curTime + LONG_WAIT; |
| 7209 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7211 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7212 | Slog.e(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7213 | "Input thread received uncaught exception: " + e, e); |
| 7214 | } |
| 7215 | } |
| 7216 | } |
| 7217 | } |
| 7218 | |
| 7219 | // ------------------------------------------------------------- |
| 7220 | // Client Session State |
| 7221 | // ------------------------------------------------------------- |
| 7222 | |
| 7223 | private final class Session extends IWindowSession.Stub |
| 7224 | implements IBinder.DeathRecipient { |
| 7225 | final IInputMethodClient mClient; |
| 7226 | final IInputContext mInputContext; |
| 7227 | final int mUid; |
| 7228 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7229 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7230 | SurfaceSession mSurfaceSession; |
| 7231 | int mNumWindow = 0; |
| 7232 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7234 | /** |
| 7235 | * Current pointer move event being dispatched to client window... must |
| 7236 | * hold key lock to access. |
| 7237 | */ |
| 7238 | QueuedEvent mPendingPointerMove; |
| 7239 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7241 | /** |
| 7242 | * Current trackball move event being dispatched to client window... must |
| 7243 | * hold key lock to access. |
| 7244 | */ |
| 7245 | QueuedEvent mPendingTrackballMove; |
| 7246 | WindowState mPendingTrackballWindow; |
| 7247 | |
| 7248 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 7249 | mClient = client; |
| 7250 | mInputContext = inputContext; |
| 7251 | mUid = Binder.getCallingUid(); |
| 7252 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7253 | StringBuilder sb = new StringBuilder(); |
| 7254 | sb.append("Session{"); |
| 7255 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7256 | sb.append(" uid "); |
| 7257 | sb.append(mUid); |
| 7258 | sb.append("}"); |
| 7259 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7261 | synchronized (mWindowMap) { |
| 7262 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 7263 | IBinder b = ServiceManager.getService( |
| 7264 | Context.INPUT_METHOD_SERVICE); |
| 7265 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 7266 | } |
| 7267 | } |
| 7268 | long ident = Binder.clearCallingIdentity(); |
| 7269 | try { |
| 7270 | // Note: it is safe to call in to the input method manager |
| 7271 | // here because we are not holding our lock. |
| 7272 | if (mInputMethodManager != null) { |
| 7273 | mInputMethodManager.addClient(client, inputContext, |
| 7274 | mUid, mPid); |
| 7275 | } else { |
| 7276 | client.setUsingInputMethod(false); |
| 7277 | } |
| 7278 | client.asBinder().linkToDeath(this, 0); |
| 7279 | } catch (RemoteException e) { |
| 7280 | // The caller has died, so we can just forget about this. |
| 7281 | try { |
| 7282 | if (mInputMethodManager != null) { |
| 7283 | mInputMethodManager.removeClient(client); |
| 7284 | } |
| 7285 | } catch (RemoteException ee) { |
| 7286 | } |
| 7287 | } finally { |
| 7288 | Binder.restoreCallingIdentity(ident); |
| 7289 | } |
| 7290 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | @Override |
| 7293 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 7294 | throws RemoteException { |
| 7295 | try { |
| 7296 | return super.onTransact(code, data, reply, flags); |
| 7297 | } catch (RuntimeException e) { |
| 7298 | // Log all 'real' exceptions thrown to the caller |
| 7299 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7300 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | } |
| 7302 | throw e; |
| 7303 | } |
| 7304 | } |
| 7305 | |
| 7306 | public void binderDied() { |
| 7307 | // Note: it is safe to call in to the input method manager |
| 7308 | // here because we are not holding our lock. |
| 7309 | try { |
| 7310 | if (mInputMethodManager != null) { |
| 7311 | mInputMethodManager.removeClient(mClient); |
| 7312 | } |
| 7313 | } catch (RemoteException e) { |
| 7314 | } |
| 7315 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 7316 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7317 | mClientDead = true; |
| 7318 | killSessionLocked(); |
| 7319 | } |
| 7320 | } |
| 7321 | |
| 7322 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7323 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 7324 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 7325 | outInputChannel); |
| 7326 | } |
| 7327 | |
| 7328 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7330 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7333 | public void remove(IWindow window) { |
| 7334 | removeWindow(this, window); |
| 7335 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7336 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7337 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 7338 | int requestedWidth, int requestedHeight, int viewFlags, |
| 7339 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7340 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7341 | return relayoutWindow(this, window, attrs, |
| 7342 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7343 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7345 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7346 | public void setTransparentRegion(IWindow window, Region region) { |
| 7347 | setTransparentRegionWindow(this, window, region); |
| 7348 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | public void setInsets(IWindow window, int touchableInsets, |
| 7351 | Rect contentInsets, Rect visibleInsets) { |
| 7352 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 7353 | visibleInsets); |
| 7354 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7356 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 7357 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 7358 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7359 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7360 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7361 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7362 | TAG, "IWindow finishDrawing called for " + window); |
| 7363 | finishDrawingWindow(this, window); |
| 7364 | } |
| 7365 | |
| 7366 | public void finishKey(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7367 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7368 | TAG, "IWindow finishKey called for " + window); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7369 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 7370 | throw new IllegalStateException("Should not be called anymore."); |
| 7371 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7372 | mKeyWaiter.finishedKey(this, window, false, |
| 7373 | KeyWaiter.RETURN_NOTHING); |
| 7374 | } |
| 7375 | |
| 7376 | public MotionEvent getPendingPointerMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7377 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7378 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7379 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 7380 | throw new IllegalStateException("Should not be called anymore."); |
| 7381 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7382 | return mKeyWaiter.finishedKey(this, window, false, |
| 7383 | KeyWaiter.RETURN_PENDING_POINTER); |
| 7384 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7387 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7389 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 7390 | throw new IllegalStateException("Should not be called anymore."); |
| 7391 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | return mKeyWaiter.finishedKey(this, window, false, |
| 7393 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 7394 | } |
| 7395 | |
| 7396 | public void setInTouchMode(boolean mode) { |
| 7397 | synchronized(mWindowMap) { |
| 7398 | mInTouchMode = mode; |
| 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | public boolean getInTouchMode() { |
| 7403 | synchronized(mWindowMap) { |
| 7404 | return mInTouchMode; |
| 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 7409 | boolean always) { |
| 7410 | synchronized(mWindowMap) { |
| 7411 | long ident = Binder.clearCallingIdentity(); |
| 7412 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7413 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7414 | windowForClientLocked(this, window, true), |
| 7415 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7416 | } finally { |
| 7417 | Binder.restoreCallingIdentity(ident); |
| 7418 | } |
| 7419 | } |
| 7420 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7421 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7422 | public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7423 | synchronized(mWindowMap) { |
| 7424 | long ident = Binder.clearCallingIdentity(); |
| 7425 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7426 | setWindowWallpaperPositionLocked( |
| 7427 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7428 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7429 | } finally { |
| 7430 | Binder.restoreCallingIdentity(ident); |
| 7431 | } |
| 7432 | } |
| 7433 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7434 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7435 | public void wallpaperOffsetsComplete(IBinder window) { |
| 7436 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 7437 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7438 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7439 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 7440 | int z, Bundle extras, boolean sync) { |
| 7441 | synchronized(mWindowMap) { |
| 7442 | long ident = Binder.clearCallingIdentity(); |
| 7443 | try { |
| 7444 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7445 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7446 | action, x, y, z, extras, sync); |
| 7447 | } finally { |
| 7448 | Binder.restoreCallingIdentity(ident); |
| 7449 | } |
| 7450 | } |
| 7451 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7452 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7453 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 7454 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 7455 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7456 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | void windowAddedLocked() { |
| 7458 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7459 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7460 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 7461 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7462 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7463 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | mSessions.add(this); |
| 7465 | } |
| 7466 | mNumWindow++; |
| 7467 | } |
| 7468 | |
| 7469 | void windowRemovedLocked() { |
| 7470 | mNumWindow--; |
| 7471 | killSessionLocked(); |
| 7472 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | void killSessionLocked() { |
| 7475 | if (mNumWindow <= 0 && mClientDead) { |
| 7476 | mSessions.remove(this); |
| 7477 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7478 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7479 | TAG, "Last window removed from " + this |
| 7480 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7481 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7482 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | try { |
| 7484 | mSurfaceSession.kill(); |
| 7485 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7486 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7487 | + mSurfaceSession + " in session " + this |
| 7488 | + ": " + e.toString()); |
| 7489 | } |
| 7490 | mSurfaceSession = null; |
| 7491 | } |
| 7492 | } |
| 7493 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7496 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 7497 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 7498 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 7499 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 7500 | pw.print(prefix); |
| 7501 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 7502 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 7503 | } |
| 7504 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 7505 | pw.print(prefix); |
| 7506 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 7507 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 7508 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7509 | } |
| 7510 | |
| 7511 | @Override |
| 7512 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7513 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | // ------------------------------------------------------------- |
| 7518 | // Client Window State |
| 7519 | // ------------------------------------------------------------- |
| 7520 | |
| 7521 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 7522 | final Session mSession; |
| 7523 | final IWindow mClient; |
| 7524 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7525 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | AppWindowToken mAppToken; |
| 7527 | AppWindowToken mTargetAppToken; |
| 7528 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 7529 | final DeathRecipient mDeathRecipient; |
| 7530 | final WindowState mAttachedWindow; |
| 7531 | final ArrayList mChildWindows = new ArrayList(); |
| 7532 | final int mBaseLayer; |
| 7533 | final int mSubLayer; |
| 7534 | final boolean mLayoutAttached; |
| 7535 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7536 | final boolean mIsWallpaper; |
| 7537 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7538 | int mViewVisibility; |
| 7539 | boolean mPolicyVisibility = true; |
| 7540 | boolean mPolicyVisibilityAfterAnim = true; |
| 7541 | boolean mAppFreezing; |
| 7542 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7543 | boolean mReportDestroySurface; |
| 7544 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7545 | boolean mAttachedHidden; // is our parent window hidden? |
| 7546 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7547 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | int mRequestedWidth; |
| 7549 | int mRequestedHeight; |
| 7550 | int mLastRequestedWidth; |
| 7551 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7552 | int mLayer; |
| 7553 | int mAnimLayer; |
| 7554 | int mLastLayer; |
| 7555 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7556 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7557 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | |
| 7559 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7560 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7561 | int mLayoutSeq = -1; |
| 7562 | |
| 7563 | Configuration mConfiguration = null; |
| 7564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | // Actual frame shown on-screen (may be modified by animation) |
| 7566 | final Rect mShownFrame = new Rect(); |
| 7567 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7568 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7570 | * Set when we have changed the size of the surface, to know that |
| 7571 | * we must tell them application to resize (and thus redraw itself). |
| 7572 | */ |
| 7573 | boolean mSurfaceResized; |
| 7574 | |
| 7575 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7576 | * Insets that determine the actually visible area |
| 7577 | */ |
| 7578 | final Rect mVisibleInsets = new Rect(); |
| 7579 | final Rect mLastVisibleInsets = new Rect(); |
| 7580 | boolean mVisibleInsetsChanged; |
| 7581 | |
| 7582 | /** |
| 7583 | * Insets that are covered by system windows |
| 7584 | */ |
| 7585 | final Rect mContentInsets = new Rect(); |
| 7586 | final Rect mLastContentInsets = new Rect(); |
| 7587 | boolean mContentInsetsChanged; |
| 7588 | |
| 7589 | /** |
| 7590 | * Set to true if we are waiting for this window to receive its |
| 7591 | * given internal insets before laying out other windows based on it. |
| 7592 | */ |
| 7593 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7594 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7595 | /** |
| 7596 | * These are the content insets that were given during layout for |
| 7597 | * this window, to be applied to windows behind it. |
| 7598 | */ |
| 7599 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7601 | /** |
| 7602 | * These are the visible insets that were given during layout for |
| 7603 | * this window, to be applied to windows behind it. |
| 7604 | */ |
| 7605 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7607 | /** |
| 7608 | * Flag indicating whether the touchable region should be adjusted by |
| 7609 | * the visible insets; if false the area outside the visible insets is |
| 7610 | * NOT touchable, so we must use those to adjust the frame during hit |
| 7611 | * tests. |
| 7612 | */ |
| 7613 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7615 | // Current transformation being applied. |
| 7616 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 7617 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 7618 | float mHScale=1, mVScale=1; |
| 7619 | float mLastHScale=1, mLastVScale=1; |
| 7620 | final Matrix mTmpMatrix = new Matrix(); |
| 7621 | |
| 7622 | // "Real" frame that the application sees. |
| 7623 | final Rect mFrame = new Rect(); |
| 7624 | final Rect mLastFrame = new Rect(); |
| 7625 | |
| 7626 | final Rect mContainingFrame = new Rect(); |
| 7627 | final Rect mDisplayFrame = new Rect(); |
| 7628 | final Rect mContentFrame = new Rect(); |
| 7629 | final Rect mVisibleFrame = new Rect(); |
| 7630 | |
| 7631 | float mShownAlpha = 1; |
| 7632 | float mAlpha = 1; |
| 7633 | float mLastAlpha = 1; |
| 7634 | |
| 7635 | // Set to true if, when the window gets displayed, it should perform |
| 7636 | // an enter animation. |
| 7637 | boolean mEnterAnimationPending; |
| 7638 | |
| 7639 | // Currently running animation. |
| 7640 | boolean mAnimating; |
| 7641 | boolean mLocalAnimating; |
| 7642 | Animation mAnimation; |
| 7643 | boolean mAnimationIsEntrance; |
| 7644 | boolean mHasTransformation; |
| 7645 | boolean mHasLocalTransformation; |
| 7646 | final Transformation mTransformation = new Transformation(); |
| 7647 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7648 | // If a window showing a wallpaper: the requested offset for the |
| 7649 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 7650 | float mWallpaperX = -1; |
| 7651 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7652 | |
| 7653 | // If a window showing a wallpaper: what fraction of the offset |
| 7654 | // range corresponds to a full virtual screen. |
| 7655 | float mWallpaperXStep = -1; |
| 7656 | float mWallpaperYStep = -1; |
| 7657 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7658 | // Wallpaper windows: pixels offset based on above variables. |
| 7659 | int mXOffset; |
| 7660 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7662 | // This is set after IWindowSession.relayout() has been called at |
| 7663 | // least once for the window. It allows us to detect the situation |
| 7664 | // where we don't yet have a surface, but should have one soon, so |
| 7665 | // we can give the window focus before waiting for the relayout. |
| 7666 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7667 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7668 | // This is set after the Surface has been created but before the |
| 7669 | // window has been drawn. During this time the surface is hidden. |
| 7670 | boolean mDrawPending; |
| 7671 | |
| 7672 | // This is set after the window has finished drawing for the first |
| 7673 | // time but before its surface is shown. The surface will be |
| 7674 | // displayed when the next layout is run. |
| 7675 | boolean mCommitDrawPending; |
| 7676 | |
| 7677 | // This is set during the time after the window's drawing has been |
| 7678 | // committed, and before its surface is actually shown. It is used |
| 7679 | // to delay showing the surface until all windows in a token are ready |
| 7680 | // to be shown. |
| 7681 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7682 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7683 | // Set when the window has been shown in the screen the first time. |
| 7684 | boolean mHasDrawn; |
| 7685 | |
| 7686 | // Currently running an exit animation? |
| 7687 | boolean mExiting; |
| 7688 | |
| 7689 | // Currently on the mDestroySurface list? |
| 7690 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7691 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7692 | // Completely remove from window manager after exit animation? |
| 7693 | boolean mRemoveOnExit; |
| 7694 | |
| 7695 | // Set when the orientation is changing and this window has not yet |
| 7696 | // been updated for the new orientation. |
| 7697 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7698 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7699 | // Is this window now (or just being) removed? |
| 7700 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7701 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7702 | // For debugging, this is the last information given to the surface flinger. |
| 7703 | boolean mSurfaceShown; |
| 7704 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 7705 | int mSurfaceLayer; |
| 7706 | float mSurfaceAlpha; |
| 7707 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7708 | // Input channel |
| 7709 | InputChannel mInputChannel; |
| 7710 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7711 | WindowState(Session s, IWindow c, WindowToken token, |
| 7712 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 7713 | int viewVisibility) { |
| 7714 | mSession = s; |
| 7715 | mClient = c; |
| 7716 | mToken = token; |
| 7717 | mAttrs.copyFrom(a); |
| 7718 | mViewVisibility = viewVisibility; |
| 7719 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 7720 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7721 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7722 | TAG, "Window " + this + " client=" + c.asBinder() |
| 7723 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 7724 | try { |
| 7725 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 7726 | } catch (RemoteException e) { |
| 7727 | mDeathRecipient = null; |
| 7728 | mAttachedWindow = null; |
| 7729 | mLayoutAttached = false; |
| 7730 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7731 | mIsWallpaper = false; |
| 7732 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7733 | mBaseLayer = 0; |
| 7734 | mSubLayer = 0; |
| 7735 | return; |
| 7736 | } |
| 7737 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7738 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7739 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7740 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7741 | // The multiplier here is to reserve space for multiple |
| 7742 | // windows in the same type layer. |
| 7743 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7744 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7745 | + TYPE_LAYER_OFFSET; |
| 7746 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7747 | mAttachedWindow = attachedWindow; |
| 7748 | mAttachedWindow.mChildWindows.add(this); |
| 7749 | mLayoutAttached = mAttrs.type != |
| 7750 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7751 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7752 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7753 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7754 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7755 | } else { |
| 7756 | // The multiplier here is to reserve space for multiple |
| 7757 | // windows in the same type layer. |
| 7758 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7759 | * TYPE_LAYER_MULTIPLIER |
| 7760 | + TYPE_LAYER_OFFSET; |
| 7761 | mSubLayer = 0; |
| 7762 | mAttachedWindow = null; |
| 7763 | mLayoutAttached = false; |
| 7764 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7765 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7766 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7767 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | WindowState appWin = this; |
| 7771 | while (appWin.mAttachedWindow != null) { |
| 7772 | appWin = mAttachedWindow; |
| 7773 | } |
| 7774 | WindowToken appToken = appWin.mToken; |
| 7775 | while (appToken.appWindowToken == null) { |
| 7776 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7777 | if (parent == null || appToken == parent) { |
| 7778 | break; |
| 7779 | } |
| 7780 | appToken = parent; |
| 7781 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7782 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | mAppToken = appToken.appWindowToken; |
| 7784 | |
| 7785 | mSurface = null; |
| 7786 | mRequestedWidth = 0; |
| 7787 | mRequestedHeight = 0; |
| 7788 | mLastRequestedWidth = 0; |
| 7789 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7790 | mXOffset = 0; |
| 7791 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7792 | mLayer = 0; |
| 7793 | mAnimLayer = 0; |
| 7794 | mLastLayer = 0; |
| 7795 | } |
| 7796 | |
| 7797 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7798 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7799 | TAG, "Attaching " + this + " token=" + mToken |
| 7800 | + ", list=" + mToken.windows); |
| 7801 | mSession.windowAddedLocked(); |
| 7802 | } |
| 7803 | |
| 7804 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7805 | mHaveFrame = true; |
| 7806 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7807 | final Rect container = mContainingFrame; |
| 7808 | container.set(pf); |
| 7809 | |
| 7810 | final Rect display = mDisplayFrame; |
| 7811 | display.set(df); |
| 7812 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7813 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7814 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7815 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7816 | display.intersect(mCompatibleScreenFrame); |
| 7817 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7818 | } |
| 7819 | |
| 7820 | final int pw = container.right - container.left; |
| 7821 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7822 | |
| 7823 | int w,h; |
| 7824 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7825 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7826 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7827 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7828 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7829 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7831 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7832 | final Rect content = mContentFrame; |
| 7833 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7834 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7835 | final Rect visible = mVisibleFrame; |
| 7836 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7838 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7839 | final int fw = frame.width(); |
| 7840 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7842 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7843 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7844 | |
| 7845 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7846 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7847 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7848 | |
| 7849 | //System.out.println("Out: " + mFrame); |
| 7850 | |
| 7851 | // Now make sure the window fits in the overall display. |
| 7852 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7854 | // Make sure the content and visible frames are inside of the |
| 7855 | // final window frame. |
| 7856 | if (content.left < frame.left) content.left = frame.left; |
| 7857 | if (content.top < frame.top) content.top = frame.top; |
| 7858 | if (content.right > frame.right) content.right = frame.right; |
| 7859 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7860 | if (visible.left < frame.left) visible.left = frame.left; |
| 7861 | if (visible.top < frame.top) visible.top = frame.top; |
| 7862 | if (visible.right > frame.right) visible.right = frame.right; |
| 7863 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7864 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7865 | final Rect contentInsets = mContentInsets; |
| 7866 | contentInsets.left = content.left-frame.left; |
| 7867 | contentInsets.top = content.top-frame.top; |
| 7868 | contentInsets.right = frame.right-content.right; |
| 7869 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7871 | final Rect visibleInsets = mVisibleInsets; |
| 7872 | visibleInsets.left = visible.left-frame.left; |
| 7873 | visibleInsets.top = visible.top-frame.top; |
| 7874 | visibleInsets.right = frame.right-visible.right; |
| 7875 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7876 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7877 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7878 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7879 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7880 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7881 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7882 | if (localLOGV) { |
| 7883 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7884 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7885 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7886 | + mRequestedWidth + ", mRequestedheight=" |
| 7887 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7888 | + "): frame=" + mFrame.toShortString() |
| 7889 | + " ci=" + contentInsets.toShortString() |
| 7890 | + " vi=" + visibleInsets.toShortString()); |
| 7891 | //} |
| 7892 | } |
| 7893 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7895 | public Rect getFrameLw() { |
| 7896 | return mFrame; |
| 7897 | } |
| 7898 | |
| 7899 | public Rect getShownFrameLw() { |
| 7900 | return mShownFrame; |
| 7901 | } |
| 7902 | |
| 7903 | public Rect getDisplayFrameLw() { |
| 7904 | return mDisplayFrame; |
| 7905 | } |
| 7906 | |
| 7907 | public Rect getContentFrameLw() { |
| 7908 | return mContentFrame; |
| 7909 | } |
| 7910 | |
| 7911 | public Rect getVisibleFrameLw() { |
| 7912 | return mVisibleFrame; |
| 7913 | } |
| 7914 | |
| 7915 | public boolean getGivenInsetsPendingLw() { |
| 7916 | return mGivenInsetsPending; |
| 7917 | } |
| 7918 | |
| 7919 | public Rect getGivenContentInsetsLw() { |
| 7920 | return mGivenContentInsets; |
| 7921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | public Rect getGivenVisibleInsetsLw() { |
| 7924 | return mGivenVisibleInsets; |
| 7925 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7926 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7927 | public WindowManager.LayoutParams getAttrs() { |
| 7928 | return mAttrs; |
| 7929 | } |
| 7930 | |
| 7931 | public int getSurfaceLayer() { |
| 7932 | return mLayer; |
| 7933 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7934 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7935 | public IApplicationToken getAppToken() { |
| 7936 | return mAppToken != null ? mAppToken.appToken : null; |
| 7937 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7938 | |
| 7939 | public long getInputDispatchingTimeoutNanos() { |
| 7940 | return mAppToken != null |
| 7941 | ? mAppToken.inputDispatchingTimeoutNanos |
| 7942 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 7943 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7944 | |
| 7945 | public boolean hasAppShownWindows() { |
| 7946 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7947 | } |
| 7948 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7949 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7950 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7951 | TAG, "Setting animation in " + this + ": " + anim); |
| 7952 | mAnimating = false; |
| 7953 | mLocalAnimating = false; |
| 7954 | mAnimation = anim; |
| 7955 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7956 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7957 | } |
| 7958 | |
| 7959 | public void clearAnimation() { |
| 7960 | if (mAnimation != null) { |
| 7961 | mAnimating = true; |
| 7962 | mLocalAnimating = false; |
| 7963 | mAnimation = null; |
| 7964 | } |
| 7965 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7966 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7967 | Surface createSurfaceLocked() { |
| 7968 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7969 | mReportDestroySurface = false; |
| 7970 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7971 | mDrawPending = true; |
| 7972 | mCommitDrawPending = false; |
| 7973 | mReadyToShow = false; |
| 7974 | if (mAppToken != null) { |
| 7975 | mAppToken.allDrawn = false; |
| 7976 | } |
| 7977 | |
| 7978 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7979 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7980 | flags |= Surface.PUSH_BUFFERS; |
| 7981 | } |
| 7982 | |
| 7983 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7984 | flags |= Surface.SECURE; |
| 7985 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7986 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7987 | TAG, "Creating surface in session " |
| 7988 | + mSession.mSurfaceSession + " window " + this |
| 7989 | + " w=" + mFrame.width() |
| 7990 | + " h=" + mFrame.height() + " format=" |
| 7991 | + mAttrs.format + " flags=" + flags); |
| 7992 | |
| 7993 | int w = mFrame.width(); |
| 7994 | int h = mFrame.height(); |
| 7995 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7996 | // for a scaled surface, we always want the requested |
| 7997 | // size. |
| 7998 | w = mRequestedWidth; |
| 7999 | h = mRequestedHeight; |
| 8000 | } |
| 8001 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 8002 | // Something is wrong and SurfaceFlinger will not like this, |
| 8003 | // try to revert to sane values |
| 8004 | if (w <= 0) w = 1; |
| 8005 | if (h <= 0) h = 1; |
| 8006 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8007 | mSurfaceShown = false; |
| 8008 | mSurfaceLayer = 0; |
| 8009 | mSurfaceAlpha = 1; |
| 8010 | mSurfaceX = 0; |
| 8011 | mSurfaceY = 0; |
| 8012 | mSurfaceW = w; |
| 8013 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8014 | try { |
| 8015 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8016 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 8017 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8018 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8019 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8020 | + mSurface + " IN SESSION " |
| 8021 | + mSession.mSurfaceSession |
| 8022 | + ": pid=" + mSession.mPid + " format=" |
| 8023 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8024 | + Integer.toHexString(flags) |
| 8025 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8026 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8027 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8028 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 8029 | return null; |
| 8030 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8031 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8032 | return null; |
| 8033 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8034 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8035 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8036 | TAG, "Got surface: " + mSurface |
| 8037 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 8038 | + ", animLayer=" + mAnimLayer); |
| 8039 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8040 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8041 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 8042 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 8043 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 8044 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | } |
| 8046 | Surface.openTransaction(); |
| 8047 | try { |
| 8048 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8049 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 8050 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8051 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 8052 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8053 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8054 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | mSurface.hide(); |
| 8056 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8057 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8058 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 8059 | Surface.SURFACE_DITHER); |
| 8060 | } |
| 8061 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8062 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8063 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 8064 | } |
| 8065 | mLastHidden = true; |
| 8066 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8067 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8068 | Surface.closeTransaction(); |
| 8069 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8070 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8071 | TAG, "Created surface " + this); |
| 8072 | } |
| 8073 | return mSurface; |
| 8074 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8076 | void destroySurfaceLocked() { |
| 8077 | // Window is no longer on-screen, so can no longer receive |
| 8078 | // key events... if we were waiting for it to finish |
| 8079 | // handling a key event, the wait is over! |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8080 | if (! ENABLE_NATIVE_INPUT_DISPATCH) { |
| 8081 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 8082 | KeyWaiter.RETURN_NOTHING); |
| 8083 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 8084 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 8085 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8086 | |
| 8087 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 8088 | mAppToken.startingDisplayed = false; |
| 8089 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8090 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8092 | mDrawPending = false; |
| 8093 | mCommitDrawPending = false; |
| 8094 | mReadyToShow = false; |
| 8095 | |
| 8096 | int i = mChildWindows.size(); |
| 8097 | while (i > 0) { |
| 8098 | i--; |
| 8099 | WindowState c = (WindowState)mChildWindows.get(i); |
| 8100 | c.mAttachedHidden = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8101 | |
| 8102 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 8103 | mInputMonitor.windowIsBecomingInvisibleLw(c); |
| 8104 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8105 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8106 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8107 | if (mReportDestroySurface) { |
| 8108 | mReportDestroySurface = false; |
| 8109 | mSurfacePendingDestroy = true; |
| 8110 | try { |
| 8111 | mClient.dispatchGetNewSurface(); |
| 8112 | // We'll really destroy on the next time around. |
| 8113 | return; |
| 8114 | } catch (RemoteException e) { |
| 8115 | } |
| 8116 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8118 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8119 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8120 | RuntimeException e = null; |
| 8121 | if (!HIDE_STACK_CRAWLS) { |
| 8122 | e = new RuntimeException(); |
| 8123 | e.fillInStackTrace(); |
| 8124 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8125 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8126 | + mSurface + ", session " + mSession, e); |
| 8127 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8129 | RuntimeException e = null; |
| 8130 | if (!HIDE_STACK_CRAWLS) { |
| 8131 | e = new RuntimeException(); |
| 8132 | e.fillInStackTrace(); |
| 8133 | } |
| 8134 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8135 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8136 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8138 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8139 | + " surface " + mSurface + " session " + mSession |
| 8140 | + ": " + e.toString()); |
| 8141 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8142 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8143 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8144 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | } |
| 8146 | } |
| 8147 | |
| 8148 | boolean finishDrawingLocked() { |
| 8149 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8150 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8151 | TAG, "finishDrawingLocked: " + mSurface); |
| 8152 | mCommitDrawPending = true; |
| 8153 | mDrawPending = false; |
| 8154 | return true; |
| 8155 | } |
| 8156 | return false; |
| 8157 | } |
| 8158 | |
| 8159 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8160 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8161 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8162 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8163 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | } |
| 8165 | mCommitDrawPending = false; |
| 8166 | mReadyToShow = true; |
| 8167 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 8168 | final AppWindowToken atoken = mAppToken; |
| 8169 | if (atoken == null || atoken.allDrawn || starting) { |
| 8170 | performShowLocked(); |
| 8171 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8172 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | } |
| 8174 | |
| 8175 | // This must be called while inside a transaction. |
| 8176 | boolean performShowLocked() { |
| 8177 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8178 | RuntimeException e = null; |
| 8179 | if (!HIDE_STACK_CRAWLS) { |
| 8180 | e = new RuntimeException(); |
| 8181 | e.fillInStackTrace(); |
| 8182 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8183 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 8185 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 8186 | } |
| 8187 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8188 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 8189 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8190 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8191 | + " during animation: policyVis=" + mPolicyVisibility |
| 8192 | + " attHidden=" + mAttachedHidden |
| 8193 | + " tok.hiddenRequested=" |
| 8194 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 8195 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8196 | + (mAppToken != null ? mAppToken.hidden : false) |
| 8197 | + " animating=" + mAnimating |
| 8198 | + " tok animating=" |
| 8199 | + (mAppToken != null ? mAppToken.animating : false)); |
| 8200 | if (!showSurfaceRobustlyLocked(this)) { |
| 8201 | return false; |
| 8202 | } |
| 8203 | mLastAlpha = -1; |
| 8204 | mHasDrawn = true; |
| 8205 | mLastHidden = false; |
| 8206 | mReadyToShow = false; |
| 8207 | enableScreenIfNeededLocked(); |
| 8208 | |
| 8209 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8211 | int i = mChildWindows.size(); |
| 8212 | while (i > 0) { |
| 8213 | i--; |
| 8214 | WindowState c = (WindowState)mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 8215 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8216 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 8217 | if (c.mSurface != null) { |
| 8218 | c.performShowLocked(); |
| 8219 | // It hadn't been shown, which means layout not |
| 8220 | // performed on it, so now we want to make sure to |
| 8221 | // do a layout. If called from within the transaction |
| 8222 | // loop, this will cause it to restart with a new |
| 8223 | // layout. |
| 8224 | mLayoutNeeded = true; |
| 8225 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8226 | } |
| 8227 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8228 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8229 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 8230 | && mAppToken != null) { |
| 8231 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8232 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 8233 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8234 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8235 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8236 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 8237 | // If this initial window is animating, stop it -- we |
| 8238 | // will do an animation to reveal it from behind the |
| 8239 | // starting window, so there is no need for it to also |
| 8240 | // be doing its own stuff. |
| 8241 | if (mAnimation != null) { |
| 8242 | mAnimation = null; |
| 8243 | // Make sure we clean up the animation. |
| 8244 | mAnimating = true; |
| 8245 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8246 | mFinishedStarting.add(mAppToken); |
| 8247 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 8248 | } |
| 8249 | mAppToken.updateReportedVisibilityLocked(); |
| 8250 | } |
| 8251 | } |
| 8252 | return true; |
| 8253 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8254 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | // This must be called while inside a transaction. Returns true if |
| 8256 | // there is more animation to run. |
| 8257 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8258 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8259 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8261 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 8262 | mHasTransformation = true; |
| 8263 | mHasLocalTransformation = true; |
| 8264 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8265 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8266 | TAG, "Starting animation in " + this + |
| 8267 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 8268 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 8269 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 8270 | mAnimation.setStartTime(currentTime); |
| 8271 | mLocalAnimating = true; |
| 8272 | mAnimating = true; |
| 8273 | } |
| 8274 | mTransformation.clear(); |
| 8275 | final boolean more = mAnimation.getTransformation( |
| 8276 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8277 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8278 | TAG, "Stepped animation in " + this + |
| 8279 | ": more=" + more + ", xform=" + mTransformation); |
| 8280 | if (more) { |
| 8281 | // we're not done! |
| 8282 | return true; |
| 8283 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8284 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8285 | TAG, "Finished animation in " + this + |
| 8286 | " @ " + currentTime); |
| 8287 | mAnimation = null; |
| 8288 | //WindowManagerService.this.dump(); |
| 8289 | } |
| 8290 | mHasLocalTransformation = false; |
| 8291 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8292 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8293 | // When our app token is animating, we kind-of pretend like |
| 8294 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 8295 | // part of this check means that we will only do this if |
| 8296 | // our window is not currently exiting, or it is not |
| 8297 | // locally animating itself. The idea being that one that |
| 8298 | // is exiting and doing a local animation should be removed |
| 8299 | // once that animation is done. |
| 8300 | mAnimating = true; |
| 8301 | mHasTransformation = true; |
| 8302 | mTransformation.clear(); |
| 8303 | return false; |
| 8304 | } else if (mHasTransformation) { |
| 8305 | // Little trick to get through the path below to act like |
| 8306 | // we have finished an animation. |
| 8307 | mAnimating = true; |
| 8308 | } else if (isAnimating()) { |
| 8309 | mAnimating = true; |
| 8310 | } |
| 8311 | } else if (mAnimation != null) { |
| 8312 | // If the display is frozen, and there is a pending animation, |
| 8313 | // clear it and make sure we run the cleanup code. |
| 8314 | mAnimating = true; |
| 8315 | mLocalAnimating = true; |
| 8316 | mAnimation = null; |
| 8317 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8319 | if (!mAnimating && !mLocalAnimating) { |
| 8320 | return false; |
| 8321 | } |
| 8322 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8323 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8324 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 8325 | + ", reportedVisible=" |
| 8326 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8327 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8328 | mAnimating = false; |
| 8329 | mLocalAnimating = false; |
| 8330 | mAnimation = null; |
| 8331 | mAnimLayer = mLayer; |
| 8332 | if (mIsImWindow) { |
| 8333 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8334 | } else if (mIsWallpaper) { |
| 8335 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8336 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8337 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8338 | + " anim layer: " + mAnimLayer); |
| 8339 | mHasTransformation = false; |
| 8340 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8341 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 8342 | if (DEBUG_VISIBILITY) { |
| 8343 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 8344 | + mPolicyVisibilityAfterAnim); |
| 8345 | } |
| 8346 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 8347 | if (!mPolicyVisibility) { |
| 8348 | if (mCurrentFocus == this) { |
| 8349 | mFocusMayChange = true; |
| 8350 | } |
| 8351 | // Window is no longer visible -- make sure if we were waiting |
| 8352 | // for it to be displayed before enabling the display, that |
| 8353 | // we allow the display to be enabled now. |
| 8354 | enableScreenIfNeededLocked(); |
| 8355 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8356 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8357 | mTransformation.clear(); |
| 8358 | if (mHasDrawn |
| 8359 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 8360 | && mAppToken != null |
| 8361 | && mAppToken.firstWindowDrawn |
| 8362 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8363 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8364 | + mToken + ": first real window done animating"); |
| 8365 | mFinishedStarting.add(mAppToken); |
| 8366 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 8367 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8368 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8369 | finishExit(); |
| 8370 | |
| 8371 | if (mAppToken != null) { |
| 8372 | mAppToken.updateReportedVisibilityLocked(); |
| 8373 | } |
| 8374 | |
| 8375 | return false; |
| 8376 | } |
| 8377 | |
| 8378 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8379 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8380 | TAG, "finishExit in " + this |
| 8381 | + ": exiting=" + mExiting |
| 8382 | + " remove=" + mRemoveOnExit |
| 8383 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8385 | final int N = mChildWindows.size(); |
| 8386 | for (int i=0; i<N; i++) { |
| 8387 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 8388 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8390 | if (!mExiting) { |
| 8391 | return; |
| 8392 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8394 | if (isWindowAnimating()) { |
| 8395 | return; |
| 8396 | } |
| 8397 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8398 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8399 | TAG, "Exit animation finished in " + this |
| 8400 | + ": remove=" + mRemoveOnExit); |
| 8401 | if (mSurface != null) { |
| 8402 | mDestroySurface.add(this); |
| 8403 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8404 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8405 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8406 | try { |
| 8407 | mSurface.hide(); |
| 8408 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8409 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8410 | } |
| 8411 | mLastHidden = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8412 | |
| 8413 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 8414 | for (int i=0; i<N; i++) { |
| 8415 | mInputMonitor.windowIsBecomingInvisibleLw((WindowState)mChildWindows.get(i)); |
| 8416 | } |
| 8417 | } else { |
| 8418 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 8419 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8420 | } |
| 8421 | mExiting = false; |
| 8422 | if (mRemoveOnExit) { |
| 8423 | mPendingRemove.add(this); |
| 8424 | mRemoveOnExit = false; |
| 8425 | } |
| 8426 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8428 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 8429 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 8430 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 8431 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 8432 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 8433 | return true; |
| 8434 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8436 | void computeShownFrameLocked() { |
| 8437 | final boolean selfTransformation = mHasLocalTransformation; |
| 8438 | Transformation attachedTransformation = |
| 8439 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 8440 | ? mAttachedWindow.mTransformation : null; |
| 8441 | Transformation appTransformation = |
| 8442 | (mAppToken != null && mAppToken.hasTransformation) |
| 8443 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8444 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8445 | // Wallpapers are animated based on the "real" window they |
| 8446 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8447 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8448 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8449 | if (mWallpaperTarget.mHasLocalTransformation && |
| 8450 | mWallpaperTarget.mAnimation != null && |
| 8451 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8452 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8453 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8454 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8455 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8456 | } |
| 8457 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8458 | mWallpaperTarget.mAppToken.hasTransformation && |
| 8459 | mWallpaperTarget.mAppToken.animation != null && |
| 8460 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8461 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8462 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8463 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8464 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8465 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8466 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8468 | if (selfTransformation || attachedTransformation != null |
| 8469 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8470 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8471 | final Rect frame = mFrame; |
| 8472 | final float tmpFloats[] = mTmpFloats; |
| 8473 | final Matrix tmpMatrix = mTmpMatrix; |
| 8474 | |
| 8475 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 8476 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8477 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8478 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8479 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 8480 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8481 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8482 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8483 | } |
| 8484 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8485 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8486 | } |
| 8487 | |
| 8488 | // "convert" it into SurfaceFlinger's format |
| 8489 | // (a 2x2 matrix + an offset) |
| 8490 | // Here we must not transform the position of the surface |
| 8491 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8492 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8494 | tmpMatrix.getValues(tmpFloats); |
| 8495 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 8496 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 8497 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 8498 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8499 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 8500 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8501 | int w = frame.width(); |
| 8502 | int h = frame.height(); |
| 8503 | mShownFrame.set(x, y, x+w, y+h); |
| 8504 | |
| 8505 | // Now set the alpha... but because our current hardware |
| 8506 | // can't do alpha transformation on a non-opaque surface, |
| 8507 | // turn it off if we are running an animation that is also |
| 8508 | // transforming since it is more important to have that |
| 8509 | // animation be smooth. |
| 8510 | mShownAlpha = mAlpha; |
| 8511 | if (!mLimitedAlphaCompositing |
| 8512 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 8513 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 8514 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8515 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8516 | if (selfTransformation) { |
| 8517 | mShownAlpha *= mTransformation.getAlpha(); |
| 8518 | } |
| 8519 | if (attachedTransformation != null) { |
| 8520 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 8521 | } |
| 8522 | if (appTransformation != null) { |
| 8523 | mShownAlpha *= appTransformation.getAlpha(); |
| 8524 | } |
| 8525 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8526 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8527 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8528 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8529 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8530 | TAG, "Continuing animation in " + this + |
| 8531 | ": " + mShownFrame + |
| 8532 | ", alpha=" + mTransformation.getAlpha()); |
| 8533 | return; |
| 8534 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8536 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8537 | if (mXOffset != 0 || mYOffset != 0) { |
| 8538 | mShownFrame.offset(mXOffset, mYOffset); |
| 8539 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8540 | mShownAlpha = mAlpha; |
| 8541 | mDsDx = 1; |
| 8542 | mDtDx = 0; |
| 8543 | mDsDy = 0; |
| 8544 | mDtDy = 1; |
| 8545 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8547 | /** |
| 8548 | * Is this window visible? It is not visible if there is no |
| 8549 | * surface, or we are in the process of running an exit animation |
| 8550 | * that will remove the surface, or its app token has been hidden. |
| 8551 | */ |
| 8552 | public boolean isVisibleLw() { |
| 8553 | final AppWindowToken atoken = mAppToken; |
| 8554 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 8555 | && (atoken == null || !atoken.hiddenRequested) |
| 8556 | && !mExiting && !mDestroying; |
| 8557 | } |
| 8558 | |
| 8559 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 8560 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 8561 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 8562 | * things like window flags that impact the keyguard. |
| 8563 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 8564 | * for this "hidden behind keyguard" state rather than overloading |
| 8565 | * mPolicyVisibility. Ungh. |
| 8566 | */ |
| 8567 | public boolean isVisibleOrBehindKeyguardLw() { |
| 8568 | final AppWindowToken atoken = mAppToken; |
| 8569 | return mSurface != null && !mAttachedHidden |
| 8570 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 8571 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)) |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 8572 | && !mExiting && !mDestroying; |
| 8573 | } |
| 8574 | |
| 8575 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8576 | * Is this window visible, ignoring its app token? It is not visible |
| 8577 | * if there is no surface, or we are in the process of running an exit animation |
| 8578 | * that will remove the surface. |
| 8579 | */ |
| 8580 | public boolean isWinVisibleLw() { |
| 8581 | final AppWindowToken atoken = mAppToken; |
| 8582 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 8583 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 8584 | && !mExiting && !mDestroying; |
| 8585 | } |
| 8586 | |
| 8587 | /** |
| 8588 | * The same as isVisible(), but follows the current hidden state of |
| 8589 | * the associated app token, not the pending requested hidden state. |
| 8590 | */ |
| 8591 | boolean isVisibleNow() { |
| 8592 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8593 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8594 | } |
| 8595 | |
| 8596 | /** |
| 8597 | * Same as isVisible(), but we also count it as visible between the |
| 8598 | * call to IWindowSession.add() and the first relayout(). |
| 8599 | */ |
| 8600 | boolean isVisibleOrAdding() { |
| 8601 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8602 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8603 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 8604 | && mPolicyVisibility && !mAttachedHidden |
| 8605 | && (atoken == null || !atoken.hiddenRequested) |
| 8606 | && !mExiting && !mDestroying; |
| 8607 | } |
| 8608 | |
| 8609 | /** |
| 8610 | * Is this window currently on-screen? It is on-screen either if it |
| 8611 | * is visible or it is currently running an animation before no longer |
| 8612 | * being visible. |
| 8613 | */ |
| 8614 | boolean isOnScreen() { |
| 8615 | final AppWindowToken atoken = mAppToken; |
| 8616 | if (atoken != null) { |
| 8617 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8618 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8619 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | } else { |
| 8621 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8622 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8623 | } |
| 8624 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8625 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | /** |
| 8627 | * Like isOnScreen(), but we don't return true if the window is part |
| 8628 | * of a transition that has not yet been started. |
| 8629 | */ |
| 8630 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8631 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8632 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8633 | return false; |
| 8634 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8635 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8636 | final boolean animating = atoken != null |
| 8637 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8639 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 8640 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8641 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8642 | } |
| 8643 | |
| 8644 | /** Is the window or its container currently animating? */ |
| 8645 | boolean isAnimating() { |
| 8646 | final WindowState attached = mAttachedWindow; |
| 8647 | final AppWindowToken atoken = mAppToken; |
| 8648 | return mAnimation != null |
| 8649 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8650 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8651 | (atoken.animation != null |
| 8652 | || atoken.inPendingTransaction)); |
| 8653 | } |
| 8654 | |
| 8655 | /** Is this window currently animating? */ |
| 8656 | boolean isWindowAnimating() { |
| 8657 | return mAnimation != null; |
| 8658 | } |
| 8659 | |
| 8660 | /** |
| 8661 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 8662 | * been drawn. |
| 8663 | */ |
| 8664 | public boolean isDisplayedLw() { |
| 8665 | final AppWindowToken atoken = mAppToken; |
| 8666 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8667 | && !mDrawPending && !mCommitDrawPending |
| 8668 | && ((!mAttachedHidden && |
| 8669 | (atoken == null || !atoken.hiddenRequested)) |
| 8670 | || mAnimating); |
| 8671 | } |
| 8672 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8673 | /** |
| 8674 | * Returns true if the window has a surface that it has drawn a |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 8675 | * complete UI in to. Note that this returns true if the orientation |
| 8676 | * is changing even if the window hasn't redrawn because we don't want |
| 8677 | * to stop things from executing during that time. |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8678 | */ |
| 8679 | public boolean isDrawnLw() { |
| 8680 | final AppWindowToken atoken = mAppToken; |
| 8681 | return mSurface != null && !mDestroying |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 8682 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8683 | } |
| 8684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8685 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 8686 | boolean shownFrame, boolean onlyOpaque) { |
| 8687 | if (mSurface == null) { |
| 8688 | return false; |
| 8689 | } |
| 8690 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 8691 | return false; |
| 8692 | } |
| 8693 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 8694 | return false; |
| 8695 | } |
| 8696 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8697 | |
| 8698 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8699 | return frame.left <= mCompatibleScreenFrame.left && |
| 8700 | frame.top <= mCompatibleScreenFrame.top && |
| 8701 | frame.right >= mCompatibleScreenFrame.right && |
| 8702 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 8703 | } else { |
| 8704 | return frame.left <= 0 && frame.top <= 0 |
| 8705 | && frame.right >= screenWidth |
| 8706 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8707 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8708 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8709 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8710 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8711 | * Return true if the window is opaque and fully drawn. This indicates |
| 8712 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8713 | */ |
| 8714 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8715 | return (mAttrs.format == PixelFormat.OPAQUE |
| 8716 | || mAttrs.type == TYPE_WALLPAPER) |
| 8717 | && mSurface != null && mAnimation == null |
| 8718 | && (mAppToken == null || mAppToken.animation == null) |
| 8719 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8720 | } |
| 8721 | |
| 8722 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 8723 | return |
| 8724 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8725 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 8726 | // only if it's visible |
| 8727 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8728 | // and only if the application fills the compatible screen |
| 8729 | mFrame.left <= mCompatibleScreenFrame.left && |
| 8730 | mFrame.top <= mCompatibleScreenFrame.top && |
| 8731 | mFrame.right >= mCompatibleScreenFrame.right && |
| 8732 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8733 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8734 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8735 | } |
| 8736 | |
| 8737 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8738 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8739 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8740 | } |
| 8741 | |
| 8742 | void removeLocked() { |
| 8743 | if (mAttachedWindow != null) { |
| 8744 | mAttachedWindow.mChildWindows.remove(this); |
| 8745 | } |
| 8746 | destroySurfaceLocked(); |
| 8747 | mSession.windowRemovedLocked(); |
| 8748 | try { |
| 8749 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8750 | } catch (RuntimeException e) { |
| 8751 | // Ignore if it has already been removed (usually because |
| 8752 | // we are doing this as part of processing a death note.) |
| 8753 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8754 | |
| 8755 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 8756 | if (mInputChannel != null) { |
| 8757 | mInputManager.unregisterInputChannel(mInputChannel); |
| 8758 | |
| 8759 | mInputChannel.dispose(); |
| 8760 | mInputChannel = null; |
| 8761 | } |
| 8762 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8763 | } |
| 8764 | |
| 8765 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8766 | public void binderDied() { |
| 8767 | try { |
| 8768 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8769 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8770 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8771 | if (win != null) { |
| 8772 | removeWindowLocked(mSession, win); |
| 8773 | } |
| 8774 | } |
| 8775 | } catch (IllegalArgumentException ex) { |
| 8776 | // This will happen if the window has already been |
| 8777 | // removed. |
| 8778 | } |
| 8779 | } |
| 8780 | } |
| 8781 | |
| 8782 | /** Returns true if this window desires key events. */ |
| 8783 | public final boolean canReceiveKeys() { |
| 8784 | return isVisibleOrAdding() |
| 8785 | && (mViewVisibility == View.VISIBLE) |
| 8786 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8787 | } |
| 8788 | |
| 8789 | public boolean hasDrawnLw() { |
| 8790 | return mHasDrawn; |
| 8791 | } |
| 8792 | |
| 8793 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8794 | return showLw(doAnimation, true); |
| 8795 | } |
| 8796 | |
| 8797 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8798 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8799 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8800 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8801 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8802 | if (doAnimation) { |
| 8803 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8804 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8805 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8806 | doAnimation = false; |
| 8807 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8808 | // Check for the case where we are currently visible and |
| 8809 | // not animating; we do not want to do animation at such a |
| 8810 | // point to become visible when we already are. |
| 8811 | doAnimation = false; |
| 8812 | } |
| 8813 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8814 | mPolicyVisibility = true; |
| 8815 | mPolicyVisibilityAfterAnim = true; |
| 8816 | if (doAnimation) { |
| 8817 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8818 | } |
| 8819 | if (requestAnim) { |
| 8820 | requestAnimationLocked(0); |
| 8821 | } |
| 8822 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8823 | } |
| 8824 | |
| 8825 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8826 | return hideLw(doAnimation, true); |
| 8827 | } |
| 8828 | |
| 8829 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8830 | if (doAnimation) { |
| 8831 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8832 | doAnimation = false; |
| 8833 | } |
| 8834 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8835 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8836 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8837 | if (!current) { |
| 8838 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8839 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8840 | if (doAnimation) { |
| 8841 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8842 | if (mAnimation == null) { |
| 8843 | doAnimation = false; |
| 8844 | } |
| 8845 | } |
| 8846 | if (doAnimation) { |
| 8847 | mPolicyVisibilityAfterAnim = false; |
| 8848 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8849 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8850 | mPolicyVisibilityAfterAnim = false; |
| 8851 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8852 | // Window is no longer visible -- make sure if we were waiting |
| 8853 | // for it to be displayed before enabling the display, that |
| 8854 | // we allow the display to be enabled now. |
| 8855 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8856 | if (mCurrentFocus == this) { |
| 8857 | mFocusMayChange = true; |
| 8858 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8859 | } |
| 8860 | if (requestAnim) { |
| 8861 | requestAnimationLocked(0); |
| 8862 | } |
| 8863 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8867 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8868 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8869 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8870 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8871 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8872 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8873 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8874 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8875 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8876 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8877 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8878 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8879 | } |
| 8880 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8881 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8882 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8883 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8884 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8885 | pw.print("="); pw.print(mAnimLayer); |
| 8886 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8887 | if (mSurface != null) { |
| 8888 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8889 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8890 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8891 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8892 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8893 | pw.print(","); pw.print(mSurfaceY); |
| 8894 | pw.print(") "); pw.print(mSurfaceW); |
| 8895 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8896 | } |
| 8897 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8898 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8899 | if (mAppToken != null) { |
| 8900 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8901 | } |
| 8902 | if (mTargetAppToken != null) { |
| 8903 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8904 | } |
| 8905 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8906 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8907 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8908 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8909 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8910 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8911 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8912 | pw.print(mPolicyVisibility); |
| 8913 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8914 | pw.print(mPolicyVisibilityAfterAnim); |
| 8915 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8916 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8917 | if (!mRelayoutCalled) { |
| 8918 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8919 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8920 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8921 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8922 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8923 | if (mXOffset != 0 || mYOffset != 0) { |
| 8924 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8925 | pw.print(" y="); pw.println(mYOffset); |
| 8926 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8927 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8928 | mGivenContentInsets.printShortString(pw); |
| 8929 | pw.print(" mGivenVisibleInsets="); |
| 8930 | mGivenVisibleInsets.printShortString(pw); |
| 8931 | pw.println(); |
| 8932 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8933 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8934 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8935 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8936 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8937 | pw.print(prefix); pw.print("mShownFrame="); |
| 8938 | mShownFrame.printShortString(pw); |
| 8939 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8940 | pw.println(); |
| 8941 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8942 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8943 | pw.println(); |
| 8944 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8945 | mContainingFrame.printShortString(pw); |
| 8946 | pw.print(" mDisplayFrame="); |
| 8947 | mDisplayFrame.printShortString(pw); |
| 8948 | pw.println(); |
| 8949 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8950 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8951 | pw.println(); |
| 8952 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8953 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8954 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8955 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8956 | pw.println(); |
| 8957 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8958 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8959 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8960 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8961 | } |
| 8962 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8963 | || mAnimation != null) { |
| 8964 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8965 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8966 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8967 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8968 | } |
| 8969 | if (mHasTransformation || mHasLocalTransformation) { |
| 8970 | pw.print(prefix); pw.print("XForm: has="); |
| 8971 | pw.print(mHasTransformation); |
| 8972 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8973 | pw.print(" "); mTransformation.printShortString(pw); |
| 8974 | pw.println(); |
| 8975 | } |
| 8976 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8977 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8978 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8979 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8980 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8981 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8982 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8983 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8984 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8985 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8986 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8987 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8988 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8989 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8990 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8991 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8992 | if (mHScale != 1 || mVScale != 1) { |
| 8993 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8994 | pw.print(" mVScale="); pw.println(mVScale); |
| 8995 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8996 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8997 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8998 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8999 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 9000 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 9001 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 9002 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 9003 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9004 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9005 | |
| 9006 | String makeInputChannelName() { |
| 9007 | return Integer.toHexString(System.identityHashCode(this)) |
| 9008 | + " " + mAttrs.getTitle(); |
| 9009 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9010 | |
| 9011 | @Override |
| 9012 | public String toString() { |
| 9013 | return "Window{" |
| 9014 | + Integer.toHexString(System.identityHashCode(this)) |
| 9015 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 9016 | } |
| 9017 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9018 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9019 | // ------------------------------------------------------------- |
| 9020 | // Window Token State |
| 9021 | // ------------------------------------------------------------- |
| 9022 | |
| 9023 | class WindowToken { |
| 9024 | // The actual token. |
| 9025 | final IBinder token; |
| 9026 | |
| 9027 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 9028 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9029 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9030 | // Set if this token was explicitly added by a client, so should |
| 9031 | // not be removed when all windows are removed. |
| 9032 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9033 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9034 | // For printing. |
| 9035 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9037 | // If this is an AppWindowToken, this is non-null. |
| 9038 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9039 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9040 | // All of the windows associated with this token. |
| 9041 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 9042 | |
| 9043 | // Is key dispatching paused for this token? |
| 9044 | boolean paused = false; |
| 9045 | |
| 9046 | // Should this token's windows be hidden? |
| 9047 | boolean hidden; |
| 9048 | |
| 9049 | // Temporary for finding which tokens no longer have visible windows. |
| 9050 | boolean hasVisible; |
| 9051 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9052 | // Set to true when this token is in a pending transaction where it |
| 9053 | // will be shown. |
| 9054 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9055 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9056 | // Set to true when this token is in a pending transaction where it |
| 9057 | // will be hidden. |
| 9058 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9059 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9060 | // Set to true when this token is in a pending transaction where its |
| 9061 | // windows will be put to the bottom of the list. |
| 9062 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9063 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9064 | // Set to true when this token is in a pending transaction where its |
| 9065 | // windows will be put to the top of the list. |
| 9066 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9067 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9068 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 9069 | token = _token; |
| 9070 | windowType = type; |
| 9071 | explicit = _explicit; |
| 9072 | } |
| 9073 | |
| 9074 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9075 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 9076 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 9077 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 9078 | pw.print(" hidden="); pw.print(hidden); |
| 9079 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9080 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 9081 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 9082 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 9083 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 9084 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 9085 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | @Override |
| 9089 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9090 | if (stringName == null) { |
| 9091 | StringBuilder sb = new StringBuilder(); |
| 9092 | sb.append("WindowToken{"); |
| 9093 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 9094 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 9095 | stringName = sb.toString(); |
| 9096 | } |
| 9097 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | } |
| 9099 | }; |
| 9100 | |
| 9101 | class AppWindowToken extends WindowToken { |
| 9102 | // Non-null only for application tokens. |
| 9103 | final IApplicationToken appToken; |
| 9104 | |
| 9105 | // All of the windows and child windows that are included in this |
| 9106 | // application token. Note this list is NOT sorted! |
| 9107 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 9108 | |
| 9109 | int groupId = -1; |
| 9110 | boolean appFullscreen; |
| 9111 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9112 | |
| 9113 | // The input dispatching timeout for this application token in nanoseconds. |
| 9114 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9116 | // These are used for determining when all windows associated with |
| 9117 | // an activity have been drawn, so they can be made visible together |
| 9118 | // at the same time. |
| 9119 | int lastTransactionSequence = mTransactionSequence-1; |
| 9120 | int numInterestingWindows; |
| 9121 | int numDrawnWindows; |
| 9122 | boolean inPendingTransaction; |
| 9123 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9124 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9125 | // Is this token going to be hidden in a little while? If so, it |
| 9126 | // won't be taken into account for setting the screen orientation. |
| 9127 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9128 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9129 | // Is this window's surface needed? This is almost like hidden, except |
| 9130 | // it will sometimes be true a little earlier: when the token has |
| 9131 | // been shown, but is still waiting for its app transition to execute |
| 9132 | // before making its windows shown. |
| 9133 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9134 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9135 | // Have we told the window clients to hide themselves? |
| 9136 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9138 | // Last visibility state we reported to the app token. |
| 9139 | boolean reportedVisible; |
| 9140 | |
| 9141 | // Set to true when the token has been removed from the window mgr. |
| 9142 | boolean removed; |
| 9143 | |
| 9144 | // Have we been asked to have this token keep the screen frozen? |
| 9145 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9147 | boolean animating; |
| 9148 | Animation animation; |
| 9149 | boolean hasTransformation; |
| 9150 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9151 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | // Offset to the window of all layers in the token, for use by |
| 9153 | // AppWindowToken animations. |
| 9154 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9155 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9156 | // Information about an application starting window if displayed. |
| 9157 | StartingData startingData; |
| 9158 | WindowState startingWindow; |
| 9159 | View startingView; |
| 9160 | boolean startingDisplayed; |
| 9161 | boolean startingMoved; |
| 9162 | boolean firstWindowDrawn; |
| 9163 | |
| 9164 | AppWindowToken(IApplicationToken _token) { |
| 9165 | super(_token.asBinder(), |
| 9166 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 9167 | appWindowToken = this; |
| 9168 | appToken = _token; |
| 9169 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9171 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9172 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9173 | TAG, "Setting animation in " + this + ": " + anim); |
| 9174 | animation = anim; |
| 9175 | animating = false; |
| 9176 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 9177 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 9178 | int zorder = anim.getZAdjustment(); |
| 9179 | int adj = 0; |
| 9180 | if (zorder == Animation.ZORDER_TOP) { |
| 9181 | adj = TYPE_LAYER_OFFSET; |
| 9182 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 9183 | adj = -TYPE_LAYER_OFFSET; |
| 9184 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9186 | if (animLayerAdjustment != adj) { |
| 9187 | animLayerAdjustment = adj; |
| 9188 | updateLayers(); |
| 9189 | } |
| 9190 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9192 | public void setDummyAnimation() { |
| 9193 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9194 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9195 | TAG, "Setting dummy animation in " + this); |
| 9196 | animation = sDummyAnimation; |
| 9197 | } |
| 9198 | } |
| 9199 | |
| 9200 | public void clearAnimation() { |
| 9201 | if (animation != null) { |
| 9202 | animation = null; |
| 9203 | animating = true; |
| 9204 | } |
| 9205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9207 | void updateLayers() { |
| 9208 | final int N = allAppWindows.size(); |
| 9209 | final int adj = animLayerAdjustment; |
| 9210 | for (int i=0; i<N; i++) { |
| 9211 | WindowState w = allAppWindows.get(i); |
| 9212 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9213 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9214 | + w.mAnimLayer); |
| 9215 | if (w == mInputMethodTarget) { |
| 9216 | setInputMethodAnimLayerAdjustment(adj); |
| 9217 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9218 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 9219 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9220 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9221 | } |
| 9222 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9224 | void sendAppVisibilityToClients() { |
| 9225 | final int N = allAppWindows.size(); |
| 9226 | for (int i=0; i<N; i++) { |
| 9227 | WindowState win = allAppWindows.get(i); |
| 9228 | if (win == startingWindow && clientHidden) { |
| 9229 | // Don't hide the starting window. |
| 9230 | continue; |
| 9231 | } |
| 9232 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9233 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9234 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 9235 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 9236 | } catch (RemoteException e) { |
| 9237 | } |
| 9238 | } |
| 9239 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9241 | void showAllWindowsLocked() { |
| 9242 | final int NW = allAppWindows.size(); |
| 9243 | for (int i=0; i<NW; i++) { |
| 9244 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9245 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9246 | "performing show on: " + w); |
| 9247 | w.performShowLocked(); |
| 9248 | } |
| 9249 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | // This must be called while inside a transaction. |
| 9252 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9253 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9254 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9256 | if (animation == sDummyAnimation) { |
| 9257 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9258 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9259 | // when it is really time to animate, this will be set to |
| 9260 | // a real animation and the next call will execute normally. |
| 9261 | return false; |
| 9262 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9264 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 9265 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9266 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9267 | TAG, "Starting animation in " + this + |
| 9268 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 9269 | + " scale=" + mTransitionAnimationScale |
| 9270 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 9271 | animation.initialize(dw, dh, dw, dh); |
| 9272 | animation.setStartTime(currentTime); |
| 9273 | animating = true; |
| 9274 | } |
| 9275 | transformation.clear(); |
| 9276 | final boolean more = animation.getTransformation( |
| 9277 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9278 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9279 | TAG, "Stepped animation in " + this + |
| 9280 | ": more=" + more + ", xform=" + transformation); |
| 9281 | if (more) { |
| 9282 | // we're done! |
| 9283 | hasTransformation = true; |
| 9284 | return true; |
| 9285 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9286 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9287 | TAG, "Finished animation in " + this + |
| 9288 | " @ " + currentTime); |
| 9289 | animation = null; |
| 9290 | } |
| 9291 | } else if (animation != null) { |
| 9292 | // If the display is frozen, and there is a pending animation, |
| 9293 | // clear it and make sure we run the cleanup code. |
| 9294 | animating = true; |
| 9295 | animation = null; |
| 9296 | } |
| 9297 | |
| 9298 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9300 | if (!animating) { |
| 9301 | return false; |
| 9302 | } |
| 9303 | |
| 9304 | clearAnimation(); |
| 9305 | animating = false; |
| 9306 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 9307 | moveInputMethodWindowsIfNeededLocked(true); |
| 9308 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9309 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9310 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9311 | TAG, "Animation done in " + this |
| 9312 | + ": reportedVisible=" + reportedVisible); |
| 9313 | |
| 9314 | transformation.clear(); |
| 9315 | if (animLayerAdjustment != 0) { |
| 9316 | animLayerAdjustment = 0; |
| 9317 | updateLayers(); |
| 9318 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9319 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | final int N = windows.size(); |
| 9321 | for (int i=0; i<N; i++) { |
| 9322 | ((WindowState)windows.get(i)).finishExit(); |
| 9323 | } |
| 9324 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9326 | return false; |
| 9327 | } |
| 9328 | |
| 9329 | void updateReportedVisibilityLocked() { |
| 9330 | if (appToken == null) { |
| 9331 | return; |
| 9332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9334 | int numInteresting = 0; |
| 9335 | int numVisible = 0; |
| 9336 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9337 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9338 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9339 | final int N = allAppWindows.size(); |
| 9340 | for (int i=0; i<N; i++) { |
| 9341 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 9342 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 9343 | || win.mViewVisibility != View.VISIBLE |
| 9344 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | continue; |
| 9346 | } |
| 9347 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9348 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9349 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9350 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9351 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9352 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9353 | + " pv=" + win.mPolicyVisibility |
| 9354 | + " dp=" + win.mDrawPending |
| 9355 | + " cdp=" + win.mCommitDrawPending |
| 9356 | + " ah=" + win.mAttachedHidden |
| 9357 | + " th=" |
| 9358 | + (win.mAppToken != null |
| 9359 | ? win.mAppToken.hiddenRequested : false) |
| 9360 | + " a=" + win.mAnimating); |
| 9361 | } |
| 9362 | } |
| 9363 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9364 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9365 | if (!win.isAnimating()) { |
| 9366 | numVisible++; |
| 9367 | } |
| 9368 | nowGone = false; |
| 9369 | } else if (win.isAnimating()) { |
| 9370 | nowGone = false; |
| 9371 | } |
| 9372 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9374 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9375 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9376 | + numInteresting + " visible=" + numVisible); |
| 9377 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9378 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9379 | TAG, "Visibility changed in " + this |
| 9380 | + ": vis=" + nowVisible); |
| 9381 | reportedVisible = nowVisible; |
| 9382 | Message m = mH.obtainMessage( |
| 9383 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 9384 | nowVisible ? 1 : 0, |
| 9385 | nowGone ? 1 : 0, |
| 9386 | this); |
| 9387 | mH.sendMessage(m); |
| 9388 | } |
| 9389 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9390 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9391 | WindowState findMainWindow() { |
| 9392 | int j = windows.size(); |
| 9393 | while (j > 0) { |
| 9394 | j--; |
| 9395 | WindowState win = windows.get(j); |
| 9396 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 9397 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 9398 | return win; |
| 9399 | } |
| 9400 | } |
| 9401 | return null; |
| 9402 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9404 | void dump(PrintWriter pw, String prefix) { |
| 9405 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9406 | if (appToken != null) { |
| 9407 | pw.print(prefix); pw.println("app=true"); |
| 9408 | } |
| 9409 | if (allAppWindows.size() > 0) { |
| 9410 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 9411 | } |
| 9412 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9413 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9414 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 9415 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 9416 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 9417 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 9418 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 9419 | if (paused || freezingScreen) { |
| 9420 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 9421 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 9422 | } |
| 9423 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 9424 | || inPendingTransaction || allDrawn) { |
| 9425 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 9426 | pw.print(numInterestingWindows); |
| 9427 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 9428 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 9429 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 9430 | } |
| 9431 | if (animating || animation != null) { |
| 9432 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 9433 | pw.print(" animation="); pw.println(animation); |
| 9434 | } |
| 9435 | if (animLayerAdjustment != 0) { |
| 9436 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 9437 | } |
| 9438 | if (hasTransformation) { |
| 9439 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 9440 | pw.print(" transformation="); transformation.printShortString(pw); |
| 9441 | pw.println(); |
| 9442 | } |
| 9443 | if (startingData != null || removed || firstWindowDrawn) { |
| 9444 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 9445 | pw.print(" removed="); pw.print(removed); |
| 9446 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 9447 | } |
| 9448 | if (startingWindow != null || startingView != null |
| 9449 | || startingDisplayed || startingMoved) { |
| 9450 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 9451 | pw.print(" startingView="); pw.print(startingView); |
| 9452 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 9453 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 9454 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9455 | } |
| 9456 | |
| 9457 | @Override |
| 9458 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9459 | if (stringName == null) { |
| 9460 | StringBuilder sb = new StringBuilder(); |
| 9461 | sb.append("AppWindowToken{"); |
| 9462 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 9463 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 9464 | stringName = sb.toString(); |
| 9465 | } |
| 9466 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | } |
| 9468 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9469 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9470 | // ------------------------------------------------------------- |
| 9471 | // DummyAnimation |
| 9472 | // ------------------------------------------------------------- |
| 9473 | |
| 9474 | // This is an animation that does nothing: it just immediately finishes |
| 9475 | // itself every time it is called. It is used as a stub animation in cases |
| 9476 | // where we want to synchronize multiple things that may be animating. |
| 9477 | static final class DummyAnimation extends Animation { |
| 9478 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 9479 | return false; |
| 9480 | } |
| 9481 | } |
| 9482 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | // ------------------------------------------------------------- |
| 9485 | // Async Handler |
| 9486 | // ------------------------------------------------------------- |
| 9487 | |
| 9488 | static final class StartingData { |
| 9489 | final String pkg; |
| 9490 | final int theme; |
| 9491 | final CharSequence nonLocalizedLabel; |
| 9492 | final int labelRes; |
| 9493 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9495 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 9496 | int _labelRes, int _icon) { |
| 9497 | pkg = _pkg; |
| 9498 | theme = _theme; |
| 9499 | nonLocalizedLabel = _nonLocalizedLabel; |
| 9500 | labelRes = _labelRes; |
| 9501 | icon = _icon; |
| 9502 | } |
| 9503 | } |
| 9504 | |
| 9505 | private final class H extends Handler { |
| 9506 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 9507 | public static final int REPORT_LOSING_FOCUS = 3; |
| 9508 | public static final int ANIMATE = 4; |
| 9509 | public static final int ADD_STARTING = 5; |
| 9510 | public static final int REMOVE_STARTING = 6; |
| 9511 | public static final int FINISHED_STARTING = 7; |
| 9512 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9513 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 9514 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 9515 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 9516 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 9517 | public static final int FORCE_GC = 15; |
| 9518 | public static final int ENABLE_SCREEN = 16; |
| 9519 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9520 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9522 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9524 | public H() { |
| 9525 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9527 | @Override |
| 9528 | public void handleMessage(Message msg) { |
| 9529 | switch (msg.what) { |
| 9530 | case REPORT_FOCUS_CHANGE: { |
| 9531 | WindowState lastFocus; |
| 9532 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9533 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9534 | synchronized(mWindowMap) { |
| 9535 | lastFocus = mLastFocus; |
| 9536 | newFocus = mCurrentFocus; |
| 9537 | if (lastFocus == newFocus) { |
| 9538 | // Focus is not changing, so nothing to do. |
| 9539 | return; |
| 9540 | } |
| 9541 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9542 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9543 | // + " to " + newFocus); |
| 9544 | if (newFocus != null && lastFocus != null |
| 9545 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9546 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9547 | mLosingFocus.add(lastFocus); |
| 9548 | lastFocus = null; |
| 9549 | } |
| 9550 | } |
| 9551 | |
| 9552 | if (lastFocus != newFocus) { |
| 9553 | //System.out.println("Changing focus from " + lastFocus |
| 9554 | // + " to " + newFocus); |
| 9555 | if (newFocus != null) { |
| 9556 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9557 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9558 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 9559 | } catch (RemoteException e) { |
| 9560 | // Ignore if process has died. |
| 9561 | } |
| 9562 | } |
| 9563 | |
| 9564 | if (lastFocus != null) { |
| 9565 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9566 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9567 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 9568 | } catch (RemoteException e) { |
| 9569 | // Ignore if process has died. |
| 9570 | } |
| 9571 | } |
| 9572 | } |
| 9573 | } break; |
| 9574 | |
| 9575 | case REPORT_LOSING_FOCUS: { |
| 9576 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9578 | synchronized(mWindowMap) { |
| 9579 | losers = mLosingFocus; |
| 9580 | mLosingFocus = new ArrayList<WindowState>(); |
| 9581 | } |
| 9582 | |
| 9583 | final int N = losers.size(); |
| 9584 | for (int i=0; i<N; i++) { |
| 9585 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9586 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9587 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 9588 | } catch (RemoteException e) { |
| 9589 | // Ignore if process has died. |
| 9590 | } |
| 9591 | } |
| 9592 | } break; |
| 9593 | |
| 9594 | case ANIMATE: { |
| 9595 | synchronized(mWindowMap) { |
| 9596 | mAnimationPending = false; |
| 9597 | performLayoutAndPlaceSurfacesLocked(); |
| 9598 | } |
| 9599 | } break; |
| 9600 | |
| 9601 | case ADD_STARTING: { |
| 9602 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9603 | final StartingData sd = wtoken.startingData; |
| 9604 | |
| 9605 | if (sd == null) { |
| 9606 | // Animation has been canceled... do nothing. |
| 9607 | return; |
| 9608 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9609 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9610 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9611 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | View view = null; |
| 9614 | try { |
| 9615 | view = mPolicy.addStartingWindow( |
| 9616 | wtoken.token, sd.pkg, |
| 9617 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 9618 | sd.icon); |
| 9619 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9620 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9621 | } |
| 9622 | |
| 9623 | if (view != null) { |
| 9624 | boolean abort = false; |
| 9625 | |
| 9626 | synchronized(mWindowMap) { |
| 9627 | if (wtoken.removed || wtoken.startingData == null) { |
| 9628 | // If the window was successfully added, then |
| 9629 | // we need to remove it. |
| 9630 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9631 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9632 | "Aborted starting " + wtoken |
| 9633 | + ": removed=" + wtoken.removed |
| 9634 | + " startingData=" + wtoken.startingData); |
| 9635 | wtoken.startingWindow = null; |
| 9636 | wtoken.startingData = null; |
| 9637 | abort = true; |
| 9638 | } |
| 9639 | } else { |
| 9640 | wtoken.startingView = view; |
| 9641 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9642 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9643 | "Added starting " + wtoken |
| 9644 | + ": startingWindow=" |
| 9645 | + wtoken.startingWindow + " startingView=" |
| 9646 | + wtoken.startingView); |
| 9647 | } |
| 9648 | |
| 9649 | if (abort) { |
| 9650 | try { |
| 9651 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 9652 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9653 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9654 | } |
| 9655 | } |
| 9656 | } |
| 9657 | } break; |
| 9658 | |
| 9659 | case REMOVE_STARTING: { |
| 9660 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9661 | IBinder token = null; |
| 9662 | View view = null; |
| 9663 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9664 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9665 | + wtoken + ": startingWindow=" |
| 9666 | + wtoken.startingWindow + " startingView=" |
| 9667 | + wtoken.startingView); |
| 9668 | if (wtoken.startingWindow != null) { |
| 9669 | view = wtoken.startingView; |
| 9670 | token = wtoken.token; |
| 9671 | wtoken.startingData = null; |
| 9672 | wtoken.startingView = null; |
| 9673 | wtoken.startingWindow = null; |
| 9674 | } |
| 9675 | } |
| 9676 | if (view != null) { |
| 9677 | try { |
| 9678 | mPolicy.removeStartingWindow(token, view); |
| 9679 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9680 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9681 | } |
| 9682 | } |
| 9683 | } break; |
| 9684 | |
| 9685 | case FINISHED_STARTING: { |
| 9686 | IBinder token = null; |
| 9687 | View view = null; |
| 9688 | while (true) { |
| 9689 | synchronized (mWindowMap) { |
| 9690 | final int N = mFinishedStarting.size(); |
| 9691 | if (N <= 0) { |
| 9692 | break; |
| 9693 | } |
| 9694 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9695 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9696 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9697 | "Finished starting " + wtoken |
| 9698 | + ": startingWindow=" + wtoken.startingWindow |
| 9699 | + " startingView=" + wtoken.startingView); |
| 9700 | |
| 9701 | if (wtoken.startingWindow == null) { |
| 9702 | continue; |
| 9703 | } |
| 9704 | |
| 9705 | view = wtoken.startingView; |
| 9706 | token = wtoken.token; |
| 9707 | wtoken.startingData = null; |
| 9708 | wtoken.startingView = null; |
| 9709 | wtoken.startingWindow = null; |
| 9710 | } |
| 9711 | |
| 9712 | try { |
| 9713 | mPolicy.removeStartingWindow(token, view); |
| 9714 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9715 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9716 | } |
| 9717 | } |
| 9718 | } break; |
| 9719 | |
| 9720 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9721 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9722 | |
| 9723 | boolean nowVisible = msg.arg1 != 0; |
| 9724 | boolean nowGone = msg.arg2 != 0; |
| 9725 | |
| 9726 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9727 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9728 | TAG, "Reporting visible in " + wtoken |
| 9729 | + " visible=" + nowVisible |
| 9730 | + " gone=" + nowGone); |
| 9731 | if (nowVisible) { |
| 9732 | wtoken.appToken.windowsVisible(); |
| 9733 | } else { |
| 9734 | wtoken.appToken.windowsGone(); |
| 9735 | } |
| 9736 | } catch (RemoteException ex) { |
| 9737 | } |
| 9738 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9740 | case WINDOW_FREEZE_TIMEOUT: { |
| 9741 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9742 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9743 | int i = mWindows.size(); |
| 9744 | while (i > 0) { |
| 9745 | i--; |
| 9746 | WindowState w = (WindowState)mWindows.get(i); |
| 9747 | if (w.mOrientationChanging) { |
| 9748 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9749 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9750 | } |
| 9751 | } |
| 9752 | performLayoutAndPlaceSurfacesLocked(); |
| 9753 | } |
| 9754 | break; |
| 9755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9757 | case HOLD_SCREEN_CHANGED: { |
| 9758 | Session oldHold; |
| 9759 | Session newHold; |
| 9760 | synchronized (mWindowMap) { |
| 9761 | oldHold = mLastReportedHold; |
| 9762 | newHold = (Session)msg.obj; |
| 9763 | mLastReportedHold = newHold; |
| 9764 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9766 | if (oldHold != newHold) { |
| 9767 | try { |
| 9768 | if (oldHold != null) { |
| 9769 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 9770 | "window", |
| 9771 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9772 | } |
| 9773 | if (newHold != null) { |
| 9774 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 9775 | "window", |
| 9776 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9777 | } |
| 9778 | } catch (RemoteException e) { |
| 9779 | } |
| 9780 | } |
| 9781 | break; |
| 9782 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9784 | case APP_TRANSITION_TIMEOUT: { |
| 9785 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9786 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9787 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9788 | "*** APP TRANSITION TIMEOUT"); |
| 9789 | mAppTransitionReady = true; |
| 9790 | mAppTransitionTimeout = true; |
| 9791 | performLayoutAndPlaceSurfacesLocked(); |
| 9792 | } |
| 9793 | } |
| 9794 | break; |
| 9795 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9796 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9797 | case PERSIST_ANIMATION_SCALE: { |
| 9798 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9799 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9800 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9801 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9802 | break; |
| 9803 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9805 | case FORCE_GC: { |
| 9806 | synchronized(mWindowMap) { |
| 9807 | if (mAnimationPending) { |
| 9808 | // If we are animating, don't do the gc now but |
| 9809 | // delay a bit so we don't interrupt the animation. |
| 9810 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9811 | 2000); |
| 9812 | return; |
| 9813 | } |
| 9814 | // If we are currently rotating the display, it will |
| 9815 | // schedule a new message when done. |
| 9816 | if (mDisplayFrozen) { |
| 9817 | return; |
| 9818 | } |
| 9819 | mFreezeGcPending = 0; |
| 9820 | } |
| 9821 | Runtime.getRuntime().gc(); |
| 9822 | break; |
| 9823 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9824 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | case ENABLE_SCREEN: { |
| 9826 | performEnableScreen(); |
| 9827 | break; |
| 9828 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9829 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9830 | case APP_FREEZE_TIMEOUT: { |
| 9831 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9832 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9833 | int i = mAppTokens.size(); |
| 9834 | while (i > 0) { |
| 9835 | i--; |
| 9836 | AppWindowToken tok = mAppTokens.get(i); |
| 9837 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9838 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9839 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9840 | } |
| 9841 | } |
| 9842 | } |
| 9843 | break; |
| 9844 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9845 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9846 | case SEND_NEW_CONFIGURATION: { |
| 9847 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9848 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9849 | break; |
| 9850 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9852 | } |
| 9853 | } |
| 9854 | } |
| 9855 | |
| 9856 | // ------------------------------------------------------------- |
| 9857 | // IWindowManager API |
| 9858 | // ------------------------------------------------------------- |
| 9859 | |
| 9860 | public IWindowSession openSession(IInputMethodClient client, |
| 9861 | IInputContext inputContext) { |
| 9862 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9863 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9864 | Session session = new Session(client, inputContext); |
| 9865 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9866 | } |
| 9867 | |
| 9868 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9869 | synchronized (mWindowMap) { |
| 9870 | // The focus for the client is the window immediately below |
| 9871 | // where we would place the input method window. |
| 9872 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9873 | WindowState imFocus; |
| 9874 | if (idx > 0) { |
| 9875 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9876 | if (imFocus != null) { |
| 9877 | if (imFocus.mSession.mClient != null && |
| 9878 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9879 | return true; |
| 9880 | } |
| 9881 | } |
| 9882 | } |
| 9883 | } |
| 9884 | return false; |
| 9885 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9886 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9887 | // ------------------------------------------------------------- |
| 9888 | // Internals |
| 9889 | // ------------------------------------------------------------- |
| 9890 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9891 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9892 | boolean throwOnError) { |
| 9893 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9894 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9895 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9896 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9897 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9898 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9899 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9900 | TAG, "Looking up client " + client + ": " + win); |
| 9901 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9902 | RuntimeException ex = new IllegalArgumentException( |
| 9903 | "Requested window " + client + " does not exist"); |
| 9904 | if (throwOnError) { |
| 9905 | throw ex; |
| 9906 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9907 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9908 | return null; |
| 9909 | } |
| 9910 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9911 | RuntimeException ex = new IllegalArgumentException( |
| 9912 | "Requested window " + client + " is in session " + |
| 9913 | win.mSession + ", not " + session); |
| 9914 | if (throwOnError) { |
| 9915 | throw ex; |
| 9916 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9917 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9918 | return null; |
| 9919 | } |
| 9920 | |
| 9921 | return win; |
| 9922 | } |
| 9923 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9924 | final void rebuildAppWindowListLocked() { |
| 9925 | int NW = mWindows.size(); |
| 9926 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9927 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9928 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9929 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9930 | // First remove all existing app windows. |
| 9931 | i=0; |
| 9932 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9933 | WindowState w = (WindowState)mWindows.get(i); |
| 9934 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9935 | WindowState win = (WindowState)mWindows.remove(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9936 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9937 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9938 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9939 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9940 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9941 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9942 | && lastWallpaper == i-1) { |
| 9943 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9944 | } |
| 9945 | i++; |
| 9946 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9947 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9948 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9949 | // so skip them before adding app tokens. |
| 9950 | lastWallpaper++; |
| 9951 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9952 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9953 | // First add all of the exiting app tokens... these are no longer |
| 9954 | // in the main app list, but still have windows shown. We put them |
| 9955 | // in the back because now that the animation is over we no longer |
| 9956 | // will care about them. |
| 9957 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9958 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9959 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9960 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9961 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9962 | // And add in the still active app tokens in Z order. |
| 9963 | NT = mAppTokens.size(); |
| 9964 | for (int j=0; j<NT; j++) { |
| 9965 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9966 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9967 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9968 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9969 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9970 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9971 | + " windows but added " + i); |
| 9972 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9973 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | private final void assignLayersLocked() { |
| 9976 | int N = mWindows.size(); |
| 9977 | int curBaseLayer = 0; |
| 9978 | int curLayer = 0; |
| 9979 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9980 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9981 | for (i=0; i<N; i++) { |
| 9982 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9983 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9984 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9985 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9986 | w.mLayer = curLayer; |
| 9987 | } else { |
| 9988 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9989 | w.mLayer = curLayer; |
| 9990 | } |
| 9991 | if (w.mTargetAppToken != null) { |
| 9992 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9993 | } else if (w.mAppToken != null) { |
| 9994 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9995 | } else { |
| 9996 | w.mAnimLayer = w.mLayer; |
| 9997 | } |
| 9998 | if (w.mIsImWindow) { |
| 9999 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10000 | } else if (w.mIsWallpaper) { |
| 10001 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10002 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10003 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10004 | + w.mAnimLayer); |
| 10005 | //System.out.println( |
| 10006 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 10007 | } |
| 10008 | } |
| 10009 | |
| 10010 | private boolean mInLayout = false; |
| 10011 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 10012 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 10013 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10014 | throw new RuntimeException("Recursive call!"); |
| 10015 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10016 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10017 | return; |
| 10018 | } |
| 10019 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10020 | if (mWaitingForConfig) { |
| 10021 | // Our configuration has changed (most likely rotation), but we |
| 10022 | // don't yet have the complete configuration to report to |
| 10023 | // applications. Don't do any window layout until we have it. |
| 10024 | return; |
| 10025 | } |
| 10026 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10027 | boolean recoveringMemory = false; |
| 10028 | if (mForceRemoves != null) { |
| 10029 | recoveringMemory = true; |
| 10030 | // Wait a little it for things to settle down, and off we go. |
| 10031 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 10032 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10033 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10034 | removeWindowInnerLocked(ws.mSession, ws); |
| 10035 | } |
| 10036 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10037 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10038 | Object tmp = new Object(); |
| 10039 | synchronized (tmp) { |
| 10040 | try { |
| 10041 | tmp.wait(250); |
| 10042 | } catch (InterruptedException e) { |
| 10043 | } |
| 10044 | } |
| 10045 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10046 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10047 | mInLayout = true; |
| 10048 | try { |
| 10049 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10050 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10051 | int i = mPendingRemove.size()-1; |
| 10052 | if (i >= 0) { |
| 10053 | while (i >= 0) { |
| 10054 | WindowState w = mPendingRemove.get(i); |
| 10055 | removeWindowInnerLocked(w.mSession, w); |
| 10056 | i--; |
| 10057 | } |
| 10058 | mPendingRemove.clear(); |
| 10059 | |
| 10060 | mInLayout = false; |
| 10061 | assignLayersLocked(); |
| 10062 | mLayoutNeeded = true; |
| 10063 | performLayoutAndPlaceSurfacesLocked(); |
| 10064 | |
| 10065 | } else { |
| 10066 | mInLayout = false; |
| 10067 | if (mLayoutNeeded) { |
| 10068 | requestAnimationLocked(0); |
| 10069 | } |
| 10070 | } |
| 10071 | } catch (RuntimeException e) { |
| 10072 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10073 | 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] | 10074 | } |
| 10075 | } |
| 10076 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10077 | private final int performLayoutLockedInner() { |
| 10078 | if (!mLayoutNeeded) { |
| 10079 | return 0; |
| 10080 | } |
| 10081 | |
| 10082 | mLayoutNeeded = false; |
| 10083 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10084 | final int dw = mDisplay.getWidth(); |
| 10085 | final int dh = mDisplay.getHeight(); |
| 10086 | |
| 10087 | final int N = mWindows.size(); |
| 10088 | int i; |
| 10089 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10090 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 10091 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 10092 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10093 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10094 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10095 | int seq = mLayoutSeq+1; |
| 10096 | if (seq < 0) seq = 0; |
| 10097 | mLayoutSeq = seq; |
| 10098 | |
| 10099 | // First perform layout of any root windows (not attached |
| 10100 | // to another window). |
| 10101 | int topAttached = -1; |
| 10102 | for (i = N-1; i >= 0; i--) { |
| 10103 | WindowState win = (WindowState) mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10104 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10105 | // Don't do layout of a window if it is not visible, or |
| 10106 | // soon won't be visible, to avoid wasting time and funky |
| 10107 | // changes while a window is animating away. |
| 10108 | final AppWindowToken atoken = win.mAppToken; |
| 10109 | final boolean gone = win.mViewVisibility == View.GONE |
| 10110 | || !win.mRelayoutCalled |
| 10111 | || win.mRootToken.hidden |
| 10112 | || (atoken != null && atoken.hiddenRequested) |
| 10113 | || win.mAttachedHidden |
| 10114 | || win.mExiting || win.mDestroying; |
| 10115 | |
| 10116 | if (!win.mLayoutAttached) { |
| 10117 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 10118 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 10119 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 10120 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 10121 | + win.mViewVisibility + " mRelayoutCalled=" |
| 10122 | + win.mRelayoutCalled + " hidden=" |
| 10123 | + win.mRootToken.hidden + " hiddenRequested=" |
| 10124 | + (atoken != null && atoken.hiddenRequested) |
| 10125 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 10126 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10127 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10128 | // If this view is GONE, then skip it -- keep the current |
| 10129 | // frame, and let the caller know so they can ignore it |
| 10130 | // if they want. (We do the normal layout for INVISIBLE |
| 10131 | // windows, since that means "perform layout as normal, |
| 10132 | // just don't display"). |
| 10133 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10134 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10135 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 10136 | win.mLayoutSeq = seq; |
| 10137 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 10138 | + win.mFrame + " mContainingFrame=" |
| 10139 | + win.mContainingFrame + " mDisplayFrame=" |
| 10140 | + win.mDisplayFrame); |
| 10141 | } else { |
| 10142 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10143 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10144 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10145 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10146 | |
| 10147 | // Now perform layout of attached windows, which usually |
| 10148 | // depend on the position of the window they are attached to. |
| 10149 | // XXX does not deal with windows that are attached to windows |
| 10150 | // that are themselves attached. |
| 10151 | for (i = topAttached; i >= 0; i--) { |
| 10152 | WindowState win = (WindowState) mWindows.get(i); |
| 10153 | |
| 10154 | // If this view is GONE, then skip it -- keep the current |
| 10155 | // frame, and let the caller know so they can ignore it |
| 10156 | // if they want. (We do the normal layout for INVISIBLE |
| 10157 | // windows, since that means "perform layout as normal, |
| 10158 | // just don't display"). |
| 10159 | if (win.mLayoutAttached) { |
| 10160 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 10161 | + " mHaveFrame=" + win.mHaveFrame |
| 10162 | + " mViewVisibility=" + win.mViewVisibility |
| 10163 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 10164 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 10165 | || !win.mHaveFrame) { |
| 10166 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 10167 | win.mLayoutSeq = seq; |
| 10168 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 10169 | + win.mFrame + " mContainingFrame=" |
| 10170 | + win.mContainingFrame + " mDisplayFrame=" |
| 10171 | + win.mDisplayFrame); |
| 10172 | } |
| 10173 | } |
| 10174 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10175 | |
| 10176 | // Window frames may have changed. Tell the input dispatcher about it. |
| 10177 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 10178 | mInputMonitor.updateInputWindowsLw(); |
| 10179 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10180 | |
| 10181 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10184 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 10185 | boolean recoveringMemory) { |
| 10186 | final long currentTime = SystemClock.uptimeMillis(); |
| 10187 | final int dw = mDisplay.getWidth(); |
| 10188 | final int dh = mDisplay.getHeight(); |
| 10189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10190 | int i; |
| 10191 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10192 | if (mFocusMayChange) { |
| 10193 | mFocusMayChange = false; |
| 10194 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 10195 | } |
| 10196 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10197 | if (mFxSession == null) { |
| 10198 | mFxSession = new SurfaceSession(); |
| 10199 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10200 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10201 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10202 | |
| 10203 | // Initialize state of exiting tokens. |
| 10204 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10205 | mExitingTokens.get(i).hasVisible = false; |
| 10206 | } |
| 10207 | |
| 10208 | // Initialize state of exiting applications. |
| 10209 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10210 | mExitingAppTokens.get(i).hasVisible = false; |
| 10211 | } |
| 10212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10213 | boolean orientationChangeComplete = true; |
| 10214 | Session holdScreen = null; |
| 10215 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10216 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10217 | boolean focusDisplayed = false; |
| 10218 | boolean animating = false; |
| 10219 | |
| 10220 | Surface.openTransaction(); |
| 10221 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10222 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10223 | int repeats = 0; |
| 10224 | int changes = 0; |
| 10225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10226 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10227 | repeats++; |
| 10228 | if (repeats > 6) { |
| 10229 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 10230 | mLayoutNeeded = false; |
| 10231 | break; |
| 10232 | } |
| 10233 | |
| 10234 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 10235 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 10236 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 10237 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 10238 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 10239 | assignLayersLocked(); |
| 10240 | mLayoutNeeded = true; |
| 10241 | } |
| 10242 | } |
| 10243 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 10244 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 10245 | if (updateOrientationFromAppTokensLocked()) { |
| 10246 | mLayoutNeeded = true; |
| 10247 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10248 | } |
| 10249 | } |
| 10250 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 10251 | mLayoutNeeded = true; |
| 10252 | } |
| 10253 | } |
| 10254 | |
| 10255 | // FIRST LOOP: Perform a layout, if needed. |
| 10256 | if (repeats < 4) { |
| 10257 | changes = performLayoutLockedInner(); |
| 10258 | if (changes != 0) { |
| 10259 | continue; |
| 10260 | } |
| 10261 | } else { |
| 10262 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 10263 | changes = 0; |
| 10264 | } |
| 10265 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10266 | final int transactionSequence = ++mTransactionSequence; |
| 10267 | |
| 10268 | // Update animations of all applications, including those |
| 10269 | // associated with exiting/removed apps |
| 10270 | boolean tokensAnimating = false; |
| 10271 | final int NAT = mAppTokens.size(); |
| 10272 | for (i=0; i<NAT; i++) { |
| 10273 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 10274 | tokensAnimating = true; |
| 10275 | } |
| 10276 | } |
| 10277 | final int NEAT = mExitingAppTokens.size(); |
| 10278 | for (i=0; i<NEAT; i++) { |
| 10279 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 10280 | tokensAnimating = true; |
| 10281 | } |
| 10282 | } |
| 10283 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10284 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 10285 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10286 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10287 | + transactionSequence + " tokensAnimating=" |
| 10288 | + tokensAnimating); |
| 10289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10290 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10291 | |
| 10292 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10293 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10294 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10295 | |
| 10296 | mPolicy.beginAnimationLw(dw, dh); |
| 10297 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10298 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10300 | for (i=N-1; i>=0; i--) { |
| 10301 | WindowState w = (WindowState)mWindows.get(i); |
| 10302 | |
| 10303 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10304 | |
| 10305 | if (w.mSurface != null) { |
| 10306 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10307 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 10308 | if ((w.mAttrs.flags |
| 10309 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10310 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10311 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10312 | wallpaperMayChange = true; |
| 10313 | } |
| 10314 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10315 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 10316 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10317 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 10318 | animating = true; |
| 10319 | //w.dump(" "); |
| 10320 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 10321 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 10322 | wallpaperMayChange = true; |
| 10323 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10324 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10325 | if (mPolicy.doesForceHide(w, attrs)) { |
| 10326 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10327 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10328 | "Animation done that could impact force hide: " |
| 10329 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10330 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10331 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10332 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 10333 | forceHiding = true; |
| 10334 | } |
| 10335 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10336 | boolean changed; |
| 10337 | if (forceHiding) { |
| 10338 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10339 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 10340 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10341 | } else { |
| 10342 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10343 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 10344 | "Now policy shown: " + w); |
| 10345 | if (changed) { |
| 10346 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10347 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10348 | // Assume we will need to animate. If |
| 10349 | // we don't (because the wallpaper will |
| 10350 | // stay with the lock screen), then we will |
| 10351 | // clean up later. |
| 10352 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 10353 | if (a != null) { |
| 10354 | w.setAnimation(a); |
| 10355 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10356 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10357 | if (mCurrentFocus == null || |
| 10358 | mCurrentFocus.mLayer < w.mLayer) { |
| 10359 | // We are showing on to of the current |
| 10360 | // focus, so re-evaluate focus to make |
| 10361 | // sure it is correct. |
| 10362 | mFocusMayChange = true; |
| 10363 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10364 | } |
| 10365 | } |
| 10366 | if (changed && (attrs.flags |
| 10367 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 10368 | wallpaperMayChange = true; |
| 10369 | } |
| 10370 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10371 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10372 | mPolicy.animatingWindowLw(w, attrs); |
| 10373 | } |
| 10374 | |
| 10375 | final AppWindowToken atoken = w.mAppToken; |
| 10376 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 10377 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 10378 | atoken.lastTransactionSequence = transactionSequence; |
| 10379 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 10380 | atoken.startingDisplayed = false; |
| 10381 | } |
| 10382 | if ((w.isOnScreen() || w.mAttrs.type |
| 10383 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 10384 | && !w.mExiting && !w.mDestroying) { |
| 10385 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10386 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10387 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10388 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10389 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10390 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10391 | + " pv=" + w.mPolicyVisibility |
| 10392 | + " dp=" + w.mDrawPending |
| 10393 | + " cdp=" + w.mCommitDrawPending |
| 10394 | + " ah=" + w.mAttachedHidden |
| 10395 | + " th=" + atoken.hiddenRequested |
| 10396 | + " a=" + w.mAnimating); |
| 10397 | } |
| 10398 | } |
| 10399 | if (w != atoken.startingWindow) { |
| 10400 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 10401 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10402 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10403 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10404 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10405 | "tokenMayBeDrawn: " + atoken |
| 10406 | + " freezingScreen=" + atoken.freezingScreen |
| 10407 | + " mAppFreezing=" + w.mAppFreezing); |
| 10408 | tokenMayBeDrawn = true; |
| 10409 | } |
| 10410 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10411 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10412 | atoken.startingDisplayed = true; |
| 10413 | } |
| 10414 | } |
| 10415 | } else if (w.mReadyToShow) { |
| 10416 | w.performShowLocked(); |
| 10417 | } |
| 10418 | } |
| 10419 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10420 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10421 | |
| 10422 | if (tokenMayBeDrawn) { |
| 10423 | // See if any windows have been drawn, so they (and others |
| 10424 | // associated with them) can now be shown. |
| 10425 | final int NT = mTokenList.size(); |
| 10426 | for (i=0; i<NT; i++) { |
| 10427 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 10428 | if (wtoken == null) { |
| 10429 | continue; |
| 10430 | } |
| 10431 | if (wtoken.freezingScreen) { |
| 10432 | int numInteresting = wtoken.numInterestingWindows; |
| 10433 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10434 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10435 | "allDrawn: " + wtoken |
| 10436 | + " interesting=" + numInteresting |
| 10437 | + " drawn=" + wtoken.numDrawnWindows); |
| 10438 | wtoken.showAllWindowsLocked(); |
| 10439 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 10440 | orientationChangeComplete = true; |
| 10441 | } |
| 10442 | } else if (!wtoken.allDrawn) { |
| 10443 | int numInteresting = wtoken.numInterestingWindows; |
| 10444 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10445 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10446 | "allDrawn: " + wtoken |
| 10447 | + " interesting=" + numInteresting |
| 10448 | + " drawn=" + wtoken.numDrawnWindows); |
| 10449 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10450 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10451 | |
| 10452 | // We can now show all of the drawn windows! |
| 10453 | if (!mOpeningApps.contains(wtoken)) { |
| 10454 | wtoken.showAllWindowsLocked(); |
| 10455 | } |
| 10456 | } |
| 10457 | } |
| 10458 | } |
| 10459 | } |
| 10460 | |
| 10461 | // If we are ready to perform an app transition, check through |
| 10462 | // all of the app tokens to be shown and see if they are ready |
| 10463 | // to go. |
| 10464 | if (mAppTransitionReady) { |
| 10465 | int NN = mOpeningApps.size(); |
| 10466 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10467 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10468 | "Checking " + NN + " opening apps (frozen=" |
| 10469 | + mDisplayFrozen + " timeout=" |
| 10470 | + mAppTransitionTimeout + ")..."); |
| 10471 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 10472 | // If the display isn't frozen, wait to do anything until |
| 10473 | // all of the apps are ready. Otherwise just go because |
| 10474 | // we'll unfreeze the display when everyone is ready. |
| 10475 | for (i=0; i<NN && goodToGo; i++) { |
| 10476 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10477 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10478 | "Check opening app" + wtoken + ": allDrawn=" |
| 10479 | + wtoken.allDrawn + " startingDisplayed=" |
| 10480 | + wtoken.startingDisplayed); |
| 10481 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 10482 | && !wtoken.startingMoved) { |
| 10483 | goodToGo = false; |
| 10484 | } |
| 10485 | } |
| 10486 | } |
| 10487 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10488 | 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] | 10489 | int transit = mNextAppTransition; |
| 10490 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10491 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10492 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10493 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10495 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10496 | mAppTransitionTimeout = false; |
| 10497 | mStartingIconInTransition = false; |
| 10498 | mSkipAppTransitionAnimation = false; |
| 10499 | |
| 10500 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 10501 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10502 | // If there are applications waiting to come to the |
| 10503 | // top of the stack, now is the time to move their windows. |
| 10504 | // (Note that we don't do apps going to the bottom |
| 10505 | // here -- we want to keep their windows in the old |
| 10506 | // Z-order until the animation completes.) |
| 10507 | if (mToTopApps.size() > 0) { |
| 10508 | NN = mAppTokens.size(); |
| 10509 | for (i=0; i<NN; i++) { |
| 10510 | AppWindowToken wtoken = mAppTokens.get(i); |
| 10511 | if (wtoken.sendingToTop) { |
| 10512 | wtoken.sendingToTop = false; |
| 10513 | moveAppWindowsLocked(wtoken, NN, false); |
| 10514 | } |
| 10515 | } |
| 10516 | mToTopApps.clear(); |
| 10517 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10518 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10519 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10520 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10521 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10522 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10523 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10524 | // The top-most window will supply the layout params, |
| 10525 | // and we will determine it below. |
| 10526 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10527 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10528 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10529 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10530 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10531 | "New wallpaper target=" + mWallpaperTarget |
| 10532 | + ", lower target=" + mLowerWallpaperTarget |
| 10533 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10534 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10535 | // Do a first pass through the tokens for two |
| 10536 | // things: |
| 10537 | // (1) Determine if both the closing and opening |
| 10538 | // app token sets are wallpaper targets, in which |
| 10539 | // case special animations are needed |
| 10540 | // (since the wallpaper needs to stay static |
| 10541 | // behind them). |
| 10542 | // (2) Find the layout params of the top-most |
| 10543 | // application window in the tokens, which is |
| 10544 | // what will control the animation theme. |
| 10545 | final int NC = mClosingApps.size(); |
| 10546 | NN = NC + mOpeningApps.size(); |
| 10547 | for (i=0; i<NN; i++) { |
| 10548 | AppWindowToken wtoken; |
| 10549 | int mode; |
| 10550 | if (i < NC) { |
| 10551 | wtoken = mClosingApps.get(i); |
| 10552 | mode = 1; |
| 10553 | } else { |
| 10554 | wtoken = mOpeningApps.get(i-NC); |
| 10555 | mode = 2; |
| 10556 | } |
| 10557 | if (mLowerWallpaperTarget != null) { |
| 10558 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 10559 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 10560 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10561 | } |
| 10562 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10563 | if (wtoken.appFullscreen) { |
| 10564 | WindowState ws = wtoken.findMainWindow(); |
| 10565 | if (ws != null) { |
| 10566 | // If this is a compatibility mode |
| 10567 | // window, we will always use its anim. |
| 10568 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 10569 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10570 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10571 | bestAnimLayer = Integer.MAX_VALUE; |
| 10572 | } else if (ws.mLayer > bestAnimLayer) { |
| 10573 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10574 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10575 | bestAnimLayer = ws.mLayer; |
| 10576 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10577 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10578 | } |
| 10579 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10580 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10581 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10582 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10583 | "Wallpaper animation!"); |
| 10584 | switch (transit) { |
| 10585 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10586 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10587 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10588 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10589 | break; |
| 10590 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10591 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10592 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10593 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10594 | break; |
| 10595 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10596 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10597 | "New transit: " + transit); |
| 10598 | } else if (oldWallpaper != null) { |
| 10599 | // We are transitioning from an activity with |
| 10600 | // a wallpaper to one without. |
| 10601 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10602 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10603 | "New transit away from wallpaper: " + transit); |
| 10604 | } else if (mWallpaperTarget != null) { |
| 10605 | // We are transitioning from an activity without |
| 10606 | // a wallpaper to now showing the wallpaper |
| 10607 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10608 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10609 | "New transit into wallpaper: " + transit); |
| 10610 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10611 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10612 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 10613 | mLastEnterAnimToken = animToken; |
| 10614 | mLastEnterAnimParams = animLp; |
| 10615 | } else if (mLastEnterAnimParams != null) { |
| 10616 | animLp = mLastEnterAnimParams; |
| 10617 | mLastEnterAnimToken = null; |
| 10618 | mLastEnterAnimParams = null; |
| 10619 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10620 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10621 | // If all closing windows are obscured, then there is |
| 10622 | // no need to do an animation. This is the case, for |
| 10623 | // example, when this transition is being done behind |
| 10624 | // the lock screen. |
| 10625 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10626 | animLp = null; |
| 10627 | } |
| 10628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10629 | NN = mOpeningApps.size(); |
| 10630 | for (i=0; i<NN; i++) { |
| 10631 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10632 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10633 | "Now opening app" + wtoken); |
| 10634 | wtoken.reportedVisible = false; |
| 10635 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10636 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10637 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10638 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10639 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | wtoken.showAllWindowsLocked(); |
| 10641 | } |
| 10642 | NN = mClosingApps.size(); |
| 10643 | for (i=0; i<NN; i++) { |
| 10644 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10645 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | "Now closing app" + wtoken); |
| 10647 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10648 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10649 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10650 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10651 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10652 | // Force the allDrawn flag, because we want to start |
| 10653 | // this guy's animations regardless of whether it's |
| 10654 | // gotten drawn. |
| 10655 | wtoken.allDrawn = true; |
| 10656 | } |
| 10657 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10658 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10660 | mOpeningApps.clear(); |
| 10661 | mClosingApps.clear(); |
| 10662 | |
| 10663 | // This has changed the visibility of windows, so perform |
| 10664 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10665 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10666 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10667 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10668 | assignLayersLocked(); |
| 10669 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10670 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10671 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10672 | } |
| 10673 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10674 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10675 | int adjResult = 0; |
| 10676 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10677 | if (!animating && mAppTransitionRunning) { |
| 10678 | // We have finished the animation of an app transition. To do |
| 10679 | // this, we have delayed a lot of operations like showing and |
| 10680 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10681 | // reflects the correct Z-order, but the window list may now |
| 10682 | // be out of sync with it. So here we will just rebuild the |
| 10683 | // entire app window list. Fun! |
| 10684 | mAppTransitionRunning = false; |
| 10685 | // Clear information about apps that were moving. |
| 10686 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10687 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10688 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10689 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10690 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10691 | moveInputMethodWindowsIfNeededLocked(false); |
| 10692 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10693 | // Since the window list has been rebuilt, focus might |
| 10694 | // have to be recomputed since the actual order of windows |
| 10695 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10696 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10697 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10698 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10699 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10700 | // At this point, there was a window with a wallpaper that |
| 10701 | // was force hiding other windows behind it, but now it |
| 10702 | // is going away. This may be simple -- just animate |
| 10703 | // away the wallpaper and its window -- or it may be |
| 10704 | // hard -- the wallpaper now needs to be shown behind |
| 10705 | // something that was hidden. |
| 10706 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10707 | if (mLowerWallpaperTarget != null |
| 10708 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10709 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10710 | "wallpaperForceHiding changed with lower=" |
| 10711 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10712 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10713 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10714 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10715 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10716 | // The lower target has become hidden before we |
| 10717 | // actually started the animation... let's completely |
| 10718 | // re-evaluate everything. |
| 10719 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10720 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10721 | } |
| 10722 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10723 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10724 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10725 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10726 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10727 | + " NEW: " + mWallpaperTarget |
| 10728 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10729 | if (mLowerWallpaperTarget == null) { |
| 10730 | // Whoops, we don't need a special wallpaper animation. |
| 10731 | // Clear them out. |
| 10732 | forceHiding = false; |
| 10733 | for (i=N-1; i>=0; i--) { |
| 10734 | WindowState w = (WindowState)mWindows.get(i); |
| 10735 | if (w.mSurface != null) { |
| 10736 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10737 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10738 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10739 | forceHiding = true; |
| 10740 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10741 | if (!w.mAnimating) { |
| 10742 | // We set the animation above so it |
| 10743 | // is not yet running. |
| 10744 | w.clearAnimation(); |
| 10745 | } |
| 10746 | } |
| 10747 | } |
| 10748 | } |
| 10749 | } |
| 10750 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10751 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10752 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10753 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10754 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10755 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10756 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10757 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10758 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10759 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10760 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10761 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10762 | assignLayersLocked(); |
| 10763 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10764 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10765 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10766 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10767 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10768 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10769 | if (mFocusMayChange) { |
| 10770 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10771 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10772 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10773 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10774 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10775 | } |
| 10776 | |
| 10777 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10778 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10779 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10780 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10781 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10782 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10783 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10784 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10785 | |
| 10786 | // THIRD LOOP: Update the surfaces of all windows. |
| 10787 | |
| 10788 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10789 | |
| 10790 | boolean obscured = false; |
| 10791 | boolean blurring = false; |
| 10792 | boolean dimming = false; |
| 10793 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10794 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10795 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10796 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10797 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10798 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10799 | for (i=N-1; i>=0; i--) { |
| 10800 | WindowState w = (WindowState)mWindows.get(i); |
| 10801 | |
| 10802 | boolean displayed = false; |
| 10803 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10804 | final int attrFlags = attrs.flags; |
| 10805 | |
| 10806 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10807 | // XXX NOTE: The logic here could be improved. We have |
| 10808 | // the decision about whether to resize a window separated |
| 10809 | // from whether to hide the surface. This can cause us to |
| 10810 | // resize a surface even if we are going to hide it. You |
| 10811 | // can see this by (1) holding device in landscape mode on |
| 10812 | // home screen; (2) tapping browser icon (device will rotate |
| 10813 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10814 | // in step 2 but then immediately hidden, causing us to |
| 10815 | // have to resize and then redraw it again in step 3. It |
| 10816 | // would be nice to figure out how to avoid this, but it is |
| 10817 | // difficult because we do need to resize surfaces in some |
| 10818 | // cases while they are hidden such as when first showing a |
| 10819 | // window. |
| 10820 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10821 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10822 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10823 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10824 | + ": new=" + w.mShownFrame + ", old=" |
| 10825 | + w.mLastShownFrame); |
| 10826 | |
| 10827 | boolean resize; |
| 10828 | int width, height; |
| 10829 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 10830 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 10831 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 10832 | // for a scaled surface, we just want to use |
| 10833 | // the requested size. |
| 10834 | width = w.mRequestedWidth; |
| 10835 | height = w.mRequestedHeight; |
| 10836 | w.mLastRequestedWidth = width; |
| 10837 | w.mLastRequestedHeight = height; |
| 10838 | w.mLastShownFrame.set(w.mShownFrame); |
| 10839 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10840 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10841 | "POS " + w.mShownFrame.left |
| 10842 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10843 | w.mSurfaceX = w.mShownFrame.left; |
| 10844 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10845 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10846 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10847 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10848 | if (!recoveringMemory) { |
| 10849 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10850 | } |
| 10851 | } |
| 10852 | } else { |
| 10853 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 10854 | width = w.mShownFrame.width(); |
| 10855 | height = w.mShownFrame.height(); |
| 10856 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10857 | } |
| 10858 | |
| 10859 | if (resize) { |
| 10860 | if (width < 1) width = 1; |
| 10861 | if (height < 1) height = 1; |
| 10862 | if (w.mSurface != null) { |
| 10863 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10864 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10865 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10866 | + w.mShownFrame.top + " SIZE " |
| 10867 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10868 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10869 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10870 | w.mSurfaceW = width; |
| 10871 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10872 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10873 | w.mSurfaceX = w.mShownFrame.left; |
| 10874 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10875 | w.mSurface.setPosition(w.mShownFrame.left, |
| 10876 | w.mShownFrame.top); |
| 10877 | } catch (RuntimeException e) { |
| 10878 | // If something goes wrong with the surface (such |
| 10879 | // as running out of memory), don't take down the |
| 10880 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10881 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10882 | + "size=(" + width + "x" + height |
| 10883 | + "), pos=(" + w.mShownFrame.left |
| 10884 | + "," + w.mShownFrame.top + ")", e); |
| 10885 | if (!recoveringMemory) { |
| 10886 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10887 | } |
| 10888 | } |
| 10889 | } |
| 10890 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10891 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10892 | w.mContentInsetsChanged = |
| 10893 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10894 | w.mVisibleInsetsChanged = |
| 10895 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10896 | boolean configChanged = |
| 10897 | w.mConfiguration != mCurConfiguration |
| 10898 | && (w.mConfiguration == null |
| 10899 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10900 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10901 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10902 | + mCurConfiguration); |
| 10903 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10904 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10905 | + ": configChanged=" + configChanged |
| 10906 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10907 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10908 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10909 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10910 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10911 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10912 | w.mLastFrame.set(w.mFrame); |
| 10913 | w.mLastContentInsets.set(w.mContentInsets); |
| 10914 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10915 | // If the screen is currently frozen, then keep |
| 10916 | // it frozen until this window draws at its new |
| 10917 | // orientation. |
| 10918 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10919 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10920 | "Resizing while display frozen: " + w); |
| 10921 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10922 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10923 | mWindowsFreezingScreen = true; |
| 10924 | // XXX should probably keep timeout from |
| 10925 | // when we first froze the display. |
| 10926 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10927 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10928 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10929 | } |
| 10930 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10931 | // If the orientation is changing, then we need to |
| 10932 | // hold off on unfreezing the display until this |
| 10933 | // window has been redrawn; to do that, we need |
| 10934 | // to go through the process of getting informed |
| 10935 | // by the application when it has finished drawing. |
| 10936 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10937 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10938 | "Orientation start waiting for draw in " |
| 10939 | + w + ", surface " + w.mSurface); |
| 10940 | w.mDrawPending = true; |
| 10941 | w.mCommitDrawPending = false; |
| 10942 | w.mReadyToShow = false; |
| 10943 | if (w.mAppToken != null) { |
| 10944 | w.mAppToken.allDrawn = false; |
| 10945 | } |
| 10946 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10947 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10948 | "Resizing window " + w + " to " + w.mFrame); |
| 10949 | mResizingWindows.add(w); |
| 10950 | } else if (w.mOrientationChanging) { |
| 10951 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10952 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10953 | "Orientation not waiting for draw in " |
| 10954 | + w + ", surface " + w.mSurface); |
| 10955 | w.mOrientationChanging = false; |
| 10956 | } |
| 10957 | } |
| 10958 | } |
| 10959 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10960 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10961 | if (!w.mLastHidden) { |
| 10962 | //dump(); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 10963 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow=" |
| 10964 | + w.mRootToken.waitingToShow + " polvis=" |
| 10965 | + w.mPolicyVisibility + " atthid=" |
| 10966 | + w.mAttachedHidden + " tokhid=" |
| 10967 | + w.mRootToken.hidden + " vis=" |
| 10968 | + w.mViewVisibility); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10969 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10970 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10971 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10972 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10973 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10974 | try { |
| 10975 | w.mSurface.hide(); |
| 10976 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10977 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10978 | } |
| 10979 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10980 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 10981 | mInputMonitor.windowIsBecomingInvisibleLw(w); |
| 10982 | } else { |
| 10983 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 10984 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10985 | } |
| 10986 | // If we are waiting for this window to handle an |
| 10987 | // orientation change, well, it is hidden, so |
| 10988 | // doesn't really matter. Note that this does |
| 10989 | // introduce a potential glitch if the window |
| 10990 | // becomes unhidden before it has drawn for the |
| 10991 | // new orientation. |
| 10992 | if (w.mOrientationChanging) { |
| 10993 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10994 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10995 | "Orientation change skips hidden " + w); |
| 10996 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10997 | } else if (w.mLastLayer != w.mAnimLayer |
| 10998 | || w.mLastAlpha != w.mShownAlpha |
| 10999 | || w.mLastDsDx != w.mDsDx |
| 11000 | || w.mLastDtDx != w.mDtDx |
| 11001 | || w.mLastDsDy != w.mDsDy |
| 11002 | || w.mLastDtDy != w.mDtDy |
| 11003 | || w.mLastHScale != w.mHScale |
| 11004 | || w.mLastVScale != w.mVScale |
| 11005 | || w.mLastHidden) { |
| 11006 | displayed = true; |
| 11007 | w.mLastAlpha = w.mShownAlpha; |
| 11008 | w.mLastLayer = w.mAnimLayer; |
| 11009 | w.mLastDsDx = w.mDsDx; |
| 11010 | w.mLastDtDx = w.mDtDx; |
| 11011 | w.mLastDsDy = w.mDsDy; |
| 11012 | w.mLastDtDy = w.mDtDy; |
| 11013 | w.mLastHScale = w.mHScale; |
| 11014 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 11015 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 11016 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11017 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 11018 | + "," + (w.mDtDx*w.mVScale) |
| 11019 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 11020 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11021 | if (w.mSurface != null) { |
| 11022 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11023 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11024 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11025 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11026 | w.mSurface.setLayer(w.mAnimLayer); |
| 11027 | w.mSurface.setMatrix( |
| 11028 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 11029 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 11030 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11031 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11032 | if (!recoveringMemory) { |
| 11033 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 11034 | } |
| 11035 | } |
| 11036 | } |
| 11037 | |
| 11038 | if (w.mLastHidden && !w.mDrawPending |
| 11039 | && !w.mCommitDrawPending |
| 11040 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 11041 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 11042 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11043 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11044 | + " during relayout"); |
| 11045 | if (showSurfaceRobustlyLocked(w)) { |
| 11046 | w.mHasDrawn = true; |
| 11047 | w.mLastHidden = false; |
| 11048 | } else { |
| 11049 | w.mOrientationChanging = false; |
| 11050 | } |
| 11051 | } |
| 11052 | if (w.mSurface != null) { |
| 11053 | w.mToken.hasVisible = true; |
| 11054 | } |
| 11055 | } else { |
| 11056 | displayed = true; |
| 11057 | } |
| 11058 | |
| 11059 | if (displayed) { |
| 11060 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 11061 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 11062 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11063 | covered = true; |
| 11064 | } |
| 11065 | } |
| 11066 | if (w.mOrientationChanging) { |
| 11067 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 11068 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11069 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11070 | "Orientation continue waiting for draw in " + w); |
| 11071 | } else { |
| 11072 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11073 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11074 | "Orientation change complete in " + w); |
| 11075 | } |
| 11076 | } |
| 11077 | w.mToken.hasVisible = true; |
| 11078 | } |
| 11079 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11080 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11081 | "Orientation change skips hidden " + w); |
| 11082 | w.mOrientationChanging = false; |
| 11083 | } |
| 11084 | |
| 11085 | final boolean canBeSeen = w.isDisplayedLw(); |
| 11086 | |
| 11087 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 11088 | focusDisplayed = true; |
| 11089 | } |
| 11090 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 11091 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11092 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11093 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11094 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11095 | if (w.mSurface != null) { |
| 11096 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 11097 | holdScreen = w.mSession; |
| 11098 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 11099 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 11100 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11101 | screenBrightness = w.mAttrs.screenBrightness; |
| 11102 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 11103 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 11104 | && buttonBrightness < 0) { |
| 11105 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 11106 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 11107 | if (canBeSeen |
| 11108 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 11109 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 11110 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 11111 | syswin = true; |
| 11112 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11113 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11114 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 11115 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 11116 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11117 | // This window completely covers everything behind it, |
| 11118 | // so we want to leave all of them as unblurred (for |
| 11119 | // performance reasons). |
| 11120 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11121 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11122 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11123 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11124 | obscured = true; |
| 11125 | if (mBackgroundFillerSurface == null) { |
| 11126 | try { |
| 11127 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11128 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11129 | 0, dw, dh, |
| 11130 | PixelFormat.OPAQUE, |
| 11131 | Surface.FX_SURFACE_NORMAL); |
| 11132 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11133 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11134 | } |
| 11135 | } |
| 11136 | try { |
| 11137 | mBackgroundFillerSurface.setPosition(0, 0); |
| 11138 | mBackgroundFillerSurface.setSize(dw, dh); |
| 11139 | // Using the same layer as Dim because they will never be shown at the |
| 11140 | // same time. |
| 11141 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 11142 | mBackgroundFillerSurface.show(); |
| 11143 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11144 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11145 | } |
| 11146 | backgroundFillerShown = true; |
| 11147 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11148 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11149 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11150 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11151 | + ": blurring=" + blurring |
| 11152 | + " obscured=" + obscured |
| 11153 | + " displayed=" + displayed); |
| 11154 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 11155 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11156 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11157 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11158 | if (mDimAnimator == null) { |
| 11159 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11160 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11161 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11162 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11163 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11164 | } |
| 11165 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 11166 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11167 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11168 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11169 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11170 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11171 | + mBlurSurface + ": CREATE"); |
| 11172 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11173 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11174 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11175 | -1, 16, 16, |
| 11176 | PixelFormat.OPAQUE, |
| 11177 | Surface.FX_SURFACE_BLUR); |
| 11178 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11179 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11180 | } |
| 11181 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11182 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11183 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 11184 | + mBlurSurface + ": pos=(0,0) (" + |
| 11185 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11186 | mBlurSurface.setPosition(0, 0); |
| 11187 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11188 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 11189 | if (!mBlurShown) { |
| 11190 | try { |
| 11191 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 11192 | + mBlurSurface + ": SHOW"); |
| 11193 | mBlurSurface.show(); |
| 11194 | } catch (RuntimeException e) { |
| 11195 | Slog.w(TAG, "Failure showing blur surface", e); |
| 11196 | } |
| 11197 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11198 | } |
| 11199 | } |
| 11200 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11201 | } |
| 11202 | } |
| 11203 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11204 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 11205 | if (obscuredChanged && mWallpaperTarget == w) { |
| 11206 | // This is the wallpaper target and its obscured state |
| 11207 | // changed... make sure the current wallaper's visibility |
| 11208 | // has been updated accordingly. |
| 11209 | updateWallpaperVisibilityLocked(); |
| 11210 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11211 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11212 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11213 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 11214 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11215 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11216 | try { |
| 11217 | mBackgroundFillerSurface.hide(); |
| 11218 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11219 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11220 | } |
| 11221 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11222 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11223 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 11224 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 11225 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11228 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11229 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11230 | + ": HIDE"); |
| 11231 | try { |
| 11232 | mBlurSurface.hide(); |
| 11233 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11234 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11235 | } |
| 11236 | mBlurShown = false; |
| 11237 | } |
| 11238 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11239 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11240 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11241 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11242 | } |
| 11243 | |
| 11244 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11245 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11246 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11247 | "With display frozen, orientationChangeComplete=" |
| 11248 | + orientationChangeComplete); |
| 11249 | if (orientationChangeComplete) { |
| 11250 | if (mWindowsFreezingScreen) { |
| 11251 | mWindowsFreezingScreen = false; |
| 11252 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 11253 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11254 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11255 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11257 | i = mResizingWindows.size(); |
| 11258 | if (i > 0) { |
| 11259 | do { |
| 11260 | i--; |
| 11261 | WindowState win = mResizingWindows.get(i); |
| 11262 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 11263 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 11264 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11265 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11266 | boolean configChanged = |
| 11267 | win.mConfiguration != mCurConfiguration |
| 11268 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11269 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 11270 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 11271 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11272 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11273 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11274 | + " / " + mCurConfiguration + " / 0x" |
| 11275 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11276 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11277 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11278 | win.mClient.resized(win.mFrame.width(), |
| 11279 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11280 | win.mLastVisibleInsets, win.mDrawPending, |
| 11281 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11282 | win.mContentInsetsChanged = false; |
| 11283 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 11284 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11285 | } catch (RemoteException e) { |
| 11286 | win.mOrientationChanging = false; |
| 11287 | } |
| 11288 | } while (i > 0); |
| 11289 | mResizingWindows.clear(); |
| 11290 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11292 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11293 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11294 | i = mDestroySurface.size(); |
| 11295 | if (i > 0) { |
| 11296 | do { |
| 11297 | i--; |
| 11298 | WindowState win = mDestroySurface.get(i); |
| 11299 | win.mDestroying = false; |
| 11300 | if (mInputMethodWindow == win) { |
| 11301 | mInputMethodWindow = null; |
| 11302 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11303 | if (win == mWallpaperTarget) { |
| 11304 | wallpaperDestroyed = true; |
| 11305 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11306 | win.destroySurfaceLocked(); |
| 11307 | } while (i > 0); |
| 11308 | mDestroySurface.clear(); |
| 11309 | } |
| 11310 | |
| 11311 | // Time to remove any exiting tokens? |
| 11312 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 11313 | WindowToken token = mExitingTokens.get(i); |
| 11314 | if (!token.hasVisible) { |
| 11315 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11316 | if (token.windowType == TYPE_WALLPAPER) { |
| 11317 | mWallpaperTokens.remove(token); |
| 11318 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11319 | } |
| 11320 | } |
| 11321 | |
| 11322 | // Time to remove any exiting applications? |
| 11323 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11324 | AppWindowToken token = mExitingAppTokens.get(i); |
| 11325 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 11326 | // Make sure there is no animation running on this token, |
| 11327 | // so any windows associated with it will be removed as |
| 11328 | // soon as their animations are complete |
| 11329 | token.animation = null; |
| 11330 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11331 | mAppTokens.remove(token); |
| 11332 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11333 | if (mLastEnterAnimToken == token) { |
| 11334 | mLastEnterAnimToken = null; |
| 11335 | mLastEnterAnimParams = null; |
| 11336 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11337 | } |
| 11338 | } |
| 11339 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11340 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11341 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11342 | if (!animating && mAppTransitionRunning) { |
| 11343 | // We have finished the animation of an app transition. To do |
| 11344 | // this, we have delayed a lot of operations like showing and |
| 11345 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 11346 | // reflects the correct Z-order, but the window list may now |
| 11347 | // be out of sync with it. So here we will just rebuild the |
| 11348 | // entire app window list. Fun! |
| 11349 | mAppTransitionRunning = false; |
| 11350 | needRelayout = true; |
| 11351 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11352 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11353 | // Clear information about apps that were moving. |
| 11354 | mToBottomApps.clear(); |
| 11355 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11356 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11357 | if (focusDisplayed) { |
| 11358 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 11359 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11360 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11361 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11362 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11363 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11364 | requestAnimationLocked(0); |
| 11365 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11366 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 11367 | } |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11368 | |
| 11369 | if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen |
| 11370 | + " holdScreen=" + holdScreen); |
| 11371 | if (!mDisplayFrozen) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11372 | setHoldScreenLocked(holdScreen != null); |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11373 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 11374 | mPowerManager.setScreenBrightnessOverride(-1); |
| 11375 | } else { |
| 11376 | mPowerManager.setScreenBrightnessOverride((int) |
| 11377 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 11378 | } |
| 11379 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 11380 | mPowerManager.setButtonBrightnessOverride(-1); |
| 11381 | } else { |
| 11382 | mPowerManager.setButtonBrightnessOverride((int) |
| 11383 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 11384 | } |
| 11385 | if (holdScreen != mHoldingScreenOn) { |
| 11386 | mHoldingScreenOn = holdScreen; |
| 11387 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 11388 | mH.sendMessage(m); |
| 11389 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11390 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11391 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11392 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11393 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11394 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 11395 | LocalPowerManager.BUTTON_EVENT, true); |
| 11396 | mTurnOnScreen = false; |
| 11397 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 11398 | |
| 11399 | // Check to see if we are now in a state where the screen should |
| 11400 | // be enabled, because the window obscured flags have changed. |
| 11401 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11402 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11403 | |
| 11404 | /** |
| 11405 | * Must be called with the main window manager lock held. |
| 11406 | */ |
| 11407 | void setHoldScreenLocked(boolean holding) { |
| 11408 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 11409 | if (holding != state) { |
| 11410 | if (holding) { |
| 11411 | mHoldingScreenWakeLock.acquire(); |
| 11412 | } else { |
| 11413 | mPolicy.screenOnStoppedLw(); |
| 11414 | mHoldingScreenWakeLock.release(); |
| 11415 | } |
| 11416 | } |
| 11417 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11418 | |
| 11419 | void requestAnimationLocked(long delay) { |
| 11420 | if (!mAnimationPending) { |
| 11421 | mAnimationPending = true; |
| 11422 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 11423 | } |
| 11424 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11426 | /** |
| 11427 | * Have the surface flinger show a surface, robustly dealing with |
| 11428 | * error conditions. In particular, if there is not enough memory |
| 11429 | * to show the surface, then we will try to get rid of other surfaces |
| 11430 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11431 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11432 | * @return Returns true if the surface was successfully shown. |
| 11433 | */ |
| 11434 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 11435 | try { |
| 11436 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11437 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11438 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11439 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11440 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 11441 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11442 | win.mTurnOnScreen = false; |
| 11443 | mTurnOnScreen = true; |
| 11444 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11445 | } |
| 11446 | return true; |
| 11447 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11448 | Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11449 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11451 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11453 | return false; |
| 11454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11456 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 11457 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11458 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11459 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11460 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11462 | if (mForceRemoves == null) { |
| 11463 | mForceRemoves = new ArrayList<WindowState>(); |
| 11464 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11466 | long callingIdentity = Binder.clearCallingIdentity(); |
| 11467 | try { |
| 11468 | // There was some problem... first, do a sanity check of the |
| 11469 | // window list to make sure we haven't left any dangling surfaces |
| 11470 | // around. |
| 11471 | int N = mWindows.size(); |
| 11472 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11473 | 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] | 11474 | for (int i=0; i<N; i++) { |
| 11475 | WindowState ws = (WindowState)mWindows.get(i); |
| 11476 | if (ws.mSurface != null) { |
| 11477 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11478 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11479 | + ws + " surface=" + ws.mSurface |
| 11480 | + " token=" + win.mToken |
| 11481 | + " pid=" + ws.mSession.mPid |
| 11482 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11483 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11484 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11485 | ws.mSurface = null; |
| 11486 | mForceRemoves.add(ws); |
| 11487 | i--; |
| 11488 | N--; |
| 11489 | leakedSurface = true; |
| 11490 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11491 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11492 | + ws + " surface=" + ws.mSurface |
| 11493 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11494 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11495 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11496 | ws.mSurface = null; |
| 11497 | leakedSurface = true; |
| 11498 | } |
| 11499 | } |
| 11500 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11502 | boolean killedApps = false; |
| 11503 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11504 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11505 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 11506 | for (int i=0; i<N; i++) { |
| 11507 | WindowState ws = (WindowState)mWindows.get(i); |
| 11508 | if (ws.mSurface != null) { |
| 11509 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 11510 | } |
| 11511 | } |
| 11512 | if (pidCandidates.size() > 0) { |
| 11513 | int[] pids = new int[pidCandidates.size()]; |
| 11514 | for (int i=0; i<pids.length; i++) { |
| 11515 | pids[i] = pidCandidates.keyAt(i); |
| 11516 | } |
| 11517 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 11518 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11519 | killedApps = true; |
| 11520 | } |
| 11521 | } catch (RemoteException e) { |
| 11522 | } |
| 11523 | } |
| 11524 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11526 | if (leakedSurface || killedApps) { |
| 11527 | // We managed to reclaim some memory, so get rid of the trouble |
| 11528 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11529 | 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] | 11530 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11531 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11532 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11533 | win.mSurface = null; |
| 11534 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11536 | try { |
| 11537 | win.mClient.dispatchGetNewSurface(); |
| 11538 | } catch (RemoteException e) { |
| 11539 | } |
| 11540 | } |
| 11541 | } finally { |
| 11542 | Binder.restoreCallingIdentity(callingIdentity); |
| 11543 | } |
| 11544 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11545 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11546 | private boolean updateFocusedWindowLocked(int mode) { |
| 11547 | WindowState newFocus = computeFocusedWindowLocked(); |
| 11548 | if (mCurrentFocus != newFocus) { |
| 11549 | // This check makes sure that we don't already have the focus |
| 11550 | // change message pending. |
| 11551 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 11552 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11553 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11554 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 11555 | final WindowState oldFocus = mCurrentFocus; |
| 11556 | mCurrentFocus = newFocus; |
| 11557 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11559 | final WindowState imWindow = mInputMethodWindow; |
| 11560 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11561 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11562 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11563 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 11564 | mLayoutNeeded = true; |
| 11565 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11566 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 11567 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11568 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 11569 | // Client will do the layout, but we need to assign layers |
| 11570 | // for handleNewWindowLocked() below. |
| 11571 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11572 | } |
| 11573 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11574 | |
| 11575 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 11576 | // If we defer assigning layers, then the caller is responsible for |
| 11577 | // doing this part. |
| 11578 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11579 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11580 | return true; |
| 11581 | } |
| 11582 | return false; |
| 11583 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11584 | |
| 11585 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
| 11586 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 11587 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
| 11588 | } else { |
| 11589 | if (mCurrentFocus != null) { |
| 11590 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 11591 | } |
| 11592 | } |
| 11593 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11594 | |
| 11595 | private WindowState computeFocusedWindowLocked() { |
| 11596 | WindowState result = null; |
| 11597 | WindowState win; |
| 11598 | |
| 11599 | int i = mWindows.size() - 1; |
| 11600 | int nextAppIndex = mAppTokens.size()-1; |
| 11601 | WindowToken nextApp = nextAppIndex >= 0 |
| 11602 | ? mAppTokens.get(nextAppIndex) : null; |
| 11603 | |
| 11604 | while (i >= 0) { |
| 11605 | win = (WindowState)mWindows.get(i); |
| 11606 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11607 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11608 | TAG, "Looking for focus: " + i |
| 11609 | + " = " + win |
| 11610 | + ", flags=" + win.mAttrs.flags |
| 11611 | + ", canReceive=" + win.canReceiveKeys()); |
| 11612 | |
| 11613 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11615 | // If this window's application has been removed, just skip it. |
| 11616 | if (thisApp != null && thisApp.removed) { |
| 11617 | i--; |
| 11618 | continue; |
| 11619 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11621 | // If there is a focused app, don't allow focus to go to any |
| 11622 | // windows below it. If this is an application window, step |
| 11623 | // through the app tokens until we find its app. |
| 11624 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11625 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11626 | int origAppIndex = nextAppIndex; |
| 11627 | while (nextAppIndex > 0) { |
| 11628 | if (nextApp == mFocusedApp) { |
| 11629 | // Whoops, we are below the focused app... no focus |
| 11630 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11631 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11632 | TAG, "Reached focused app: " + mFocusedApp); |
| 11633 | return null; |
| 11634 | } |
| 11635 | nextAppIndex--; |
| 11636 | nextApp = mAppTokens.get(nextAppIndex); |
| 11637 | if (nextApp == thisApp) { |
| 11638 | break; |
| 11639 | } |
| 11640 | } |
| 11641 | if (thisApp != nextApp) { |
| 11642 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11643 | // happen, but if it does we can get totally hosed... |
| 11644 | // so restart at the original app. |
| 11645 | nextAppIndex = origAppIndex; |
| 11646 | nextApp = mAppTokens.get(nextAppIndex); |
| 11647 | } |
| 11648 | } |
| 11649 | |
| 11650 | // Dispatch to this window if it is wants key events. |
| 11651 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11652 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11653 | TAG, "Found focus @ " + i + " = " + win); |
| 11654 | result = win; |
| 11655 | break; |
| 11656 | } |
| 11657 | |
| 11658 | i--; |
| 11659 | } |
| 11660 | |
| 11661 | return result; |
| 11662 | } |
| 11663 | |
| 11664 | private void startFreezingDisplayLocked() { |
| 11665 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11666 | // Freezing the display also suspends key event delivery, to |
| 11667 | // keep events from going astray while the display is reconfigured. |
| 11668 | // If someone has changed orientation again while the screen is |
| 11669 | // still frozen, the events will continue to be blocked while the |
| 11670 | // successive orientation change is processed. To prevent spurious |
| 11671 | // ANRs, we reset the event dispatch timeout in this case. |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11672 | if (! ENABLE_NATIVE_INPUT_DISPATCH) { |
| 11673 | synchronized (mKeyWaiter) { |
| 11674 | mKeyWaiter.mWasFrozen = true; |
| 11675 | } |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11676 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11677 | return; |
| 11678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11680 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11681 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11682 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11683 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11684 | if (mFreezeGcPending != 0) { |
| 11685 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11686 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11687 | mH.removeMessages(H.FORCE_GC); |
| 11688 | Runtime.getRuntime().gc(); |
| 11689 | mFreezeGcPending = now; |
| 11690 | } |
| 11691 | } else { |
| 11692 | mFreezeGcPending = now; |
| 11693 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11694 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11695 | if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException()); |
| 11696 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11697 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11698 | |
| 11699 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 11700 | mInputMonitor.freezeInputDispatchingLw(); |
| 11701 | } |
| 11702 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11703 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11704 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11705 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11706 | mAppTransitionReady = true; |
| 11707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11709 | if (PROFILE_ORIENTATION) { |
| 11710 | File file = new File("/data/system/frozen"); |
| 11711 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11712 | } |
| 11713 | Surface.freezeDisplay(0); |
| 11714 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11715 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11716 | private void stopFreezingDisplayLocked() { |
| 11717 | if (!mDisplayFrozen) { |
| 11718 | return; |
| 11719 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11720 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11721 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11722 | return; |
| 11723 | } |
| 11724 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11725 | if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException()); |
| 11726 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11727 | mDisplayFrozen = false; |
| 11728 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11729 | if (PROFILE_ORIENTATION) { |
| 11730 | Debug.stopMethodTracing(); |
| 11731 | } |
| 11732 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11733 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11734 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 11735 | // too because regular key delivery processing should resume immediately. |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11736 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 11737 | mInputMonitor.thawInputDispatchingLw(); |
| 11738 | } else { |
| 11739 | synchronized (mKeyWaiter) { |
| 11740 | mKeyWaiter.mWasFrozen = true; |
| 11741 | mKeyWaiter.notifyAll(); |
| 11742 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11743 | } |
| 11744 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11745 | // While the display is frozen we don't re-compute the orientation |
| 11746 | // to avoid inconsistent states. However, something interesting |
| 11747 | // could have actually changed during that time so re-evaluate it |
| 11748 | // now to catch that. |
| 11749 | if (updateOrientationFromAppTokensLocked()) { |
| 11750 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 11751 | } |
| 11752 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11753 | // A little kludge: a lot could have happened while the |
| 11754 | // display was frozen, so now that we are coming back we |
| 11755 | // do a gc so that any remote references the system |
| 11756 | // processes holds on others can be released if they are |
| 11757 | // no longer needed. |
| 11758 | mH.removeMessages(H.FORCE_GC); |
| 11759 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11760 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11762 | mScreenFrozenLock.release(); |
| 11763 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11764 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11765 | @Override |
| 11766 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11767 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11768 | != PackageManager.PERMISSION_GRANTED) { |
| 11769 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11770 | + Binder.getCallingPid() |
| 11771 | + ", uid=" + Binder.getCallingUid()); |
| 11772 | return; |
| 11773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11774 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11775 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 11776 | pw.println("Input Dispatcher State:"); |
| 11777 | mInputManager.dump(pw); |
| 11778 | } else { |
| 11779 | pw.println("Input State:"); |
| 11780 | mQueue.dump(pw, " "); |
| 11781 | } |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11782 | pw.println(" "); |
| 11783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11784 | synchronized(mWindowMap) { |
| 11785 | pw.println("Current Window Manager state:"); |
| 11786 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 11787 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11788 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11789 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11790 | w.dump(pw, " "); |
| 11791 | } |
| 11792 | if (mInputMethodDialogs.size() > 0) { |
| 11793 | pw.println(" "); |
| 11794 | pw.println(" Input method dialogs:"); |
| 11795 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11796 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11797 | 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] | 11798 | } |
| 11799 | } |
| 11800 | if (mPendingRemove.size() > 0) { |
| 11801 | pw.println(" "); |
| 11802 | pw.println(" Remove pending for:"); |
| 11803 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11804 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11805 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11806 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11807 | w.dump(pw, " "); |
| 11808 | } |
| 11809 | } |
| 11810 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11811 | pw.println(" "); |
| 11812 | pw.println(" Windows force removing:"); |
| 11813 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11814 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11815 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11816 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11817 | w.dump(pw, " "); |
| 11818 | } |
| 11819 | } |
| 11820 | if (mDestroySurface.size() > 0) { |
| 11821 | pw.println(" "); |
| 11822 | pw.println(" Windows waiting to destroy their surface:"); |
| 11823 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11824 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11825 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11826 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11827 | w.dump(pw, " "); |
| 11828 | } |
| 11829 | } |
| 11830 | if (mLosingFocus.size() > 0) { |
| 11831 | pw.println(" "); |
| 11832 | pw.println(" Windows losing focus:"); |
| 11833 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11834 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11835 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11836 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11837 | w.dump(pw, " "); |
| 11838 | } |
| 11839 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11840 | if (mResizingWindows.size() > 0) { |
| 11841 | pw.println(" "); |
| 11842 | pw.println(" Windows waiting to resize:"); |
| 11843 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11844 | WindowState w = mResizingWindows.get(i); |
| 11845 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11846 | pw.print(w); pw.println(":"); |
| 11847 | w.dump(pw, " "); |
| 11848 | } |
| 11849 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11850 | if (mSessions.size() > 0) { |
| 11851 | pw.println(" "); |
| 11852 | pw.println(" All active sessions:"); |
| 11853 | Iterator<Session> it = mSessions.iterator(); |
| 11854 | while (it.hasNext()) { |
| 11855 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11856 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11857 | s.dump(pw, " "); |
| 11858 | } |
| 11859 | } |
| 11860 | if (mTokenMap.size() > 0) { |
| 11861 | pw.println(" "); |
| 11862 | pw.println(" All tokens:"); |
| 11863 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11864 | while (it.hasNext()) { |
| 11865 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11866 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11867 | token.dump(pw, " "); |
| 11868 | } |
| 11869 | } |
| 11870 | if (mTokenList.size() > 0) { |
| 11871 | pw.println(" "); |
| 11872 | pw.println(" Window token list:"); |
| 11873 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11874 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 11875 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11876 | } |
| 11877 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11878 | if (mWallpaperTokens.size() > 0) { |
| 11879 | pw.println(" "); |
| 11880 | pw.println(" Wallpaper tokens:"); |
| 11881 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11882 | WindowToken token = mWallpaperTokens.get(i); |
| 11883 | pw.print(" Wallpaper #"); pw.print(i); |
| 11884 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11885 | token.dump(pw, " "); |
| 11886 | } |
| 11887 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11888 | if (mAppTokens.size() > 0) { |
| 11889 | pw.println(" "); |
| 11890 | pw.println(" Application tokens in Z order:"); |
| 11891 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11892 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11893 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11894 | } |
| 11895 | } |
| 11896 | if (mFinishedStarting.size() > 0) { |
| 11897 | pw.println(" "); |
| 11898 | pw.println(" Finishing start of application tokens:"); |
| 11899 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11900 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11901 | pw.print(" Finished Starting #"); pw.print(i); |
| 11902 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11903 | token.dump(pw, " "); |
| 11904 | } |
| 11905 | } |
| 11906 | if (mExitingTokens.size() > 0) { |
| 11907 | pw.println(" "); |
| 11908 | pw.println(" Exiting tokens:"); |
| 11909 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11910 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11911 | pw.print(" Exiting #"); pw.print(i); |
| 11912 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11913 | token.dump(pw, " "); |
| 11914 | } |
| 11915 | } |
| 11916 | if (mExitingAppTokens.size() > 0) { |
| 11917 | pw.println(" "); |
| 11918 | pw.println(" Exiting application tokens:"); |
| 11919 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11920 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11921 | pw.print(" Exiting App #"); pw.print(i); |
| 11922 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11923 | token.dump(pw, " "); |
| 11924 | } |
| 11925 | } |
| 11926 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11927 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11928 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11929 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11930 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11931 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11932 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11933 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11934 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11935 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11936 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11937 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11938 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11939 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11940 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11941 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11942 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11943 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11944 | if (mDimAnimator != null) { |
| 11945 | mDimAnimator.printTo(pw); |
| 11946 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11947 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11948 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11949 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11950 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11951 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11952 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11953 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11954 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11955 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11956 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11957 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11958 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11959 | pw.print(" mRotation="); pw.print(mRotation); |
| 11960 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11961 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11962 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11963 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11964 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11965 | pw.print(" mNextAppTransition=0x"); |
| 11966 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11967 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11968 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11969 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11970 | if (mNextAppTransitionPackage != null) { |
| 11971 | pw.print(" mNextAppTransitionPackage="); |
| 11972 | pw.print(mNextAppTransitionPackage); |
| 11973 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11974 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11975 | pw.print(", mNextAppTransitionExit=0x"); |
| 11976 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11977 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11978 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11979 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11980 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11981 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11982 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11983 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11984 | if (mOpeningApps.size() > 0) { |
| 11985 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11986 | } |
| 11987 | if (mClosingApps.size() > 0) { |
| 11988 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11989 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11990 | if (mToTopApps.size() > 0) { |
| 11991 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11992 | } |
| 11993 | if (mToBottomApps.size() > 0) { |
| 11994 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11995 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11996 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11997 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11998 | |
| 11999 | if (! ENABLE_NATIVE_INPUT_DISPATCH) { |
| 12000 | pw.println(" KeyWaiter state:"); |
| 12001 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 12002 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 12003 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 12004 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 12005 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 12006 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| 12007 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12008 | } |
| 12009 | } |
| 12010 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 12011 | // 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] | 12012 | public void monitor() { |
| 12013 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 12014 | synchronized (mKeyguardTokenWatcher) { } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12015 | synchronized (mKeyWaiter) { } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 12016 | synchronized (mInputMonitor) { } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12017 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12018 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 12019 | public void virtualKeyFeedback(KeyEvent event) { |
| 12020 | mPolicy.keyFeedbackFromInput(event); |
| 12021 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 12022 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12023 | /** |
| 12024 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 12025 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12026 | */ |
| 12027 | private static class DimAnimator { |
| 12028 | Surface mDimSurface; |
| 12029 | boolean mDimShown = false; |
| 12030 | float mDimCurrentAlpha; |
| 12031 | float mDimTargetAlpha; |
| 12032 | float mDimDeltaPerMs; |
| 12033 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 12034 | |
| 12035 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12036 | |
| 12037 | DimAnimator (SurfaceSession session) { |
| 12038 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12039 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12040 | + mDimSurface + ": CREATE"); |
| 12041 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 12042 | mDimSurface = new Surface(session, 0, |
| 12043 | "DimSurface", |
| 12044 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12045 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 12046 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12047 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12048 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12049 | } |
| 12050 | } |
| 12051 | } |
| 12052 | |
| 12053 | /** |
| 12054 | * Show the dim surface. |
| 12055 | */ |
| 12056 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 12057 | if (!mDimShown) { |
| 12058 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 12059 | dw + "x" + dh + ")"); |
| 12060 | mDimShown = true; |
| 12061 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 12062 | mLastDimWidth = dw; |
| 12063 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 12064 | mDimSurface.setPosition(0, 0); |
| 12065 | mDimSurface.setSize(dw, dh); |
| 12066 | mDimSurface.show(); |
| 12067 | } catch (RuntimeException e) { |
| 12068 | Slog.w(TAG, "Failure showing dim surface", e); |
| 12069 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 12070 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 12071 | mLastDimWidth = dw; |
| 12072 | mLastDimHeight = dh; |
| 12073 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12074 | } |
| 12075 | } |
| 12076 | |
| 12077 | /** |
| 12078 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 12079 | * {@link updateSurface} after all windows are examined. |
| 12080 | */ |
| 12081 | void updateParameters(WindowState w, long currentTime) { |
| 12082 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 12083 | |
| 12084 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12085 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 12086 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12087 | if (mDimTargetAlpha != target) { |
| 12088 | // If the desired dim level has changed, then |
| 12089 | // start an animation to it. |
| 12090 | mLastDimAnimTime = currentTime; |
| 12091 | long duration = (w.mAnimating && w.mAnimation != null) |
| 12092 | ? w.mAnimation.computeDurationHint() |
| 12093 | : DEFAULT_DIM_DURATION; |
| 12094 | if (target > mDimTargetAlpha) { |
| 12095 | // This is happening behind the activity UI, |
| 12096 | // so we can make it run a little longer to |
| 12097 | // give a stronger impression without disrupting |
| 12098 | // the user. |
| 12099 | duration *= DIM_DURATION_MULTIPLIER; |
| 12100 | } |
| 12101 | if (duration < 1) { |
| 12102 | // Don't divide by zero |
| 12103 | duration = 1; |
| 12104 | } |
| 12105 | mDimTargetAlpha = target; |
| 12106 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 12107 | } |
| 12108 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 12109 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12110 | /** |
| 12111 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 12112 | * false when the animation is finished and the dim surface is hidden. |
| 12113 | */ |
| 12114 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 12115 | if (!dimming) { |
| 12116 | if (mDimTargetAlpha != 0) { |
| 12117 | mLastDimAnimTime = currentTime; |
| 12118 | mDimTargetAlpha = 0; |
| 12119 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 12120 | } |
| 12121 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 12122 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12123 | boolean animating = false; |
| 12124 | if (mLastDimAnimTime != 0) { |
| 12125 | mDimCurrentAlpha += mDimDeltaPerMs |
| 12126 | * (currentTime-mLastDimAnimTime); |
| 12127 | boolean more = true; |
| 12128 | if (displayFrozen) { |
| 12129 | // If the display is frozen, there is no reason to animate. |
| 12130 | more = false; |
| 12131 | } else if (mDimDeltaPerMs > 0) { |
| 12132 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 12133 | more = false; |
| 12134 | } |
| 12135 | } else if (mDimDeltaPerMs < 0) { |
| 12136 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 12137 | more = false; |
| 12138 | } |
| 12139 | } else { |
| 12140 | more = false; |
| 12141 | } |
| 12142 | |
| 12143 | // Do we need to continue animating? |
| 12144 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12145 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12146 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 12147 | mLastDimAnimTime = currentTime; |
| 12148 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 12149 | animating = true; |
| 12150 | } else { |
| 12151 | mDimCurrentAlpha = mDimTargetAlpha; |
| 12152 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12153 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12154 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 12155 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 12156 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12157 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12158 | + ": HIDE"); |
| 12159 | try { |
| 12160 | mDimSurface.hide(); |
| 12161 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12162 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12163 | } |
| 12164 | mDimShown = false; |
| 12165 | } |
| 12166 | } |
| 12167 | } |
| 12168 | return animating; |
| 12169 | } |
| 12170 | |
| 12171 | public void printTo(PrintWriter pw) { |
| 12172 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 12173 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 12174 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 12175 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 12176 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 12177 | } |
| 12178 | } |
| 12179 | |
| 12180 | /** |
| 12181 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 12182 | * This is used for opening/closing transition for apps in compatible mode. |
| 12183 | */ |
| 12184 | private static class FadeInOutAnimation extends Animation { |
| 12185 | int mWidth; |
| 12186 | boolean mFadeIn; |
| 12187 | |
| 12188 | public FadeInOutAnimation(boolean fadeIn) { |
| 12189 | setInterpolator(new AccelerateInterpolator()); |
| 12190 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 12191 | mFadeIn = fadeIn; |
| 12192 | } |
| 12193 | |
| 12194 | @Override |
| 12195 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 12196 | float x = interpolatedTime; |
| 12197 | if (!mFadeIn) { |
| 12198 | x = 1.0f - x; // reverse the interpolation for fade out |
| 12199 | } |
| 12200 | if (x < 0.5) { |
| 12201 | // move the window out of the screen. |
| 12202 | t.getMatrix().setTranslate(mWidth, 0); |
| 12203 | } else { |
| 12204 | t.getMatrix().setTranslate(0, 0);// show |
| 12205 | t.setAlpha((x - 0.5f) * 2); |
| 12206 | } |
| 12207 | } |
| 12208 | |
| 12209 | @Override |
| 12210 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 12211 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 12212 | mWidth = width; |
| 12213 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12214 | |
| 12215 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 12216 | public int getZAdjustment() { |
| 12217 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12218 | } |
| 12219 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12220 | } |