| 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; |
| 106 | import android.view.InputTarget; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import android.view.KeyEvent; |
| 108 | import android.view.MotionEvent; |
| 109 | import android.view.RawInputEvent; |
| 110 | import android.view.Surface; |
| 111 | import android.view.SurfaceSession; |
| 112 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 113 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.view.ViewTreeObserver; |
| 115 | import android.view.WindowManager; |
| 116 | import android.view.WindowManagerImpl; |
| 117 | import android.view.WindowManagerPolicy; |
| 118 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 119 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import android.view.animation.Animation; |
| 121 | import android.view.animation.AnimationUtils; |
| 122 | import android.view.animation.Transformation; |
| 123 | |
| 124 | import java.io.BufferedWriter; |
| 125 | import java.io.File; |
| 126 | import java.io.FileDescriptor; |
| 127 | import java.io.IOException; |
| 128 | import java.io.OutputStream; |
| 129 | import java.io.OutputStreamWriter; |
| 130 | import java.io.PrintWriter; |
| 131 | import java.io.StringWriter; |
| 132 | import java.net.Socket; |
| 133 | import java.util.ArrayList; |
| 134 | import java.util.HashMap; |
| 135 | import java.util.HashSet; |
| 136 | import java.util.Iterator; |
| 137 | import java.util.List; |
| 138 | |
| 139 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 140 | public class WindowManagerService extends IWindowManager.Stub |
| 141 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | static final String TAG = "WindowManager"; |
| 143 | static final boolean DEBUG = false; |
| 144 | static final boolean DEBUG_FOCUS = false; |
| 145 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 146 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | static final boolean DEBUG_LAYERS = false; |
| 149 | static final boolean DEBUG_INPUT = false; |
| 150 | static final boolean DEBUG_INPUT_METHOD = false; |
| 151 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 152 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 154 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 156 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 157 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 158 | static final boolean DEBUG_WALLPAPER = false; |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 159 | static final boolean DEBUG_FREEZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 161 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 162 | static final boolean MEASURE_LATENCY = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 163 | static final boolean ENABLE_NATIVE_INPUT_DISPATCH = |
| 164 | WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 165 | static private LatencyTimer lt; |
| 166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | static final boolean PROFILE_ORIENTATION = false; |
| 168 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 169 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 172 | static final int KEY_REPEAT_DELAY = 50; |
| 173 | |
| 174 | /** How much to multiply the policy's type layer, to reserve room |
| 175 | * for multiple windows of the same type and Z-ordering adjustment |
| 176 | * with TYPE_LAYER_OFFSET. */ |
| 177 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 180 | * or below others in the same layer. */ |
| 181 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 182 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** How much to increment the layer for each window, to reserve room |
| 184 | * for effect surfaces between them. |
| 185 | */ |
| 186 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | /** The maximum length we will accept for a loaded animation duration: |
| 189 | * this is 10 seconds. |
| 190 | */ |
| 191 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 192 | |
| 193 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 194 | * value to another, when no window animation is driving it. |
| 195 | */ |
| 196 | static final int DEFAULT_DIM_DURATION = 200; |
| 197 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 198 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 199 | * compatible windows. |
| 200 | */ |
| 201 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 204 | */ |
| 205 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 206 | |
| 207 | // Maximum number of milliseconds to wait for input event injection. |
| 208 | // FIXME is this value reasonable? |
| 209 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 210 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 211 | static final int INJECT_FAILED = 0; |
| 212 | static final int INJECT_SUCCEEDED = 1; |
| 213 | static final int INJECT_NO_PERMISSION = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 214 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 216 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 217 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 218 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 219 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 220 | /** The minimum time between dispatching touch events. */ |
| 221 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 222 | |
| 223 | // Last touch event time |
| 224 | long mLastTouchEventTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 225 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 226 | // Last touch event type |
| 227 | int mLastTouchEventType = OTHER_EVENT; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 228 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 229 | // Time to wait before calling useractivity again. This saves CPU usage |
| 230 | // when we get a flood of touch events. |
| 231 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 232 | |
| 233 | // Last time we call user activity |
| 234 | long mLastUserActivityCallTime = 0; |
| 235 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 236 | // Last time we updated battery stats |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 237 | long mLastBatteryStatsCallTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 240 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 244 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 245 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 246 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 248 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 250 | private static final int ALLOW_DISABLE_YES = 1; |
| 251 | private static final int ALLOW_DISABLE_NO = 0; |
| 252 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 253 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 254 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 255 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 256 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 258 | if (shouldAllowDisableKeyguard()) { |
| 259 | mPolicy.enableKeyguard(false); |
| 260 | mKeyguardDisabled = true; |
| 261 | } else { |
| 262 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 263 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | } |
| 265 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 266 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 267 | synchronized (mKeyguardTokenWatcher) { |
| 268 | mKeyguardDisabled = false; |
| 269 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | }; |
| 273 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 274 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 275 | @Override |
| 276 | public void onReceive(Context context, Intent intent) { |
| 277 | mPolicy.enableKeyguard(true); |
| 278 | synchronized(mKeyguardTokenWatcher) { |
| 279 | // lazily evaluate this next time we're asked to disable keyguard |
| 280 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 281 | mKeyguardDisabled = false; |
| 282 | } |
| 283 | } |
| 284 | }; |
| 285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | final Context mContext; |
| 287 | |
| 288 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | final boolean mLimitedAlphaCompositing; |
| 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 WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 293 | |
| 294 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 295 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | final IBatteryStats mBatteryStats; |
| 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 | /** |
| 299 | * All currently active sessions with clients. |
| 300 | */ |
| 301 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | /** |
| 304 | * Mapping from an IWindow IBinder to the server's Window object. |
| 305 | * This is also used as the lock for all of our state. |
| 306 | */ |
| 307 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 308 | |
| 309 | /** |
| 310 | * Mapping from a token IBinder to a WindowToken object. |
| 311 | */ |
| 312 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 313 | new HashMap<IBinder, WindowToken>(); |
| 314 | |
| 315 | /** |
| 316 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 317 | * over them. |
| 318 | */ |
| 319 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | /** |
| 322 | * Window tokens that are in the process of exiting, but still |
| 323 | * on screen for animations. |
| 324 | */ |
| 325 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 326 | |
| 327 | /** |
| 328 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 329 | * controlling the ordering of windows in different applications. This |
| 330 | * contains WindowToken objects. |
| 331 | */ |
| 332 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 333 | |
| 334 | /** |
| 335 | * Application tokens that are in the process of exiting, but still |
| 336 | * on screen for animations. |
| 337 | */ |
| 338 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 339 | |
| 340 | /** |
| 341 | * List of window tokens that have finished starting their application, |
| 342 | * and now need to have the policy remove their windows. |
| 343 | */ |
| 344 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 345 | |
| 346 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 347 | * This was the app token that was used to retrieve the last enter |
| 348 | * animation. It will be used for the next exit animation. |
| 349 | */ |
| 350 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 351 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 352 | /** |
| 353 | * These were the layout params used to retrieve the last enter animation. |
| 354 | * They will be used for the next exit animation. |
| 355 | */ |
| 356 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 357 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 358 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | * Z-ordered (bottom-most first) list of all Window objects. |
| 360 | */ |
| 361 | final ArrayList mWindows = new ArrayList(); |
| 362 | |
| 363 | /** |
| 364 | * Windows that are being resized. Used so we can tell the client about |
| 365 | * the resize after closing the transaction in which we resized the |
| 366 | * underlying surface. |
| 367 | */ |
| 368 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 369 | |
| 370 | /** |
| 371 | * Windows whose animations have ended and now must be removed. |
| 372 | */ |
| 373 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 374 | |
| 375 | /** |
| 376 | * Windows whose surface should be destroyed. |
| 377 | */ |
| 378 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 379 | |
| 380 | /** |
| 381 | * Windows that have lost input focus and are waiting for the new |
| 382 | * focus window to be displayed before they are told about this. |
| 383 | */ |
| 384 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 385 | |
| 386 | /** |
| 387 | * This is set when we have run out of memory, and will either be an empty |
| 388 | * list or contain windows that need to be force removed. |
| 389 | */ |
| 390 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 391 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | IInputMethodManager mInputMethodManager; |
| 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 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 395 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | Surface mBlurSurface; |
| 397 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 398 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | int mTransactionSequence = 0; |
| 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 | final float[] mTmpFloats = new float[9]; |
| 402 | |
| 403 | boolean mSafeMode; |
| 404 | boolean mDisplayEnabled = false; |
| 405 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 406 | int mInitialDisplayWidth = 0; |
| 407 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | int mRotation = 0; |
| 409 | int mRequestedRotation = 0; |
| 410 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 411 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | ArrayList<IRotationWatcher> mRotationWatchers |
| 413 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 414 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | boolean mLayoutNeeded = true; |
| 416 | boolean mAnimationPending = false; |
| 417 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 418 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | boolean mWindowsFreezingScreen = false; |
| 420 | long mFreezeGcPending = 0; |
| 421 | int mAppsFreezingScreen = 0; |
| 422 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 423 | int mLayoutSeq = 0; |
| 424 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 425 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 426 | boolean mFocusMayChange; |
| 427 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 428 | Configuration mCurConfiguration = new Configuration(); |
| 429 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | // This is held as long as we have the screen frozen, to give us time to |
| 431 | // perform a rotation animation when turning off shows the lock screen which |
| 432 | // changes the orientation. |
| 433 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | // State management of app transitions. When we are preparing for a |
| 436 | // transition, mNextAppTransition will be the kind of transition to |
| 437 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 438 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 439 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 440 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 441 | String mNextAppTransitionPackage; |
| 442 | int mNextAppTransitionEnter; |
| 443 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 445 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | boolean mAppTransitionTimeout = false; |
| 447 | boolean mStartingIconInTransition = false; |
| 448 | boolean mSkipAppTransitionAnimation = false; |
| 449 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 450 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 451 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 452 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 453 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | Display mDisplay; |
| 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 | H mH = new H(); |
| 457 | |
| 458 | WindowState mCurrentFocus = null; |
| 459 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 460 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | // This just indicates the window the input method is on top of, not |
| 462 | // necessarily the window its input is going to. |
| 463 | WindowState mInputMethodTarget = null; |
| 464 | WindowState mUpcomingInputMethodTarget = null; |
| 465 | boolean mInputMethodTargetWaitingAnim; |
| 466 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | WindowState mInputMethodWindow = null; |
| 469 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 470 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 471 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 472 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 473 | // If non-null, this is the currently visible window that is associated |
| 474 | // with the wallpaper. |
| 475 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 476 | // If non-null, we are in the middle of animating from one wallpaper target |
| 477 | // to another, and this is the lower one in Z-order. |
| 478 | WindowState mLowerWallpaperTarget = null; |
| 479 | // If non-null, we are in the middle of animating from one wallpaper target |
| 480 | // to another, and this is the higher one in Z-order. |
| 481 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 482 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 483 | float mLastWallpaperX = -1; |
| 484 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 485 | float mLastWallpaperXStep = -1; |
| 486 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 487 | boolean mSendingPointersToWallpaper = false; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 488 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 489 | // changing its scroll position. |
| 490 | WindowState mWaitingOnWallpaper; |
| 491 | // The last time we had a timeout when waiting for a wallpaper. |
| 492 | long mLastWallpaperTimeoutTime; |
| 493 | // We give a wallpaper up to 150ms to finish scrolling. |
| 494 | static final long WALLPAPER_TIMEOUT = 150; |
| 495 | // Time we wait after a timeout before trying to wait again. |
| 496 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 497 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | AppWindowToken mFocusedApp = null; |
| 499 | |
| 500 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | float mWindowAnimationScale = 1.0f; |
| 503 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 506 | final KeyQ mQueue; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 507 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | final InputDispatcherThread mInputThread; |
| 509 | |
| 510 | // Who is holding the screen on. |
| 511 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 512 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 513 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 514 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | /** |
| 517 | * Whether the UI is currently running in touch mode (not showing |
| 518 | * navigational focus because the user is directly pressing the screen). |
| 519 | */ |
| 520 | boolean mInTouchMode = false; |
| 521 | |
| 522 | private ViewServer mViewServer; |
| 523 | |
| 524 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 525 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 526 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 527 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 528 | |
| 529 | // The frame use to limit the size of the app running in compatibility mode. |
| 530 | Rect mCompatibleScreenFrame = new Rect(); |
| 531 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 532 | Surface mBackgroundFillerSurface = null; |
| 533 | boolean mBackgroundFillerShown = false; |
| 534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | public static WindowManagerService main(Context context, |
| 536 | PowerManagerService pm, boolean haveInputMethods) { |
| 537 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 538 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 539 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | synchronized (thr) { |
| 541 | while (thr.mService == null) { |
| 542 | try { |
| 543 | thr.wait(); |
| 544 | } catch (InterruptedException e) { |
| 545 | } |
| 546 | } |
| 547 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | return thr.mService; |
| 550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | static class WMThread extends Thread { |
| 553 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | private final Context mContext; |
| 556 | private final PowerManagerService mPM; |
| 557 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | public WMThread(Context context, PowerManagerService pm, |
| 560 | boolean haveInputMethods) { |
| 561 | super("WindowManager"); |
| 562 | mContext = context; |
| 563 | mPM = pm; |
| 564 | mHaveInputMethods = haveInputMethods; |
| 565 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 566 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | public void run() { |
| 568 | Looper.prepare(); |
| 569 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 570 | mHaveInputMethods); |
| 571 | android.os.Process.setThreadPriority( |
| 572 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | synchronized (this) { |
| 575 | mService = s; |
| 576 | notifyAll(); |
| 577 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | Looper.loop(); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | static class PolicyThread extends Thread { |
| 584 | private final WindowManagerPolicy mPolicy; |
| 585 | private final WindowManagerService mService; |
| 586 | private final Context mContext; |
| 587 | private final PowerManagerService mPM; |
| 588 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 589 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | public PolicyThread(WindowManagerPolicy policy, |
| 591 | WindowManagerService service, Context context, |
| 592 | PowerManagerService pm) { |
| 593 | super("WindowManagerPolicy"); |
| 594 | mPolicy = policy; |
| 595 | mService = service; |
| 596 | mContext = context; |
| 597 | mPM = pm; |
| 598 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 599 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | public void run() { |
| 601 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 602 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 605 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | android.os.Process.setThreadPriority( |
| 607 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 608 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 609 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | synchronized (this) { |
| 611 | mRunning = true; |
| 612 | notifyAll(); |
| 613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | Looper.loop(); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | private WindowManagerService(Context context, PowerManagerService pm, |
| 620 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 621 | if (MEASURE_LATENCY) { |
| 622 | lt = new LatencyTimer(100, 1000); |
| 623 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | mContext = context; |
| 626 | mHaveInputMethods = haveInputMethods; |
| 627 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 628 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 629 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | mPowerManager = pm; |
| 631 | mPowerManager.setPolicy(mPolicy); |
| 632 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 633 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 634 | "SCREEN_FROZEN"); |
| 635 | mScreenFrozenLock.setReferenceCounted(false); |
| 636 | |
| 637 | mActivityManager = ActivityManagerNative.getDefault(); |
| 638 | mBatteryStats = BatteryStatsService.getService(); |
| 639 | |
| 640 | // Get persisted window scale setting |
| 641 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 642 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 643 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 644 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 645 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 646 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 647 | IntentFilter filter = new IntentFilter(); |
| 648 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 649 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 650 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 651 | int max_events_per_sec = 35; |
| 652 | try { |
| 653 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 654 | .get("windowsmgr.max_events_per_sec")); |
| 655 | if (max_events_per_sec < 1) { |
| 656 | max_events_per_sec = 35; |
| 657 | } |
| 658 | } catch (NumberFormatException e) { |
| 659 | } |
| 660 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 661 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 662 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 663 | "KEEP_SCREEN_ON_FLAG"); |
| 664 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 666 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 667 | mInputManager = new InputManager(context, this, mPolicy, pmc, mPowerManager); |
| 668 | } else { |
| 669 | mInputManager = null; |
| 670 | } |
| 671 | mQueue = new KeyQ(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | mInputThread = new InputDispatcherThread(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 675 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 676 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | synchronized (thr) { |
| 678 | while (!thr.mRunning) { |
| 679 | try { |
| 680 | thr.wait(); |
| 681 | } catch (InterruptedException e) { |
| 682 | } |
| 683 | } |
| 684 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 685 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 686 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 687 | mInputManager.start(); |
| 688 | } else { |
| 689 | mInputThread.start(); |
| 690 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 691 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | // Add ourself to the Watchdog monitors. |
| 693 | Watchdog.getInstance().addMonitor(this); |
| 694 | } |
| 695 | |
| 696 | @Override |
| 697 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 698 | throws RemoteException { |
| 699 | try { |
| 700 | return super.onTransact(code, data, reply, flags); |
| 701 | } catch (RuntimeException e) { |
| 702 | // The window manager only throws security exceptions, so let's |
| 703 | // log all others. |
| 704 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 705 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | } |
| 707 | throw e; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | private void placeWindowAfter(Object pos, WindowState window) { |
| 712 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 713 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | TAG, "Adding window " + window + " at " |
| 715 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 716 | mWindows.add(i+1, window); |
| 717 | } |
| 718 | |
| 719 | private void placeWindowBefore(Object pos, WindowState window) { |
| 720 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 721 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | TAG, "Adding window " + window + " at " |
| 723 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 724 | mWindows.add(i, window); |
| 725 | } |
| 726 | |
| 727 | //This method finds out the index of a window that has the same app token as |
| 728 | //win. used for z ordering the windows in mWindows |
| 729 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 730 | //use a local variable to cache mWindows |
| 731 | ArrayList localmWindows = mWindows; |
| 732 | int jmax = localmWindows.size(); |
| 733 | if(jmax == 0) { |
| 734 | return -1; |
| 735 | } |
| 736 | for(int j = (jmax-1); j >= 0; j--) { |
| 737 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 738 | if(wentry.mAppToken == win.mAppToken) { |
| 739 | return j; |
| 740 | } |
| 741 | } |
| 742 | return -1; |
| 743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 746 | final IWindow client = win.mClient; |
| 747 | final WindowToken token = win.mToken; |
| 748 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | final int N = localmWindows.size(); |
| 751 | final WindowState attached = win.mAttachedWindow; |
| 752 | int i; |
| 753 | if (attached == null) { |
| 754 | int tokenWindowsPos = token.windows.size(); |
| 755 | if (token.appWindowToken != null) { |
| 756 | int index = tokenWindowsPos-1; |
| 757 | if (index >= 0) { |
| 758 | // If this application has existing windows, we |
| 759 | // simply place the new window on top of them... but |
| 760 | // keep the starting window on top. |
| 761 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 762 | // Base windows go behind everything else. |
| 763 | placeWindowBefore(token.windows.get(0), win); |
| 764 | tokenWindowsPos = 0; |
| 765 | } else { |
| 766 | AppWindowToken atoken = win.mAppToken; |
| 767 | if (atoken != null && |
| 768 | token.windows.get(index) == atoken.startingWindow) { |
| 769 | placeWindowBefore(token.windows.get(index), win); |
| 770 | tokenWindowsPos--; |
| 771 | } else { |
| 772 | int newIdx = findIdxBasedOnAppTokens(win); |
| 773 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 774 | //there is a window above this one associated with the same |
| 775 | //apptoken note that the window could be a floating window |
| 776 | //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] | 777 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 778 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 779 | TAG, "Adding window " + win + " at " |
| 780 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | localmWindows.add(newIdx+1, win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 782 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 786 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | TAG, "Figuring out where to add app window " |
| 788 | + client.asBinder() + " (token=" + token + ")"); |
| 789 | // Figure out where the window should go, based on the |
| 790 | // order of applications. |
| 791 | final int NA = mAppTokens.size(); |
| 792 | Object pos = null; |
| 793 | for (i=NA-1; i>=0; i--) { |
| 794 | AppWindowToken t = mAppTokens.get(i); |
| 795 | if (t == token) { |
| 796 | i--; |
| 797 | break; |
| 798 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 799 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 800 | // We haven't reached the token yet; if this token |
| 801 | // is not going to the bottom and has windows, we can |
| 802 | // use it as an anchor for when we do reach the token. |
| 803 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | pos = t.windows.get(0); |
| 805 | } |
| 806 | } |
| 807 | // We now know the index into the apps. If we found |
| 808 | // an app window above, that gives us the position; else |
| 809 | // we need to look some more. |
| 810 | if (pos != null) { |
| 811 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 812 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 814 | if (atoken != null) { |
| 815 | final int NC = atoken.windows.size(); |
| 816 | if (NC > 0) { |
| 817 | WindowState bottom = atoken.windows.get(0); |
| 818 | if (bottom.mSubLayer < 0) { |
| 819 | pos = bottom; |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | placeWindowBefore(pos, win); |
| 824 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 825 | // Continue looking down until we find the first |
| 826 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | while (i >= 0) { |
| 828 | AppWindowToken t = mAppTokens.get(i); |
| 829 | final int NW = t.windows.size(); |
| 830 | if (NW > 0) { |
| 831 | pos = t.windows.get(NW-1); |
| 832 | break; |
| 833 | } |
| 834 | i--; |
| 835 | } |
| 836 | if (pos != null) { |
| 837 | // Move in front of any windows attached to this |
| 838 | // one. |
| 839 | WindowToken atoken = |
| 840 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 841 | if (atoken != null) { |
| 842 | final int NC = atoken.windows.size(); |
| 843 | if (NC > 0) { |
| 844 | WindowState top = atoken.windows.get(NC-1); |
| 845 | if (top.mSubLayer >= 0) { |
| 846 | pos = top; |
| 847 | } |
| 848 | } |
| 849 | } |
| 850 | placeWindowAfter(pos, win); |
| 851 | } else { |
| 852 | // Just search for the start of this layer. |
| 853 | final int myLayer = win.mBaseLayer; |
| 854 | for (i=0; i<N; i++) { |
| 855 | WindowState w = (WindowState)localmWindows.get(i); |
| 856 | if (w.mBaseLayer > myLayer) { |
| 857 | break; |
| 858 | } |
| 859 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 860 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 861 | TAG, "Adding window " + win + " at " |
| 862 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | localmWindows.add(i, win); |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | } else { |
| 868 | // Figure out where window should go, based on layer. |
| 869 | final int myLayer = win.mBaseLayer; |
| 870 | for (i=N-1; i>=0; i--) { |
| 871 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 872 | i++; |
| 873 | break; |
| 874 | } |
| 875 | } |
| 876 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 877 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 878 | TAG, "Adding window " + win + " at " |
| 879 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | localmWindows.add(i, win); |
| 881 | } |
| 882 | if (addToToken) { |
| 883 | token.windows.add(tokenWindowsPos, win); |
| 884 | } |
| 885 | |
| 886 | } else { |
| 887 | // Figure out this window's ordering relative to the window |
| 888 | // it is attached to. |
| 889 | final int NA = token.windows.size(); |
| 890 | final int sublayer = win.mSubLayer; |
| 891 | int largestSublayer = Integer.MIN_VALUE; |
| 892 | WindowState windowWithLargestSublayer = null; |
| 893 | for (i=0; i<NA; i++) { |
| 894 | WindowState w = token.windows.get(i); |
| 895 | final int wSublayer = w.mSubLayer; |
| 896 | if (wSublayer >= largestSublayer) { |
| 897 | largestSublayer = wSublayer; |
| 898 | windowWithLargestSublayer = w; |
| 899 | } |
| 900 | if (sublayer < 0) { |
| 901 | // For negative sublayers, we go below all windows |
| 902 | // in the same sublayer. |
| 903 | if (wSublayer >= sublayer) { |
| 904 | if (addToToken) { |
| 905 | token.windows.add(i, win); |
| 906 | } |
| 907 | placeWindowBefore( |
| 908 | wSublayer >= 0 ? attached : w, win); |
| 909 | break; |
| 910 | } |
| 911 | } else { |
| 912 | // For positive sublayers, we go above all windows |
| 913 | // in the same sublayer. |
| 914 | if (wSublayer > sublayer) { |
| 915 | if (addToToken) { |
| 916 | token.windows.add(i, win); |
| 917 | } |
| 918 | placeWindowBefore(w, win); |
| 919 | break; |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | if (i >= NA) { |
| 924 | if (addToToken) { |
| 925 | token.windows.add(win); |
| 926 | } |
| 927 | if (sublayer < 0) { |
| 928 | placeWindowBefore(attached, win); |
| 929 | } else { |
| 930 | placeWindowAfter(largestSublayer >= 0 |
| 931 | ? windowWithLargestSublayer |
| 932 | : attached, |
| 933 | win); |
| 934 | } |
| 935 | } |
| 936 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 937 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | if (win.mAppToken != null && addToToken) { |
| 939 | win.mAppToken.allAppWindows.add(win); |
| 940 | } |
| 941 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | static boolean canBeImeTarget(WindowState w) { |
| 944 | final int fl = w.mAttrs.flags |
| 945 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 946 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 947 | return w.isVisibleOrAdding(); |
| 948 | } |
| 949 | return false; |
| 950 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 951 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 953 | final ArrayList localmWindows = mWindows; |
| 954 | final int N = localmWindows.size(); |
| 955 | WindowState w = null; |
| 956 | int i = N; |
| 957 | while (i > 0) { |
| 958 | i--; |
| 959 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 960 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 961 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | // + Integer.toHexString(w.mAttrs.flags)); |
| 963 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 964 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 965 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | // Yet more tricksyness! If this window is a "starting" |
| 967 | // window, we do actually want to be on top of it, but |
| 968 | // it is not -really- where input will go. So if the caller |
| 969 | // is not actually looking to move the IME, look down below |
| 970 | // for a real window to target... |
| 971 | if (!willMove |
| 972 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 973 | && i > 0) { |
| 974 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 975 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 976 | i--; |
| 977 | w = wb; |
| 978 | } |
| 979 | } |
| 980 | break; |
| 981 | } |
| 982 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 983 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 985 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 986 | 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] | 987 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 988 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | if (willMove && w != null) { |
| 990 | final WindowState curTarget = mInputMethodTarget; |
| 991 | if (curTarget != null && curTarget.mAppToken != null) { |
| 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 | // Now some fun for dealing with window animations that |
| 994 | // modify the Z order. We need to look at all windows below |
| 995 | // the current target that are in this app, finding the highest |
| 996 | // visible one in layering. |
| 997 | AppWindowToken token = curTarget.mAppToken; |
| 998 | WindowState highestTarget = null; |
| 999 | int highestPos = 0; |
| 1000 | if (token.animating || token.animation != null) { |
| 1001 | int pos = 0; |
| 1002 | pos = localmWindows.indexOf(curTarget); |
| 1003 | while (pos >= 0) { |
| 1004 | WindowState win = (WindowState)localmWindows.get(pos); |
| 1005 | if (win.mAppToken != token) { |
| 1006 | break; |
| 1007 | } |
| 1008 | if (!win.mRemoved) { |
| 1009 | if (highestTarget == null || win.mAnimLayer > |
| 1010 | highestTarget.mAnimLayer) { |
| 1011 | highestTarget = win; |
| 1012 | highestPos = pos; |
| 1013 | } |
| 1014 | } |
| 1015 | pos--; |
| 1016 | } |
| 1017 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1018 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1020 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | + mNextAppTransition + " " + highestTarget |
| 1022 | + " animating=" + highestTarget.isAnimating() |
| 1023 | + " layer=" + highestTarget.mAnimLayer |
| 1024 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1025 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1026 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | // If we are currently setting up for an animation, |
| 1028 | // hold everything until we can find out what will happen. |
| 1029 | mInputMethodTargetWaitingAnim = true; |
| 1030 | mInputMethodTarget = highestTarget; |
| 1031 | return highestPos + 1; |
| 1032 | } else if (highestTarget.isAnimating() && |
| 1033 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1034 | // If the window we are currently targeting is involved |
| 1035 | // with an animation, and it is on top of the next target |
| 1036 | // we will be over, then hold off on moving until |
| 1037 | // that is done. |
| 1038 | mInputMethodTarget = highestTarget; |
| 1039 | return highestPos + 1; |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1044 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1045 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | if (w != null) { |
| 1047 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1048 | if (DEBUG_INPUT_METHOD) { |
| 1049 | RuntimeException e = null; |
| 1050 | if (!HIDE_STACK_CRAWLS) { |
| 1051 | e = new RuntimeException(); |
| 1052 | e.fillInStackTrace(); |
| 1053 | } |
| 1054 | Slog.w(TAG, "Moving IM target from " |
| 1055 | + mInputMethodTarget + " to " + w, e); |
| 1056 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | mInputMethodTarget = w; |
| 1058 | if (w.mAppToken != null) { |
| 1059 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1060 | } else { |
| 1061 | setInputMethodAnimLayerAdjustment(0); |
| 1062 | } |
| 1063 | } |
| 1064 | return i+1; |
| 1065 | } |
| 1066 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1067 | if (DEBUG_INPUT_METHOD) { |
| 1068 | RuntimeException e = null; |
| 1069 | if (!HIDE_STACK_CRAWLS) { |
| 1070 | e = new RuntimeException(); |
| 1071 | e.fillInStackTrace(); |
| 1072 | } |
| 1073 | Slog.w(TAG, "Moving IM target from " |
| 1074 | + mInputMethodTarget + " to null", e); |
| 1075 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | mInputMethodTarget = null; |
| 1077 | setInputMethodAnimLayerAdjustment(0); |
| 1078 | } |
| 1079 | return -1; |
| 1080 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1083 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1084 | if (pos >= 0) { |
| 1085 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1086 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1087 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | mWindows.add(pos, win); |
| 1089 | moveInputMethodDialogsLocked(pos+1); |
| 1090 | return; |
| 1091 | } |
| 1092 | win.mTargetAppToken = null; |
| 1093 | addWindowToListInOrderLocked(win, true); |
| 1094 | moveInputMethodDialogsLocked(pos); |
| 1095 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1096 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1098 | 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] | 1099 | mInputMethodAnimLayerAdjustment = adj; |
| 1100 | WindowState imw = mInputMethodWindow; |
| 1101 | if (imw != null) { |
| 1102 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1103 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | + " anim layer: " + imw.mAnimLayer); |
| 1105 | int wi = imw.mChildWindows.size(); |
| 1106 | while (wi > 0) { |
| 1107 | wi--; |
| 1108 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1109 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1110 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | + " anim layer: " + cw.mAnimLayer); |
| 1112 | } |
| 1113 | } |
| 1114 | int di = mInputMethodDialogs.size(); |
| 1115 | while (di > 0) { |
| 1116 | di --; |
| 1117 | imw = mInputMethodDialogs.get(di); |
| 1118 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1119 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | + " anim layer: " + imw.mAnimLayer); |
| 1121 | } |
| 1122 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1125 | int wpos = mWindows.indexOf(win); |
| 1126 | if (wpos >= 0) { |
| 1127 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1128 | 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] | 1129 | mWindows.remove(wpos); |
| 1130 | int NC = win.mChildWindows.size(); |
| 1131 | while (NC > 0) { |
| 1132 | NC--; |
| 1133 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1134 | int cpos = mWindows.indexOf(cw); |
| 1135 | if (cpos >= 0) { |
| 1136 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1137 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1138 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | mWindows.remove(cpos); |
| 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | return interestingPos; |
| 1144 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1145 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1147 | addWindowToListInOrderLocked(win, false); |
| 1148 | // This is a hack to get all of the child windows added as well |
| 1149 | // at the right position. Child windows should be rare and |
| 1150 | // this case should be rare, so it shouldn't be that big a deal. |
| 1151 | int wpos = mWindows.indexOf(win); |
| 1152 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1153 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1154 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | mWindows.remove(wpos); |
| 1156 | reAddWindowLocked(wpos, win); |
| 1157 | } |
| 1158 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | void logWindowList(String prefix) { |
| 1161 | int N = mWindows.size(); |
| 1162 | while (N > 0) { |
| 1163 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1164 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | } |
| 1166 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | void moveInputMethodDialogsLocked(int pos) { |
| 1169 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1172 | 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] | 1173 | for (int i=0; i<N; i++) { |
| 1174 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1175 | } |
| 1176 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1177 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | logWindowList(" "); |
| 1179 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | if (pos >= 0) { |
| 1182 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1183 | if (pos < mWindows.size()) { |
| 1184 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1185 | if (wp == mInputMethodWindow) { |
| 1186 | pos++; |
| 1187 | } |
| 1188 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1189 | 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] | 1190 | for (int i=0; i<N; i++) { |
| 1191 | WindowState win = dialogs.get(i); |
| 1192 | win.mTargetAppToken = targetAppToken; |
| 1193 | pos = reAddWindowLocked(pos, win); |
| 1194 | } |
| 1195 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1196 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | logWindowList(" "); |
| 1198 | } |
| 1199 | return; |
| 1200 | } |
| 1201 | for (int i=0; i<N; i++) { |
| 1202 | WindowState win = dialogs.get(i); |
| 1203 | win.mTargetAppToken = null; |
| 1204 | reAddWindowToListInOrderLocked(win); |
| 1205 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1206 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | logWindowList(" "); |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1213 | final WindowState imWin = mInputMethodWindow; |
| 1214 | final int DN = mInputMethodDialogs.size(); |
| 1215 | if (imWin == null && DN == 0) { |
| 1216 | return false; |
| 1217 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1218 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1220 | if (imPos >= 0) { |
| 1221 | // In this case, the input method windows are to be placed |
| 1222 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1224 | // First check to see if the input method windows are already |
| 1225 | // located here, and contiguous. |
| 1226 | final int N = mWindows.size(); |
| 1227 | WindowState firstImWin = imPos < N |
| 1228 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | // Figure out the actual input method window that should be |
| 1231 | // at the bottom of their stack. |
| 1232 | WindowState baseImWin = imWin != null |
| 1233 | ? imWin : mInputMethodDialogs.get(0); |
| 1234 | if (baseImWin.mChildWindows.size() > 0) { |
| 1235 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1236 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1237 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1239 | if (firstImWin == baseImWin) { |
| 1240 | // The windows haven't moved... but are they still contiguous? |
| 1241 | // First find the top IM window. |
| 1242 | int pos = imPos+1; |
| 1243 | while (pos < N) { |
| 1244 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1245 | break; |
| 1246 | } |
| 1247 | pos++; |
| 1248 | } |
| 1249 | pos++; |
| 1250 | // Now there should be no more input method windows above. |
| 1251 | while (pos < N) { |
| 1252 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1253 | break; |
| 1254 | } |
| 1255 | pos++; |
| 1256 | } |
| 1257 | if (pos >= N) { |
| 1258 | // All is good! |
| 1259 | return false; |
| 1260 | } |
| 1261 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | if (imWin != null) { |
| 1264 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1265 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | logWindowList(" "); |
| 1267 | } |
| 1268 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1269 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1270 | 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] | 1271 | logWindowList(" "); |
| 1272 | } |
| 1273 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1274 | reAddWindowLocked(imPos, imWin); |
| 1275 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1276 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | logWindowList(" "); |
| 1278 | } |
| 1279 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1280 | } else { |
| 1281 | moveInputMethodDialogsLocked(imPos); |
| 1282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | } else { |
| 1285 | // In this case, the input method windows go in a fixed layer, |
| 1286 | // because they aren't currently associated with a focus window. |
| 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 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1289 | 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] | 1290 | tmpRemoveWindowLocked(0, imWin); |
| 1291 | imWin.mTargetAppToken = null; |
| 1292 | reAddWindowToListInOrderLocked(imWin); |
| 1293 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1294 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | logWindowList(" "); |
| 1296 | } |
| 1297 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1298 | } else { |
| 1299 | moveInputMethodDialogsLocked(-1);; |
| 1300 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1302 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | if (needAssignLayers) { |
| 1305 | assignLayersLocked(); |
| 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 | return true; |
| 1309 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1310 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | void adjustInputMethodDialogsLocked() { |
| 1312 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1313 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1314 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1315 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1316 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1317 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1318 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1319 | ? wallpaperTarget.mAppToken.animation : null) |
| 1320 | + " upper=" + mUpperWallpaperTarget |
| 1321 | + " lower=" + mLowerWallpaperTarget); |
| 1322 | return (wallpaperTarget != null |
| 1323 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1324 | && wallpaperTarget.mAppToken.animation != null))) |
| 1325 | || mUpperWallpaperTarget != null |
| 1326 | || mLowerWallpaperTarget != null; |
| 1327 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1328 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1329 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1330 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1331 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1332 | int adjustWallpaperWindowsLocked() { |
| 1333 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1334 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1335 | final int dw = mDisplay.getWidth(); |
| 1336 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1337 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1338 | // First find top-most window that has asked to be on top of the |
| 1339 | // wallpaper; all wallpapers go behind it. |
| 1340 | final ArrayList localmWindows = mWindows; |
| 1341 | int N = localmWindows.size(); |
| 1342 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1343 | WindowState foundW = null; |
| 1344 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1345 | WindowState topCurW = null; |
| 1346 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1347 | int i = N; |
| 1348 | while (i > 0) { |
| 1349 | i--; |
| 1350 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1351 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1352 | if (topCurW == null) { |
| 1353 | topCurW = w; |
| 1354 | topCurI = i; |
| 1355 | } |
| 1356 | continue; |
| 1357 | } |
| 1358 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1359 | if (w.mAppToken != null) { |
| 1360 | // If this window's app token is hidden and not animating, |
| 1361 | // it is of no interest to us. |
| 1362 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1363 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1364 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1365 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1366 | continue; |
| 1367 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1368 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1369 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1370 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1371 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1372 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1373 | && (mWallpaperTarget == w |
| 1374 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1375 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1376 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1377 | foundW = w; |
| 1378 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1379 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1380 | && w.mAppToken.animation != null) |
| 1381 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1382 | // The current wallpaper target is animating, so we'll |
| 1383 | // look behind it for another possible target and figure |
| 1384 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1385 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1386 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1387 | continue; |
| 1388 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1389 | break; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1393 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1394 | // If we are currently waiting for an app transition, and either |
| 1395 | // the current target or the next target are involved with it, |
| 1396 | // then hold off on doing anything with the wallpaper. |
| 1397 | // Note that we are checking here for just whether the target |
| 1398 | // is part of an app token... which is potentially overly aggressive |
| 1399 | // (the app token may not be involved in the transition), but good |
| 1400 | // enough (we'll just wait until whatever transition is pending |
| 1401 | // executes). |
| 1402 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1403 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1404 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1405 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1406 | } |
| 1407 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1408 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1409 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1410 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1411 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1412 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1413 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1414 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1415 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1416 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1417 | + " oldTarget: " + mWallpaperTarget); |
| 1418 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1419 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1420 | mLowerWallpaperTarget = null; |
| 1421 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1422 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1423 | WindowState oldW = mWallpaperTarget; |
| 1424 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1425 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1426 | // Now what is happening... if the current and new targets are |
| 1427 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1428 | if (foundW != null && oldW != null) { |
| 1429 | boolean oldAnim = oldW.mAnimation != null |
| 1430 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1431 | boolean foundAnim = foundW.mAnimation != null |
| 1432 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1433 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1434 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1435 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1436 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1437 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1438 | int oldI = localmWindows.indexOf(oldW); |
| 1439 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1440 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1441 | } |
| 1442 | if (oldI >= 0) { |
| 1443 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1444 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1445 | + "=" + oldW + "; new#" + foundI |
| 1446 | + "=" + foundW); |
| 1447 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1448 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1449 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1450 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1451 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1452 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1453 | } |
| 1454 | mWallpaperTarget = oldW; |
| 1455 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1456 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1457 | // Now set the upper and lower wallpaper targets |
| 1458 | // correctly, and make sure that we are positioning |
| 1459 | // the wallpaper below the lower. |
| 1460 | if (foundI > oldI) { |
| 1461 | // The new target is on top of the old one. |
| 1462 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1463 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1464 | } |
| 1465 | mUpperWallpaperTarget = foundW; |
| 1466 | mLowerWallpaperTarget = oldW; |
| 1467 | foundW = oldW; |
| 1468 | foundI = oldI; |
| 1469 | } else { |
| 1470 | // The new target is below the old one. |
| 1471 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1472 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1473 | } |
| 1474 | mUpperWallpaperTarget = oldW; |
| 1475 | mLowerWallpaperTarget = foundW; |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1480 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1481 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1482 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1483 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1484 | || (mLowerWallpaperTarget.mAppToken != null |
| 1485 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1486 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1487 | || (mUpperWallpaperTarget.mAppToken != null |
| 1488 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1489 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1490 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1491 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1492 | } |
| 1493 | mLowerWallpaperTarget = null; |
| 1494 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1495 | } |
| 1496 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1497 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1498 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1499 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1500 | // The window is visible to the compositor... but is it visible |
| 1501 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1502 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1503 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1504 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1505 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1506 | // its layer adjustment. Only do this if we are not transfering |
| 1507 | // between two wallpaper targets. |
| 1508 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1509 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1510 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1511 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1512 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1513 | * TYPE_LAYER_MULTIPLIER |
| 1514 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1515 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1516 | // Now w is the window we are supposed to be behind... but we |
| 1517 | // 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] | 1518 | // AND any starting window associated with it, AND below the |
| 1519 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1520 | while (foundI > 0) { |
| 1521 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1522 | if (wb.mBaseLayer < maxLayer && |
| 1523 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1524 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1525 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1526 | // This window is not related to the previous one in any |
| 1527 | // interesting way, so stop here. |
| 1528 | break; |
| 1529 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1530 | foundW = wb; |
| 1531 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1532 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1533 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1534 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1535 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1536 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1537 | if (foundW == null && topCurW != null) { |
| 1538 | // There is no wallpaper target, so it goes at the bottom. |
| 1539 | // We will assume it is the same place as last time, if known. |
| 1540 | foundW = topCurW; |
| 1541 | foundI = topCurI+1; |
| 1542 | } else { |
| 1543 | // Okay i is the position immediately above the wallpaper. Look at |
| 1544 | // what is below it for later. |
| 1545 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1546 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1547 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1548 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1549 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1550 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1551 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1552 | } |
| 1553 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1554 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1555 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1556 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1557 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1558 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1559 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1560 | // are correctly placed. |
| 1561 | int curTokenIndex = mWallpaperTokens.size(); |
| 1562 | while (curTokenIndex > 0) { |
| 1563 | curTokenIndex--; |
| 1564 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1565 | if (token.hidden == visible) { |
| 1566 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1567 | token.hidden = !visible; |
| 1568 | // Need to do a layout to ensure the wallpaper now has the |
| 1569 | // correct size. |
| 1570 | mLayoutNeeded = true; |
| 1571 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1572 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1573 | int curWallpaperIndex = token.windows.size(); |
| 1574 | while (curWallpaperIndex > 0) { |
| 1575 | curWallpaperIndex--; |
| 1576 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1577 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1578 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1579 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1580 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1581 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1582 | // First, make sure the client has the current visibility |
| 1583 | // state. |
| 1584 | if (wallpaper.mWallpaperVisible != visible) { |
| 1585 | wallpaper.mWallpaperVisible = visible; |
| 1586 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1587 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1588 | "Setting visibility of wallpaper " + wallpaper |
| 1589 | + ": " + visible); |
| 1590 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1591 | } catch (RemoteException e) { |
| 1592 | } |
| 1593 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1594 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1595 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1596 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1597 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1598 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1599 | // First, if this window is at the current index, then all |
| 1600 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1601 | if (wallpaper == foundW) { |
| 1602 | foundI--; |
| 1603 | foundW = foundI > 0 |
| 1604 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1605 | continue; |
| 1606 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1607 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1608 | // The window didn't match... the current wallpaper window, |
| 1609 | // wherever it is, is in the wrong place, so make sure it is |
| 1610 | // not in the list. |
| 1611 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1612 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1613 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1614 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1615 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1616 | if (oldIndex < foundI) { |
| 1617 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1618 | } |
| 1619 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1620 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1621 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1622 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1623 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1624 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1625 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1626 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1627 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1630 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1631 | return changed; |
| 1632 | } |
| 1633 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1634 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1635 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1636 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1637 | mWallpaperAnimLayerAdjustment = adj; |
| 1638 | int curTokenIndex = mWallpaperTokens.size(); |
| 1639 | while (curTokenIndex > 0) { |
| 1640 | curTokenIndex--; |
| 1641 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1642 | int curWallpaperIndex = token.windows.size(); |
| 1643 | while (curWallpaperIndex > 0) { |
| 1644 | curWallpaperIndex--; |
| 1645 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1646 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1647 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1648 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1653 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1654 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1655 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1656 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1657 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1658 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1659 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1660 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1661 | changed = wallpaperWin.mXOffset != offset; |
| 1662 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1663 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1664 | + wallpaperWin + " x: " + offset); |
| 1665 | wallpaperWin.mXOffset = offset; |
| 1666 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1667 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1668 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1669 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1670 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1671 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1672 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1673 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1674 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1675 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1676 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1677 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1678 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1679 | + wallpaperWin + " y: " + offset); |
| 1680 | changed = true; |
| 1681 | wallpaperWin.mYOffset = offset; |
| 1682 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1683 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1684 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1685 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1686 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1687 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1688 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1689 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1690 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1691 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1692 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1693 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1694 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1695 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1696 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1697 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1698 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1699 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1700 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1701 | if (mWaitingOnWallpaper != null) { |
| 1702 | long start = SystemClock.uptimeMillis(); |
| 1703 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1704 | < start) { |
| 1705 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1706 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1707 | "Waiting for offset complete..."); |
| 1708 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1709 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1710 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1711 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1712 | if ((start+WALLPAPER_TIMEOUT) |
| 1713 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1714 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1715 | + wallpaperWin); |
| 1716 | mLastWallpaperTimeoutTime = start; |
| 1717 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1718 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1719 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1722 | } catch (RemoteException e) { |
| 1723 | } |
| 1724 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1725 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1726 | return changed; |
| 1727 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1728 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1729 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1730 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1731 | if (mWaitingOnWallpaper != null && |
| 1732 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1733 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1734 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1738 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1739 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1740 | final int dw = mDisplay.getWidth(); |
| 1741 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1742 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1743 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1744 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1745 | WindowState target = mWallpaperTarget; |
| 1746 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1747 | if (target.mWallpaperX >= 0) { |
| 1748 | mLastWallpaperX = target.mWallpaperX; |
| 1749 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1750 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1751 | } |
| 1752 | if (target.mWallpaperY >= 0) { |
| 1753 | mLastWallpaperY = target.mWallpaperY; |
| 1754 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1755 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1756 | } |
| 1757 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1758 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1759 | int curTokenIndex = mWallpaperTokens.size(); |
| 1760 | while (curTokenIndex > 0) { |
| 1761 | curTokenIndex--; |
| 1762 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1763 | int curWallpaperIndex = token.windows.size(); |
| 1764 | while (curWallpaperIndex > 0) { |
| 1765 | curWallpaperIndex--; |
| 1766 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1767 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1768 | wallpaper.computeShownFrameLocked(); |
| 1769 | changed = true; |
| 1770 | // We only want to be synchronous with one wallpaper. |
| 1771 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1775 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1776 | return changed; |
| 1777 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1778 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1779 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1780 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1781 | final int dw = mDisplay.getWidth(); |
| 1782 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1783 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1784 | int curTokenIndex = mWallpaperTokens.size(); |
| 1785 | while (curTokenIndex > 0) { |
| 1786 | curTokenIndex--; |
| 1787 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1788 | if (token.hidden == visible) { |
| 1789 | token.hidden = !visible; |
| 1790 | // Need to do a layout to ensure the wallpaper now has the |
| 1791 | // correct size. |
| 1792 | mLayoutNeeded = true; |
| 1793 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1794 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1795 | int curWallpaperIndex = token.windows.size(); |
| 1796 | while (curWallpaperIndex > 0) { |
| 1797 | curWallpaperIndex--; |
| 1798 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1799 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1800 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1801 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1802 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1803 | if (wallpaper.mWallpaperVisible != visible) { |
| 1804 | wallpaper.mWallpaperVisible = visible; |
| 1805 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1806 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1807 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1808 | + ": " + visible); |
| 1809 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1810 | } catch (RemoteException e) { |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | } |
| 1815 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1816 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1817 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1818 | MotionEvent pointer, long eventTime) { |
| 1819 | int curTokenIndex = mWallpaperTokens.size(); |
| 1820 | while (curTokenIndex > 0) { |
| 1821 | curTokenIndex--; |
| 1822 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1823 | int curWallpaperIndex = token.windows.size(); |
| 1824 | while (curWallpaperIndex > 0) { |
| 1825 | curWallpaperIndex--; |
| 1826 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1827 | if ((wallpaper.mAttrs.flags & |
| 1828 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1829 | continue; |
| 1830 | } |
| 1831 | try { |
| 1832 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1833 | if (srcWin != null) { |
| 1834 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1835 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1836 | } else { |
| 1837 | ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top); |
| 1838 | } |
| 1839 | switch (pointer.getAction()) { |
| 1840 | case MotionEvent.ACTION_DOWN: |
| 1841 | mSendingPointersToWallpaper = true; |
| 1842 | break; |
| 1843 | case MotionEvent.ACTION_UP: |
| 1844 | mSendingPointersToWallpaper = false; |
| 1845 | break; |
| 1846 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1847 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1848 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1849 | Slog.w(TAG, "Failure sending pointer to wallpaper", e); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1850 | } |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1854 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1855 | void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin, |
| 1856 | MotionEvent pointer, long eventTime, boolean skipped) { |
| 1857 | if (relWin != null) { |
| 1858 | mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top); |
| 1859 | } else { |
| 1860 | mPolicy.dispatchedPointerEventLw(pointer, 0, 0); |
| 1861 | } |
| 1862 | |
| 1863 | // If we sent an initial down to the wallpaper, then continue |
| 1864 | // sending events until the final up. |
| 1865 | if (mSendingPointersToWallpaper) { |
| 1866 | if (skipped) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1867 | Slog.i(TAG, "Sending skipped pointer to wallpaper!"); |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1868 | } |
| 1869 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1870 | |
| 1871 | // If we are on top of the wallpaper, then the wallpaper also |
| 1872 | // gets to see this movement. |
| 1873 | } else if (srcWin != null |
| 1874 | && pointer.getAction() == MotionEvent.ACTION_DOWN |
| 1875 | && mWallpaperTarget == srcWin |
| 1876 | && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 1877 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1878 | } |
| 1879 | } |
| 1880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | public int addWindow(Session session, IWindow client, |
| 1882 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1883 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | int res = mPolicy.checkAddPermission(attrs); |
| 1885 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1886 | return res; |
| 1887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | boolean reportNewConfig = false; |
| 1890 | WindowState attachedWindow = null; |
| 1891 | WindowState win = null; |
| 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 | synchronized(mWindowMap) { |
| 1894 | // Instantiating a Display requires talking with the simulator, |
| 1895 | // so don't do it until we know the system is mostly up and |
| 1896 | // running. |
| 1897 | if (mDisplay == null) { |
| 1898 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1899 | mDisplay = wm.getDefaultDisplay(); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1900 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1901 | mInitialDisplayHeight = mDisplay.getHeight(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1902 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 1903 | mInputManager.setDisplaySize(0, |
| 1904 | mInitialDisplayWidth, mInitialDisplayHeight); |
| 1905 | } else { |
| 1906 | mQueue.setDisplay(mDisplay); |
| 1907 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | reportNewConfig = true; |
| 1909 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1912 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1914 | } |
| 1915 | |
| 1916 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1917 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1919 | 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] | 1920 | + attrs.token + ". Aborting."); |
| 1921 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1922 | } |
| 1923 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1924 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1925 | 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] | 1926 | + attrs.token + ". Aborting."); |
| 1927 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | boolean addToken = false; |
| 1932 | WindowToken token = mTokenMap.get(attrs.token); |
| 1933 | if (token == null) { |
| 1934 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1935 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1936 | 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] | 1937 | + attrs.token + ". Aborting."); |
| 1938 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1939 | } |
| 1940 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1941 | 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] | 1942 | + attrs.token + ". Aborting."); |
| 1943 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1944 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1945 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1946 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1947 | + attrs.token + ". Aborting."); |
| 1948 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1949 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | token = new WindowToken(attrs.token, -1, false); |
| 1951 | addToken = true; |
| 1952 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1953 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1954 | AppWindowToken atoken = token.appWindowToken; |
| 1955 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1956 | 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] | 1957 | + token + ". Aborting."); |
| 1958 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1959 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1960 | 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] | 1961 | + token + ". Aborting."); |
| 1962 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1963 | } |
| 1964 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1965 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1966 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1968 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1969 | } |
| 1970 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1971 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1972 | 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] | 1973 | + attrs.token + ". Aborting."); |
| 1974 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1975 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1976 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1977 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1978 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1979 | + attrs.token + ". Aborting."); |
| 1980 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1981 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | win = new WindowState(session, client, token, |
| 1985 | attachedWindow, attrs, viewVisibility); |
| 1986 | if (win.mDeathRecipient == null) { |
| 1987 | // Client has apparently died, so there is no reason to |
| 1988 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1989 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | + " that is dead, aborting."); |
| 1991 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1992 | } |
| 1993 | |
| 1994 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1995 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1997 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1998 | return res; |
| 1999 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2000 | |
| 2001 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 2002 | if (outInputChannel != null) { |
| 2003 | String name = win.makeInputChannelName(); |
| 2004 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2005 | win.mInputChannel = inputChannels[0]; |
| 2006 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2007 | |
| 2008 | mInputManager.registerInputChannel(win.mInputChannel); |
| 2009 | } |
| 2010 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2011 | |
| 2012 | // From now on, no exceptions or errors allowed! |
| 2013 | |
| 2014 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2015 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2016 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | if (addToken) { |
| 2019 | mTokenMap.put(attrs.token, token); |
| 2020 | mTokenList.add(token); |
| 2021 | } |
| 2022 | win.attach(); |
| 2023 | mWindowMap.put(client.asBinder(), win); |
| 2024 | |
| 2025 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2026 | token.appWindowToken != null) { |
| 2027 | token.appWindowToken.startingWindow = win; |
| 2028 | } |
| 2029 | |
| 2030 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2031 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2033 | mInputMethodWindow = win; |
| 2034 | addInputMethodWindowToListLocked(win); |
| 2035 | imMayMove = false; |
| 2036 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2037 | mInputMethodDialogs.add(win); |
| 2038 | addWindowToListInOrderLocked(win, true); |
| 2039 | adjustInputMethodDialogsLocked(); |
| 2040 | imMayMove = false; |
| 2041 | } else { |
| 2042 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2043 | if (attrs.type == TYPE_WALLPAPER) { |
| 2044 | mLastWallpaperTimeoutTime = 0; |
| 2045 | adjustWallpaperWindowsLocked(); |
| 2046 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2047 | adjustWallpaperWindowsLocked(); |
| 2048 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2049 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2050 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2051 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2052 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2053 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| 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 | if (mInTouchMode) { |
| 2056 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2057 | } |
| 2058 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2059 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2060 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2061 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2062 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | if (win.canReceiveKeys()) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2064 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 2065 | == true) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | imMayMove = false; |
| 2067 | } |
| 2068 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2070 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2071 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | assignLayersLocked(); |
| 2075 | // Don't do layout here, the window must call |
| 2076 | // relayout to be displayed, so we'll do it there. |
| 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 | //dump(); |
| 2079 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2080 | if (focusChanged) { |
| 2081 | if (mCurrentFocus != null) { |
| 2082 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 2083 | } |
| 2084 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2085 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | TAG, "New client " + client.asBinder() |
| 2087 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2088 | |
| 2089 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2090 | reportNewConfig = true; |
| 2091 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 2095 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 2096 | // identity anyway, so it's safe to just clear & restore around this whole |
| 2097 | // block. |
| 2098 | final long origId = Binder.clearCallingIdentity(); |
| 2099 | if (reportNewConfig) { |
| 2100 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2101 | } |
| 2102 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2103 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2104 | return res; |
| 2105 | } |
| 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 | public void removeWindow(Session session, IWindow client) { |
| 2108 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2109 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | if (win == null) { |
| 2111 | return; |
| 2112 | } |
| 2113 | removeWindowLocked(session, win); |
| 2114 | } |
| 2115 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2116 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | public void removeWindowLocked(Session session, WindowState win) { |
| 2118 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2119 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | TAG, "Remove " + win + " client=" |
| 2121 | + Integer.toHexString(System.identityHashCode( |
| 2122 | win.mClient.asBinder())) |
| 2123 | + ", surface=" + win.mSurface); |
| 2124 | |
| 2125 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2126 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2127 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2129 | + " mExiting=" + win.mExiting |
| 2130 | + " isAnimating=" + win.isAnimating() |
| 2131 | + " app-animation=" |
| 2132 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2133 | + " inPendingTransaction=" |
| 2134 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2135 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2136 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2137 | boolean wasVisible = false; |
| 2138 | // First, see if we need to run an animation. If we do, we have |
| 2139 | // to hold off on removing the window until the animation is done. |
| 2140 | // If the display is frozen, just remove immediately, since the |
| 2141 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2142 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | // If we are not currently running the exit animation, we |
| 2144 | // need to see about starting one. |
| 2145 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2148 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2149 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2150 | } |
| 2151 | // Try starting an animation. |
| 2152 | if (applyAnimationLocked(win, transit, false)) { |
| 2153 | win.mExiting = true; |
| 2154 | } |
| 2155 | } |
| 2156 | if (win.mExiting || win.isAnimating()) { |
| 2157 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2158 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | win.mExiting = true; |
| 2160 | win.mRemoveOnExit = true; |
| 2161 | mLayoutNeeded = true; |
| 2162 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2163 | performLayoutAndPlaceSurfacesLocked(); |
| 2164 | if (win.mAppToken != null) { |
| 2165 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2166 | } |
| 2167 | //dump(); |
| 2168 | Binder.restoreCallingIdentity(origId); |
| 2169 | return; |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | removeWindowInnerLocked(session, win); |
| 2174 | // Removing a visible window will effect the computed orientation |
| 2175 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2176 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2177 | != mForcedAppOrientation |
| 2178 | && updateOrientationFromAppTokensLocked()) { |
| 2179 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2180 | } |
| 2181 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2182 | Binder.restoreCallingIdentity(origId); |
| 2183 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 2186 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2187 | KeyWaiter.RETURN_NOTHING); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2189 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2192 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2193 | if (mInputMethodTarget == win) { |
| 2194 | moveInputMethodWindowsIfNeededLocked(false); |
| 2195 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2196 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2197 | if (false) { |
| 2198 | RuntimeException e = new RuntimeException("here"); |
| 2199 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2200 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2201 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2203 | mPolicy.removeWindowLw(win); |
| 2204 | win.removeLocked(); |
| 2205 | |
| 2206 | mWindowMap.remove(win.mClient.asBinder()); |
| 2207 | mWindows.remove(win); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2208 | 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] | 2209 | |
| 2210 | if (mInputMethodWindow == win) { |
| 2211 | mInputMethodWindow = null; |
| 2212 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2213 | mInputMethodDialogs.remove(win); |
| 2214 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | final WindowToken token = win.mToken; |
| 2217 | final AppWindowToken atoken = win.mAppToken; |
| 2218 | token.windows.remove(win); |
| 2219 | if (atoken != null) { |
| 2220 | atoken.allAppWindows.remove(win); |
| 2221 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2222 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | TAG, "**** Removing window " + win + ": count=" |
| 2224 | + token.windows.size()); |
| 2225 | if (token.windows.size() == 0) { |
| 2226 | if (!token.explicit) { |
| 2227 | mTokenMap.remove(token.token); |
| 2228 | mTokenList.remove(token); |
| 2229 | } else if (atoken != null) { |
| 2230 | atoken.firstWindowDrawn = false; |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | if (atoken != null) { |
| 2235 | if (atoken.startingWindow == win) { |
| 2236 | atoken.startingWindow = null; |
| 2237 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2238 | // If this is the last window and we had requested a starting |
| 2239 | // transition window, well there is no point now. |
| 2240 | atoken.startingData = null; |
| 2241 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2242 | // If this is the last window except for a starting transition |
| 2243 | // window, we need to get rid of the starting transition. |
| 2244 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2245 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | + ": no more real windows"); |
| 2247 | } |
| 2248 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2249 | mH.sendMessage(m); |
| 2250 | } |
| 2251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2252 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2253 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2254 | mLastWallpaperTimeoutTime = 0; |
| 2255 | adjustWallpaperWindowsLocked(); |
| 2256 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2257 | adjustWallpaperWindowsLocked(); |
| 2258 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2259 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | if (!mInLayout) { |
| 2261 | assignLayersLocked(); |
| 2262 | mLayoutNeeded = true; |
| 2263 | performLayoutAndPlaceSurfacesLocked(); |
| 2264 | if (win.mAppToken != null) { |
| 2265 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2266 | } |
| 2267 | } |
| 2268 | } |
| 2269 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2270 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2271 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2272 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2273 | if (where != null) { |
| 2274 | Slog.i(TAG, str, where); |
| 2275 | } else { |
| 2276 | Slog.i(TAG, str); |
| 2277 | } |
| 2278 | } |
| 2279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2281 | long origId = Binder.clearCallingIdentity(); |
| 2282 | try { |
| 2283 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2284 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2286 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | Surface.openTransaction(); |
| 2288 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2289 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2290 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | w.mSurface.setTransparentRegionHint(region); |
| 2292 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2293 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | Surface.closeTransaction(); |
| 2295 | } |
| 2296 | } |
| 2297 | } |
| 2298 | } finally { |
| 2299 | Binder.restoreCallingIdentity(origId); |
| 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2304 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | Rect visibleInsets) { |
| 2306 | long origId = Binder.clearCallingIdentity(); |
| 2307 | try { |
| 2308 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2309 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2310 | if (w != null) { |
| 2311 | w.mGivenInsetsPending = false; |
| 2312 | w.mGivenContentInsets.set(contentInsets); |
| 2313 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2314 | w.mTouchableInsets = touchableInsets; |
| 2315 | mLayoutNeeded = true; |
| 2316 | performLayoutAndPlaceSurfacesLocked(); |
| 2317 | } |
| 2318 | } |
| 2319 | } finally { |
| 2320 | Binder.restoreCallingIdentity(origId); |
| 2321 | } |
| 2322 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2325 | Rect outDisplayFrame) { |
| 2326 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2327 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | if (win == null) { |
| 2329 | outDisplayFrame.setEmpty(); |
| 2330 | return; |
| 2331 | } |
| 2332 | outDisplayFrame.set(win.mDisplayFrame); |
| 2333 | } |
| 2334 | } |
| 2335 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2336 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2337 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2338 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2339 | window.mWallpaperX = x; |
| 2340 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2341 | window.mWallpaperXStep = xStep; |
| 2342 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2343 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2344 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2345 | } |
| 2346 | } |
| 2347 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2348 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2349 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2350 | synchronized (mWindowMap) { |
| 2351 | if (mWaitingOnWallpaper != null && |
| 2352 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2353 | mWaitingOnWallpaper = null; |
| 2354 | mWindowMap.notifyAll(); |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2358 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2359 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2360 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2361 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2362 | || window == mUpperWallpaperTarget) { |
| 2363 | boolean doWait = sync; |
| 2364 | int curTokenIndex = mWallpaperTokens.size(); |
| 2365 | while (curTokenIndex > 0) { |
| 2366 | curTokenIndex--; |
| 2367 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2368 | int curWallpaperIndex = token.windows.size(); |
| 2369 | while (curWallpaperIndex > 0) { |
| 2370 | curWallpaperIndex--; |
| 2371 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2372 | try { |
| 2373 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2374 | x, y, z, extras, sync); |
| 2375 | // We only want to be synchronous with one wallpaper. |
| 2376 | sync = false; |
| 2377 | } catch (RemoteException e) { |
| 2378 | } |
| 2379 | } |
| 2380 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2381 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2382 | if (doWait) { |
| 2383 | // XXX Need to wait for result. |
| 2384 | } |
| 2385 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2386 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2387 | return null; |
| 2388 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | public int relayoutWindow(Session session, IWindow client, |
| 2391 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2392 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2393 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2394 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | boolean displayed = false; |
| 2396 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2397 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2399 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2401 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | if (win == null) { |
| 2403 | return 0; |
| 2404 | } |
| 2405 | win.mRequestedWidth = requestedWidth; |
| 2406 | win.mRequestedHeight = requestedHeight; |
| 2407 | |
| 2408 | if (attrs != null) { |
| 2409 | mPolicy.adjustWindowParamsLw(attrs); |
| 2410 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2411 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | int attrChanges = 0; |
| 2413 | int flagChanges = 0; |
| 2414 | if (attrs != null) { |
| 2415 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2416 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2417 | } |
| 2418 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2419 | 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] | 2420 | |
| 2421 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2422 | win.mAlpha = attrs.alpha; |
| 2423 | } |
| 2424 | |
| 2425 | final boolean scaledWindow = |
| 2426 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2427 | |
| 2428 | if (scaledWindow) { |
| 2429 | // requested{Width|Height} Surface's physical size |
| 2430 | // attrs.{width|height} Size on screen |
| 2431 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2432 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2433 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2434 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2435 | } else { |
| 2436 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | boolean imMayMove = (flagChanges&( |
| 2440 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2441 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2443 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2444 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2445 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2446 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2447 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2448 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | win.mRelayoutCalled = true; |
| 2451 | final int oldVisibility = win.mViewVisibility; |
| 2452 | win.mViewVisibility = viewVisibility; |
| 2453 | if (viewVisibility == View.VISIBLE && |
| 2454 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2455 | displayed = !win.isVisibleLw(); |
| 2456 | if (win.mExiting) { |
| 2457 | win.mExiting = false; |
| 2458 | win.mAnimation = null; |
| 2459 | } |
| 2460 | if (win.mDestroying) { |
| 2461 | win.mDestroying = false; |
| 2462 | mDestroySurface.remove(win); |
| 2463 | } |
| 2464 | if (oldVisibility == View.GONE) { |
| 2465 | win.mEnterAnimationPending = true; |
| 2466 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2467 | if (displayed) { |
| 2468 | if (win.mSurface != null && !win.mDrawPending |
| 2469 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2470 | && mPolicy.isScreenOn()) { |
| 2471 | applyEnterAnimationLocked(win); |
| 2472 | } |
| 2473 | if ((win.mAttrs.flags |
| 2474 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2475 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2476 | "Relayout window turning screen on: " + win); |
| 2477 | win.mTurnOnScreen = true; |
| 2478 | } |
| 2479 | int diff = 0; |
| 2480 | if (win.mConfiguration != mCurConfiguration |
| 2481 | && (win.mConfiguration == null |
| 2482 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2483 | win.mConfiguration = mCurConfiguration; |
| 2484 | if (DEBUG_CONFIGURATION) { |
| 2485 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2486 | + win.mConfiguration + " / 0x" |
| 2487 | + Integer.toHexString(diff)); |
| 2488 | } |
| 2489 | outConfig.setTo(mCurConfiguration); |
| 2490 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2491 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2493 | // To change the format, we need to re-build the surface. |
| 2494 | win.destroySurfaceLocked(); |
| 2495 | displayed = true; |
| 2496 | } |
| 2497 | try { |
| 2498 | Surface surface = win.createSurfaceLocked(); |
| 2499 | if (surface != null) { |
| 2500 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2501 | win.mReportDestroySurface = false; |
| 2502 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2503 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2504 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2506 | // For some reason there isn't a surface. Clear the |
| 2507 | // caller's object so they see the same state. |
| 2508 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2509 | } |
| 2510 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2511 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2512 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2513 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | Binder.restoreCallingIdentity(origId); |
| 2515 | return 0; |
| 2516 | } |
| 2517 | if (displayed) { |
| 2518 | focusMayChange = true; |
| 2519 | } |
| 2520 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2521 | && mInputMethodWindow == null) { |
| 2522 | mInputMethodWindow = win; |
| 2523 | imMayMove = true; |
| 2524 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2525 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2526 | && win.mAppToken != null |
| 2527 | && win.mAppToken.startingWindow != null) { |
| 2528 | // Special handling of starting window over the base |
| 2529 | // window of the app: propagate lock screen flags to it, |
| 2530 | // to provide the correct semantics while starting. |
| 2531 | final int mask = |
| 2532 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2533 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2534 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2535 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2536 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2537 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | } else { |
| 2539 | win.mEnterAnimationPending = false; |
| 2540 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2541 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2542 | + ": mExiting=" + win.mExiting |
| 2543 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | // If we are not currently running the exit animation, we |
| 2545 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2546 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | // Try starting an animation; if there isn't one, we |
| 2548 | // can destroy the surface right away. |
| 2549 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2550 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2551 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2552 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2553 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2555 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | win.mExiting = true; |
| 2557 | mKeyWaiter.finishedKey(session, client, true, |
| 2558 | KeyWaiter.RETURN_NOTHING); |
| 2559 | } else if (win.isAnimating()) { |
| 2560 | // Currently in a hide animation... turn this into |
| 2561 | // an exit. |
| 2562 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2563 | } else if (win == mWallpaperTarget) { |
| 2564 | // If the wallpaper is currently behind this |
| 2565 | // window, we need to change both of them inside |
| 2566 | // of a transaction to avoid artifacts. |
| 2567 | win.mExiting = true; |
| 2568 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | } else { |
| 2570 | if (mInputMethodWindow == win) { |
| 2571 | mInputMethodWindow = null; |
| 2572 | } |
| 2573 | win.destroySurfaceLocked(); |
| 2574 | } |
| 2575 | } |
| 2576 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2577 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2578 | if (win.mSurface == null || (win.getAttrs().flags |
| 2579 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2580 | || win.mSurfacePendingDestroy) { |
| 2581 | // We are being called from a local process, which |
| 2582 | // means outSurface holds its current surface. Ensure the |
| 2583 | // surface object is cleared, but we don't want it actually |
| 2584 | // destroyed at this point. |
| 2585 | win.mSurfacePendingDestroy = false; |
| 2586 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2587 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2588 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2589 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2590 | "Keeping surface, will report destroy: " + win); |
| 2591 | win.mReportDestroySurface = true; |
| 2592 | outSurface.copyFrom(win.mSurface); |
| 2593 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2596 | if (focusMayChange) { |
| 2597 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2598 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | imMayMove = false; |
| 2600 | } |
| 2601 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2602 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2603 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2604 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2605 | // reassign them at this point if the IM window state gets shuffled |
| 2606 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2609 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2610 | // Little hack here -- we -should- be able to rely on the |
| 2611 | // function to return true if the IME has moved and needs |
| 2612 | // its layer recomputed. However, if the IME was hidden |
| 2613 | // and isn't actually moved in the list, its layer may be |
| 2614 | // 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] | 2615 | assignLayers = true; |
| 2616 | } |
| 2617 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2618 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2619 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2620 | assignLayers = true; |
| 2621 | } |
| 2622 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2624 | mLayoutNeeded = true; |
| 2625 | win.mGivenInsetsPending = insetsPending; |
| 2626 | if (assignLayers) { |
| 2627 | assignLayersLocked(); |
| 2628 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2629 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2631 | if (displayed && win.mIsWallpaper) { |
| 2632 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2633 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2634 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | if (win.mAppToken != null) { |
| 2636 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2637 | } |
| 2638 | outFrame.set(win.mFrame); |
| 2639 | outContentInsets.set(win.mContentInsets); |
| 2640 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2641 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2643 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | + ", requestedHeight=" + requestedHeight |
| 2645 | + ", viewVisibility=" + viewVisibility |
| 2646 | + "\nRelayout returning frame=" + outFrame |
| 2647 | + ", surface=" + outSurface); |
| 2648 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2649 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2651 | |
| 2652 | inTouchMode = mInTouchMode; |
| 2653 | } |
| 2654 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2655 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | sendNewConfiguration(); |
| 2657 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2658 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2660 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2662 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2663 | } |
| 2664 | |
| 2665 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2666 | final long origId = Binder.clearCallingIdentity(); |
| 2667 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2668 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2670 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2671 | adjustWallpaperWindowsLocked(); |
| 2672 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2673 | mLayoutNeeded = true; |
| 2674 | performLayoutAndPlaceSurfacesLocked(); |
| 2675 | } |
| 2676 | } |
| 2677 | Binder.restoreCallingIdentity(origId); |
| 2678 | } |
| 2679 | |
| 2680 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2681 | 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] | 2682 | + (lp != null ? lp.packageName : null) |
| 2683 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2684 | if (lp != null && lp.windowAnimations != 0) { |
| 2685 | // If this is a system resource, don't try to load it from the |
| 2686 | // application resources. It is nice to avoid loading application |
| 2687 | // resources if we can. |
| 2688 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2689 | int resId = lp.windowAnimations; |
| 2690 | if ((resId&0xFF000000) == 0x01000000) { |
| 2691 | packageName = "android"; |
| 2692 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2693 | 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] | 2694 | + packageName); |
| 2695 | return AttributeCache.instance().get(packageName, resId, |
| 2696 | com.android.internal.R.styleable.WindowAnimation); |
| 2697 | } |
| 2698 | return null; |
| 2699 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2700 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2701 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2702 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2703 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2704 | if (packageName != null) { |
| 2705 | if ((resId&0xFF000000) == 0x01000000) { |
| 2706 | packageName = "android"; |
| 2707 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2708 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2709 | + packageName); |
| 2710 | return AttributeCache.instance().get(packageName, resId, |
| 2711 | com.android.internal.R.styleable.WindowAnimation); |
| 2712 | } |
| 2713 | return null; |
| 2714 | } |
| 2715 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | private void applyEnterAnimationLocked(WindowState win) { |
| 2717 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2718 | if (win.mEnterAnimationPending) { |
| 2719 | win.mEnterAnimationPending = false; |
| 2720 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2721 | } |
| 2722 | |
| 2723 | applyAnimationLocked(win, transit, true); |
| 2724 | } |
| 2725 | |
| 2726 | private boolean applyAnimationLocked(WindowState win, |
| 2727 | int transit, boolean isEntrance) { |
| 2728 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2729 | // If we are trying to apply an animation, but already running |
| 2730 | // an animation of the same type, then just leave that one alone. |
| 2731 | return true; |
| 2732 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2733 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | // Only apply an animation if the display isn't frozen. If it is |
| 2735 | // frozen, there is no reason to animate and it can cause strange |
| 2736 | // artifacts when we unfreeze the display if some different animation |
| 2737 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2738 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2740 | int attr = -1; |
| 2741 | Animation a = null; |
| 2742 | if (anim != 0) { |
| 2743 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2744 | } else { |
| 2745 | switch (transit) { |
| 2746 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2747 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2748 | break; |
| 2749 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2750 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2751 | break; |
| 2752 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2753 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2754 | break; |
| 2755 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2756 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2757 | break; |
| 2758 | } |
| 2759 | if (attr >= 0) { |
| 2760 | a = loadAnimation(win.mAttrs, attr); |
| 2761 | } |
| 2762 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2763 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2765 | + " mAnimation=" + win.mAnimation |
| 2766 | + " isEntrance=" + isEntrance); |
| 2767 | if (a != null) { |
| 2768 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2769 | RuntimeException e = null; |
| 2770 | if (!HIDE_STACK_CRAWLS) { |
| 2771 | e = new RuntimeException(); |
| 2772 | e.fillInStackTrace(); |
| 2773 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2774 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | } |
| 2776 | win.setAnimation(a); |
| 2777 | win.mAnimationIsEntrance = isEntrance; |
| 2778 | } |
| 2779 | } else { |
| 2780 | win.clearAnimation(); |
| 2781 | } |
| 2782 | |
| 2783 | return win.mAnimation != null; |
| 2784 | } |
| 2785 | |
| 2786 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2787 | int anim = 0; |
| 2788 | Context context = mContext; |
| 2789 | if (animAttr >= 0) { |
| 2790 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2791 | if (ent != null) { |
| 2792 | context = ent.context; |
| 2793 | anim = ent.array.getResourceId(animAttr, 0); |
| 2794 | } |
| 2795 | } |
| 2796 | if (anim != 0) { |
| 2797 | return AnimationUtils.loadAnimation(context, anim); |
| 2798 | } |
| 2799 | return null; |
| 2800 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2801 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2802 | private Animation loadAnimation(String packageName, int resId) { |
| 2803 | int anim = 0; |
| 2804 | Context context = mContext; |
| 2805 | if (resId >= 0) { |
| 2806 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2807 | if (ent != null) { |
| 2808 | context = ent.context; |
| 2809 | anim = resId; |
| 2810 | } |
| 2811 | } |
| 2812 | if (anim != 0) { |
| 2813 | return AnimationUtils.loadAnimation(context, anim); |
| 2814 | } |
| 2815 | return null; |
| 2816 | } |
| 2817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2818 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2819 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2820 | // Only apply an animation if the display isn't frozen. If it is |
| 2821 | // frozen, there is no reason to animate and it can cause strange |
| 2822 | // artifacts when we unfreeze the display if some different animation |
| 2823 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2824 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2825 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2826 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2827 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2828 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2829 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2830 | } else if (mNextAppTransitionPackage != null) { |
| 2831 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2832 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2833 | } else { |
| 2834 | int animAttr = 0; |
| 2835 | switch (transit) { |
| 2836 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2837 | animAttr = enter |
| 2838 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2839 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2840 | break; |
| 2841 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2842 | animAttr = enter |
| 2843 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2844 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2845 | break; |
| 2846 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2847 | animAttr = enter |
| 2848 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2849 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2850 | break; |
| 2851 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2852 | animAttr = enter |
| 2853 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2854 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2855 | break; |
| 2856 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2857 | animAttr = enter |
| 2858 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2859 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2860 | break; |
| 2861 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2862 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2863 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2864 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2865 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2866 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2867 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2868 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2869 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2870 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2871 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2872 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2873 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2874 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2875 | break; |
| 2876 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2877 | animAttr = enter |
| 2878 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2879 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2880 | break; |
| 2881 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2882 | animAttr = enter |
| 2883 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2884 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2885 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2886 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2887 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2888 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2889 | + " anim=" + a |
| 2890 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2891 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | if (a != null) { |
| 2894 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2895 | RuntimeException e = null; |
| 2896 | if (!HIDE_STACK_CRAWLS) { |
| 2897 | e = new RuntimeException(); |
| 2898 | e.fillInStackTrace(); |
| 2899 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2900 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
| 2902 | wtoken.setAnimation(a); |
| 2903 | } |
| 2904 | } else { |
| 2905 | wtoken.clearAnimation(); |
| 2906 | } |
| 2907 | |
| 2908 | return wtoken.animation != null; |
| 2909 | } |
| 2910 | |
| 2911 | // ------------------------------------------------------------- |
| 2912 | // Application Window Tokens |
| 2913 | // ------------------------------------------------------------- |
| 2914 | |
| 2915 | public void validateAppTokens(List tokens) { |
| 2916 | int v = tokens.size()-1; |
| 2917 | int m = mAppTokens.size()-1; |
| 2918 | while (v >= 0 && m >= 0) { |
| 2919 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2920 | if (wtoken.removed) { |
| 2921 | m--; |
| 2922 | continue; |
| 2923 | } |
| 2924 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2925 | 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] | 2926 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2927 | } |
| 2928 | v--; |
| 2929 | m--; |
| 2930 | } |
| 2931 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2932 | 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] | 2933 | v--; |
| 2934 | } |
| 2935 | while (m >= 0) { |
| 2936 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2937 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2938 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | } |
| 2940 | m--; |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | boolean checkCallingPermission(String permission, String func) { |
| 2945 | // Quick check: if the calling permission is me, it's all okay. |
| 2946 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2947 | return true; |
| 2948 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2950 | if (mContext.checkCallingPermission(permission) |
| 2951 | == PackageManager.PERMISSION_GRANTED) { |
| 2952 | return true; |
| 2953 | } |
| 2954 | String msg = "Permission Denial: " + func + " from pid=" |
| 2955 | + Binder.getCallingPid() |
| 2956 | + ", uid=" + Binder.getCallingUid() |
| 2957 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2958 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | return false; |
| 2960 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2961 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2963 | WindowToken wtoken = mTokenMap.get(token); |
| 2964 | if (wtoken == null) { |
| 2965 | return null; |
| 2966 | } |
| 2967 | return wtoken.appWindowToken; |
| 2968 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2969 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | public void addWindowToken(IBinder token, int type) { |
| 2971 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2972 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2973 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | synchronized(mWindowMap) { |
| 2977 | WindowToken wtoken = mTokenMap.get(token); |
| 2978 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2979 | 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] | 2980 | return; |
| 2981 | } |
| 2982 | wtoken = new WindowToken(token, type, true); |
| 2983 | mTokenMap.put(token, wtoken); |
| 2984 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2985 | if (type == TYPE_WALLPAPER) { |
| 2986 | mWallpaperTokens.add(wtoken); |
| 2987 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | } |
| 2989 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2990 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2991 | public void removeWindowToken(IBinder token) { |
| 2992 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2993 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2994 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | final long origId = Binder.clearCallingIdentity(); |
| 2998 | synchronized(mWindowMap) { |
| 2999 | WindowToken wtoken = mTokenMap.remove(token); |
| 3000 | mTokenList.remove(wtoken); |
| 3001 | if (wtoken != null) { |
| 3002 | boolean delayed = false; |
| 3003 | if (!wtoken.hidden) { |
| 3004 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | final int N = wtoken.windows.size(); |
| 3007 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3008 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | for (int i=0; i<N; i++) { |
| 3010 | WindowState win = wtoken.windows.get(i); |
| 3011 | |
| 3012 | if (win.isAnimating()) { |
| 3013 | delayed = true; |
| 3014 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3015 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | if (win.isVisibleNow()) { |
| 3017 | applyAnimationLocked(win, |
| 3018 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3019 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3020 | KeyWaiter.RETURN_NOTHING); |
| 3021 | changed = true; |
| 3022 | } |
| 3023 | } |
| 3024 | |
| 3025 | if (changed) { |
| 3026 | mLayoutNeeded = true; |
| 3027 | performLayoutAndPlaceSurfacesLocked(); |
| 3028 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3029 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3030 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | if (delayed) { |
| 3032 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3033 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3034 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | } |
| 3036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3038 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3039 | 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] | 3040 | } |
| 3041 | } |
| 3042 | Binder.restoreCallingIdentity(origId); |
| 3043 | } |
| 3044 | |
| 3045 | public void addAppToken(int addPos, IApplicationToken token, |
| 3046 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3047 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3048 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3049 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3051 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3052 | synchronized(mWindowMap) { |
| 3053 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3054 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3055 | 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] | 3056 | return; |
| 3057 | } |
| 3058 | wtoken = new AppWindowToken(token); |
| 3059 | wtoken.groupId = groupId; |
| 3060 | wtoken.appFullscreen = fullscreen; |
| 3061 | wtoken.requestedOrientation = requestedOrientation; |
| 3062 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3063 | 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] | 3064 | mTokenMap.put(token.asBinder(), wtoken); |
| 3065 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3066 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3067 | // Application tokens start out hidden. |
| 3068 | wtoken.hidden = true; |
| 3069 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3071 | //dump(); |
| 3072 | } |
| 3073 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3074 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | public void setAppGroupId(IBinder token, int groupId) { |
| 3076 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3077 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3078 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | synchronized(mWindowMap) { |
| 3082 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3083 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3084 | 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] | 3085 | return; |
| 3086 | } |
| 3087 | wtoken.groupId = groupId; |
| 3088 | } |
| 3089 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3090 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3091 | public int getOrientationFromWindowsLocked() { |
| 3092 | int pos = mWindows.size() - 1; |
| 3093 | while (pos >= 0) { |
| 3094 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 3095 | pos--; |
| 3096 | if (wtoken.mAppToken != null) { |
| 3097 | // We hit an application window. so the orientation will be determined by the |
| 3098 | // app window. No point in continuing further. |
| 3099 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3100 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3101 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3102 | continue; |
| 3103 | } |
| 3104 | int req = wtoken.mAttrs.screenOrientation; |
| 3105 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3106 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3107 | continue; |
| 3108 | } else { |
| 3109 | return req; |
| 3110 | } |
| 3111 | } |
| 3112 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3113 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3114 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3116 | int pos = mAppTokens.size() - 1; |
| 3117 | int curGroup = 0; |
| 3118 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3119 | boolean findingBehind = false; |
| 3120 | boolean haveGroup = false; |
| 3121 | boolean lastFullscreen = false; |
| 3122 | while (pos >= 0) { |
| 3123 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3124 | pos--; |
| 3125 | // if we're about to tear down this window and not seek for |
| 3126 | // the behind activity, don't use it for orientation |
| 3127 | if (!findingBehind |
| 3128 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3129 | continue; |
| 3130 | } |
| 3131 | |
| 3132 | if (!haveGroup) { |
| 3133 | // We ignore any hidden applications on the top. |
| 3134 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3135 | continue; |
| 3136 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3137 | haveGroup = true; |
| 3138 | curGroup = wtoken.groupId; |
| 3139 | lastOrientation = wtoken.requestedOrientation; |
| 3140 | } else if (curGroup != wtoken.groupId) { |
| 3141 | // If we have hit a new application group, and the bottom |
| 3142 | // of the previous group didn't explicitly say to use |
| 3143 | // the orientation behind it, and the last app was |
| 3144 | // full screen, then we'll stick with the |
| 3145 | // user's orientation. |
| 3146 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3147 | && lastFullscreen) { |
| 3148 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3151 | int or = wtoken.requestedOrientation; |
| 3152 | // If this application is fullscreen, and didn't explicitly say |
| 3153 | // to use the orientation behind it, then just take whatever |
| 3154 | // orientation it has and ignores whatever is under it. |
| 3155 | lastFullscreen = wtoken.appFullscreen; |
| 3156 | if (lastFullscreen |
| 3157 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3158 | return or; |
| 3159 | } |
| 3160 | // If this application has requested an explicit orientation, |
| 3161 | // then use it. |
| 3162 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3163 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3164 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3165 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3166 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3167 | return or; |
| 3168 | } |
| 3169 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3170 | } |
| 3171 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3172 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3175 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3176 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3177 | "updateOrientationFromAppTokens()")) { |
| 3178 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3179 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3180 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3181 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3182 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3183 | |
| 3184 | synchronized(mWindowMap) { |
| 3185 | if (updateOrientationFromAppTokensLocked()) { |
| 3186 | if (freezeThisOneIfNeeded != null) { |
| 3187 | AppWindowToken wtoken = findAppWindowToken( |
| 3188 | freezeThisOneIfNeeded); |
| 3189 | if (wtoken != null) { |
| 3190 | startAppFreezingScreenLocked(wtoken, |
| 3191 | ActivityInfo.CONFIG_ORIENTATION); |
| 3192 | } |
| 3193 | } |
| 3194 | config = computeNewConfigurationLocked(); |
| 3195 | |
| 3196 | } else if (currentConfig != null) { |
| 3197 | // No obvious action we need to take, but if our current |
| 3198 | // state mismatches the activity maanager's, update it |
| 3199 | mTempConfiguration.setToDefaults(); |
| 3200 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3201 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3202 | mWaitingForConfig = true; |
| 3203 | mLayoutNeeded = true; |
| 3204 | startFreezingDisplayLocked(); |
| 3205 | config = new Configuration(mTempConfiguration); |
| 3206 | } |
| 3207 | } |
| 3208 | } |
| 3209 | } |
| 3210 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3211 | Binder.restoreCallingIdentity(ident); |
| 3212 | return config; |
| 3213 | } |
| 3214 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3215 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3216 | * Determine the new desired orientation of the display, returning |
| 3217 | * a non-null new Configuration if it has changed from the current |
| 3218 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3219 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3220 | * SCREEN. This will typically be done for you if you call |
| 3221 | * sendNewConfiguration(). |
| 3222 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | * The orientation is computed from non-application windows first. If none of |
| 3224 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3225 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3227 | * android.os.IBinder) |
| 3228 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3229 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3230 | if (mDisplayFrozen) { |
| 3231 | // If the display is frozen, some activities may be in the middle |
| 3232 | // of restarting, and thus have removed their old window. If the |
| 3233 | // window has the flag to hide the lock screen, then the lock screen |
| 3234 | // can re-appear and inflict its own orientation on us. Keep the |
| 3235 | // orientation stable until this all settles down. |
| 3236 | return false; |
| 3237 | } |
| 3238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | long ident = Binder.clearCallingIdentity(); |
| 3241 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3242 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3243 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | mForcedAppOrientation = req; |
| 3246 | //send a message to Policy indicating orientation change to take |
| 3247 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3248 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3249 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3250 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3251 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | } |
| 3253 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3254 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3255 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(ident); |
| 3258 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3260 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3261 | int computeForcedAppOrientationLocked() { |
| 3262 | int req = getOrientationFromWindowsLocked(); |
| 3263 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3264 | req = getOrientationFromAppTokensLocked(); |
| 3265 | } |
| 3266 | return req; |
| 3267 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3268 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3269 | public void setNewConfiguration(Configuration config) { |
| 3270 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3271 | "setNewConfiguration()")) { |
| 3272 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3273 | } |
| 3274 | |
| 3275 | synchronized(mWindowMap) { |
| 3276 | mCurConfiguration = new Configuration(config); |
| 3277 | mWaitingForConfig = false; |
| 3278 | performLayoutAndPlaceSurfacesLocked(); |
| 3279 | } |
| 3280 | } |
| 3281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3282 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3283 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3284 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3285 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | synchronized(mWindowMap) { |
| 3289 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3290 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3291 | 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] | 3292 | return; |
| 3293 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3294 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3295 | wtoken.requestedOrientation = requestedOrientation; |
| 3296 | } |
| 3297 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3299 | public int getAppOrientation(IApplicationToken token) { |
| 3300 | synchronized(mWindowMap) { |
| 3301 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3302 | if (wtoken == null) { |
| 3303 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | return wtoken.requestedOrientation; |
| 3307 | } |
| 3308 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3311 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3312 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3313 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | synchronized(mWindowMap) { |
| 3317 | boolean changed = false; |
| 3318 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3319 | 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] | 3320 | changed = mFocusedApp != null; |
| 3321 | mFocusedApp = null; |
| 3322 | mKeyWaiter.tickle(); |
| 3323 | } else { |
| 3324 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3325 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3326 | 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] | 3327 | return; |
| 3328 | } |
| 3329 | changed = mFocusedApp != newFocus; |
| 3330 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3331 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | mKeyWaiter.tickle(); |
| 3333 | } |
| 3334 | |
| 3335 | if (moveFocusNow && changed) { |
| 3336 | final long origId = Binder.clearCallingIdentity(); |
| 3337 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3338 | Binder.restoreCallingIdentity(origId); |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | public void prepareAppTransition(int transit) { |
| 3344 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3345 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3346 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3348 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3350 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3351 | TAG, "Prepare app transition: transit=" + transit |
| 3352 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3353 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3354 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3355 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3357 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3358 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3359 | // Opening a new task always supersedes a close for the anim. |
| 3360 | mNextAppTransition = transit; |
| 3361 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3362 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3363 | // Opening a new activity always supersedes a close for the anim. |
| 3364 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | } |
| 3366 | mAppTransitionReady = false; |
| 3367 | mAppTransitionTimeout = false; |
| 3368 | mStartingIconInTransition = false; |
| 3369 | mSkipAppTransitionAnimation = false; |
| 3370 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3371 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3372 | 5000); |
| 3373 | } |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | public int getPendingAppTransition() { |
| 3378 | return mNextAppTransition; |
| 3379 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3380 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3381 | public void overridePendingAppTransition(String packageName, |
| 3382 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3383 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3384 | mNextAppTransitionPackage = packageName; |
| 3385 | mNextAppTransitionEnter = enterAnim; |
| 3386 | mNextAppTransitionExit = exitAnim; |
| 3387 | } |
| 3388 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | public void executeAppTransition() { |
| 3391 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3392 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3393 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3397 | if (DEBUG_APP_TRANSITIONS) { |
| 3398 | RuntimeException e = new RuntimeException("here"); |
| 3399 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3400 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3401 | + mNextAppTransition, e); |
| 3402 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3403 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | mAppTransitionReady = true; |
| 3405 | final long origId = Binder.clearCallingIdentity(); |
| 3406 | performLayoutAndPlaceSurfacesLocked(); |
| 3407 | Binder.restoreCallingIdentity(origId); |
| 3408 | } |
| 3409 | } |
| 3410 | } |
| 3411 | |
| 3412 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3413 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3414 | IBinder transferFrom, boolean createIfNeeded) { |
| 3415 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3416 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3417 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3421 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3423 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3426 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3427 | 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] | 3428 | return; |
| 3429 | } |
| 3430 | |
| 3431 | // If the display is frozen, we won't do anything until the |
| 3432 | // actual window is displayed so there is no reason to put in |
| 3433 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3434 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | return; |
| 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 | if (wtoken.startingData != null) { |
| 3439 | return; |
| 3440 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3442 | if (transferFrom != null) { |
| 3443 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3444 | if (ttoken != null) { |
| 3445 | WindowState startingWindow = ttoken.startingWindow; |
| 3446 | if (startingWindow != null) { |
| 3447 | if (mStartingIconInTransition) { |
| 3448 | // In this case, the starting icon has already |
| 3449 | // been displayed, so start letting windows get |
| 3450 | // shown immediately without any more transitions. |
| 3451 | mSkipAppTransitionAnimation = true; |
| 3452 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3453 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | "Moving existing starting from " + ttoken |
| 3455 | + " to " + wtoken); |
| 3456 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3457 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3458 | // Transfer the starting window over to the new |
| 3459 | // token. |
| 3460 | wtoken.startingData = ttoken.startingData; |
| 3461 | wtoken.startingView = ttoken.startingView; |
| 3462 | wtoken.startingWindow = startingWindow; |
| 3463 | ttoken.startingData = null; |
| 3464 | ttoken.startingView = null; |
| 3465 | ttoken.startingWindow = null; |
| 3466 | ttoken.startingMoved = true; |
| 3467 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3468 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3469 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3470 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3471 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | mWindows.remove(startingWindow); |
| 3473 | ttoken.windows.remove(startingWindow); |
| 3474 | ttoken.allAppWindows.remove(startingWindow); |
| 3475 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3476 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | // Propagate other interesting state between the |
| 3478 | // tokens. If the old token is displayed, we should |
| 3479 | // immediately force the new one to be displayed. If |
| 3480 | // it is animating, we need to move that animation to |
| 3481 | // the new one. |
| 3482 | if (ttoken.allDrawn) { |
| 3483 | wtoken.allDrawn = true; |
| 3484 | } |
| 3485 | if (ttoken.firstWindowDrawn) { |
| 3486 | wtoken.firstWindowDrawn = true; |
| 3487 | } |
| 3488 | if (!ttoken.hidden) { |
| 3489 | wtoken.hidden = false; |
| 3490 | wtoken.hiddenRequested = false; |
| 3491 | wtoken.willBeHidden = false; |
| 3492 | } |
| 3493 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3494 | wtoken.clientHidden = ttoken.clientHidden; |
| 3495 | wtoken.sendAppVisibilityToClients(); |
| 3496 | } |
| 3497 | if (ttoken.animation != null) { |
| 3498 | wtoken.animation = ttoken.animation; |
| 3499 | wtoken.animating = ttoken.animating; |
| 3500 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3501 | ttoken.animation = null; |
| 3502 | ttoken.animLayerAdjustment = 0; |
| 3503 | wtoken.updateLayers(); |
| 3504 | ttoken.updateLayers(); |
| 3505 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | mLayoutNeeded = true; |
| 3509 | performLayoutAndPlaceSurfacesLocked(); |
| 3510 | Binder.restoreCallingIdentity(origId); |
| 3511 | return; |
| 3512 | } else if (ttoken.startingData != null) { |
| 3513 | // The previous app was getting ready to show a |
| 3514 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3515 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3516 | "Moving pending starting from " + ttoken |
| 3517 | + " to " + wtoken); |
| 3518 | wtoken.startingData = ttoken.startingData; |
| 3519 | ttoken.startingData = null; |
| 3520 | ttoken.startingMoved = true; |
| 3521 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3522 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3523 | // want to process the message ASAP, before any other queued |
| 3524 | // messages. |
| 3525 | mH.sendMessageAtFrontOfQueue(m); |
| 3526 | return; |
| 3527 | } |
| 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | // There is no existing starting window, and the caller doesn't |
| 3532 | // want us to create one, so that's it! |
| 3533 | if (!createIfNeeded) { |
| 3534 | return; |
| 3535 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3536 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3537 | // If this is a translucent or wallpaper window, then don't |
| 3538 | // show a starting window -- the current effect (a full-screen |
| 3539 | // opaque starting window that fades away to the real contents |
| 3540 | // when it is ready) does not work for this. |
| 3541 | if (theme != 0) { |
| 3542 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3543 | com.android.internal.R.styleable.Window); |
| 3544 | if (ent.array.getBoolean( |
| 3545 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3546 | return; |
| 3547 | } |
| 3548 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3549 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3550 | return; |
| 3551 | } |
| 3552 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3553 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3554 | return; |
| 3555 | } |
| 3556 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | mStartingIconInTransition = true; |
| 3559 | wtoken.startingData = new StartingData( |
| 3560 | pkg, theme, nonLocalizedLabel, |
| 3561 | labelRes, icon); |
| 3562 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3563 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3564 | // want to process the message ASAP, before any other queued |
| 3565 | // messages. |
| 3566 | mH.sendMessageAtFrontOfQueue(m); |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | public void setAppWillBeHidden(IBinder token) { |
| 3571 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3572 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3573 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | AppWindowToken wtoken; |
| 3577 | |
| 3578 | synchronized(mWindowMap) { |
| 3579 | wtoken = findAppWindowToken(token); |
| 3580 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3581 | 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] | 3582 | return; |
| 3583 | } |
| 3584 | wtoken.willBeHidden = true; |
| 3585 | } |
| 3586 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3587 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3588 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3589 | boolean visible, int transit, boolean performLayout) { |
| 3590 | boolean delayed = false; |
| 3591 | |
| 3592 | if (wtoken.clientHidden == visible) { |
| 3593 | wtoken.clientHidden = !visible; |
| 3594 | wtoken.sendAppVisibilityToClients(); |
| 3595 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | wtoken.willBeHidden = false; |
| 3598 | if (wtoken.hidden == visible) { |
| 3599 | final int N = wtoken.allAppWindows.size(); |
| 3600 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3601 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3603 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3604 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3605 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3606 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3607 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | if (wtoken.animation == sDummyAnimation) { |
| 3609 | wtoken.animation = null; |
| 3610 | } |
| 3611 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3612 | changed = true; |
| 3613 | if (wtoken.animation != null) { |
| 3614 | delayed = runningAppAnimation = true; |
| 3615 | } |
| 3616 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3617 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | for (int i=0; i<N; i++) { |
| 3619 | WindowState win = wtoken.allAppWindows.get(i); |
| 3620 | if (win == wtoken.startingWindow) { |
| 3621 | continue; |
| 3622 | } |
| 3623 | |
| 3624 | if (win.isAnimating()) { |
| 3625 | delayed = true; |
| 3626 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3627 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3628 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | //win.dump(" "); |
| 3630 | if (visible) { |
| 3631 | if (!win.isVisibleNow()) { |
| 3632 | if (!runningAppAnimation) { |
| 3633 | applyAnimationLocked(win, |
| 3634 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3635 | } |
| 3636 | changed = true; |
| 3637 | } |
| 3638 | } else if (win.isVisibleNow()) { |
| 3639 | if (!runningAppAnimation) { |
| 3640 | applyAnimationLocked(win, |
| 3641 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3642 | } |
| 3643 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3644 | KeyWaiter.RETURN_NOTHING); |
| 3645 | changed = true; |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3650 | if (!visible) { |
| 3651 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3652 | } else { |
| 3653 | // If we are being set visible, and the starting window is |
| 3654 | // not yet displayed, then make sure it doesn't get displayed. |
| 3655 | WindowState swin = wtoken.startingWindow; |
| 3656 | if (swin != null && (swin.mDrawPending |
| 3657 | || swin.mCommitDrawPending)) { |
| 3658 | swin.mPolicyVisibility = false; |
| 3659 | swin.mPolicyVisibilityAfterAnim = false; |
| 3660 | } |
| 3661 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3662 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3663 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3665 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3666 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3667 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3669 | if (performLayout) { |
| 3670 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3671 | performLayoutAndPlaceSurfacesLocked(); |
| 3672 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | if (wtoken.animation != null) { |
| 3677 | delayed = true; |
| 3678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | return delayed; |
| 3681 | } |
| 3682 | |
| 3683 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3684 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3685 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3686 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | AppWindowToken wtoken; |
| 3690 | |
| 3691 | synchronized(mWindowMap) { |
| 3692 | wtoken = findAppWindowToken(token); |
| 3693 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3694 | 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] | 3695 | return; |
| 3696 | } |
| 3697 | |
| 3698 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3699 | RuntimeException e = null; |
| 3700 | if (!HIDE_STACK_CRAWLS) { |
| 3701 | e = new RuntimeException(); |
| 3702 | e.fillInStackTrace(); |
| 3703 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3704 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3705 | + "): mNextAppTransition=" + mNextAppTransition |
| 3706 | + " hidden=" + wtoken.hidden |
| 3707 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3708 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3709 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | // If we are preparing an app transition, then delay changing |
| 3711 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3712 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3713 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | // Already in requested state, don't do anything more. |
| 3715 | if (wtoken.hiddenRequested != visible) { |
| 3716 | return; |
| 3717 | } |
| 3718 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3719 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3720 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | TAG, "Setting dummy animation on: " + wtoken); |
| 3722 | wtoken.setDummyAnimation(); |
| 3723 | mOpeningApps.remove(wtoken); |
| 3724 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3725 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | wtoken.inPendingTransaction = true; |
| 3727 | if (visible) { |
| 3728 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | wtoken.startingDisplayed = false; |
| 3730 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3731 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3732 | // If the token is currently hidden (should be the |
| 3733 | // common case), then we need to set up to wait for |
| 3734 | // its windows to be ready. |
| 3735 | if (wtoken.hidden) { |
| 3736 | wtoken.allDrawn = false; |
| 3737 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3738 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3739 | if (wtoken.clientHidden) { |
| 3740 | // In the case where we are making an app visible |
| 3741 | // but holding off for a transition, we still need |
| 3742 | // to tell the client to make its windows visible so |
| 3743 | // they get drawn. Otherwise, we will wait on |
| 3744 | // performing the transition until all windows have |
| 3745 | // been drawn, they never will be, and we are sad. |
| 3746 | wtoken.clientHidden = false; |
| 3747 | wtoken.sendAppVisibilityToClients(); |
| 3748 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | } |
| 3750 | } else { |
| 3751 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3752 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3753 | // If the token is currently visible (should be the |
| 3754 | // common case), then set up to wait for it to be hidden. |
| 3755 | if (!wtoken.hidden) { |
| 3756 | wtoken.waitingToHide = true; |
| 3757 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | } |
| 3759 | return; |
| 3760 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3763 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | wtoken.updateReportedVisibilityLocked(); |
| 3765 | Binder.restoreCallingIdentity(origId); |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3770 | boolean unfreezeSurfaceNow, boolean force) { |
| 3771 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3772 | 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] | 3773 | + " force=" + force); |
| 3774 | final int N = wtoken.allAppWindows.size(); |
| 3775 | boolean unfrozeWindows = false; |
| 3776 | for (int i=0; i<N; i++) { |
| 3777 | WindowState w = wtoken.allAppWindows.get(i); |
| 3778 | if (w.mAppFreezing) { |
| 3779 | w.mAppFreezing = false; |
| 3780 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3781 | w.mOrientationChanging = true; |
| 3782 | } |
| 3783 | unfrozeWindows = true; |
| 3784 | } |
| 3785 | } |
| 3786 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3787 | 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] | 3788 | wtoken.freezingScreen = false; |
| 3789 | mAppsFreezingScreen--; |
| 3790 | } |
| 3791 | if (unfreezeSurfaceNow) { |
| 3792 | if (unfrozeWindows) { |
| 3793 | mLayoutNeeded = true; |
| 3794 | performLayoutAndPlaceSurfacesLocked(); |
| 3795 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3796 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3797 | } |
| 3798 | } |
| 3799 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3800 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3802 | int configChanges) { |
| 3803 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3804 | RuntimeException e = null; |
| 3805 | if (!HIDE_STACK_CRAWLS) { |
| 3806 | e = new RuntimeException(); |
| 3807 | e.fillInStackTrace(); |
| 3808 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3809 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3811 | + wtoken.freezingScreen, e); |
| 3812 | } |
| 3813 | if (!wtoken.hiddenRequested) { |
| 3814 | if (!wtoken.freezingScreen) { |
| 3815 | wtoken.freezingScreen = true; |
| 3816 | mAppsFreezingScreen++; |
| 3817 | if (mAppsFreezingScreen == 1) { |
| 3818 | startFreezingDisplayLocked(); |
| 3819 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3820 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3821 | 5000); |
| 3822 | } |
| 3823 | } |
| 3824 | final int N = wtoken.allAppWindows.size(); |
| 3825 | for (int i=0; i<N; i++) { |
| 3826 | WindowState w = wtoken.allAppWindows.get(i); |
| 3827 | w.mAppFreezing = true; |
| 3828 | } |
| 3829 | } |
| 3830 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3831 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3833 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3834 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3835 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3839 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3840 | 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] | 3841 | return; |
| 3842 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3843 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3845 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3846 | 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] | 3847 | return; |
| 3848 | } |
| 3849 | final long origId = Binder.clearCallingIdentity(); |
| 3850 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3851 | Binder.restoreCallingIdentity(origId); |
| 3852 | } |
| 3853 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3856 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3857 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3858 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | synchronized(mWindowMap) { |
| 3862 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3863 | if (wtoken == null || wtoken.appToken == null) { |
| 3864 | return; |
| 3865 | } |
| 3866 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3867 | 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] | 3868 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3869 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3870 | Binder.restoreCallingIdentity(origId); |
| 3871 | } |
| 3872 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | public void removeAppToken(IBinder token) { |
| 3875 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3876 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3877 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | AppWindowToken wtoken = null; |
| 3881 | AppWindowToken startingToken = null; |
| 3882 | boolean delayed = false; |
| 3883 | |
| 3884 | final long origId = Binder.clearCallingIdentity(); |
| 3885 | synchronized(mWindowMap) { |
| 3886 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3887 | mTokenList.remove(basewtoken); |
| 3888 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3889 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3890 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3891 | wtoken.inPendingTransaction = false; |
| 3892 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3893 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | if (mClosingApps.contains(wtoken)) { |
| 3895 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3896 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3898 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | delayed = true; |
| 3900 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3901 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3903 | + " animation=" + wtoken.animation |
| 3904 | + " animating=" + wtoken.animating); |
| 3905 | if (delayed) { |
| 3906 | // set the token aside because it has an active animation to be finished |
| 3907 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3908 | } else { |
| 3909 | // Make sure there is no animation running on this token, |
| 3910 | // so any windows associated with it will be removed as |
| 3911 | // soon as their animations are complete |
| 3912 | wtoken.animation = null; |
| 3913 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3914 | } |
| 3915 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3916 | if (mLastEnterAnimToken == wtoken) { |
| 3917 | mLastEnterAnimToken = null; |
| 3918 | mLastEnterAnimParams = null; |
| 3919 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3920 | wtoken.removed = true; |
| 3921 | if (wtoken.startingData != null) { |
| 3922 | startingToken = wtoken; |
| 3923 | } |
| 3924 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3925 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3926 | 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] | 3927 | mFocusedApp = null; |
| 3928 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3929 | mKeyWaiter.tickle(); |
| 3930 | } |
| 3931 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3932 | 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] | 3933 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3934 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3935 | if (!delayed && wtoken != null) { |
| 3936 | wtoken.updateReportedVisibilityLocked(); |
| 3937 | } |
| 3938 | } |
| 3939 | Binder.restoreCallingIdentity(origId); |
| 3940 | |
| 3941 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3942 | 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] | 3943 | + startingToken + ": app token removed"); |
| 3944 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3945 | mH.sendMessage(m); |
| 3946 | } |
| 3947 | } |
| 3948 | |
| 3949 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3950 | final int NW = token.windows.size(); |
| 3951 | for (int i=0; i<NW; i++) { |
| 3952 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3953 | 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] | 3954 | mWindows.remove(win); |
| 3955 | int j = win.mChildWindows.size(); |
| 3956 | while (j > 0) { |
| 3957 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3958 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3959 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3960 | "Tmp removing child window " + cwin); |
| 3961 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | } |
| 3963 | } |
| 3964 | return NW > 0; |
| 3965 | } |
| 3966 | |
| 3967 | void dumpAppTokensLocked() { |
| 3968 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3969 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | } |
| 3971 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | void dumpWindowsLocked() { |
| 3974 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3975 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | } |
| 3977 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3978 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | private int findWindowOffsetLocked(int tokenPos) { |
| 3980 | final int NW = mWindows.size(); |
| 3981 | |
| 3982 | if (tokenPos >= mAppTokens.size()) { |
| 3983 | int i = NW; |
| 3984 | while (i > 0) { |
| 3985 | i--; |
| 3986 | WindowState win = (WindowState)mWindows.get(i); |
| 3987 | if (win.getAppToken() != null) { |
| 3988 | return i+1; |
| 3989 | } |
| 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | while (tokenPos > 0) { |
| 3994 | // Find the first app token below the new position that has |
| 3995 | // a window displayed. |
| 3996 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3997 | 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] | 3998 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3999 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4000 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4001 | "Skipping token -- currently sending to bottom"); |
| 4002 | tokenPos--; |
| 4003 | continue; |
| 4004 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | int i = wtoken.windows.size(); |
| 4006 | while (i > 0) { |
| 4007 | i--; |
| 4008 | WindowState win = wtoken.windows.get(i); |
| 4009 | int j = win.mChildWindows.size(); |
| 4010 | while (j > 0) { |
| 4011 | j--; |
| 4012 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4013 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4014 | for (int pos=NW-1; pos>=0; pos--) { |
| 4015 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4016 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | "Found child win @" + (pos+1)); |
| 4018 | return pos+1; |
| 4019 | } |
| 4020 | } |
| 4021 | } |
| 4022 | } |
| 4023 | for (int pos=NW-1; pos>=0; pos--) { |
| 4024 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4025 | 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] | 4026 | return pos+1; |
| 4027 | } |
| 4028 | } |
| 4029 | } |
| 4030 | tokenPos--; |
| 4031 | } |
| 4032 | |
| 4033 | return 0; |
| 4034 | } |
| 4035 | |
| 4036 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4037 | final int NCW = win.mChildWindows.size(); |
| 4038 | boolean added = false; |
| 4039 | for (int j=0; j<NCW; j++) { |
| 4040 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 4041 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4042 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4043 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4044 | mWindows.add(index, win); |
| 4045 | index++; |
| 4046 | added = true; |
| 4047 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4048 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4049 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4050 | mWindows.add(index, cwin); |
| 4051 | index++; |
| 4052 | } |
| 4053 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4054 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4055 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4056 | mWindows.add(index, win); |
| 4057 | index++; |
| 4058 | } |
| 4059 | return index; |
| 4060 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4061 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4063 | final int NW = token.windows.size(); |
| 4064 | for (int i=0; i<NW; i++) { |
| 4065 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4066 | } |
| 4067 | return index; |
| 4068 | } |
| 4069 | |
| 4070 | public void moveAppToken(int index, IBinder token) { |
| 4071 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4072 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4073 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4077 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4079 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4080 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4081 | 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] | 4082 | + token + " (" + wtoken + ")"); |
| 4083 | return; |
| 4084 | } |
| 4085 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4086 | 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] | 4087 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4088 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4090 | 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] | 4091 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4092 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4093 | 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] | 4094 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4095 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4096 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4098 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | mLayoutNeeded = true; |
| 4100 | performLayoutAndPlaceSurfacesLocked(); |
| 4101 | } |
| 4102 | Binder.restoreCallingIdentity(origId); |
| 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4107 | // XXX This should be done more efficiently! |
| 4108 | // (take advantage of the fact that both lists should be |
| 4109 | // ordered in the same way.) |
| 4110 | int N = tokens.size(); |
| 4111 | for (int i=0; i<N; i++) { |
| 4112 | IBinder token = tokens.get(i); |
| 4113 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4114 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4115 | 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] | 4116 | + token + " (" + wtoken + ")"); |
| 4117 | i--; |
| 4118 | N--; |
| 4119 | } |
| 4120 | } |
| 4121 | } |
| 4122 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4123 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4124 | boolean updateFocusAndLayout) { |
| 4125 | // First remove all of the windows from the list. |
| 4126 | tmpRemoveAppWindowsLocked(wtoken); |
| 4127 | |
| 4128 | // Where to start adding? |
| 4129 | int pos = findWindowOffsetLocked(tokenPos); |
| 4130 | |
| 4131 | // And now add them back at the correct place. |
| 4132 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4133 | |
| 4134 | if (updateFocusAndLayout) { |
| 4135 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4136 | assignLayersLocked(); |
| 4137 | } |
| 4138 | mLayoutNeeded = true; |
| 4139 | performLayoutAndPlaceSurfacesLocked(); |
| 4140 | } |
| 4141 | } |
| 4142 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4143 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4144 | // First remove all of the windows from the list. |
| 4145 | final int N = tokens.size(); |
| 4146 | int i; |
| 4147 | for (i=0; i<N; i++) { |
| 4148 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4149 | if (token != null) { |
| 4150 | tmpRemoveAppWindowsLocked(token); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | // Where to start adding? |
| 4155 | int pos = findWindowOffsetLocked(tokenPos); |
| 4156 | |
| 4157 | // And now add them back at the correct place. |
| 4158 | for (i=0; i<N; i++) { |
| 4159 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4160 | if (token != null) { |
| 4161 | pos = reAddAppWindowsLocked(pos, token); |
| 4162 | } |
| 4163 | } |
| 4164 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4165 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4166 | assignLayersLocked(); |
| 4167 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | mLayoutNeeded = true; |
| 4169 | performLayoutAndPlaceSurfacesLocked(); |
| 4170 | |
| 4171 | //dump(); |
| 4172 | } |
| 4173 | |
| 4174 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4175 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4176 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4177 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | final long origId = Binder.clearCallingIdentity(); |
| 4181 | synchronized(mWindowMap) { |
| 4182 | removeAppTokensLocked(tokens); |
| 4183 | final int N = tokens.size(); |
| 4184 | for (int i=0; i<N; i++) { |
| 4185 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4186 | if (wt != null) { |
| 4187 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4188 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4189 | mToTopApps.remove(wt); |
| 4190 | mToBottomApps.remove(wt); |
| 4191 | mToTopApps.add(wt); |
| 4192 | wt.sendingToBottom = false; |
| 4193 | wt.sendingToTop = true; |
| 4194 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | } |
| 4196 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4197 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4198 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4199 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4200 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | } |
| 4202 | Binder.restoreCallingIdentity(origId); |
| 4203 | } |
| 4204 | |
| 4205 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4206 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4207 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4208 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | final long origId = Binder.clearCallingIdentity(); |
| 4212 | synchronized(mWindowMap) { |
| 4213 | removeAppTokensLocked(tokens); |
| 4214 | final int N = tokens.size(); |
| 4215 | int pos = 0; |
| 4216 | for (int i=0; i<N; i++) { |
| 4217 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4218 | if (wt != null) { |
| 4219 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4220 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4221 | mToTopApps.remove(wt); |
| 4222 | mToBottomApps.remove(wt); |
| 4223 | mToBottomApps.add(i, wt); |
| 4224 | wt.sendingToTop = false; |
| 4225 | wt.sendingToBottom = true; |
| 4226 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4227 | pos++; |
| 4228 | } |
| 4229 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4230 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4231 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4232 | moveAppWindowsLocked(tokens, 0); |
| 4233 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | } |
| 4235 | Binder.restoreCallingIdentity(origId); |
| 4236 | } |
| 4237 | |
| 4238 | // ------------------------------------------------------------- |
| 4239 | // Misc IWindowSession methods |
| 4240 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4241 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4242 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4243 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4244 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4245 | // called before DevicePolicyManagerService has started. |
| 4246 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4247 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4248 | Context.DEVICE_POLICY_SERVICE); |
| 4249 | if (dpm != null) { |
| 4250 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4251 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4252 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4253 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4254 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4255 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4259 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4260 | != PackageManager.PERMISSION_GRANTED) { |
| 4261 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4262 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4263 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4264 | synchronized (mKeyguardTokenWatcher) { |
| 4265 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4266 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4270 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | != PackageManager.PERMISSION_GRANTED) { |
| 4272 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4273 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4274 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4275 | synchronized (mKeyguardTokenWatcher) { |
| 4276 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4277 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4278 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4279 | // If we are the last one to reenable the keyguard wait until |
| 4280 | // we have actually finished reenabling until returning. |
| 4281 | // It is possible that reenableKeyguard() can be called before |
| 4282 | // the previous disableKeyguard() is handled, in which case |
| 4283 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4284 | // be called. In that case mKeyguardDisabled will be false here |
| 4285 | // and we have nothing to wait for. |
| 4286 | while (mKeyguardDisabled) { |
| 4287 | try { |
| 4288 | mKeyguardTokenWatcher.wait(); |
| 4289 | } catch (InterruptedException e) { |
| 4290 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | } |
| 4294 | } |
| 4295 | } |
| 4296 | |
| 4297 | /** |
| 4298 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4299 | */ |
| 4300 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4301 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | != PackageManager.PERMISSION_GRANTED) { |
| 4303 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4304 | } |
| 4305 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4306 | public void onKeyguardExitResult(boolean success) { |
| 4307 | try { |
| 4308 | callback.onKeyguardExitResult(success); |
| 4309 | } catch (RemoteException e) { |
| 4310 | // Client has died, we don't care. |
| 4311 | } |
| 4312 | } |
| 4313 | }); |
| 4314 | } |
| 4315 | |
| 4316 | public boolean inKeyguardRestrictedInputMode() { |
| 4317 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4318 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4319 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4320 | public void closeSystemDialogs(String reason) { |
| 4321 | synchronized(mWindowMap) { |
| 4322 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4323 | WindowState w = (WindowState)mWindows.get(i); |
| 4324 | if (w.mSurface != null) { |
| 4325 | try { |
| 4326 | w.mClient.closeSystemDialogs(reason); |
| 4327 | } catch (RemoteException e) { |
| 4328 | } |
| 4329 | } |
| 4330 | } |
| 4331 | } |
| 4332 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | static float fixScale(float scale) { |
| 4335 | if (scale < 0) scale = 0; |
| 4336 | else if (scale > 20) scale = 20; |
| 4337 | return Math.abs(scale); |
| 4338 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | public void setAnimationScale(int which, float scale) { |
| 4341 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4342 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4343 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | if (scale < 0) scale = 0; |
| 4347 | else if (scale > 20) scale = 20; |
| 4348 | scale = Math.abs(scale); |
| 4349 | switch (which) { |
| 4350 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4351 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4352 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4353 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4354 | // Persist setting |
| 4355 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4356 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | public void setAnimationScales(float[] scales) { |
| 4359 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4360 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4361 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | if (scales != null) { |
| 4365 | if (scales.length >= 1) { |
| 4366 | mWindowAnimationScale = fixScale(scales[0]); |
| 4367 | } |
| 4368 | if (scales.length >= 2) { |
| 4369 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4370 | } |
| 4371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4373 | // Persist setting |
| 4374 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4375 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | public float getAnimationScale(int which) { |
| 4378 | switch (which) { |
| 4379 | case 0: return mWindowAnimationScale; |
| 4380 | case 1: return mTransitionAnimationScale; |
| 4381 | } |
| 4382 | return 0; |
| 4383 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | public float[] getAnimationScales() { |
| 4386 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4387 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4388 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | public int getSwitchState(int sw) { |
| 4390 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4391 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4392 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4393 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4394 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4395 | return mInputManager.getSwitchState(sw); |
| 4396 | } else { |
| 4397 | return KeyInputQueue.getSwitchState(sw); |
| 4398 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4399 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4402 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4403 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4404 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4405 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4406 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4407 | return mInputManager.getSwitchState(devid, sw); |
| 4408 | } else { |
| 4409 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4410 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4412 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | public int getScancodeState(int sw) { |
| 4414 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4415 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4416 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4418 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4419 | return mInputManager.getScancodeState(sw); |
| 4420 | } else { |
| 4421 | return mQueue.getScancodeState(sw); |
| 4422 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4426 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4427 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4428 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4429 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4430 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4431 | return mInputManager.getScancodeState(devid, sw); |
| 4432 | } else { |
| 4433 | return mQueue.getScancodeState(devid, sw); |
| 4434 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4436 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4437 | public int getTrackballScancodeState(int sw) { |
| 4438 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4439 | "getTrackballScancodeState()")) { |
| 4440 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4441 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4442 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4443 | return mInputManager.getTrackballScancodeState(sw); |
| 4444 | } else { |
| 4445 | return mQueue.getTrackballScancodeState(sw); |
| 4446 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | public int getDPadScancodeState(int sw) { |
| 4450 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4451 | "getDPadScancodeState()")) { |
| 4452 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4453 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4454 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4455 | return mInputManager.getDPadScancodeState(sw); |
| 4456 | } else { |
| 4457 | return mQueue.getDPadScancodeState(sw); |
| 4458 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4459 | } |
| 4460 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | public int getKeycodeState(int sw) { |
| 4462 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4463 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4464 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4465 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4466 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4467 | return mInputManager.getKeycodeState(sw); |
| 4468 | } else { |
| 4469 | return mQueue.getKeycodeState(sw); |
| 4470 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4474 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4475 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4476 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4478 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4479 | return mInputManager.getKeycodeState(devid, sw); |
| 4480 | } else { |
| 4481 | return mQueue.getKeycodeState(devid, sw); |
| 4482 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4484 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4485 | public int getTrackballKeycodeState(int sw) { |
| 4486 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4487 | "getTrackballKeycodeState()")) { |
| 4488 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4489 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4490 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4491 | return mInputManager.getTrackballKeycodeState(sw); |
| 4492 | } else { |
| 4493 | return mQueue.getTrackballKeycodeState(sw); |
| 4494 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | public int getDPadKeycodeState(int sw) { |
| 4498 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4499 | "getDPadKeycodeState()")) { |
| 4500 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4501 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4502 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4503 | return mInputManager.getDPadKeycodeState(sw); |
| 4504 | } else { |
| 4505 | return mQueue.getDPadKeycodeState(sw); |
| 4506 | } |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4507 | } |
| 4508 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4510 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4511 | return mInputManager.hasKeys(keycodes, keyExists); |
| 4512 | } else { |
| 4513 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4514 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4516 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | public void enableScreenAfterBoot() { |
| 4518 | synchronized(mWindowMap) { |
| 4519 | if (mSystemBooted) { |
| 4520 | return; |
| 4521 | } |
| 4522 | mSystemBooted = true; |
| 4523 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | performEnableScreen(); |
| 4526 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4527 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4528 | public void enableScreenIfNeededLocked() { |
| 4529 | if (mDisplayEnabled) { |
| 4530 | return; |
| 4531 | } |
| 4532 | if (!mSystemBooted) { |
| 4533 | return; |
| 4534 | } |
| 4535 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4536 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4537 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | public void performEnableScreen() { |
| 4539 | synchronized(mWindowMap) { |
| 4540 | if (mDisplayEnabled) { |
| 4541 | return; |
| 4542 | } |
| 4543 | if (!mSystemBooted) { |
| 4544 | return; |
| 4545 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | // Don't enable the screen until all existing windows |
| 4548 | // have been drawn. |
| 4549 | final int N = mWindows.size(); |
| 4550 | for (int i=0; i<N; i++) { |
| 4551 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 4552 | if (w.isVisibleLw() && !w.mObscured |
| 4553 | && (w.mOrientationChanging || !w.isDrawnLw())) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4554 | return; |
| 4555 | } |
| 4556 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4558 | mDisplayEnabled = true; |
| 4559 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4560 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4561 | StringWriter sw = new StringWriter(); |
| 4562 | PrintWriter pw = new PrintWriter(sw); |
| 4563 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4564 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4565 | } |
| 4566 | try { |
| 4567 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4568 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4569 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | Parcel data = Parcel.obtain(); |
| 4571 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4572 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4573 | data, null, 0); |
| 4574 | data.recycle(); |
| 4575 | } |
| 4576 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4577 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | } |
| 4579 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4580 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4582 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4583 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4584 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4585 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 setInTouchMode(boolean mode) { |
| 4589 | synchronized(mWindowMap) { |
| 4590 | mInTouchMode = mode; |
| 4591 | } |
| 4592 | } |
| 4593 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4594 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4595 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4596 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4597 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4598 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | } |
| 4600 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4601 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4603 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4604 | public void setRotationUnchecked(int rotation, |
| 4605 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4606 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4607 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4609 | long origId = Binder.clearCallingIdentity(); |
| 4610 | boolean changed; |
| 4611 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4612 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4614 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4615 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4616 | sendNewConfiguration(); |
| 4617 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4618 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4619 | Binder.restoreCallingIdentity(origId); |
| 4620 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4621 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4622 | /** |
| 4623 | * Apply a new rotation to the screen, respecting the requests of |
| 4624 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4625 | * re-evaluate the desired rotation. |
| 4626 | * |
| 4627 | * Returns null if the rotation has been changed. In this case YOU |
| 4628 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4629 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4630 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | boolean changed; |
| 4632 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4633 | rotation = mRequestedRotation; |
| 4634 | } else { |
| 4635 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4636 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4638 | 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] | 4639 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4641 | 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] | 4642 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4643 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4645 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | "Rotation changed to " + rotation |
| 4647 | + " from " + mRotation |
| 4648 | + " (forceApp=" + mForcedAppOrientation |
| 4649 | + ", req=" + mRequestedRotation + ")"); |
| 4650 | mRotation = rotation; |
| 4651 | mWindowsFreezingScreen = true; |
| 4652 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4653 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4654 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4655 | mWaitingForConfig = true; |
| 4656 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4658 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4659 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4660 | mInputManager.setDisplayOrientation(0, rotation); |
| 4661 | } else { |
| 4662 | mQueue.setOrientation(rotation); |
| 4663 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4665 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | } |
| 4667 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4668 | WindowState w = (WindowState)mWindows.get(i); |
| 4669 | if (w.mSurface != null) { |
| 4670 | w.mOrientationChanging = true; |
| 4671 | } |
| 4672 | } |
| 4673 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4674 | try { |
| 4675 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4676 | } catch (RemoteException e) { |
| 4677 | } |
| 4678 | } |
| 4679 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | return changed; |
| 4682 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4683 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | public int getRotation() { |
| 4685 | return mRotation; |
| 4686 | } |
| 4687 | |
| 4688 | public int watchRotation(IRotationWatcher watcher) { |
| 4689 | final IBinder watcherBinder = watcher.asBinder(); |
| 4690 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4691 | public void binderDied() { |
| 4692 | synchronized (mWindowMap) { |
| 4693 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4694 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4695 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4696 | if (removed != null) { |
| 4697 | removed.asBinder().unlinkToDeath(this, 0); |
| 4698 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | i--; |
| 4700 | } |
| 4701 | } |
| 4702 | } |
| 4703 | } |
| 4704 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | synchronized (mWindowMap) { |
| 4707 | try { |
| 4708 | watcher.asBinder().linkToDeath(dr, 0); |
| 4709 | mRotationWatchers.add(watcher); |
| 4710 | } catch (RemoteException e) { |
| 4711 | // Client died, no cleanup needed. |
| 4712 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4713 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | return mRotation; |
| 4715 | } |
| 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * Starts the view server on the specified port. |
| 4720 | * |
| 4721 | * @param port The port to listener to. |
| 4722 | * |
| 4723 | * @return True if the server was successfully started, false otherwise. |
| 4724 | * |
| 4725 | * @see com.android.server.ViewServer |
| 4726 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4727 | */ |
| 4728 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4729 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4730 | return false; |
| 4731 | } |
| 4732 | |
| 4733 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4734 | return false; |
| 4735 | } |
| 4736 | |
| 4737 | if (port < 1024) { |
| 4738 | return false; |
| 4739 | } |
| 4740 | |
| 4741 | if (mViewServer != null) { |
| 4742 | if (!mViewServer.isRunning()) { |
| 4743 | try { |
| 4744 | return mViewServer.start(); |
| 4745 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4746 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4747 | } |
| 4748 | } |
| 4749 | return false; |
| 4750 | } |
| 4751 | |
| 4752 | try { |
| 4753 | mViewServer = new ViewServer(this, port); |
| 4754 | return mViewServer.start(); |
| 4755 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4756 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | } |
| 4758 | return false; |
| 4759 | } |
| 4760 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4761 | private boolean isSystemSecure() { |
| 4762 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4763 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4764 | } |
| 4765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4766 | /** |
| 4767 | * Stops the view server if it exists. |
| 4768 | * |
| 4769 | * @return True if the server stopped, false if it wasn't started or |
| 4770 | * couldn't be stopped. |
| 4771 | * |
| 4772 | * @see com.android.server.ViewServer |
| 4773 | */ |
| 4774 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4775 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4776 | return false; |
| 4777 | } |
| 4778 | |
| 4779 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4780 | return false; |
| 4781 | } |
| 4782 | |
| 4783 | if (mViewServer != null) { |
| 4784 | return mViewServer.stop(); |
| 4785 | } |
| 4786 | return false; |
| 4787 | } |
| 4788 | |
| 4789 | /** |
| 4790 | * Indicates whether the view server is running. |
| 4791 | * |
| 4792 | * @return True if the server is running, false otherwise. |
| 4793 | * |
| 4794 | * @see com.android.server.ViewServer |
| 4795 | */ |
| 4796 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4797 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4798 | return false; |
| 4799 | } |
| 4800 | |
| 4801 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4802 | return false; |
| 4803 | } |
| 4804 | |
| 4805 | return mViewServer != null && mViewServer.isRunning(); |
| 4806 | } |
| 4807 | |
| 4808 | /** |
| 4809 | * Lists all availble windows in the system. The listing is written in the |
| 4810 | * specified Socket's output stream with the following syntax: |
| 4811 | * windowHashCodeInHexadecimal windowName |
| 4812 | * Each line of the ouput represents a different window. |
| 4813 | * |
| 4814 | * @param client The remote client to send the listing to. |
| 4815 | * @return False if an error occured, true otherwise. |
| 4816 | */ |
| 4817 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4818 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4819 | return false; |
| 4820 | } |
| 4821 | |
| 4822 | boolean result = true; |
| 4823 | |
| 4824 | Object[] windows; |
| 4825 | synchronized (mWindowMap) { |
| 4826 | windows = new Object[mWindows.size()]; |
| 4827 | //noinspection unchecked |
| 4828 | windows = mWindows.toArray(windows); |
| 4829 | } |
| 4830 | |
| 4831 | BufferedWriter out = null; |
| 4832 | |
| 4833 | // Any uncaught exception will crash the system process |
| 4834 | try { |
| 4835 | OutputStream clientStream = client.getOutputStream(); |
| 4836 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4837 | |
| 4838 | final int count = windows.length; |
| 4839 | for (int i = 0; i < count; i++) { |
| 4840 | final WindowState w = (WindowState) windows[i]; |
| 4841 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4842 | out.write(' '); |
| 4843 | out.append(w.mAttrs.getTitle()); |
| 4844 | out.write('\n'); |
| 4845 | } |
| 4846 | |
| 4847 | out.write("DONE.\n"); |
| 4848 | out.flush(); |
| 4849 | } catch (Exception e) { |
| 4850 | result = false; |
| 4851 | } finally { |
| 4852 | if (out != null) { |
| 4853 | try { |
| 4854 | out.close(); |
| 4855 | } catch (IOException e) { |
| 4856 | result = false; |
| 4857 | } |
| 4858 | } |
| 4859 | } |
| 4860 | |
| 4861 | return result; |
| 4862 | } |
| 4863 | |
| 4864 | /** |
| 4865 | * Sends a command to a target window. The result of the command, if any, will be |
| 4866 | * written in the output stream of the specified socket. |
| 4867 | * |
| 4868 | * The parameters must follow this syntax: |
| 4869 | * windowHashcode extra |
| 4870 | * |
| 4871 | * Where XX is the length in characeters of the windowTitle. |
| 4872 | * |
| 4873 | * The first parameter is the target window. The window with the specified hashcode |
| 4874 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4875 | * will be delivered to the target window and as parameters to the command itself. |
| 4876 | * |
| 4877 | * @param client The remote client to sent the result, if any, to. |
| 4878 | * @param command The command to execute. |
| 4879 | * @param parameters The command parameters. |
| 4880 | * |
| 4881 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4882 | * not indicate whether the command itself was successful. |
| 4883 | */ |
| 4884 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4885 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | return false; |
| 4887 | } |
| 4888 | |
| 4889 | boolean success = true; |
| 4890 | Parcel data = null; |
| 4891 | Parcel reply = null; |
| 4892 | |
| 4893 | // Any uncaught exception will crash the system process |
| 4894 | try { |
| 4895 | // Find the hashcode of the window |
| 4896 | int index = parameters.indexOf(' '); |
| 4897 | if (index == -1) { |
| 4898 | index = parameters.length(); |
| 4899 | } |
| 4900 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4901 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | |
| 4903 | // Extract the command's parameter after the window description |
| 4904 | if (index < parameters.length()) { |
| 4905 | parameters = parameters.substring(index + 1); |
| 4906 | } else { |
| 4907 | parameters = ""; |
| 4908 | } |
| 4909 | |
| 4910 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4911 | if (window == null) { |
| 4912 | return false; |
| 4913 | } |
| 4914 | |
| 4915 | data = Parcel.obtain(); |
| 4916 | data.writeInterfaceToken("android.view.IWindow"); |
| 4917 | data.writeString(command); |
| 4918 | data.writeString(parameters); |
| 4919 | data.writeInt(1); |
| 4920 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4921 | |
| 4922 | reply = Parcel.obtain(); |
| 4923 | |
| 4924 | final IBinder binder = window.mClient.asBinder(); |
| 4925 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4926 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4927 | |
| 4928 | reply.readException(); |
| 4929 | |
| 4930 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4931 | 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] | 4932 | success = false; |
| 4933 | } finally { |
| 4934 | if (data != null) { |
| 4935 | data.recycle(); |
| 4936 | } |
| 4937 | if (reply != null) { |
| 4938 | reply.recycle(); |
| 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | return success; |
| 4943 | } |
| 4944 | |
| 4945 | private WindowState findWindow(int hashCode) { |
| 4946 | if (hashCode == -1) { |
| 4947 | return getFocusedWindow(); |
| 4948 | } |
| 4949 | |
| 4950 | synchronized (mWindowMap) { |
| 4951 | final ArrayList windows = mWindows; |
| 4952 | final int count = windows.size(); |
| 4953 | |
| 4954 | for (int i = 0; i < count; i++) { |
| 4955 | WindowState w = (WindowState) windows.get(i); |
| 4956 | if (System.identityHashCode(w) == hashCode) { |
| 4957 | return w; |
| 4958 | } |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | return null; |
| 4963 | } |
| 4964 | |
| 4965 | /* |
| 4966 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4967 | * that to config-changed listeners if appropriate. |
| 4968 | */ |
| 4969 | void sendNewConfiguration() { |
| 4970 | try { |
| 4971 | mActivityManager.updateConfiguration(null); |
| 4972 | } catch (RemoteException e) { |
| 4973 | } |
| 4974 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4976 | public Configuration computeNewConfiguration() { |
| 4977 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4978 | return computeNewConfigurationLocked(); |
| 4979 | } |
| 4980 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4981 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4982 | Configuration computeNewConfigurationLocked() { |
| 4983 | Configuration config = new Configuration(); |
| 4984 | if (!computeNewConfigurationLocked(config)) { |
| 4985 | return null; |
| 4986 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4987 | return config; |
| 4988 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4989 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4990 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4991 | if (mDisplay == null) { |
| 4992 | return false; |
| 4993 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4994 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 4995 | mInputManager.getInputConfiguration(config); |
| 4996 | } else { |
| 4997 | mQueue.getInputConfiguration(config); |
| 4998 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4999 | |
| 5000 | // Use the effective "visual" dimensions based on current rotation |
| 5001 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5002 | || mRotation == Surface.ROTATION_270); |
| 5003 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5004 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5005 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5006 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5007 | if (dw < dh) { |
| 5008 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5009 | } else if (dw > dh) { |
| 5010 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5011 | } |
| 5012 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5013 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5014 | DisplayMetrics dm = new DisplayMetrics(); |
| 5015 | mDisplay.getMetrics(dm); |
| 5016 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5017 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5018 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5019 | // Note we only do this once because at this point we don't |
| 5020 | // expect the screen to change in this way at runtime, and want |
| 5021 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5022 | int longSize = dw; |
| 5023 | int shortSize = dh; |
| 5024 | if (longSize < shortSize) { |
| 5025 | int tmp = longSize; |
| 5026 | longSize = shortSize; |
| 5027 | shortSize = tmp; |
| 5028 | } |
| 5029 | longSize = (int)(longSize/dm.density); |
| 5030 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5031 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5032 | // These semi-magic numbers define our compatibility modes for |
| 5033 | // applications with different screens. Don't change unless you |
| 5034 | // make sure to test lots and lots of apps! |
| 5035 | if (longSize < 470) { |
| 5036 | // This is shorter than an HVGA normal density screen (which |
| 5037 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5038 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5039 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5040 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5041 | // What size is this screen screen? |
| 5042 | if (longSize >= 800 && shortSize >= 600) { |
| 5043 | // SVGA or larger screens at medium density are the point |
| 5044 | // at which we consider it to be an extra large screen. |
| 5045 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5046 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5047 | // VGA or larger screens at medium density are the point |
| 5048 | // at which we consider it to be a large screen. |
| 5049 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5050 | } else { |
| 5051 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5052 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5053 | // If this screen is wider than normal HVGA, or taller |
| 5054 | // than FWVGA, then for old apps we want to run in size |
| 5055 | // compatibility mode. |
| 5056 | if (shortSize > 321 || longSize > 570) { |
| 5057 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5058 | } |
| 5059 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5060 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5061 | // Is this a long screen? |
| 5062 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5063 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5064 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5065 | } else { |
| 5066 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5067 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5068 | } |
| 5069 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5070 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5071 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5072 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5073 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5074 | mPolicy.adjustConfigurationLw(config); |
| 5075 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5076 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5077 | |
| 5078 | /* Notifies the window manager about a broken input channel. |
| 5079 | * |
| 5080 | * Called by the InputManager. |
| 5081 | */ |
| 5082 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5083 | synchronized (mWindowMap) { |
| 5084 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5085 | if (windowState == null) { |
| 5086 | return; // irrelevant |
| 5087 | } |
| 5088 | |
| 5089 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5090 | removeWindowLocked(windowState.mSession, windowState); |
| 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | /* Notifies the window manager about a broken input channel. |
| 5095 | * |
| 5096 | * Called by the InputManager. |
| 5097 | */ |
| 5098 | public long notifyInputChannelANR(InputChannel inputChannel) { |
| 5099 | IApplicationToken appToken; |
| 5100 | synchronized (mWindowMap) { |
| 5101 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5102 | if (windowState == null) { |
| 5103 | return -2; // irrelevant, abort dispatching (-2) |
| 5104 | } |
| 5105 | |
| 5106 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5107 | + windowState.mAttrs.getTitle()); |
| 5108 | appToken = windowState.getAppToken(); |
| 5109 | } |
| 5110 | |
| 5111 | try { |
| 5112 | // Notify the activity manager about the timeout and let it decide whether |
| 5113 | // to abort dispatching or keep waiting. |
| 5114 | boolean abort = appToken.keyDispatchingTimedOut(); |
| 5115 | if (abort) { |
| 5116 | return -2; // abort dispatching |
| 5117 | } |
| 5118 | |
| 5119 | // Return new timeout. |
| 5120 | // We use -1 for infinite timeout to avoid clash with -2 magic number. |
| 5121 | long newTimeout = appToken.getKeyDispatchingTimeout() * 1000000; |
| 5122 | return newTimeout < 0 ? -1 : newTimeout; |
| 5123 | } catch (RemoteException ex) { |
| 5124 | return -2; // abort dispatching |
| 5125 | } |
| 5126 | } |
| 5127 | |
| 5128 | /* Notifies the window manager about a broken input channel. |
| 5129 | * |
| 5130 | * Called by the InputManager. |
| 5131 | */ |
| 5132 | public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) { |
| 5133 | // Nothing to do just now. |
| 5134 | // Just wait for the user to dismiss the ANR dialog. |
| 5135 | |
| 5136 | // TODO We could try to automatically dismiss the ANR dialog on recovery |
| 5137 | // although that might be disorienting. |
| 5138 | } |
| 5139 | |
| 5140 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5141 | int windowCount = mWindows.size(); |
| 5142 | for (int i = 0; i < windowCount; i++) { |
| 5143 | WindowState windowState = (WindowState) mWindows.get(i); |
| 5144 | if (windowState.mInputChannel == inputChannel) { |
| 5145 | return windowState; |
| 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | return null; |
| 5150 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5151 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5152 | // ------------------------------------------------------------- |
| 5153 | // Input Events and Focus Management |
| 5154 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5155 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5156 | private boolean checkInjectionPermissionTd(WindowState focus, |
| 5157 | int injectorPid, int injectorUid) { |
| 5158 | if (injectorUid > 0 && (focus == null || injectorUid != focus.mSession.mUid)) { |
| 5159 | if (mContext.checkPermission( |
| 5160 | android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid) |
| 5161 | != PackageManager.PERMISSION_GRANTED) { |
| 5162 | Slog.w(TAG, "Permission denied: injecting key event from pid " |
| 5163 | + injectorPid + " uid " + injectorUid + " to window " + focus |
| 5164 | + " owned by uid " + focus.mSession.mUid); |
| 5165 | return false; |
| 5166 | } |
| 5167 | } |
| 5168 | return true; |
| 5169 | } |
| 5170 | |
| 5171 | /* Gets the input targets for a key event. |
| 5172 | * |
| 5173 | * Called by the InputManager on the InputDispatcher thread. |
| 5174 | */ |
| 5175 | public int getKeyEventTargetsTd(InputTargetList inputTargets, |
| 5176 | KeyEvent event, int nature, int policyFlags, int injectorPid, int injectorUid) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5177 | if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event); |
| 5178 | |
| 5179 | // TODO what do we do with mDisplayFrozen? |
| 5180 | // TODO what do we do with focus.mToken.paused? |
| 5181 | |
| 5182 | WindowState focus = getFocusedWindow(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5183 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5184 | if (! checkInjectionPermissionTd(focus, injectorPid, injectorUid)) { |
| 5185 | return InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5188 | if (mPolicy.interceptKeyTi(focus, event.getKeyCode(), event.getMetaState(), |
| 5189 | event.getAction() == KeyEvent.ACTION_DOWN, |
| 5190 | event.getRepeatCount(), event.getFlags())) { |
| 5191 | // Policy consumed the event. |
| 5192 | return InputManager.INPUT_EVENT_INJECTION_SUCCEEDED; |
| 5193 | } |
| 5194 | |
| 5195 | if (focus == null) { |
| 5196 | return InputManager.INPUT_EVENT_INJECTION_FAILED; |
| 5197 | } |
| 5198 | |
| 5199 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5200 | |
| 5201 | addInputTargetTd(inputTargets, focus, InputTarget.FLAG_SYNC); |
| 5202 | return InputManager.INPUT_EVENT_INJECTION_SUCCEEDED; |
| 5203 | } |
| 5204 | |
| 5205 | /* Gets the input targets for a motion event. |
| 5206 | * |
| 5207 | * Called by the InputManager on the InputDispatcher thread. |
| 5208 | */ |
| 5209 | public int getMotionEventTargetsTd(InputTargetList inputTargets, |
| 5210 | MotionEvent event, int nature, int policyFlags, int injectorPid, int injectorUid) { |
| 5211 | switch (nature) { |
| 5212 | case InputQueue.INPUT_EVENT_NATURE_TRACKBALL: |
| 5213 | return getMotionEventTargetsForTrackballTd(inputTargets, event, policyFlags, |
| 5214 | injectorPid, injectorUid); |
| 5215 | |
| 5216 | case InputQueue.INPUT_EVENT_NATURE_TOUCH: |
| 5217 | return getMotionEventTargetsForTouchTd(inputTargets, event, policyFlags, |
| 5218 | injectorPid, injectorUid); |
| 5219 | |
| 5220 | default: |
| 5221 | return InputManager.INPUT_EVENT_INJECTION_FAILED; |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | /* Gets the input targets for a trackball event. |
| 5226 | * |
| 5227 | * Called by the InputManager on the InputDispatcher thread. |
| 5228 | */ |
| 5229 | private int getMotionEventTargetsForTrackballTd(InputTargetList inputTargets, |
| 5230 | MotionEvent event, int policyFlags, int injectorPid, int injectorUid) { |
| 5231 | WindowState focus = getFocusedWindow(); |
| 5232 | |
| 5233 | if (! checkInjectionPermissionTd(focus, injectorPid, injectorUid)) { |
| 5234 | return InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED; |
| 5235 | } |
| 5236 | |
| 5237 | if (focus == null) { |
| 5238 | return InputManager.INPUT_EVENT_INJECTION_FAILED; |
| 5239 | } |
| 5240 | |
| 5241 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5242 | |
| 5243 | addInputTargetTd(inputTargets, focus, InputTarget.FLAG_SYNC); |
| 5244 | return InputManager.INPUT_EVENT_INJECTION_SUCCEEDED; |
| 5245 | } |
| 5246 | |
| 5247 | /* Set to true when a fat touch has been detected during the processing of a touch event. |
| 5248 | * |
| 5249 | * Only used by getMotionEventTargetsForTouchTd. |
| 5250 | * Set to true whenever a fat touch is detected and reset to false on ACTION_UP. |
| 5251 | */ |
| 5252 | private boolean mFatTouch; |
| 5253 | |
| 5254 | /* Set to true when we think the touch event. |
| 5255 | * |
| 5256 | * Only used by getMotionEventTargetsForTouchTd. |
| 5257 | * Set to true on ACTION_DOWN and set to false on ACTION_UP. |
| 5258 | */ |
| 5259 | private boolean mTouchDown; |
| 5260 | |
| 5261 | /* Current target of Motion events. |
| 5262 | * |
| 5263 | * Only used by getMotionEventTargetsForTouchTd. |
| 5264 | * Initialized on ACTION_DOWN and cleared on ACTION_UP. |
| 5265 | */ |
| 5266 | private WindowState mTouchFocus; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5267 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5268 | /* Windows above the target that would like to receive an "outside" touch event |
| 5269 | * for any down events outside of them. |
| 5270 | * |
| 5271 | * Only used by getMotionEventTargetsForTouchTd. |
| 5272 | * Initialized on ACTION_DOWN and cleared immediately afterwards. |
| 5273 | */ |
| 5274 | private ArrayList<WindowState> mOutsideTouchTargets = new ArrayList<WindowState>(); |
| 5275 | |
| 5276 | /* Wallpaper windows that are currently receiving touch events. |
| 5277 | * |
| 5278 | * Only used by getMotionEventTargetsForTouchTd. |
| 5279 | * Initialized on ACTION_DOWN and cleared on ACTION_UP. |
| 5280 | */ |
| 5281 | private ArrayList<WindowState> mWallpaperTouchTargets = new ArrayList<WindowState>(); |
| 5282 | |
| 5283 | /* Gets the input targets for a touch event. |
| 5284 | * |
| 5285 | * Called by the InputManager on the InputDispatcher thread. |
| 5286 | */ |
| 5287 | private int getMotionEventTargetsForTouchTd(InputTargetList inputTargets, |
| 5288 | MotionEvent event, int policyFlags, int injectorPid, int injectorUid) { |
| 5289 | final int action = event.getAction(); |
| 5290 | |
| 5291 | if (action == MotionEvent.ACTION_DOWN) { |
| 5292 | updateTouchFocusBeforeDownTd(event, policyFlags); |
| 5293 | } else { |
| 5294 | updateTouchFocusBeforeNonDownTd(event, policyFlags); |
| 5295 | } |
| 5296 | |
| 5297 | boolean skipDelivery = false; |
| 5298 | int touchTargetFlags = 0; |
| 5299 | |
| 5300 | int injectionResult = InputManager.INPUT_EVENT_INJECTION_SUCCEEDED; |
| 5301 | WindowState focusedTouchTarget = mTouchFocus; |
| 5302 | if (focusedTouchTarget == null) { |
| 5303 | // In this case we are either dropping the event, or have received |
| 5304 | // a move or up without a down. It is common to receive move |
| 5305 | // events in such a way, since this means the user is moving the |
| 5306 | // pointer without actually pressing down. All other cases should |
| 5307 | // be atypical, so let's log them. |
| 5308 | if (action != MotionEvent.ACTION_MOVE) { |
| 5309 | Slog.w(TAG, "No window to dispatch pointer action " + action); |
| 5310 | injectionResult = InputManager.INPUT_EVENT_INJECTION_FAILED; |
| 5311 | } |
| 5312 | } else { |
| 5313 | // We have a valid focused touch target. |
| 5314 | if (! checkInjectionPermissionTd(focusedTouchTarget, injectorPid, injectorUid)) { |
| 5315 | return InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED; |
| 5316 | } |
| 5317 | |
| 5318 | wakeupIfNeeded(focusedTouchTarget, eventType(event)); |
| 5319 | |
| 5320 | if ((focusedTouchTarget.mAttrs.flags & |
| 5321 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 5322 | // Target wants to ignore fat touch events |
| 5323 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(event); |
| 5324 | |
| 5325 | if (cheekPress) { |
| 5326 | if ((action == MotionEvent.ACTION_DOWN)) { |
| 5327 | mFatTouch = true; |
| 5328 | skipDelivery = true; |
| 5329 | } else { |
| 5330 | if (! mFatTouch) { |
| 5331 | // cancel the earlier event |
| 5332 | touchTargetFlags |= InputTarget.FLAG_CANCEL; |
| 5333 | mFatTouch = true; |
| 5334 | } else { |
| 5335 | skipDelivery = true; |
| 5336 | } |
| 5337 | } |
| 5338 | } |
| 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | if (! skipDelivery) { |
| 5343 | int outsideTargetCount = mOutsideTouchTargets.size(); |
| 5344 | for (int i = 0; i < outsideTargetCount; i++) { |
| 5345 | WindowState outsideTouchTarget = mOutsideTouchTargets.get(i); |
| 5346 | addInputTargetTd(inputTargets, outsideTouchTarget, |
| 5347 | InputTarget.FLAG_OUTSIDE | touchTargetFlags); |
| 5348 | } |
| 5349 | |
| 5350 | int wallpaperTargetCount = mWallpaperTouchTargets.size(); |
| 5351 | for (int i = 0; i < wallpaperTargetCount; i++) { |
| 5352 | WindowState wallpaperTouchTarget = mWallpaperTouchTargets.get(i); |
| 5353 | addInputTargetTd(inputTargets, wallpaperTouchTarget, |
| 5354 | touchTargetFlags); |
| 5355 | } |
| 5356 | |
| 5357 | if (focusedTouchTarget != null) { |
| 5358 | addInputTargetTd(inputTargets, focusedTouchTarget, |
| 5359 | InputTarget.FLAG_SYNC | touchTargetFlags); |
| 5360 | } |
| 5361 | } |
| 5362 | |
| 5363 | if (action == MotionEvent.ACTION_UP) { |
| 5364 | updateTouchFocusAfterUpTd(event, policyFlags); |
| 5365 | } |
| 5366 | |
| 5367 | return injectionResult; |
| 5368 | } |
| 5369 | |
| 5370 | private void updateTouchFocusBeforeDownTd(MotionEvent event, int policyFlags) { |
| 5371 | if (mTouchDown) { |
| 5372 | // This is weird, we got a down, but we thought it was already down! |
| 5373 | // XXX: We should probably send an ACTION_UP to the current target. |
| 5374 | Slog.w(TAG, "Pointer down received while already down in: " + mTouchFocus); |
| 5375 | updateTouchFocusAfterUpTd(event, policyFlags); |
| 5376 | } |
| 5377 | |
| 5378 | mTouchDown = true; |
| 5379 | mPowerManager.logPointerDownEvent(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5380 | |
| 5381 | final boolean screenWasOff = (policyFlags & WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5382 | synchronized (mWindowMap) { |
| 5383 | final int x = (int) event.getX(); |
| 5384 | final int y = (int) event.getY(); |
| 5385 | |
| 5386 | final ArrayList windows = mWindows; |
| 5387 | final int N = windows.size(); |
| 5388 | WindowState topErrWindow = null; |
| 5389 | final Rect tmpRect = mTempRect; |
| 5390 | for (int i= N - 1; i >= 0; i--) { |
| 5391 | WindowState child = (WindowState) windows.get(i); |
| 5392 | //Slog.i(TAG, "Checking dispatch to: " + child); |
| 5393 | |
| 5394 | final int flags = child.mAttrs.flags; |
| 5395 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5396 | if (topErrWindow == null) { |
| 5397 | topErrWindow = child; |
| 5398 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5399 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5400 | |
| 5401 | if (!child.isVisibleLw()) { |
| 5402 | //Slog.i(TAG, "Not visible!"); |
| 5403 | continue; |
| 5404 | } |
| 5405 | |
| 5406 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) == 0) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5407 | tmpRect.set(child.mFrame); |
| 5408 | if (child.mTouchableInsets == ViewTreeObserver |
| 5409 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5410 | // The touch is inside of the window if it is |
| 5411 | // inside the frame, AND the content part of that |
| 5412 | // frame that was given by the application. |
| 5413 | tmpRect.left += child.mGivenContentInsets.left; |
| 5414 | tmpRect.top += child.mGivenContentInsets.top; |
| 5415 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5416 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5417 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5418 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5419 | // The touch is inside of the window if it is |
| 5420 | // inside the frame, AND the visible part of that |
| 5421 | // frame that was given by the application. |
| 5422 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5423 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5424 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5425 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5426 | } |
| 5427 | final int touchFlags = flags & |
| 5428 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5429 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5430 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5431 | //Slog.i(TAG, "Using this target!"); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5432 | if (! screenWasOff || (flags & |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5433 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5434 | mTouchFocus = child; |
| 5435 | } else { |
| 5436 | //Slog.i(TAG, "Waking, skip!"); |
| 5437 | mTouchFocus = null; |
| 5438 | } |
| 5439 | break; |
| 5440 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5441 | } |
| 5442 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5443 | if ((flags & WindowManager.LayoutParams |
| 5444 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5445 | //Slog.i(TAG, "Adding to outside target list: " + child); |
| 5446 | mOutsideTouchTargets.add(child); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5447 | } |
| 5448 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5449 | |
| 5450 | // If there's an error window but it's not accepting focus (typically because |
| 5451 | // it is not yet visible) just wait for it -- any other focused window may in fact |
| 5452 | // be in ANR state. |
| 5453 | if (topErrWindow != null && mTouchFocus != topErrWindow) { |
| 5454 | mTouchFocus = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5455 | } |
| 5456 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5457 | // Drop the touch focus if the window is not visible. |
| 5458 | if (mTouchFocus != null && ! mTouchFocus.isVisibleLw()) { |
| 5459 | mTouchFocus = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5460 | } |
| 5461 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5462 | // Determine wallpaper targets. |
| 5463 | if (mTouchFocus != null |
| 5464 | && mTouchFocus == mWallpaperTarget |
| 5465 | && mTouchFocus.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5466 | int curTokenIndex = mWallpaperTokens.size(); |
| 5467 | while (curTokenIndex > 0) { |
| 5468 | curTokenIndex--; |
| 5469 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5470 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5471 | int curWallpaperIndex = token.windows.size(); |
| 5472 | while (curWallpaperIndex > 0) { |
| 5473 | curWallpaperIndex--; |
| 5474 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 5475 | if ((wallpaper.mAttrs.flags & |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5476 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) == 0) { |
| 5477 | mWallpaperTouchTargets.add(wallpaper); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5478 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5479 | } |
| 5480 | } |
| 5481 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5482 | } |
| 5483 | } |
| 5484 | |
| 5485 | private void updateTouchFocusBeforeNonDownTd(MotionEvent event, int policyFlags) { |
| 5486 | synchronized (mWindowMap) { |
| 5487 | // Drop the touch focus if the window is not visible. |
| 5488 | if (mTouchFocus != null && ! mTouchFocus.isVisibleLw()) { |
| 5489 | mTouchFocus = null; |
| 5490 | mWallpaperTouchTargets.clear(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5491 | } |
| 5492 | } |
| 5493 | } |
| 5494 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5495 | private void updateTouchFocusAfterUpTd(MotionEvent event, int policyFlags) { |
| 5496 | mFatTouch = false; |
| 5497 | mTouchDown = false; |
| 5498 | mTouchFocus = null; |
| 5499 | mOutsideTouchTargets.clear(); |
| 5500 | mWallpaperTouchTargets.clear(); |
| 5501 | |
| 5502 | mPowerManager.logPointerUpEvent(); |
| 5503 | } |
| 5504 | |
| 5505 | /* Adds a window to a list of input targets. |
| 5506 | * Do NOT call this method while holding any locks because the call to |
| 5507 | * appToken.getKeyDispatchingTimeout() can potentially call into the ActivityManager |
| 5508 | * and create a deadlock hazard. |
| 5509 | */ |
| 5510 | private void addInputTargetTd(InputTargetList inputTargets, WindowState window, int flags) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5511 | if (window.mInputChannel == null) { |
| 5512 | return; |
| 5513 | } |
| 5514 | |
| 5515 | long timeoutNanos = -1; |
| 5516 | IApplicationToken appToken = window.getAppToken(); |
| 5517 | |
| 5518 | if (appToken != null) { |
| 5519 | try { |
| 5520 | timeoutNanos = appToken.getKeyDispatchingTimeout() * 1000000; |
| 5521 | } catch (RemoteException ex) { |
| 5522 | Slog.w(TAG, "Could not get key dispatching timeout.", ex); |
| 5523 | } |
| 5524 | } |
| 5525 | |
| 5526 | inputTargets.add(window.mInputChannel, flags, timeoutNanos, |
| 5527 | - window.mFrame.left, - window.mFrame.top); |
| 5528 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | |
| 5530 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5531 | long curTime = SystemClock.uptimeMillis(); |
| 5532 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 5533 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5534 | if (mLastTouchEventType == eventType && |
| 5535 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 5536 | return; |
| 5537 | } |
| 5538 | mLastUserActivityCallTime = curTime; |
| 5539 | mLastTouchEventType = eventType; |
| 5540 | } |
| 5541 | |
| 5542 | if (targetWin == null |
| 5543 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 5544 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | } |
| 5546 | } |
| 5547 | |
| 5548 | // tells if it's a cheek event or not -- this function is stateful |
| 5549 | private static final int EVENT_NONE = 0; |
| 5550 | private static final int EVENT_UNKNOWN = 0; |
| 5551 | private static final int EVENT_CHEEK = 0; |
| 5552 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 5553 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 5554 | private int mEventState = EVENT_NONE; |
| 5555 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5557 | private int eventType(MotionEvent ev) { |
| 5558 | float size = ev.getSize(); |
| 5559 | switch (ev.getAction()) { |
| 5560 | case MotionEvent.ACTION_DOWN: |
| 5561 | mEventSize = size; |
| 5562 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 5563 | case MotionEvent.ACTION_UP: |
| 5564 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5565 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5566 | case MotionEvent.ACTION_MOVE: |
| 5567 | final int N = ev.getHistorySize(); |
| 5568 | if (size > mEventSize) mEventSize = size; |
| 5569 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 5570 | for (int i=0; i<N; i++) { |
| 5571 | size = ev.getHistoricalSize(i); |
| 5572 | if (size > mEventSize) mEventSize = size; |
| 5573 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 5574 | } |
| 5575 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 5576 | return TOUCH_EVENT; |
| 5577 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5578 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | } |
| 5580 | default: |
| 5581 | // not good |
| 5582 | return OTHER_EVENT; |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | /** |
| 5587 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5588 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5589 | private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5590 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | "dispatchPointer " + ev); |
| 5592 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5593 | if (MEASURE_LATENCY) { |
| 5594 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 5595 | } |
| 5596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5597 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5598 | ev, true, false, pid, uid); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5599 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5600 | if (MEASURE_LATENCY) { |
| 5601 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 5602 | } |
| 5603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5604 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | if (action == MotionEvent.ACTION_UP) { |
| 5607 | // let go of our target |
| 5608 | mKeyWaiter.mMotionTarget = null; |
| 5609 | mPowerManager.logPointerUpEvent(); |
| 5610 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 5611 | mPowerManager.logPointerDownEvent(); |
| 5612 | } |
| 5613 | |
| 5614 | if (targetObj == null) { |
| 5615 | // In this case we are either dropping the event, or have received |
| 5616 | // a move or up without a down. It is common to receive move |
| 5617 | // events in such a way, since this means the user is moving the |
| 5618 | // pointer without actually pressing down. All other cases should |
| 5619 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5620 | if (action != MotionEvent.ACTION_MOVE) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5621 | 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] | 5622 | } |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5623 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5624 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5625 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | if (qev != null) { |
| 5627 | mQueue.recycleEvent(qev); |
| 5628 | } |
| 5629 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5630 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | } |
| 5632 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5633 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5634 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5635 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | if (qev != null) { |
| 5637 | mQueue.recycleEvent(qev); |
| 5638 | } |
| 5639 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5640 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5642 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5643 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5644 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5645 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5646 | final long eventTimeNano = ev.getEventTimeNano(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5647 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5648 | //Slog.i(TAG, "Sending " + ev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | |
| 5650 | if (uid != 0 && uid != target.mSession.mUid) { |
| 5651 | if (mContext.checkPermission( |
| 5652 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5653 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5654 | 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] | 5655 | + pid + " uid " + uid + " to window " + target |
| 5656 | + " owned by uid " + target.mSession.mUid); |
| 5657 | if (qev != null) { |
| 5658 | mQueue.recycleEvent(qev); |
| 5659 | } |
| 5660 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5661 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5662 | } |
| 5663 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5664 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5665 | if (MEASURE_LATENCY) { |
| 5666 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5667 | } |
| 5668 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5669 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 5671 | //target wants to ignore fat touch events |
| 5672 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 5673 | //explicit flag to return without processing event further |
| 5674 | boolean returnFlag = false; |
| 5675 | if((action == MotionEvent.ACTION_DOWN)) { |
| 5676 | mFatTouch = false; |
| 5677 | if(cheekPress) { |
| 5678 | mFatTouch = true; |
| 5679 | returnFlag = true; |
| 5680 | } |
| 5681 | } else { |
| 5682 | if(action == MotionEvent.ACTION_UP) { |
| 5683 | if(mFatTouch) { |
| 5684 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 5685 | mFatTouch = false; |
| 5686 | returnFlag = true; |
| 5687 | } else if(cheekPress) { |
| 5688 | //cancel the earlier event |
| 5689 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5690 | action = MotionEvent.ACTION_CANCEL; |
| 5691 | } |
| 5692 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 5693 | if(mFatTouch) { |
| 5694 | //two cases here |
| 5695 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5696 | //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] | 5697 | returnFlag = true; |
| 5698 | } else if(cheekPress) { |
| 5699 | //valid down followed by invalid moves |
| 5700 | //an invalid move have to cancel earlier action |
| 5701 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5702 | action = MotionEvent.ACTION_CANCEL; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5703 | 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] | 5704 | //note that the subsequent invalid moves will not get here |
| 5705 | mFatTouch = true; |
| 5706 | } |
| 5707 | } |
| 5708 | } //else if action |
| 5709 | if(returnFlag) { |
| 5710 | //recycle que, ev |
| 5711 | if (qev != null) { |
| 5712 | mQueue.recycleEvent(qev); |
| 5713 | } |
| 5714 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5715 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5716 | } |
| 5717 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5718 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 5719 | // Enable this for testing the "right" value |
| 5720 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5721 | int max_events_per_sec = 35; |
| 5722 | try { |
| 5723 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5724 | .get("windowsmgr.max_events_per_sec")); |
| 5725 | if (max_events_per_sec < 1) { |
| 5726 | max_events_per_sec = 35; |
| 5727 | } |
| 5728 | } catch (NumberFormatException e) { |
| 5729 | } |
| 5730 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5731 | } |
| 5732 | |
| 5733 | /* |
| 5734 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5735 | * e.g. constant contact with the screen |
| 5736 | */ |
| 5737 | if (action == MotionEvent.ACTION_MOVE) { |
| 5738 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5739 | long now = SystemClock.uptimeMillis(); |
| 5740 | if (now < nextEventTime) { |
| 5741 | try { |
| 5742 | Thread.sleep(nextEventTime - now); |
| 5743 | } catch (InterruptedException e) { |
| 5744 | } |
| 5745 | mLastTouchEventTime = nextEventTime; |
| 5746 | } else { |
| 5747 | mLastTouchEventTime = now; |
| 5748 | } |
| 5749 | } |
| 5750 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5751 | if (MEASURE_LATENCY) { |
| 5752 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5753 | } |
| 5754 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5755 | synchronized(mWindowMap) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5756 | if (!target.isVisibleLw()) { |
| 5757 | // During this motion dispatch, the target window has become |
| 5758 | // invisible. |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5759 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5760 | if (qev != null) { |
| 5761 | mQueue.recycleEvent(qev); |
| 5762 | } |
| 5763 | ev.recycle(); |
| 5764 | return INJECT_SUCCEEDED; |
| 5765 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5767 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5768 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5769 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5770 | ev = null; |
| 5771 | } else { |
| 5772 | if (action == MotionEvent.ACTION_DOWN) { |
| 5773 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5774 | if (out != null) { |
| 5775 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5776 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5777 | do { |
| 5778 | final Rect frame = out.mFrame; |
| 5779 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5780 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5781 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5782 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5783 | 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] | 5784 | } |
| 5785 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5786 | out = out.mNextOutsideTouch; |
| 5787 | } while (out != null); |
| 5788 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5789 | } |
| 5790 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5791 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5792 | dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5793 | |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5794 | final Rect frame = target.mFrame; |
| 5795 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5796 | mKeyWaiter.bindTargetWindowLocked(target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | } |
| 5798 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5799 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5800 | // finally offset the event to the target's coordinate system and |
| 5801 | // dispatch the event. |
| 5802 | try { |
| 5803 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5804 | Slog.v(TAG, "Delivering pointer " + qev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5805 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5806 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5807 | if (MEASURE_LATENCY) { |
| 5808 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5809 | } |
| 5810 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5811 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5812 | |
| 5813 | if (MEASURE_LATENCY) { |
| 5814 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5815 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5816 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5818 | Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5819 | mKeyWaiter.mMotionTarget = null; |
| 5820 | try { |
| 5821 | removeWindow(target.mSession, target.mClient); |
| 5822 | } catch (java.util.NoSuchElementException ex) { |
| 5823 | // This will happen if the window has already been |
| 5824 | // removed. |
| 5825 | } |
| 5826 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5827 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5829 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | /** |
| 5831 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5832 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5833 | private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5834 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5835 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5836 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5838 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5839 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5840 | Slog.w(TAG, "No focus window, dropping trackball: " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5841 | if (qev != null) { |
| 5842 | mQueue.recycleEvent(qev); |
| 5843 | } |
| 5844 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5845 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5846 | } |
| 5847 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5848 | if (qev != null) { |
| 5849 | mQueue.recycleEvent(qev); |
| 5850 | } |
| 5851 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5852 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5853 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | WindowState focus = (WindowState)focusObj; |
| 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 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5858 | if (mContext.checkPermission( |
| 5859 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5860 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5861 | 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] | 5862 | + pid + " uid " + uid + " to window " + focus |
| 5863 | + " owned by uid " + focus.mSession.mUid); |
| 5864 | if (qev != null) { |
| 5865 | mQueue.recycleEvent(qev); |
| 5866 | } |
| 5867 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5868 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | } |
| 5870 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5874 | synchronized(mWindowMap) { |
| 5875 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5876 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5877 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5878 | // We don't deliver movement events to the client, we hold |
| 5879 | // them and wait for them to call back. |
| 5880 | ev = null; |
| 5881 | } else { |
| 5882 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5883 | } |
| 5884 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5886 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5887 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5888 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5889 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5890 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | try { |
| 5892 | removeWindow(focus.mSession, focus.mClient); |
| 5893 | } catch (java.util.NoSuchElementException ex) { |
| 5894 | // This will happen if the window has already been |
| 5895 | // removed. |
| 5896 | } |
| 5897 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5898 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5899 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5900 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | /** |
| 5903 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5904 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5905 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5906 | if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5907 | |
| 5908 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5909 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5910 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5911 | Slog.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5912 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5913 | } |
| 5914 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5915 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5916 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5917 | |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5918 | // Okay we have finished waiting for the last event to be processed. |
| 5919 | // First off, if this is a repeat event, check to see if there is |
| 5920 | // a corresponding up event in the queue. If there is, we will |
| 5921 | // just drop the repeat, because it makes no sense to repeat after |
| 5922 | // the user has released a key. (This is especially important for |
| 5923 | // long presses.) |
| 5924 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5925 | return INJECT_SUCCEEDED; |
| 5926 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5928 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5929 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5930 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | TAG, "Dispatching to " + focus + ": " + event); |
| 5932 | |
| 5933 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5934 | if (mContext.checkPermission( |
| 5935 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5936 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5937 | 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] | 5938 | + pid + " uid " + uid + " to window " + focus |
| 5939 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5940 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5941 | } |
| 5942 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5943 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5944 | synchronized(mWindowMap) { |
| 5945 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5946 | } |
| 5947 | |
| 5948 | // NOSHIP extra state logging |
| 5949 | mKeyWaiter.recordDispatchState(event, focus); |
| 5950 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5951 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | try { |
| 5953 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5954 | Slog.v(TAG, "Delivering key " + event.getKeyCode() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5955 | + " to " + focus); |
| 5956 | } |
| 5957 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5958 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5959 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5960 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5961 | try { |
| 5962 | removeWindow(focus.mSession, focus.mClient); |
| 5963 | } catch (java.util.NoSuchElementException ex) { |
| 5964 | // This will happen if the window has already been |
| 5965 | // removed. |
| 5966 | } |
| 5967 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5968 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5969 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5971 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5972 | public void pauseKeyDispatching(IBinder _token) { |
| 5973 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5974 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5975 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | synchronized (mWindowMap) { |
| 5979 | WindowToken token = mTokenMap.get(_token); |
| 5980 | if (token != null) { |
| 5981 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5982 | } |
| 5983 | } |
| 5984 | } |
| 5985 | |
| 5986 | public void resumeKeyDispatching(IBinder _token) { |
| 5987 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5988 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5989 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | synchronized (mWindowMap) { |
| 5993 | WindowToken token = mTokenMap.get(_token); |
| 5994 | if (token != null) { |
| 5995 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5996 | } |
| 5997 | } |
| 5998 | } |
| 5999 | |
| 6000 | public void setEventDispatching(boolean enabled) { |
| 6001 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6002 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6003 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | synchronized (mWindowMap) { |
| 6007 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 6008 | } |
| 6009 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6010 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6011 | /** |
| 6012 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6013 | * |
| 6014 | * @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] | 6015 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6016 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6017 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6018 | */ |
| 6019 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6020 | long downTime = ev.getDownTime(); |
| 6021 | long eventTime = ev.getEventTime(); |
| 6022 | |
| 6023 | int action = ev.getAction(); |
| 6024 | int code = ev.getKeyCode(); |
| 6025 | int repeatCount = ev.getRepeatCount(); |
| 6026 | int metaState = ev.getMetaState(); |
| 6027 | int deviceId = ev.getDeviceId(); |
| 6028 | int scancode = ev.getScanCode(); |
| 6029 | |
| 6030 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6031 | if (downTime == 0) downTime = eventTime; |
| 6032 | |
| 6033 | 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] | 6034 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6035 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6036 | final int pid = Binder.getCallingPid(); |
| 6037 | final int uid = Binder.getCallingUid(); |
| 6038 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6039 | |
| 6040 | final int result; |
| 6041 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6042 | result = mInputManager.injectKeyEvent(newEvent, InputQueue.INPUT_EVENT_NATURE_KEY, |
| 6043 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6044 | } else { |
| 6045 | result = dispatchKey(newEvent, pid, uid); |
| 6046 | if (sync) { |
| 6047 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| 6048 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6049 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6050 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6051 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6052 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /** |
| 6056 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6057 | * |
| 6058 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6059 | * {@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] | 6060 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6061 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6062 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6063 | */ |
| 6064 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6065 | final int pid = Binder.getCallingPid(); |
| 6066 | final int uid = Binder.getCallingUid(); |
| 6067 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6068 | |
| 6069 | final int result; |
| 6070 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6071 | result = mInputManager.injectMotionEvent(ev, InputQueue.INPUT_EVENT_NATURE_TOUCH, |
| 6072 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6073 | } else { |
| 6074 | result = dispatchPointer(null, ev, pid, uid); |
| 6075 | if (sync) { |
| 6076 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| 6077 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6079 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6080 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6081 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6082 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6083 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6084 | /** |
| 6085 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6086 | * |
| 6087 | * @param ev A motion event describing the trackball action. (As noted in |
| 6088 | * {@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] | 6089 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6090 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6091 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6092 | */ |
| 6093 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6094 | final int pid = Binder.getCallingPid(); |
| 6095 | final int uid = Binder.getCallingUid(); |
| 6096 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6097 | |
| 6098 | final int result; |
| 6099 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6100 | result = mInputManager.injectMotionEvent(ev, InputQueue.INPUT_EVENT_NATURE_TRACKBALL, |
| 6101 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6102 | } else { |
| 6103 | result = dispatchTrackball(null, ev, pid, uid); |
| 6104 | if (sync) { |
| 6105 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| 6106 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6108 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6109 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6110 | return reportInjectionResult(result); |
| 6111 | } |
| 6112 | |
| 6113 | private boolean reportInjectionResult(int result) { |
| 6114 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 6115 | switch (result) { |
| 6116 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6117 | Slog.w(TAG, "Input event injection permission denied."); |
| 6118 | throw new SecurityException( |
| 6119 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6120 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| 6121 | Slog.v(TAG, "Input event injection succeeded."); |
| 6122 | return true; |
| 6123 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6124 | Slog.w(TAG, "Input event injection timed out."); |
| 6125 | return false; |
| 6126 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6127 | default: |
| 6128 | Slog.w(TAG, "Input event injection failed."); |
| 6129 | return false; |
| 6130 | } |
| 6131 | } else { |
| 6132 | switch (result) { |
| 6133 | case INJECT_NO_PERMISSION: |
| 6134 | throw new SecurityException( |
| 6135 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6136 | case INJECT_SUCCEEDED: |
| 6137 | return true; |
| 6138 | } |
| 6139 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6140 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6141 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6142 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6143 | private WindowState getFocusedWindow() { |
| 6144 | synchronized (mWindowMap) { |
| 6145 | return getFocusedWindowLocked(); |
| 6146 | } |
| 6147 | } |
| 6148 | |
| 6149 | private WindowState getFocusedWindowLocked() { |
| 6150 | return mCurrentFocus; |
| 6151 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6152 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6153 | /** |
| 6154 | * This class holds the state for dispatching key events. This state |
| 6155 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 6156 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 6157 | * but not the other way around. |
| 6158 | */ |
| 6159 | final class KeyWaiter { |
| 6160 | // NOSHIP debugging |
| 6161 | public class DispatchState { |
| 6162 | private KeyEvent event; |
| 6163 | private WindowState focus; |
| 6164 | private long time; |
| 6165 | private WindowState lastWin; |
| 6166 | private IBinder lastBinder; |
| 6167 | private boolean finished; |
| 6168 | private boolean gotFirstWindow; |
| 6169 | private boolean eventDispatching; |
| 6170 | private long timeToSwitch; |
| 6171 | private boolean wasFrozen; |
| 6172 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6173 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6175 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 6176 | focus = theFocus; |
| 6177 | event = theEvent; |
| 6178 | time = System.currentTimeMillis(); |
| 6179 | // snapshot KeyWaiter state |
| 6180 | lastWin = mLastWin; |
| 6181 | lastBinder = mLastBinder; |
| 6182 | finished = mFinished; |
| 6183 | gotFirstWindow = mGotFirstWindow; |
| 6184 | eventDispatching = mEventDispatching; |
| 6185 | timeToSwitch = mTimeToSwitch; |
| 6186 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6187 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | // cache the paused state at ctor time as well |
| 6189 | if (theFocus == null || theFocus.mToken == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6190 | focusPaused = false; |
| 6191 | } else { |
| 6192 | focusPaused = theFocus.mToken.paused; |
| 6193 | } |
| 6194 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | public String toString() { |
| 6197 | return "{{" + event + " to " + focus + " @ " + time |
| 6198 | + " lw=" + lastWin + " lb=" + lastBinder |
| 6199 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 6200 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6201 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| Christopher Tate | 46d4525 | 2010-02-09 15:48:57 -0800 | [diff] [blame] | 6202 | + " mcf=" + curFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6203 | } |
| 6204 | }; |
| 6205 | private DispatchState mDispatchState = null; |
| 6206 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 6207 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 6208 | } |
| 6209 | // END NOSHIP |
| 6210 | |
| 6211 | public static final int RETURN_NOTHING = 0; |
| 6212 | public static final int RETURN_PENDING_POINTER = 1; |
| 6213 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6214 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6215 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 6216 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6218 | private WindowState mLastWin = null; |
| 6219 | private IBinder mLastBinder = null; |
| 6220 | private boolean mFinished = true; |
| 6221 | private boolean mGotFirstWindow = false; |
| 6222 | private boolean mEventDispatching = true; |
| 6223 | private long mTimeToSwitch = 0; |
| 6224 | /* package */ boolean mWasFrozen = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6226 | // Target of Motion events |
| 6227 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6228 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | // Windows above the target who would like to receive an "outside" |
| 6230 | // touch event for any down events outside of them. |
| 6231 | WindowState mOutsideTouchTargets; |
| 6232 | |
| 6233 | /** |
| 6234 | * Wait for the last event dispatch to complete, then find the next |
| 6235 | * target that should receive the given event and wait for that one |
| 6236 | * to be ready to receive it. |
| 6237 | */ |
| 6238 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 6239 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6240 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6241 | long startTime = SystemClock.uptimeMillis(); |
| 6242 | long keyDispatchingTimeout = 5 * 1000; |
| 6243 | long waitedFor = 0; |
| 6244 | |
| 6245 | while (true) { |
| 6246 | // Figure out which window we care about. It is either the |
| 6247 | // last window we are waiting to have process the event or, |
| 6248 | // if none, then the next window we think the event should go |
| 6249 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 6250 | // it may change before we lock. Thus we must check it again. |
| 6251 | WindowState targetWin = mLastWin; |
| 6252 | boolean targetIsNew = targetWin == null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6253 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 6255 | ", mLastWin=" + mLastWin); |
| 6256 | if (targetIsNew) { |
| 6257 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6258 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | if (target == SKIP_TARGET_TOKEN) { |
| 6260 | // The user has pressed a special key, and we are |
| 6261 | // dropping all pending events before it. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6262 | if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | + " " + nextMotion); |
| 6264 | return null; |
| 6265 | } |
| 6266 | if (target == CONSUMED_EVENT_TOKEN) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6267 | if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | + " " + nextMotion); |
| 6269 | return target; |
| 6270 | } |
| 6271 | targetWin = (WindowState)target; |
| 6272 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | // Now: is it okay to send the next event to this window? |
| 6277 | synchronized (this) { |
| 6278 | // First: did we come here based on the last window not |
| 6279 | // being null, but it changed by the time we got here? |
| 6280 | // If so, try again. |
| 6281 | if (!targetIsNew && mLastWin == null) { |
| 6282 | continue; |
| 6283 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | // We never dispatch events if not finished with the |
| 6286 | // last one, or the display is frozen. |
| 6287 | if (mFinished && !mDisplayFrozen) { |
| 6288 | // If event dispatching is disabled, then we |
| 6289 | // just consume the events. |
| 6290 | if (!mEventDispatching) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6291 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | "Skipping event; dispatching disabled: " |
| 6293 | + nextKey + " " + nextMotion); |
| 6294 | return null; |
| 6295 | } |
| 6296 | if (targetWin != null) { |
| 6297 | // If this is a new target, and that target is not |
| 6298 | // paused or unresponsive, then all looks good to |
| 6299 | // handle the event. |
| 6300 | if (targetIsNew && !targetWin.mToken.paused) { |
| 6301 | return targetWin; |
| 6302 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | // If we didn't find a target window, and there is no |
| 6305 | // focused app window, then just eat the events. |
| 6306 | } else if (mFocusedApp == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6307 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | "Skipping event; no focused app: " |
| 6309 | + nextKey + " " + nextMotion); |
| 6310 | return null; |
| 6311 | } |
| 6312 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6313 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6314 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | TAG, "Waiting for last key in " + mLastBinder |
| 6316 | + " target=" + targetWin |
| 6317 | + " mFinished=" + mFinished |
| 6318 | + " mDisplayFrozen=" + mDisplayFrozen |
| 6319 | + " targetIsNew=" + targetIsNew |
| 6320 | + " paused=" |
| 6321 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6322 | + " mFocusedApp=" + mFocusedApp |
| 6323 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6325 | targetApp = targetWin != null |
| 6326 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6327 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6328 | long curTimeout = keyDispatchingTimeout; |
| 6329 | if (mTimeToSwitch != 0) { |
| 6330 | long now = SystemClock.uptimeMillis(); |
| 6331 | if (mTimeToSwitch <= now) { |
| 6332 | // If an app switch key has been pressed, and we have |
| 6333 | // waited too long for the current app to finish |
| 6334 | // processing keys, then wait no more! |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6335 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6336 | continue; |
| 6337 | } |
| 6338 | long switchTimeout = mTimeToSwitch - now; |
| 6339 | if (curTimeout > switchTimeout) { |
| 6340 | curTimeout = switchTimeout; |
| 6341 | } |
| 6342 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | try { |
| 6345 | // after that continue |
| 6346 | // processing keys, so we don't get stuck. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6347 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6348 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 6349 | wait(curTimeout); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6350 | if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6352 | + startTime + " switchTime=" + mTimeToSwitch |
| 6353 | + " target=" + targetWin + " mLW=" + mLastWin |
| 6354 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 6355 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | } catch (InterruptedException e) { |
| 6357 | } |
| 6358 | } |
| 6359 | |
| 6360 | // If we were frozen during configuration change, restart the |
| 6361 | // timeout checks from now; otherwise look at whether we timed |
| 6362 | // out before awakening. |
| 6363 | if (mWasFrozen) { |
| 6364 | waitedFor = 0; |
| 6365 | mWasFrozen = false; |
| 6366 | } else { |
| 6367 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 6368 | } |
| 6369 | |
| 6370 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 6371 | IApplicationToken at = null; |
| 6372 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6373 | Slog.w(TAG, "Key dispatching timed out sending to " + |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 6375 | : "<null>: no window ready for key dispatch")); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | // NOSHIP debugging |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6377 | Slog.w(TAG, "Previous dispatch state: " + mDispatchState); |
| 6378 | Slog.w(TAG, "Current dispatch state: " + |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 6379 | new DispatchState(nextKey, targetWin)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | // END NOSHIP |
| 6381 | //dump(); |
| 6382 | if (targetWin != null) { |
| 6383 | at = targetWin.getAppToken(); |
| 6384 | } else if (targetApp != null) { |
| 6385 | at = targetApp.appToken; |
| 6386 | } |
| 6387 | } |
| 6388 | |
| 6389 | boolean abort = true; |
| 6390 | if (at != null) { |
| 6391 | try { |
| 6392 | long timeout = at.getKeyDispatchingTimeout(); |
| 6393 | if (timeout > waitedFor) { |
| 6394 | // we did not wait the proper amount of time for this application. |
| 6395 | // set the timeout to be the real timeout and wait again. |
| 6396 | keyDispatchingTimeout = timeout - waitedFor; |
| 6397 | continue; |
| 6398 | } else { |
| 6399 | abort = at.keyDispatchingTimedOut(); |
| 6400 | } |
| 6401 | } catch (RemoteException ex) { |
| 6402 | } |
| 6403 | } |
| 6404 | |
| 6405 | synchronized (this) { |
| 6406 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 6407 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6408 | if (mLastWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6409 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6410 | "Window " + mLastWin + |
| 6411 | " timed out on key input"); |
| 6412 | if (mLastWin.mToken.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6413 | Slog.w(TAG, "Un-pausing dispatching to this window"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6414 | mLastWin.mToken.paused = false; |
| 6415 | } |
| 6416 | } |
| 6417 | if (mMotionTarget == targetWin) { |
| 6418 | mMotionTarget = null; |
| 6419 | } |
| 6420 | mLastWin = null; |
| 6421 | mLastBinder = null; |
| 6422 | if (failIfTimeout || targetWin == null) { |
| 6423 | return null; |
| 6424 | } |
| 6425 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6426 | 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] | 6427 | startTime = SystemClock.uptimeMillis(); |
| 6428 | } |
| 6429 | } |
| 6430 | } |
| 6431 | } |
| 6432 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6435 | MotionEvent nextMotion, boolean isPointerEvent, |
| 6436 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6437 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6439 | if (nextKey != null) { |
| 6440 | // Find the target window for a normal key event. |
| 6441 | final int keycode = nextKey.getKeyCode(); |
| 6442 | final int repeatCount = nextKey.getRepeatCount(); |
| 6443 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 6444 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6447 | if (callingUid == 0 || |
| 6448 | mContext.checkPermission( |
| 6449 | android.Manifest.permission.INJECT_EVENTS, |
| 6450 | callingPid, callingUid) |
| 6451 | == PackageManager.PERMISSION_GRANTED) { |
| 6452 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6453 | nextKey.getMetaState(), down, repeatCount, |
| 6454 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6455 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6456 | Slog.w(TAG, "Event timeout during app switch: dropping " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6457 | + nextKey); |
| 6458 | return SKIP_TARGET_TOKEN; |
| 6459 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6460 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6461 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6463 | WindowState focus = null; |
| 6464 | synchronized(mWindowMap) { |
| 6465 | focus = getFocusedWindowLocked(); |
| 6466 | } |
| 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 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6469 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6470 | if (callingUid == 0 || |
| 6471 | (focus != null && callingUid == focus.mSession.mUid) || |
| 6472 | mContext.checkPermission( |
| 6473 | android.Manifest.permission.INJECT_EVENTS, |
| 6474 | callingPid, callingUid) |
| 6475 | == PackageManager.PERMISSION_GRANTED) { |
| 6476 | if (mPolicy.interceptKeyTi(focus, |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6477 | keycode, nextKey.getMetaState(), down, repeatCount, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6478 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6479 | return CONSUMED_EVENT_TOKEN; |
| 6480 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6482 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | return focus; |
| 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 | } else if (!isPointerEvent) { |
| 6486 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 6487 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6488 | 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] | 6489 | + nextMotion); |
| 6490 | return SKIP_TARGET_TOKEN; |
| 6491 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | WindowState focus = null; |
| 6494 | synchronized(mWindowMap) { |
| 6495 | focus = getFocusedWindowLocked(); |
| 6496 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6497 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6498 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 6499 | return focus; |
| 6500 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6502 | if (nextMotion == null) { |
| 6503 | return SKIP_TARGET_TOKEN; |
| 6504 | } |
| 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 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 6507 | KeyEvent.KEYCODE_UNKNOWN); |
| 6508 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6509 | 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] | 6510 | + nextMotion); |
| 6511 | return SKIP_TARGET_TOKEN; |
| 6512 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6513 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6514 | // Find the target window for a pointer event. |
| 6515 | int action = nextMotion.getAction(); |
| 6516 | final float xf = nextMotion.getX(); |
| 6517 | final float yf = nextMotion.getY(); |
| 6518 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6519 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | final boolean screenWasOff = qev != null |
| 6521 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6523 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | synchronized(mWindowMap) { |
| 6526 | synchronized (this) { |
| 6527 | if (action == MotionEvent.ACTION_DOWN) { |
| 6528 | if (mMotionTarget != null) { |
| 6529 | // this is weird, we got a pen down, but we thought it was |
| 6530 | // already down! |
| 6531 | // XXX: We should probably send an ACTION_UP to the current |
| 6532 | // target. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6533 | 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] | 6534 | + mMotionTarget); |
| 6535 | mMotionTarget = null; |
| 6536 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6537 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6538 | // ACTION_DOWN is special, because we need to lock next events to |
| 6539 | // the window we'll land onto. |
| 6540 | final int x = (int)xf; |
| 6541 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6542 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6543 | final ArrayList windows = mWindows; |
| 6544 | final int N = windows.size(); |
| 6545 | WindowState topErrWindow = null; |
| 6546 | final Rect tmpRect = mTempRect; |
| 6547 | for (int i=N-1; i>=0; i--) { |
| 6548 | WindowState child = (WindowState)windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6549 | //Slog.i(TAG, "Checking dispatch to: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6550 | final int flags = child.mAttrs.flags; |
| 6551 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 6552 | if (topErrWindow == null) { |
| 6553 | topErrWindow = child; |
| 6554 | } |
| 6555 | } |
| 6556 | if (!child.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6557 | //Slog.i(TAG, "Not visible!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6558 | continue; |
| 6559 | } |
| 6560 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6561 | //Slog.i(TAG, "Not touchable!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6562 | if ((flags & WindowManager.LayoutParams |
| 6563 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 6564 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 6565 | mOutsideTouchTargets = child; |
| 6566 | } |
| 6567 | continue; |
| 6568 | } |
| 6569 | tmpRect.set(child.mFrame); |
| 6570 | if (child.mTouchableInsets == ViewTreeObserver |
| 6571 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 6572 | // The touch is inside of the window if it is |
| 6573 | // inside the frame, AND the content part of that |
| 6574 | // frame that was given by the application. |
| 6575 | tmpRect.left += child.mGivenContentInsets.left; |
| 6576 | tmpRect.top += child.mGivenContentInsets.top; |
| 6577 | tmpRect.right -= child.mGivenContentInsets.right; |
| 6578 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 6579 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 6580 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 6581 | // The touch is inside of the window if it is |
| 6582 | // inside the frame, AND the visible part of that |
| 6583 | // frame that was given by the application. |
| 6584 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 6585 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 6586 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 6587 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 6588 | } |
| 6589 | final int touchFlags = flags & |
| 6590 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 6591 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 6592 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6593 | //Slog.i(TAG, "Using this target!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6594 | if (!screenWasOff || (flags & |
| 6595 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 6596 | mMotionTarget = child; |
| 6597 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6598 | //Slog.i(TAG, "Waking, skip!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6599 | mMotionTarget = null; |
| 6600 | } |
| 6601 | break; |
| 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 | if ((flags & WindowManager.LayoutParams |
| 6605 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 6606 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 6607 | mOutsideTouchTargets = child; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6608 | //Slog.i(TAG, "Adding to outside target list: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | // if there's an error window but it's not accepting |
| 6613 | // focus (typically because it is not yet visible) just |
| 6614 | // wait for it -- any other focused window may in fact |
| 6615 | // be in ANR state. |
| 6616 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 6617 | mMotionTarget = null; |
| 6618 | } |
| 6619 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | target = mMotionTarget; |
| 6622 | } |
| 6623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6625 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | // Pointer events are a little different -- if there isn't a |
| 6628 | // target found for any event, then just drop it. |
| 6629 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 6630 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6631 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6632 | boolean checkShouldDispatchKey(int keycode) { |
| 6633 | synchronized (this) { |
| 6634 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 6635 | mTimeToSwitch = 0; |
| 6636 | return true; |
| 6637 | } |
| 6638 | if (mTimeToSwitch != 0 |
| 6639 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 6640 | return false; |
| 6641 | } |
| 6642 | return true; |
| 6643 | } |
| 6644 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6646 | void bindTargetWindowLocked(WindowState win, |
| 6647 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6648 | synchronized (this) { |
| 6649 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 6650 | } |
| 6651 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6652 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6653 | void bindTargetWindowLocked(WindowState win) { |
| 6654 | synchronized (this) { |
| 6655 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | void bindTargetWindowLockedLocked(WindowState win, |
| 6660 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6661 | mLastWin = win; |
| 6662 | mLastBinder = win.mClient.asBinder(); |
| 6663 | mFinished = false; |
| 6664 | if (pendingMotion != null) { |
| 6665 | final Session s = win.mSession; |
| 6666 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 6667 | releasePendingPointerLocked(s); |
| 6668 | s.mPendingPointerMove = pendingMotion; |
| 6669 | s.mPendingPointerWindow = win; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6670 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6671 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 6672 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 6673 | releasePendingTrackballLocked(s); |
| 6674 | s.mPendingTrackballMove = pendingMotion; |
| 6675 | s.mPendingTrackballWindow = win; |
| 6676 | } |
| 6677 | } |
| 6678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6680 | void releasePendingPointerLocked(Session s) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6681 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6682 | "releasePendingPointer " + s.mPendingPointerMove); |
| 6683 | if (s.mPendingPointerMove != null) { |
| 6684 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 6685 | s.mPendingPointerMove = null; |
| 6686 | } |
| 6687 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6688 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6689 | void releasePendingTrackballLocked(Session s) { |
| 6690 | if (s.mPendingTrackballMove != null) { |
| 6691 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 6692 | s.mPendingTrackballMove = null; |
| 6693 | } |
| 6694 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6695 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 6697 | int returnWhat) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6698 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 6700 | |
| 6701 | if (client == null) { |
| 6702 | return null; |
| 6703 | } |
| 6704 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6705 | MotionEvent res = null; |
| 6706 | QueuedEvent qev = null; |
| 6707 | WindowState win = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6710 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6711 | TAG, "finishedKey: client=" + client.asBinder() |
| 6712 | + ", force=" + force + ", last=" + mLastBinder |
| 6713 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 6714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 6716 | qev = session.mPendingPointerMove; |
| 6717 | win = session.mPendingPointerWindow; |
| 6718 | session.mPendingPointerMove = null; |
| 6719 | session.mPendingPointerWindow = null; |
| 6720 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 6721 | qev = session.mPendingTrackballMove; |
| 6722 | win = session.mPendingTrackballWindow; |
| 6723 | session.mPendingTrackballMove = null; |
| 6724 | session.mPendingTrackballWindow = null; |
| 6725 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6726 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6727 | if (mLastBinder == client.asBinder()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6728 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6729 | TAG, "finishedKey: last paused=" |
| 6730 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 6731 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 6732 | || !mEventDispatching)) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6733 | doFinishedKeyLocked(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | } else { |
| 6735 | // Make sure to wake up anyone currently waiting to |
| 6736 | // dispatch a key, so they can re-evaluate their |
| 6737 | // current situation. |
| 6738 | mFinished = true; |
| 6739 | notifyAll(); |
| 6740 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6743 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6744 | res = (MotionEvent)qev.event; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6745 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6746 | "Returning pending motion: " + res); |
| 6747 | mQueue.recycleEvent(qev); |
| 6748 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6749 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6750 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6751 | } |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6752 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6753 | |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6754 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6755 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 6756 | dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6757 | } |
| 6758 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6759 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6760 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | void tickle() { |
| 6764 | synchronized (this) { |
| 6765 | notifyAll(); |
| 6766 | } |
| 6767 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6768 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | void handleNewWindowLocked(WindowState newWindow) { |
| 6770 | if (!newWindow.canReceiveKeys()) { |
| 6771 | return; |
| 6772 | } |
| 6773 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6774 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | TAG, "New key dispatch window: win=" |
| 6776 | + newWindow.mClient.asBinder() |
| 6777 | + ", last=" + mLastBinder |
| 6778 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6779 | + "), finished=" + mFinished + ", paused=" |
| 6780 | + newWindow.mToken.paused); |
| 6781 | |
| 6782 | // Displaying a window implicitly causes dispatching to |
| 6783 | // be unpaused. (This is to protect against bugs if someone |
| 6784 | // pauses dispatching but forgets to resume.) |
| 6785 | newWindow.mToken.paused = false; |
| 6786 | |
| 6787 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6788 | |
| 6789 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6790 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | "New SYSTEM_ERROR window; resetting state"); |
| 6792 | mLastWin = null; |
| 6793 | mLastBinder = null; |
| 6794 | mMotionTarget = null; |
| 6795 | mFinished = true; |
| 6796 | } else if (mLastWin != null) { |
| 6797 | // If the new window is above the window we are |
| 6798 | // waiting on, then stop waiting and let key dispatching |
| 6799 | // start on the new guy. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6800 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6801 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6802 | + ", new win layer=" + newWindow.mLayer); |
| 6803 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6804 | // The new window is above the old; finish pending input to the last |
| 6805 | // window and start directing it to the new one. |
| 6806 | mLastWin.mToken.paused = false; |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6807 | doFinishedKeyLocked(false); // does a notifyAll() |
| 6808 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6809 | } |
| 6810 | } |
| 6811 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6812 | // Now that we've put a new window state in place, make the event waiter |
| 6813 | // take notice and retarget its attentions. |
| 6814 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | } |
| 6816 | } |
| 6817 | |
| 6818 | void pauseDispatchingLocked(WindowToken token) { |
| 6819 | synchronized (this) |
| 6820 | { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6821 | if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6822 | token.paused = true; |
| 6823 | |
| 6824 | /* |
| 6825 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6826 | mPaused = true; |
| 6827 | } else { |
| 6828 | if (mLastWin == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6829 | 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] | 6830 | } else if (mFinished) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6831 | 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] | 6832 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6833 | 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] | 6834 | } |
| 6835 | } |
| 6836 | */ |
| 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | void resumeDispatchingLocked(WindowToken token) { |
| 6841 | synchronized (this) { |
| 6842 | if (token.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6843 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6844 | TAG, "Resuming WindowToken " + token |
| 6845 | + ", last=" + mLastBinder |
| 6846 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6847 | + "), finished=" + mFinished + ", paused=" |
| 6848 | + token.paused); |
| 6849 | token.paused = false; |
| 6850 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6851 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6852 | } else { |
| 6853 | notifyAll(); |
| 6854 | } |
| 6855 | } |
| 6856 | } |
| 6857 | } |
| 6858 | |
| 6859 | void setEventDispatchingLocked(boolean enabled) { |
| 6860 | synchronized (this) { |
| 6861 | mEventDispatching = enabled; |
| 6862 | notifyAll(); |
| 6863 | } |
| 6864 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6865 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | void appSwitchComing() { |
| 6867 | synchronized (this) { |
| 6868 | // Don't wait for more than .5 seconds for app to finish |
| 6869 | // processing the pending events. |
| 6870 | long now = SystemClock.uptimeMillis() + 500; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6871 | if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6872 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6873 | mTimeToSwitch = now; |
| 6874 | } |
| 6875 | notifyAll(); |
| 6876 | } |
| 6877 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6878 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6879 | private final void doFinishedKeyLocked(boolean force) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | if (mLastWin != null) { |
| 6881 | releasePendingPointerLocked(mLastWin.mSession); |
| 6882 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6883 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6884 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6885 | if (force || mLastWin == null || !mLastWin.mToken.paused |
| 6886 | || !mLastWin.isVisibleLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6887 | // If the current window has been paused, we aren't -really- |
| 6888 | // finished... so let the waiters still wait. |
| 6889 | mLastWin = null; |
| 6890 | mLastBinder = null; |
| 6891 | } |
| 6892 | mFinished = true; |
| 6893 | notifyAll(); |
| 6894 | } |
| 6895 | } |
| 6896 | |
| 6897 | private class KeyQ extends KeyInputQueue |
| 6898 | implements KeyInputQueue.FilterCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6900 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | } |
| 6902 | |
| 6903 | @Override |
| 6904 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6905 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6906 | return true; |
| 6907 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6909 | switch (event.type) { |
| 6910 | case RawInputEvent.EV_KEY: { |
| 6911 | // XXX begin hack |
| 6912 | if (DEBUG) { |
| 6913 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6914 | if (event.value != 0) { |
| 6915 | // G down |
| 6916 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6917 | } |
| 6918 | return false; |
| 6919 | } |
| 6920 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6921 | if (event.value != 0) { |
| 6922 | //dump(); |
| 6923 | } |
| 6924 | return false; |
| 6925 | } |
| 6926 | } |
| 6927 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6928 | |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6929 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6930 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6932 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6933 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6934 | mPowerManager.goToSleep(event.when); |
| 6935 | } |
| 6936 | |
| 6937 | if (screenIsOff) { |
| 6938 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6939 | } |
| 6940 | if (screenIsDim) { |
| 6941 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6942 | } |
| 6943 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6944 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6945 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6949 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6950 | filterQueue(this); |
| 6951 | mKeyWaiter.appSwitchComing(); |
| 6952 | } |
| 6953 | return true; |
| 6954 | } else { |
| 6955 | return false; |
| 6956 | } |
| 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_REL: { |
| 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.isWakeRelMovementTq(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 | case RawInputEvent.EV_ABS: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6977 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6978 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6979 | if (screenIsOff) { |
| 6980 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6981 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6982 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6983 | return false; |
| 6984 | } |
| 6985 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6986 | } |
| 6987 | if (screenIsDim) { |
| 6988 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6989 | } |
| 6990 | return true; |
| 6991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | default: |
| 6994 | return true; |
| 6995 | } |
| 6996 | } |
| 6997 | |
| 6998 | public int filterEvent(QueuedEvent ev) { |
| 6999 | switch (ev.classType) { |
| 7000 | case RawInputEvent.CLASS_KEYBOARD: |
| 7001 | KeyEvent ke = (KeyEvent)ev.event; |
| 7002 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7003 | Slog.w(TAG, "Dropping movement key during app switch: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7004 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 7005 | return FILTER_REMOVE; |
| 7006 | } |
| 7007 | return FILTER_ABORT; |
| 7008 | default: |
| 7009 | return FILTER_KEEP; |
| 7010 | } |
| 7011 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7012 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7013 | |
| 7014 | public boolean detectSafeMode() { |
| 7015 | mSafeMode = mPolicy.detectSafeMode(); |
| 7016 | return mSafeMode; |
| 7017 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7018 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7019 | public void systemReady() { |
| 7020 | mPolicy.systemReady(); |
| 7021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7022 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7023 | private final class InputDispatcherThread extends Thread { |
| 7024 | // Time to wait when there is nothing to do: 9999 seconds. |
| 7025 | static final int LONG_WAIT=9999*1000; |
| 7026 | |
| 7027 | public InputDispatcherThread() { |
| 7028 | super("InputDispatcher"); |
| 7029 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7030 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | @Override |
| 7032 | public void run() { |
| 7033 | while (true) { |
| 7034 | try { |
| 7035 | process(); |
| 7036 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7037 | Slog.e(TAG, "Exception in input dispatcher", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7038 | } |
| 7039 | } |
| 7040 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | private void process() { |
| 7043 | android.os.Process.setThreadPriority( |
| 7044 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7046 | // The last key event we saw |
| 7047 | KeyEvent lastKey = null; |
| 7048 | |
| 7049 | // Last keydown time for auto-repeating keys |
| 7050 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 7051 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7052 | long downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7053 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7054 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7055 | int keyRepeatCount = 0; |
| 7056 | |
| 7057 | // Need to report that configuration has changed? |
| 7058 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7059 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7060 | while (true) { |
| 7061 | long curTime = SystemClock.uptimeMillis(); |
| 7062 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7063 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7064 | TAG, "Waiting for next key: now=" + curTime |
| 7065 | + ", repeat @ " + nextKeyTime); |
| 7066 | |
| 7067 | // Retrieve next event, waiting only as long as the next |
| 7068 | // repeat timeout. If the configuration has changed, then |
| 7069 | // don't wait at all -- we'll report the change as soon as |
| 7070 | // we have processed all events. |
| 7071 | QueuedEvent ev = mQueue.getEvent( |
| 7072 | (int)((!configChanged && curTime < nextKeyTime) |
| 7073 | ? (nextKeyTime-curTime) : 0)); |
| 7074 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7075 | if (DEBUG_INPUT && ev != null) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7076 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 7077 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7078 | if (MEASURE_LATENCY) { |
| 7079 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 7080 | } |
| 7081 | |
| Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 7082 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 7083 | // cancel key repeat at the request of the policy. |
| 7084 | lastKey = null; |
| 7085 | downTime = 0; |
| 7086 | lastKeyTime = curTime; |
| 7087 | nextKeyTime = curTime + LONG_WAIT; |
| 7088 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7089 | try { |
| 7090 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7091 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7092 | int eventType; |
| 7093 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 7094 | eventType = eventType((MotionEvent)ev.event); |
| 7095 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 7096 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 7097 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 7098 | } else { |
| 7099 | eventType = LocalPowerManager.OTHER_EVENT; |
| 7100 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7101 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7102 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 7103 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 7104 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 7105 | mBatteryStats.noteInputEvent(); |
| 7106 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7107 | } catch (RemoteException e) { |
| 7108 | // Ignore |
| 7109 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 7110 | |
| Mike Lockwood | 5db4240 | 2009-11-30 14:51:51 -0500 | [diff] [blame] | 7111 | if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) { |
| 7112 | // do not wake screen in this case |
| 7113 | } else if (eventType != TOUCH_EVENT |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 7114 | && eventType != LONG_TOUCH_EVENT |
| 7115 | && eventType != CHEEK_EVENT) { |
| 7116 | mPowerManager.userActivity(curTime, false, |
| 7117 | eventType, false); |
| 7118 | } else if (mLastTouchEventType != eventType |
| 7119 | || (curTime - mLastUserActivityCallTime) |
| 7120 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 7121 | mLastUserActivityCallTime = curTime; |
| 7122 | mLastTouchEventType = eventType; |
| 7123 | mPowerManager.userActivity(curTime, false, |
| 7124 | eventType, false); |
| 7125 | } |
| 7126 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7127 | switch (ev.classType) { |
| 7128 | case RawInputEvent.CLASS_KEYBOARD: |
| 7129 | KeyEvent ke = (KeyEvent)ev.event; |
| 7130 | if (ke.isDown()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7131 | lastKeyTime = curTime; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7132 | if (lastKey != null && |
| 7133 | ke.getKeyCode() == lastKey.getKeyCode()) { |
| 7134 | keyRepeatCount++; |
| 7135 | // Arbitrary long timeout to block |
| 7136 | // repeating here since we know that |
| 7137 | // the device driver takes care of it. |
| 7138 | nextKeyTime = lastKeyTime + LONG_WAIT; |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 7139 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7140 | TAG, "Received repeated key down"); |
| 7141 | } else { |
| 7142 | downTime = curTime; |
| 7143 | keyRepeatCount = 0; |
| 7144 | nextKeyTime = lastKeyTime |
| 7145 | + ViewConfiguration.getLongPressTimeout(); |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 7146 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7147 | TAG, "Received key down: first repeat @ " |
| 7148 | + nextKeyTime); |
| 7149 | } |
| 7150 | lastKey = ke; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7151 | } else { |
| 7152 | lastKey = null; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7153 | downTime = 0; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7154 | keyRepeatCount = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7155 | // Arbitrary long timeout. |
| 7156 | lastKeyTime = curTime; |
| 7157 | nextKeyTime = curTime + LONG_WAIT; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7158 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7159 | TAG, "Received key up: ignore repeat @ " |
| 7160 | + nextKeyTime); |
| 7161 | } |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 7162 | if (keyRepeatCount > 0) { |
| 7163 | dispatchKey(KeyEvent.changeTimeRepeat(ke, |
| 7164 | ke.getEventTime(), keyRepeatCount), 0, 0); |
| 7165 | } else { |
| 7166 | dispatchKey(ke, 0, 0); |
| 7167 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7168 | mQueue.recycleEvent(ev); |
| 7169 | break; |
| 7170 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7171 | //Slog.i(TAG, "Read next event " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 7173 | break; |
| 7174 | case RawInputEvent.CLASS_TRACKBALL: |
| 7175 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 7176 | break; |
| 7177 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 7178 | configChanged = true; |
| 7179 | break; |
| 7180 | default: |
| 7181 | mQueue.recycleEvent(ev); |
| 7182 | break; |
| 7183 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7185 | } else if (configChanged) { |
| 7186 | configChanged = false; |
| 7187 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7188 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7189 | } else if (lastKey != null) { |
| 7190 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7192 | // Timeout occurred while key was down. If it is at or |
| 7193 | // past the key repeat time, dispatch the repeat. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7194 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 7196 | + ", now=" + curTime); |
| 7197 | if (curTime < nextKeyTime) { |
| 7198 | continue; |
| 7199 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7200 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7201 | lastKeyTime = nextKeyTime; |
| 7202 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 7203 | keyRepeatCount++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7204 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | TAG, "Key repeat: count=" + keyRepeatCount |
| 7206 | + ", next @ " + nextKeyTime); |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7207 | KeyEvent newEvent; |
| 7208 | if (downTime != 0 && (downTime |
| 7209 | + ViewConfiguration.getLongPressTimeout()) |
| 7210 | <= curTime) { |
| 7211 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 7212 | curTime, keyRepeatCount, |
| 7213 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 7214 | downTime = 0; |
| 7215 | } else { |
| 7216 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 7217 | curTime, keyRepeatCount); |
| 7218 | } |
| 7219 | dispatchKey(newEvent, 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7220 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7221 | } else { |
| 7222 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7224 | lastKeyTime = curTime; |
| 7225 | nextKeyTime = curTime + LONG_WAIT; |
| 7226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7229 | Slog.e(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7230 | "Input thread received uncaught exception: " + e, e); |
| 7231 | } |
| 7232 | } |
| 7233 | } |
| 7234 | } |
| 7235 | |
| 7236 | // ------------------------------------------------------------- |
| 7237 | // Client Session State |
| 7238 | // ------------------------------------------------------------- |
| 7239 | |
| 7240 | private final class Session extends IWindowSession.Stub |
| 7241 | implements IBinder.DeathRecipient { |
| 7242 | final IInputMethodClient mClient; |
| 7243 | final IInputContext mInputContext; |
| 7244 | final int mUid; |
| 7245 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7246 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7247 | SurfaceSession mSurfaceSession; |
| 7248 | int mNumWindow = 0; |
| 7249 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7251 | /** |
| 7252 | * Current pointer move event being dispatched to client window... must |
| 7253 | * hold key lock to access. |
| 7254 | */ |
| 7255 | QueuedEvent mPendingPointerMove; |
| 7256 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7258 | /** |
| 7259 | * Current trackball move event being dispatched to client window... must |
| 7260 | * hold key lock to access. |
| 7261 | */ |
| 7262 | QueuedEvent mPendingTrackballMove; |
| 7263 | WindowState mPendingTrackballWindow; |
| 7264 | |
| 7265 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 7266 | mClient = client; |
| 7267 | mInputContext = inputContext; |
| 7268 | mUid = Binder.getCallingUid(); |
| 7269 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7270 | StringBuilder sb = new StringBuilder(); |
| 7271 | sb.append("Session{"); |
| 7272 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7273 | sb.append(" uid "); |
| 7274 | sb.append(mUid); |
| 7275 | sb.append("}"); |
| 7276 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7278 | synchronized (mWindowMap) { |
| 7279 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 7280 | IBinder b = ServiceManager.getService( |
| 7281 | Context.INPUT_METHOD_SERVICE); |
| 7282 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 7283 | } |
| 7284 | } |
| 7285 | long ident = Binder.clearCallingIdentity(); |
| 7286 | try { |
| 7287 | // Note: it is safe to call in to the input method manager |
| 7288 | // here because we are not holding our lock. |
| 7289 | if (mInputMethodManager != null) { |
| 7290 | mInputMethodManager.addClient(client, inputContext, |
| 7291 | mUid, mPid); |
| 7292 | } else { |
| 7293 | client.setUsingInputMethod(false); |
| 7294 | } |
| 7295 | client.asBinder().linkToDeath(this, 0); |
| 7296 | } catch (RemoteException e) { |
| 7297 | // The caller has died, so we can just forget about this. |
| 7298 | try { |
| 7299 | if (mInputMethodManager != null) { |
| 7300 | mInputMethodManager.removeClient(client); |
| 7301 | } |
| 7302 | } catch (RemoteException ee) { |
| 7303 | } |
| 7304 | } finally { |
| 7305 | Binder.restoreCallingIdentity(ident); |
| 7306 | } |
| 7307 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7308 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7309 | @Override |
| 7310 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 7311 | throws RemoteException { |
| 7312 | try { |
| 7313 | return super.onTransact(code, data, reply, flags); |
| 7314 | } catch (RuntimeException e) { |
| 7315 | // Log all 'real' exceptions thrown to the caller |
| 7316 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7317 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7318 | } |
| 7319 | throw e; |
| 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | public void binderDied() { |
| 7324 | // Note: it is safe to call in to the input method manager |
| 7325 | // here because we are not holding our lock. |
| 7326 | try { |
| 7327 | if (mInputMethodManager != null) { |
| 7328 | mInputMethodManager.removeClient(mClient); |
| 7329 | } |
| 7330 | } catch (RemoteException e) { |
| 7331 | } |
| 7332 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 7333 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | mClientDead = true; |
| 7335 | killSessionLocked(); |
| 7336 | } |
| 7337 | } |
| 7338 | |
| 7339 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7340 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 7341 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 7342 | outInputChannel); |
| 7343 | } |
| 7344 | |
| 7345 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7346 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7347 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 remove(IWindow window) { |
| 7351 | removeWindow(this, window); |
| 7352 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7353 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7354 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 7355 | int requestedWidth, int requestedHeight, int viewFlags, |
| 7356 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7357 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | return relayoutWindow(this, window, attrs, |
| 7359 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7360 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7361 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7363 | public void setTransparentRegion(IWindow window, Region region) { |
| 7364 | setTransparentRegionWindow(this, window, region); |
| 7365 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | public void setInsets(IWindow window, int touchableInsets, |
| 7368 | Rect contentInsets, Rect visibleInsets) { |
| 7369 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 7370 | visibleInsets); |
| 7371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7373 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 7374 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 7375 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7377 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7378 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | TAG, "IWindow finishDrawing called for " + window); |
| 7380 | finishDrawingWindow(this, window); |
| 7381 | } |
| 7382 | |
| 7383 | public void finishKey(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7384 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7385 | TAG, "IWindow finishKey called for " + window); |
| 7386 | mKeyWaiter.finishedKey(this, window, false, |
| 7387 | KeyWaiter.RETURN_NOTHING); |
| 7388 | } |
| 7389 | |
| 7390 | public MotionEvent getPendingPointerMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7391 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 7393 | return mKeyWaiter.finishedKey(this, window, false, |
| 7394 | KeyWaiter.RETURN_PENDING_POINTER); |
| 7395 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7397 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7398 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7399 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 7400 | return mKeyWaiter.finishedKey(this, window, false, |
| 7401 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 7402 | } |
| 7403 | |
| 7404 | public void setInTouchMode(boolean mode) { |
| 7405 | synchronized(mWindowMap) { |
| 7406 | mInTouchMode = mode; |
| 7407 | } |
| 7408 | } |
| 7409 | |
| 7410 | public boolean getInTouchMode() { |
| 7411 | synchronized(mWindowMap) { |
| 7412 | return mInTouchMode; |
| 7413 | } |
| 7414 | } |
| 7415 | |
| 7416 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 7417 | boolean always) { |
| 7418 | synchronized(mWindowMap) { |
| 7419 | long ident = Binder.clearCallingIdentity(); |
| 7420 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7421 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7422 | windowForClientLocked(this, window, true), |
| 7423 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7424 | } finally { |
| 7425 | Binder.restoreCallingIdentity(ident); |
| 7426 | } |
| 7427 | } |
| 7428 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7429 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7430 | 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] | 7431 | synchronized(mWindowMap) { |
| 7432 | long ident = Binder.clearCallingIdentity(); |
| 7433 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7434 | setWindowWallpaperPositionLocked( |
| 7435 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7436 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7437 | } finally { |
| 7438 | Binder.restoreCallingIdentity(ident); |
| 7439 | } |
| 7440 | } |
| 7441 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7442 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7443 | public void wallpaperOffsetsComplete(IBinder window) { |
| 7444 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 7445 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7446 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7447 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 7448 | int z, Bundle extras, boolean sync) { |
| 7449 | synchronized(mWindowMap) { |
| 7450 | long ident = Binder.clearCallingIdentity(); |
| 7451 | try { |
| 7452 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7453 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7454 | action, x, y, z, extras, sync); |
| 7455 | } finally { |
| 7456 | Binder.restoreCallingIdentity(ident); |
| 7457 | } |
| 7458 | } |
| 7459 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7460 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7461 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 7462 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 7463 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | void windowAddedLocked() { |
| 7466 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7467 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7468 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 7469 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7470 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7471 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7472 | mSessions.add(this); |
| 7473 | } |
| 7474 | mNumWindow++; |
| 7475 | } |
| 7476 | |
| 7477 | void windowRemovedLocked() { |
| 7478 | mNumWindow--; |
| 7479 | killSessionLocked(); |
| 7480 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7481 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7482 | void killSessionLocked() { |
| 7483 | if (mNumWindow <= 0 && mClientDead) { |
| 7484 | mSessions.remove(this); |
| 7485 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7486 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7487 | TAG, "Last window removed from " + this |
| 7488 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7489 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7490 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7491 | try { |
| 7492 | mSurfaceSession.kill(); |
| 7493 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7494 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | + mSurfaceSession + " in session " + this |
| 7496 | + ": " + e.toString()); |
| 7497 | } |
| 7498 | mSurfaceSession = null; |
| 7499 | } |
| 7500 | } |
| 7501 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7504 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 7505 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 7506 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 7507 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 7508 | pw.print(prefix); |
| 7509 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 7510 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 7511 | } |
| 7512 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 7513 | pw.print(prefix); |
| 7514 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 7515 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 7516 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7517 | } |
| 7518 | |
| 7519 | @Override |
| 7520 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7521 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | } |
| 7523 | } |
| 7524 | |
| 7525 | // ------------------------------------------------------------- |
| 7526 | // Client Window State |
| 7527 | // ------------------------------------------------------------- |
| 7528 | |
| 7529 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 7530 | final Session mSession; |
| 7531 | final IWindow mClient; |
| 7532 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7533 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7534 | AppWindowToken mAppToken; |
| 7535 | AppWindowToken mTargetAppToken; |
| 7536 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 7537 | final DeathRecipient mDeathRecipient; |
| 7538 | final WindowState mAttachedWindow; |
| 7539 | final ArrayList mChildWindows = new ArrayList(); |
| 7540 | final int mBaseLayer; |
| 7541 | final int mSubLayer; |
| 7542 | final boolean mLayoutAttached; |
| 7543 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7544 | final boolean mIsWallpaper; |
| 7545 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | int mViewVisibility; |
| 7547 | boolean mPolicyVisibility = true; |
| 7548 | boolean mPolicyVisibilityAfterAnim = true; |
| 7549 | boolean mAppFreezing; |
| 7550 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7551 | boolean mReportDestroySurface; |
| 7552 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7553 | boolean mAttachedHidden; // is our parent window hidden? |
| 7554 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7555 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7556 | int mRequestedWidth; |
| 7557 | int mRequestedHeight; |
| 7558 | int mLastRequestedWidth; |
| 7559 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | int mLayer; |
| 7561 | int mAnimLayer; |
| 7562 | int mLastLayer; |
| 7563 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7564 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7565 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7566 | |
| 7567 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7568 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7569 | int mLayoutSeq = -1; |
| 7570 | |
| 7571 | Configuration mConfiguration = null; |
| 7572 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7573 | // Actual frame shown on-screen (may be modified by animation) |
| 7574 | final Rect mShownFrame = new Rect(); |
| 7575 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7576 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7577 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7578 | * Set when we have changed the size of the surface, to know that |
| 7579 | * we must tell them application to resize (and thus redraw itself). |
| 7580 | */ |
| 7581 | boolean mSurfaceResized; |
| 7582 | |
| 7583 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7584 | * Insets that determine the actually visible area |
| 7585 | */ |
| 7586 | final Rect mVisibleInsets = new Rect(); |
| 7587 | final Rect mLastVisibleInsets = new Rect(); |
| 7588 | boolean mVisibleInsetsChanged; |
| 7589 | |
| 7590 | /** |
| 7591 | * Insets that are covered by system windows |
| 7592 | */ |
| 7593 | final Rect mContentInsets = new Rect(); |
| 7594 | final Rect mLastContentInsets = new Rect(); |
| 7595 | boolean mContentInsetsChanged; |
| 7596 | |
| 7597 | /** |
| 7598 | * Set to true if we are waiting for this window to receive its |
| 7599 | * given internal insets before laying out other windows based on it. |
| 7600 | */ |
| 7601 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7603 | /** |
| 7604 | * These are the content insets that were given during layout for |
| 7605 | * this window, to be applied to windows behind it. |
| 7606 | */ |
| 7607 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | /** |
| 7610 | * These are the visible insets that were given during layout for |
| 7611 | * this window, to be applied to windows behind it. |
| 7612 | */ |
| 7613 | final Rect mGivenVisibleInsets = new Rect(); |
| 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 | /** |
| 7616 | * Flag indicating whether the touchable region should be adjusted by |
| 7617 | * the visible insets; if false the area outside the visible insets is |
| 7618 | * NOT touchable, so we must use those to adjust the frame during hit |
| 7619 | * tests. |
| 7620 | */ |
| 7621 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7622 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | // Current transformation being applied. |
| 7624 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 7625 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 7626 | float mHScale=1, mVScale=1; |
| 7627 | float mLastHScale=1, mLastVScale=1; |
| 7628 | final Matrix mTmpMatrix = new Matrix(); |
| 7629 | |
| 7630 | // "Real" frame that the application sees. |
| 7631 | final Rect mFrame = new Rect(); |
| 7632 | final Rect mLastFrame = new Rect(); |
| 7633 | |
| 7634 | final Rect mContainingFrame = new Rect(); |
| 7635 | final Rect mDisplayFrame = new Rect(); |
| 7636 | final Rect mContentFrame = new Rect(); |
| 7637 | final Rect mVisibleFrame = new Rect(); |
| 7638 | |
| 7639 | float mShownAlpha = 1; |
| 7640 | float mAlpha = 1; |
| 7641 | float mLastAlpha = 1; |
| 7642 | |
| 7643 | // Set to true if, when the window gets displayed, it should perform |
| 7644 | // an enter animation. |
| 7645 | boolean mEnterAnimationPending; |
| 7646 | |
| 7647 | // Currently running animation. |
| 7648 | boolean mAnimating; |
| 7649 | boolean mLocalAnimating; |
| 7650 | Animation mAnimation; |
| 7651 | boolean mAnimationIsEntrance; |
| 7652 | boolean mHasTransformation; |
| 7653 | boolean mHasLocalTransformation; |
| 7654 | final Transformation mTransformation = new Transformation(); |
| 7655 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7656 | // If a window showing a wallpaper: the requested offset for the |
| 7657 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 7658 | float mWallpaperX = -1; |
| 7659 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7660 | |
| 7661 | // If a window showing a wallpaper: what fraction of the offset |
| 7662 | // range corresponds to a full virtual screen. |
| 7663 | float mWallpaperXStep = -1; |
| 7664 | float mWallpaperYStep = -1; |
| 7665 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7666 | // Wallpaper windows: pixels offset based on above variables. |
| 7667 | int mXOffset; |
| 7668 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7669 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7670 | // This is set after IWindowSession.relayout() has been called at |
| 7671 | // least once for the window. It allows us to detect the situation |
| 7672 | // where we don't yet have a surface, but should have one soon, so |
| 7673 | // we can give the window focus before waiting for the relayout. |
| 7674 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7676 | // This is set after the Surface has been created but before the |
| 7677 | // window has been drawn. During this time the surface is hidden. |
| 7678 | boolean mDrawPending; |
| 7679 | |
| 7680 | // This is set after the window has finished drawing for the first |
| 7681 | // time but before its surface is shown. The surface will be |
| 7682 | // displayed when the next layout is run. |
| 7683 | boolean mCommitDrawPending; |
| 7684 | |
| 7685 | // This is set during the time after the window's drawing has been |
| 7686 | // committed, and before its surface is actually shown. It is used |
| 7687 | // to delay showing the surface until all windows in a token are ready |
| 7688 | // to be shown. |
| 7689 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7690 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7691 | // Set when the window has been shown in the screen the first time. |
| 7692 | boolean mHasDrawn; |
| 7693 | |
| 7694 | // Currently running an exit animation? |
| 7695 | boolean mExiting; |
| 7696 | |
| 7697 | // Currently on the mDestroySurface list? |
| 7698 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7699 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7700 | // Completely remove from window manager after exit animation? |
| 7701 | boolean mRemoveOnExit; |
| 7702 | |
| 7703 | // Set when the orientation is changing and this window has not yet |
| 7704 | // been updated for the new orientation. |
| 7705 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7707 | // Is this window now (or just being) removed? |
| 7708 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7709 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7710 | // For debugging, this is the last information given to the surface flinger. |
| 7711 | boolean mSurfaceShown; |
| 7712 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 7713 | int mSurfaceLayer; |
| 7714 | float mSurfaceAlpha; |
| 7715 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7716 | // Input channel |
| 7717 | InputChannel mInputChannel; |
| 7718 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | WindowState(Session s, IWindow c, WindowToken token, |
| 7720 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 7721 | int viewVisibility) { |
| 7722 | mSession = s; |
| 7723 | mClient = c; |
| 7724 | mToken = token; |
| 7725 | mAttrs.copyFrom(a); |
| 7726 | mViewVisibility = viewVisibility; |
| 7727 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 7728 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7729 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7730 | TAG, "Window " + this + " client=" + c.asBinder() |
| 7731 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 7732 | try { |
| 7733 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 7734 | } catch (RemoteException e) { |
| 7735 | mDeathRecipient = null; |
| 7736 | mAttachedWindow = null; |
| 7737 | mLayoutAttached = false; |
| 7738 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7739 | mIsWallpaper = false; |
| 7740 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7741 | mBaseLayer = 0; |
| 7742 | mSubLayer = 0; |
| 7743 | return; |
| 7744 | } |
| 7745 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7746 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7747 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7748 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7749 | // The multiplier here is to reserve space for multiple |
| 7750 | // windows in the same type layer. |
| 7751 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7752 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7753 | + TYPE_LAYER_OFFSET; |
| 7754 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7755 | mAttachedWindow = attachedWindow; |
| 7756 | mAttachedWindow.mChildWindows.add(this); |
| 7757 | mLayoutAttached = mAttrs.type != |
| 7758 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7759 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7760 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7761 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7762 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7763 | } else { |
| 7764 | // The multiplier here is to reserve space for multiple |
| 7765 | // windows in the same type layer. |
| 7766 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7767 | * TYPE_LAYER_MULTIPLIER |
| 7768 | + TYPE_LAYER_OFFSET; |
| 7769 | mSubLayer = 0; |
| 7770 | mAttachedWindow = null; |
| 7771 | mLayoutAttached = false; |
| 7772 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7773 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7774 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7775 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7776 | } |
| 7777 | |
| 7778 | WindowState appWin = this; |
| 7779 | while (appWin.mAttachedWindow != null) { |
| 7780 | appWin = mAttachedWindow; |
| 7781 | } |
| 7782 | WindowToken appToken = appWin.mToken; |
| 7783 | while (appToken.appWindowToken == null) { |
| 7784 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7785 | if (parent == null || appToken == parent) { |
| 7786 | break; |
| 7787 | } |
| 7788 | appToken = parent; |
| 7789 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7790 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | mAppToken = appToken.appWindowToken; |
| 7792 | |
| 7793 | mSurface = null; |
| 7794 | mRequestedWidth = 0; |
| 7795 | mRequestedHeight = 0; |
| 7796 | mLastRequestedWidth = 0; |
| 7797 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7798 | mXOffset = 0; |
| 7799 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7800 | mLayer = 0; |
| 7801 | mAnimLayer = 0; |
| 7802 | mLastLayer = 0; |
| 7803 | } |
| 7804 | |
| 7805 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7806 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | TAG, "Attaching " + this + " token=" + mToken |
| 7808 | + ", list=" + mToken.windows); |
| 7809 | mSession.windowAddedLocked(); |
| 7810 | } |
| 7811 | |
| 7812 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7813 | mHaveFrame = true; |
| 7814 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7815 | final Rect container = mContainingFrame; |
| 7816 | container.set(pf); |
| 7817 | |
| 7818 | final Rect display = mDisplayFrame; |
| 7819 | display.set(df); |
| 7820 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7821 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7822 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7823 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7824 | display.intersect(mCompatibleScreenFrame); |
| 7825 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7826 | } |
| 7827 | |
| 7828 | final int pw = container.right - container.left; |
| 7829 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | |
| 7831 | int w,h; |
| 7832 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7833 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7834 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7835 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7836 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7837 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7838 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | final Rect content = mContentFrame; |
| 7841 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7843 | final Rect visible = mVisibleFrame; |
| 7844 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7845 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7846 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7847 | final int fw = frame.width(); |
| 7848 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7850 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7851 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7852 | |
| 7853 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7854 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7855 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7856 | |
| 7857 | //System.out.println("Out: " + mFrame); |
| 7858 | |
| 7859 | // Now make sure the window fits in the overall display. |
| 7860 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7861 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7862 | // Make sure the content and visible frames are inside of the |
| 7863 | // final window frame. |
| 7864 | if (content.left < frame.left) content.left = frame.left; |
| 7865 | if (content.top < frame.top) content.top = frame.top; |
| 7866 | if (content.right > frame.right) content.right = frame.right; |
| 7867 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7868 | if (visible.left < frame.left) visible.left = frame.left; |
| 7869 | if (visible.top < frame.top) visible.top = frame.top; |
| 7870 | if (visible.right > frame.right) visible.right = frame.right; |
| 7871 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7872 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | final Rect contentInsets = mContentInsets; |
| 7874 | contentInsets.left = content.left-frame.left; |
| 7875 | contentInsets.top = content.top-frame.top; |
| 7876 | contentInsets.right = frame.right-content.right; |
| 7877 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7878 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7879 | final Rect visibleInsets = mVisibleInsets; |
| 7880 | visibleInsets.left = visible.left-frame.left; |
| 7881 | visibleInsets.top = visible.top-frame.top; |
| 7882 | visibleInsets.right = frame.right-visible.right; |
| 7883 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7884 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7885 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7886 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7887 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7888 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7889 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7890 | if (localLOGV) { |
| 7891 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7892 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7893 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7894 | + mRequestedWidth + ", mRequestedheight=" |
| 7895 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7896 | + "): frame=" + mFrame.toShortString() |
| 7897 | + " ci=" + contentInsets.toShortString() |
| 7898 | + " vi=" + visibleInsets.toShortString()); |
| 7899 | //} |
| 7900 | } |
| 7901 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | public Rect getFrameLw() { |
| 7904 | return mFrame; |
| 7905 | } |
| 7906 | |
| 7907 | public Rect getShownFrameLw() { |
| 7908 | return mShownFrame; |
| 7909 | } |
| 7910 | |
| 7911 | public Rect getDisplayFrameLw() { |
| 7912 | return mDisplayFrame; |
| 7913 | } |
| 7914 | |
| 7915 | public Rect getContentFrameLw() { |
| 7916 | return mContentFrame; |
| 7917 | } |
| 7918 | |
| 7919 | public Rect getVisibleFrameLw() { |
| 7920 | return mVisibleFrame; |
| 7921 | } |
| 7922 | |
| 7923 | public boolean getGivenInsetsPendingLw() { |
| 7924 | return mGivenInsetsPending; |
| 7925 | } |
| 7926 | |
| 7927 | public Rect getGivenContentInsetsLw() { |
| 7928 | return mGivenContentInsets; |
| 7929 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7930 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7931 | public Rect getGivenVisibleInsetsLw() { |
| 7932 | return mGivenVisibleInsets; |
| 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 WindowManager.LayoutParams getAttrs() { |
| 7936 | return mAttrs; |
| 7937 | } |
| 7938 | |
| 7939 | public int getSurfaceLayer() { |
| 7940 | return mLayer; |
| 7941 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7943 | public IApplicationToken getAppToken() { |
| 7944 | return mAppToken != null ? mAppToken.appToken : null; |
| 7945 | } |
| 7946 | |
| 7947 | public boolean hasAppShownWindows() { |
| 7948 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7949 | } |
| 7950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7951 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7952 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | TAG, "Setting animation in " + this + ": " + anim); |
| 7954 | mAnimating = false; |
| 7955 | mLocalAnimating = false; |
| 7956 | mAnimation = anim; |
| 7957 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7958 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7959 | } |
| 7960 | |
| 7961 | public void clearAnimation() { |
| 7962 | if (mAnimation != null) { |
| 7963 | mAnimating = true; |
| 7964 | mLocalAnimating = false; |
| 7965 | mAnimation = null; |
| 7966 | } |
| 7967 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7969 | Surface createSurfaceLocked() { |
| 7970 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7971 | mReportDestroySurface = false; |
| 7972 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7973 | mDrawPending = true; |
| 7974 | mCommitDrawPending = false; |
| 7975 | mReadyToShow = false; |
| 7976 | if (mAppToken != null) { |
| 7977 | mAppToken.allDrawn = false; |
| 7978 | } |
| 7979 | |
| 7980 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7981 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7982 | flags |= Surface.PUSH_BUFFERS; |
| 7983 | } |
| 7984 | |
| 7985 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7986 | flags |= Surface.SECURE; |
| 7987 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7988 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7989 | TAG, "Creating surface in session " |
| 7990 | + mSession.mSurfaceSession + " window " + this |
| 7991 | + " w=" + mFrame.width() |
| 7992 | + " h=" + mFrame.height() + " format=" |
| 7993 | + mAttrs.format + " flags=" + flags); |
| 7994 | |
| 7995 | int w = mFrame.width(); |
| 7996 | int h = mFrame.height(); |
| 7997 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7998 | // for a scaled surface, we always want the requested |
| 7999 | // size. |
| 8000 | w = mRequestedWidth; |
| 8001 | h = mRequestedHeight; |
| 8002 | } |
| 8003 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 8004 | // Something is wrong and SurfaceFlinger will not like this, |
| 8005 | // try to revert to sane values |
| 8006 | if (w <= 0) w = 1; |
| 8007 | if (h <= 0) h = 1; |
| 8008 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8009 | mSurfaceShown = false; |
| 8010 | mSurfaceLayer = 0; |
| 8011 | mSurfaceAlpha = 1; |
| 8012 | mSurfaceX = 0; |
| 8013 | mSurfaceY = 0; |
| 8014 | mSurfaceW = w; |
| 8015 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8016 | try { |
| 8017 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8018 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 8019 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8020 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8021 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8022 | + mSurface + " IN SESSION " |
| 8023 | + mSession.mSurfaceSession |
| 8024 | + ": pid=" + mSession.mPid + " format=" |
| 8025 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8026 | + Integer.toHexString(flags) |
| 8027 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8028 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8029 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8030 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 8031 | return null; |
| 8032 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8033 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8034 | return null; |
| 8035 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8036 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8037 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | TAG, "Got surface: " + mSurface |
| 8039 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 8040 | + ", animLayer=" + mAnimLayer); |
| 8041 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8042 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8043 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 8044 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 8045 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 8046 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8047 | } |
| 8048 | Surface.openTransaction(); |
| 8049 | try { |
| 8050 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8051 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 8052 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8053 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 8054 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8056 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8057 | mSurface.hide(); |
| 8058 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8059 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8060 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 8061 | Surface.SURFACE_DITHER); |
| 8062 | } |
| 8063 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8064 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8065 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 8066 | } |
| 8067 | mLastHidden = true; |
| 8068 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8069 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8070 | Surface.closeTransaction(); |
| 8071 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8072 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8073 | TAG, "Created surface " + this); |
| 8074 | } |
| 8075 | return mSurface; |
| 8076 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8077 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8078 | void destroySurfaceLocked() { |
| 8079 | // Window is no longer on-screen, so can no longer receive |
| 8080 | // key events... if we were waiting for it to finish |
| 8081 | // handling a key event, the wait is over! |
| 8082 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 8083 | KeyWaiter.RETURN_NOTHING); |
| 8084 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 8085 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 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; |
| 8101 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8102 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8103 | if (mReportDestroySurface) { |
| 8104 | mReportDestroySurface = false; |
| 8105 | mSurfacePendingDestroy = true; |
| 8106 | try { |
| 8107 | mClient.dispatchGetNewSurface(); |
| 8108 | // We'll really destroy on the next time around. |
| 8109 | return; |
| 8110 | } catch (RemoteException e) { |
| 8111 | } |
| 8112 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8113 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8114 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8115 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8116 | RuntimeException e = null; |
| 8117 | if (!HIDE_STACK_CRAWLS) { |
| 8118 | e = new RuntimeException(); |
| 8119 | e.fillInStackTrace(); |
| 8120 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8121 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8122 | + mSurface + ", session " + mSession, e); |
| 8123 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8124 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8125 | RuntimeException e = null; |
| 8126 | if (!HIDE_STACK_CRAWLS) { |
| 8127 | e = new RuntimeException(); |
| 8128 | e.fillInStackTrace(); |
| 8129 | } |
| 8130 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8131 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8132 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8133 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8134 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8135 | + " surface " + mSurface + " session " + mSession |
| 8136 | + ": " + e.toString()); |
| 8137 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8138 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8139 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8140 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8141 | } |
| 8142 | } |
| 8143 | |
| 8144 | boolean finishDrawingLocked() { |
| 8145 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8146 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8147 | TAG, "finishDrawingLocked: " + mSurface); |
| 8148 | mCommitDrawPending = true; |
| 8149 | mDrawPending = false; |
| 8150 | return true; |
| 8151 | } |
| 8152 | return false; |
| 8153 | } |
| 8154 | |
| 8155 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8156 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8157 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8158 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8159 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8160 | } |
| 8161 | mCommitDrawPending = false; |
| 8162 | mReadyToShow = true; |
| 8163 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 8164 | final AppWindowToken atoken = mAppToken; |
| 8165 | if (atoken == null || atoken.allDrawn || starting) { |
| 8166 | performShowLocked(); |
| 8167 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8168 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8169 | } |
| 8170 | |
| 8171 | // This must be called while inside a transaction. |
| 8172 | boolean performShowLocked() { |
| 8173 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8174 | RuntimeException e = null; |
| 8175 | if (!HIDE_STACK_CRAWLS) { |
| 8176 | e = new RuntimeException(); |
| 8177 | e.fillInStackTrace(); |
| 8178 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8179 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8180 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 8181 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 8182 | } |
| 8183 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8184 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 8185 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8186 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8187 | + " during animation: policyVis=" + mPolicyVisibility |
| 8188 | + " attHidden=" + mAttachedHidden |
| 8189 | + " tok.hiddenRequested=" |
| 8190 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 8191 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | + (mAppToken != null ? mAppToken.hidden : false) |
| 8193 | + " animating=" + mAnimating |
| 8194 | + " tok animating=" |
| 8195 | + (mAppToken != null ? mAppToken.animating : false)); |
| 8196 | if (!showSurfaceRobustlyLocked(this)) { |
| 8197 | return false; |
| 8198 | } |
| 8199 | mLastAlpha = -1; |
| 8200 | mHasDrawn = true; |
| 8201 | mLastHidden = false; |
| 8202 | mReadyToShow = false; |
| 8203 | enableScreenIfNeededLocked(); |
| 8204 | |
| 8205 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8207 | int i = mChildWindows.size(); |
| 8208 | while (i > 0) { |
| 8209 | i--; |
| 8210 | WindowState c = (WindowState)mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 8211 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8212 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 8213 | if (c.mSurface != null) { |
| 8214 | c.performShowLocked(); |
| 8215 | // It hadn't been shown, which means layout not |
| 8216 | // performed on it, so now we want to make sure to |
| 8217 | // do a layout. If called from within the transaction |
| 8218 | // loop, this will cause it to restart with a new |
| 8219 | // layout. |
| 8220 | mLayoutNeeded = true; |
| 8221 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8222 | } |
| 8223 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8224 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8225 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 8226 | && mAppToken != null) { |
| 8227 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8228 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 8229 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8230 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8231 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8232 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 8233 | // If this initial window is animating, stop it -- we |
| 8234 | // will do an animation to reveal it from behind the |
| 8235 | // starting window, so there is no need for it to also |
| 8236 | // be doing its own stuff. |
| 8237 | if (mAnimation != null) { |
| 8238 | mAnimation = null; |
| 8239 | // Make sure we clean up the animation. |
| 8240 | mAnimating = true; |
| 8241 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8242 | mFinishedStarting.add(mAppToken); |
| 8243 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 8244 | } |
| 8245 | mAppToken.updateReportedVisibilityLocked(); |
| 8246 | } |
| 8247 | } |
| 8248 | return true; |
| 8249 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8251 | // This must be called while inside a transaction. Returns true if |
| 8252 | // there is more animation to run. |
| 8253 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8254 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8257 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 8258 | mHasTransformation = true; |
| 8259 | mHasLocalTransformation = true; |
| 8260 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8261 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | TAG, "Starting animation in " + this + |
| 8263 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 8264 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 8265 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 8266 | mAnimation.setStartTime(currentTime); |
| 8267 | mLocalAnimating = true; |
| 8268 | mAnimating = true; |
| 8269 | } |
| 8270 | mTransformation.clear(); |
| 8271 | final boolean more = mAnimation.getTransformation( |
| 8272 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8273 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | TAG, "Stepped animation in " + this + |
| 8275 | ": more=" + more + ", xform=" + mTransformation); |
| 8276 | if (more) { |
| 8277 | // we're not done! |
| 8278 | return true; |
| 8279 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8280 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8281 | TAG, "Finished animation in " + this + |
| 8282 | " @ " + currentTime); |
| 8283 | mAnimation = null; |
| 8284 | //WindowManagerService.this.dump(); |
| 8285 | } |
| 8286 | mHasLocalTransformation = false; |
| 8287 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8288 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8289 | // When our app token is animating, we kind-of pretend like |
| 8290 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 8291 | // part of this check means that we will only do this if |
| 8292 | // our window is not currently exiting, or it is not |
| 8293 | // locally animating itself. The idea being that one that |
| 8294 | // is exiting and doing a local animation should be removed |
| 8295 | // once that animation is done. |
| 8296 | mAnimating = true; |
| 8297 | mHasTransformation = true; |
| 8298 | mTransformation.clear(); |
| 8299 | return false; |
| 8300 | } else if (mHasTransformation) { |
| 8301 | // Little trick to get through the path below to act like |
| 8302 | // we have finished an animation. |
| 8303 | mAnimating = true; |
| 8304 | } else if (isAnimating()) { |
| 8305 | mAnimating = true; |
| 8306 | } |
| 8307 | } else if (mAnimation != null) { |
| 8308 | // If the display is frozen, and there is a pending animation, |
| 8309 | // clear it and make sure we run the cleanup code. |
| 8310 | mAnimating = true; |
| 8311 | mLocalAnimating = true; |
| 8312 | mAnimation = null; |
| 8313 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8314 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8315 | if (!mAnimating && !mLocalAnimating) { |
| 8316 | return false; |
| 8317 | } |
| 8318 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8319 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 8321 | + ", reportedVisible=" |
| 8322 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8324 | mAnimating = false; |
| 8325 | mLocalAnimating = false; |
| 8326 | mAnimation = null; |
| 8327 | mAnimLayer = mLayer; |
| 8328 | if (mIsImWindow) { |
| 8329 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8330 | } else if (mIsWallpaper) { |
| 8331 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8333 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8334 | + " anim layer: " + mAnimLayer); |
| 8335 | mHasTransformation = false; |
| 8336 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8337 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 8338 | if (DEBUG_VISIBILITY) { |
| 8339 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 8340 | + mPolicyVisibilityAfterAnim); |
| 8341 | } |
| 8342 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 8343 | if (!mPolicyVisibility) { |
| 8344 | if (mCurrentFocus == this) { |
| 8345 | mFocusMayChange = true; |
| 8346 | } |
| 8347 | // Window is no longer visible -- make sure if we were waiting |
| 8348 | // for it to be displayed before enabling the display, that |
| 8349 | // we allow the display to be enabled now. |
| 8350 | enableScreenIfNeededLocked(); |
| 8351 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8352 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8353 | mTransformation.clear(); |
| 8354 | if (mHasDrawn |
| 8355 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 8356 | && mAppToken != null |
| 8357 | && mAppToken.firstWindowDrawn |
| 8358 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8359 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8360 | + mToken + ": first real window done animating"); |
| 8361 | mFinishedStarting.add(mAppToken); |
| 8362 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 8363 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8365 | finishExit(); |
| 8366 | |
| 8367 | if (mAppToken != null) { |
| 8368 | mAppToken.updateReportedVisibilityLocked(); |
| 8369 | } |
| 8370 | |
| 8371 | return false; |
| 8372 | } |
| 8373 | |
| 8374 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8375 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8376 | TAG, "finishExit in " + this |
| 8377 | + ": exiting=" + mExiting |
| 8378 | + " remove=" + mRemoveOnExit |
| 8379 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8381 | final int N = mChildWindows.size(); |
| 8382 | for (int i=0; i<N; i++) { |
| 8383 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 8384 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8386 | if (!mExiting) { |
| 8387 | return; |
| 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 (isWindowAnimating()) { |
| 8391 | return; |
| 8392 | } |
| 8393 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8394 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8395 | TAG, "Exit animation finished in " + this |
| 8396 | + ": remove=" + mRemoveOnExit); |
| 8397 | if (mSurface != null) { |
| 8398 | mDestroySurface.add(this); |
| 8399 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8400 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8401 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8402 | try { |
| 8403 | mSurface.hide(); |
| 8404 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8405 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8406 | } |
| 8407 | mLastHidden = true; |
| 8408 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 8409 | } |
| 8410 | mExiting = false; |
| 8411 | if (mRemoveOnExit) { |
| 8412 | mPendingRemove.add(this); |
| 8413 | mRemoveOnExit = false; |
| 8414 | } |
| 8415 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8417 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 8418 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 8419 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 8420 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 8421 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 8422 | return true; |
| 8423 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8425 | void computeShownFrameLocked() { |
| 8426 | final boolean selfTransformation = mHasLocalTransformation; |
| 8427 | Transformation attachedTransformation = |
| 8428 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 8429 | ? mAttachedWindow.mTransformation : null; |
| 8430 | Transformation appTransformation = |
| 8431 | (mAppToken != null && mAppToken.hasTransformation) |
| 8432 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8433 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8434 | // Wallpapers are animated based on the "real" window they |
| 8435 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8436 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8437 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8438 | if (mWallpaperTarget.mHasLocalTransformation && |
| 8439 | mWallpaperTarget.mAnimation != null && |
| 8440 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8441 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8442 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8443 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8444 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8445 | } |
| 8446 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8447 | mWallpaperTarget.mAppToken.hasTransformation && |
| 8448 | mWallpaperTarget.mAppToken.animation != null && |
| 8449 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8450 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8451 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8452 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 8453 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8454 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8455 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8456 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8457 | if (selfTransformation || attachedTransformation != null |
| 8458 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8459 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8460 | final Rect frame = mFrame; |
| 8461 | final float tmpFloats[] = mTmpFloats; |
| 8462 | final Matrix tmpMatrix = mTmpMatrix; |
| 8463 | |
| 8464 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 8465 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8466 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8467 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8468 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 8469 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8470 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8471 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8472 | } |
| 8473 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8474 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8475 | } |
| 8476 | |
| 8477 | // "convert" it into SurfaceFlinger's format |
| 8478 | // (a 2x2 matrix + an offset) |
| 8479 | // Here we must not transform the position of the surface |
| 8480 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8481 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8482 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8483 | tmpMatrix.getValues(tmpFloats); |
| 8484 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 8485 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 8486 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 8487 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8488 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 8489 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8490 | int w = frame.width(); |
| 8491 | int h = frame.height(); |
| 8492 | mShownFrame.set(x, y, x+w, y+h); |
| 8493 | |
| 8494 | // Now set the alpha... but because our current hardware |
| 8495 | // can't do alpha transformation on a non-opaque surface, |
| 8496 | // turn it off if we are running an animation that is also |
| 8497 | // transforming since it is more important to have that |
| 8498 | // animation be smooth. |
| 8499 | mShownAlpha = mAlpha; |
| 8500 | if (!mLimitedAlphaCompositing |
| 8501 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 8502 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 8503 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8504 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8505 | if (selfTransformation) { |
| 8506 | mShownAlpha *= mTransformation.getAlpha(); |
| 8507 | } |
| 8508 | if (attachedTransformation != null) { |
| 8509 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 8510 | } |
| 8511 | if (appTransformation != null) { |
| 8512 | mShownAlpha *= appTransformation.getAlpha(); |
| 8513 | } |
| 8514 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8515 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8516 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8517 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8518 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8519 | TAG, "Continuing animation in " + this + |
| 8520 | ": " + mShownFrame + |
| 8521 | ", alpha=" + mTransformation.getAlpha()); |
| 8522 | return; |
| 8523 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8525 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8526 | if (mXOffset != 0 || mYOffset != 0) { |
| 8527 | mShownFrame.offset(mXOffset, mYOffset); |
| 8528 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8529 | mShownAlpha = mAlpha; |
| 8530 | mDsDx = 1; |
| 8531 | mDtDx = 0; |
| 8532 | mDsDy = 0; |
| 8533 | mDtDy = 1; |
| 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 | /** |
| 8537 | * Is this window visible? It is not visible if there is no |
| 8538 | * surface, or we are in the process of running an exit animation |
| 8539 | * that will remove the surface, or its app token has been hidden. |
| 8540 | */ |
| 8541 | public boolean isVisibleLw() { |
| 8542 | final AppWindowToken atoken = mAppToken; |
| 8543 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 8544 | && (atoken == null || !atoken.hiddenRequested) |
| 8545 | && !mExiting && !mDestroying; |
| 8546 | } |
| 8547 | |
| 8548 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 8549 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 8550 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 8551 | * things like window flags that impact the keyguard. |
| 8552 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 8553 | * for this "hidden behind keyguard" state rather than overloading |
| 8554 | * mPolicyVisibility. Ungh. |
| 8555 | */ |
| 8556 | public boolean isVisibleOrBehindKeyguardLw() { |
| 8557 | final AppWindowToken atoken = mAppToken; |
| 8558 | return mSurface != null && !mAttachedHidden |
| 8559 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 8560 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)) |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 8561 | && !mExiting && !mDestroying; |
| 8562 | } |
| 8563 | |
| 8564 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8565 | * Is this window visible, ignoring its app token? It is not visible |
| 8566 | * if there is no surface, or we are in the process of running an exit animation |
| 8567 | * that will remove the surface. |
| 8568 | */ |
| 8569 | public boolean isWinVisibleLw() { |
| 8570 | final AppWindowToken atoken = mAppToken; |
| 8571 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 8572 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 8573 | && !mExiting && !mDestroying; |
| 8574 | } |
| 8575 | |
| 8576 | /** |
| 8577 | * The same as isVisible(), but follows the current hidden state of |
| 8578 | * the associated app token, not the pending requested hidden state. |
| 8579 | */ |
| 8580 | boolean isVisibleNow() { |
| 8581 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8582 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8583 | } |
| 8584 | |
| 8585 | /** |
| 8586 | * Same as isVisible(), but we also count it as visible between the |
| 8587 | * call to IWindowSession.add() and the first relayout(). |
| 8588 | */ |
| 8589 | boolean isVisibleOrAdding() { |
| 8590 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8591 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8592 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 8593 | && mPolicyVisibility && !mAttachedHidden |
| 8594 | && (atoken == null || !atoken.hiddenRequested) |
| 8595 | && !mExiting && !mDestroying; |
| 8596 | } |
| 8597 | |
| 8598 | /** |
| 8599 | * Is this window currently on-screen? It is on-screen either if it |
| 8600 | * is visible or it is currently running an animation before no longer |
| 8601 | * being visible. |
| 8602 | */ |
| 8603 | boolean isOnScreen() { |
| 8604 | final AppWindowToken atoken = mAppToken; |
| 8605 | if (atoken != null) { |
| 8606 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8607 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8608 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8609 | } else { |
| 8610 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8611 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | } |
| 8613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | /** |
| 8616 | * Like isOnScreen(), but we don't return true if the window is part |
| 8617 | * of a transition that has not yet been started. |
| 8618 | */ |
| 8619 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8620 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8621 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8622 | return false; |
| 8623 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8624 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8625 | final boolean animating = atoken != null |
| 8626 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8627 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8628 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 8629 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8630 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8631 | } |
| 8632 | |
| 8633 | /** Is the window or its container currently animating? */ |
| 8634 | boolean isAnimating() { |
| 8635 | final WindowState attached = mAttachedWindow; |
| 8636 | final AppWindowToken atoken = mAppToken; |
| 8637 | return mAnimation != null |
| 8638 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8639 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | (atoken.animation != null |
| 8641 | || atoken.inPendingTransaction)); |
| 8642 | } |
| 8643 | |
| 8644 | /** Is this window currently animating? */ |
| 8645 | boolean isWindowAnimating() { |
| 8646 | return mAnimation != null; |
| 8647 | } |
| 8648 | |
| 8649 | /** |
| 8650 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 8651 | * been drawn. |
| 8652 | */ |
| 8653 | public boolean isDisplayedLw() { |
| 8654 | final AppWindowToken atoken = mAppToken; |
| 8655 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8656 | && !mDrawPending && !mCommitDrawPending |
| 8657 | && ((!mAttachedHidden && |
| 8658 | (atoken == null || !atoken.hiddenRequested)) |
| 8659 | || mAnimating); |
| 8660 | } |
| 8661 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8662 | /** |
| 8663 | * 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] | 8664 | * complete UI in to. Note that this returns true if the orientation |
| 8665 | * is changing even if the window hasn't redrawn because we don't want |
| 8666 | * to stop things from executing during that time. |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8667 | */ |
| 8668 | public boolean isDrawnLw() { |
| 8669 | final AppWindowToken atoken = mAppToken; |
| 8670 | return mSurface != null && !mDestroying |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 8671 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8672 | } |
| 8673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8674 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 8675 | boolean shownFrame, boolean onlyOpaque) { |
| 8676 | if (mSurface == null) { |
| 8677 | return false; |
| 8678 | } |
| 8679 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 8680 | return false; |
| 8681 | } |
| 8682 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 8683 | return false; |
| 8684 | } |
| 8685 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8686 | |
| 8687 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8688 | return frame.left <= mCompatibleScreenFrame.left && |
| 8689 | frame.top <= mCompatibleScreenFrame.top && |
| 8690 | frame.right >= mCompatibleScreenFrame.right && |
| 8691 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 8692 | } else { |
| 8693 | return frame.left <= 0 && frame.top <= 0 |
| 8694 | && frame.right >= screenWidth |
| 8695 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8696 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8697 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8698 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8699 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8700 | * Return true if the window is opaque and fully drawn. This indicates |
| 8701 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8702 | */ |
| 8703 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8704 | return (mAttrs.format == PixelFormat.OPAQUE |
| 8705 | || mAttrs.type == TYPE_WALLPAPER) |
| 8706 | && mSurface != null && mAnimation == null |
| 8707 | && (mAppToken == null || mAppToken.animation == null) |
| 8708 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8709 | } |
| 8710 | |
| 8711 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 8712 | return |
| 8713 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8714 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 8715 | // only if it's visible |
| 8716 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8717 | // and only if the application fills the compatible screen |
| 8718 | mFrame.left <= mCompatibleScreenFrame.left && |
| 8719 | mFrame.top <= mCompatibleScreenFrame.top && |
| 8720 | mFrame.right >= mCompatibleScreenFrame.right && |
| 8721 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8722 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8723 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8724 | } |
| 8725 | |
| 8726 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8727 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8728 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8729 | } |
| 8730 | |
| 8731 | void removeLocked() { |
| 8732 | if (mAttachedWindow != null) { |
| 8733 | mAttachedWindow.mChildWindows.remove(this); |
| 8734 | } |
| 8735 | destroySurfaceLocked(); |
| 8736 | mSession.windowRemovedLocked(); |
| 8737 | try { |
| 8738 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8739 | } catch (RuntimeException e) { |
| 8740 | // Ignore if it has already been removed (usually because |
| 8741 | // we are doing this as part of processing a death note.) |
| 8742 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8743 | |
| 8744 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 8745 | if (mInputChannel != null) { |
| 8746 | mInputManager.unregisterInputChannel(mInputChannel); |
| 8747 | |
| 8748 | mInputChannel.dispose(); |
| 8749 | mInputChannel = null; |
| 8750 | } |
| 8751 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8752 | } |
| 8753 | |
| 8754 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8755 | public void binderDied() { |
| 8756 | try { |
| 8757 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8758 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8759 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8760 | if (win != null) { |
| 8761 | removeWindowLocked(mSession, win); |
| 8762 | } |
| 8763 | } |
| 8764 | } catch (IllegalArgumentException ex) { |
| 8765 | // This will happen if the window has already been |
| 8766 | // removed. |
| 8767 | } |
| 8768 | } |
| 8769 | } |
| 8770 | |
| 8771 | /** Returns true if this window desires key events. */ |
| 8772 | public final boolean canReceiveKeys() { |
| 8773 | return isVisibleOrAdding() |
| 8774 | && (mViewVisibility == View.VISIBLE) |
| 8775 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8776 | } |
| 8777 | |
| 8778 | public boolean hasDrawnLw() { |
| 8779 | return mHasDrawn; |
| 8780 | } |
| 8781 | |
| 8782 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8783 | return showLw(doAnimation, true); |
| 8784 | } |
| 8785 | |
| 8786 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8787 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8788 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8789 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8790 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8791 | if (doAnimation) { |
| 8792 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8793 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8794 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8795 | doAnimation = false; |
| 8796 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8797 | // Check for the case where we are currently visible and |
| 8798 | // not animating; we do not want to do animation at such a |
| 8799 | // point to become visible when we already are. |
| 8800 | doAnimation = false; |
| 8801 | } |
| 8802 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8803 | mPolicyVisibility = true; |
| 8804 | mPolicyVisibilityAfterAnim = true; |
| 8805 | if (doAnimation) { |
| 8806 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8807 | } |
| 8808 | if (requestAnim) { |
| 8809 | requestAnimationLocked(0); |
| 8810 | } |
| 8811 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8812 | } |
| 8813 | |
| 8814 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8815 | return hideLw(doAnimation, true); |
| 8816 | } |
| 8817 | |
| 8818 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8819 | if (doAnimation) { |
| 8820 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8821 | doAnimation = false; |
| 8822 | } |
| 8823 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8824 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8825 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8826 | if (!current) { |
| 8827 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8828 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8829 | if (doAnimation) { |
| 8830 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8831 | if (mAnimation == null) { |
| 8832 | doAnimation = false; |
| 8833 | } |
| 8834 | } |
| 8835 | if (doAnimation) { |
| 8836 | mPolicyVisibilityAfterAnim = false; |
| 8837 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8838 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8839 | mPolicyVisibilityAfterAnim = false; |
| 8840 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8841 | // Window is no longer visible -- make sure if we were waiting |
| 8842 | // for it to be displayed before enabling the display, that |
| 8843 | // we allow the display to be enabled now. |
| 8844 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8845 | if (mCurrentFocus == this) { |
| 8846 | mFocusMayChange = true; |
| 8847 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8848 | } |
| 8849 | if (requestAnim) { |
| 8850 | requestAnimationLocked(0); |
| 8851 | } |
| 8852 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8853 | } |
| 8854 | |
| 8855 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8856 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8857 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8858 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8859 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8860 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8861 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8862 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8863 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8864 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8865 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8866 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8867 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8868 | } |
| 8869 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8870 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8871 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8872 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8873 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8874 | pw.print("="); pw.print(mAnimLayer); |
| 8875 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8876 | if (mSurface != null) { |
| 8877 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8878 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8879 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8880 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8881 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8882 | pw.print(","); pw.print(mSurfaceY); |
| 8883 | pw.print(") "); pw.print(mSurfaceW); |
| 8884 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8885 | } |
| 8886 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8887 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8888 | if (mAppToken != null) { |
| 8889 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8890 | } |
| 8891 | if (mTargetAppToken != null) { |
| 8892 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8893 | } |
| 8894 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8895 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8896 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8897 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8898 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8899 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8900 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8901 | pw.print(mPolicyVisibility); |
| 8902 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8903 | pw.print(mPolicyVisibilityAfterAnim); |
| 8904 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8905 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8906 | if (!mRelayoutCalled) { |
| 8907 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8908 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8909 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8910 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8911 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8912 | if (mXOffset != 0 || mYOffset != 0) { |
| 8913 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8914 | pw.print(" y="); pw.println(mYOffset); |
| 8915 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8916 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8917 | mGivenContentInsets.printShortString(pw); |
| 8918 | pw.print(" mGivenVisibleInsets="); |
| 8919 | mGivenVisibleInsets.printShortString(pw); |
| 8920 | pw.println(); |
| 8921 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8922 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8923 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8924 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8925 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8926 | pw.print(prefix); pw.print("mShownFrame="); |
| 8927 | mShownFrame.printShortString(pw); |
| 8928 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8929 | pw.println(); |
| 8930 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8931 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8932 | pw.println(); |
| 8933 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8934 | mContainingFrame.printShortString(pw); |
| 8935 | pw.print(" mDisplayFrame="); |
| 8936 | mDisplayFrame.printShortString(pw); |
| 8937 | pw.println(); |
| 8938 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8939 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8940 | pw.println(); |
| 8941 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8942 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8943 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8944 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8945 | pw.println(); |
| 8946 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8947 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8948 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8949 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8950 | } |
| 8951 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8952 | || mAnimation != null) { |
| 8953 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8954 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8955 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8956 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8957 | } |
| 8958 | if (mHasTransformation || mHasLocalTransformation) { |
| 8959 | pw.print(prefix); pw.print("XForm: has="); |
| 8960 | pw.print(mHasTransformation); |
| 8961 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8962 | pw.print(" "); mTransformation.printShortString(pw); |
| 8963 | pw.println(); |
| 8964 | } |
| 8965 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8966 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8967 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8968 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8969 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8970 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8971 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8972 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8973 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8974 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8975 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8976 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8977 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8978 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8979 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8980 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8981 | if (mHScale != 1 || mVScale != 1) { |
| 8982 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8983 | pw.print(" mVScale="); pw.println(mVScale); |
| 8984 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8985 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8986 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8987 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8988 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8989 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8990 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8991 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8992 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8993 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8994 | |
| 8995 | String makeInputChannelName() { |
| 8996 | return Integer.toHexString(System.identityHashCode(this)) |
| 8997 | + " " + mAttrs.getTitle(); |
| 8998 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8999 | |
| 9000 | @Override |
| 9001 | public String toString() { |
| 9002 | return "Window{" |
| 9003 | + Integer.toHexString(System.identityHashCode(this)) |
| 9004 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 9005 | } |
| 9006 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9007 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9008 | // ------------------------------------------------------------- |
| 9009 | // Window Token State |
| 9010 | // ------------------------------------------------------------- |
| 9011 | |
| 9012 | class WindowToken { |
| 9013 | // The actual token. |
| 9014 | final IBinder token; |
| 9015 | |
| 9016 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 9017 | final int windowType; |
| 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 | // Set if this token was explicitly added by a client, so should |
| 9020 | // not be removed when all windows are removed. |
| 9021 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9022 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9023 | // For printing. |
| 9024 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9025 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9026 | // If this is an AppWindowToken, this is non-null. |
| 9027 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9029 | // All of the windows associated with this token. |
| 9030 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 9031 | |
| 9032 | // Is key dispatching paused for this token? |
| 9033 | boolean paused = false; |
| 9034 | |
| 9035 | // Should this token's windows be hidden? |
| 9036 | boolean hidden; |
| 9037 | |
| 9038 | // Temporary for finding which tokens no longer have visible windows. |
| 9039 | boolean hasVisible; |
| 9040 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9041 | // Set to true when this token is in a pending transaction where it |
| 9042 | // will be shown. |
| 9043 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9044 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9045 | // Set to true when this token is in a pending transaction where it |
| 9046 | // will be hidden. |
| 9047 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9048 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9049 | // Set to true when this token is in a pending transaction where its |
| 9050 | // windows will be put to the bottom of the list. |
| 9051 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9052 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9053 | // Set to true when this token is in a pending transaction where its |
| 9054 | // windows will be put to the top of the list. |
| 9055 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9057 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 9058 | token = _token; |
| 9059 | windowType = type; |
| 9060 | explicit = _explicit; |
| 9061 | } |
| 9062 | |
| 9063 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9064 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 9065 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 9066 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 9067 | pw.print(" hidden="); pw.print(hidden); |
| 9068 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9069 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 9070 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 9071 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 9072 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 9073 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 9074 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9075 | } |
| 9076 | |
| 9077 | @Override |
| 9078 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9079 | if (stringName == null) { |
| 9080 | StringBuilder sb = new StringBuilder(); |
| 9081 | sb.append("WindowToken{"); |
| 9082 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 9083 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 9084 | stringName = sb.toString(); |
| 9085 | } |
| 9086 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9087 | } |
| 9088 | }; |
| 9089 | |
| 9090 | class AppWindowToken extends WindowToken { |
| 9091 | // Non-null only for application tokens. |
| 9092 | final IApplicationToken appToken; |
| 9093 | |
| 9094 | // All of the windows and child windows that are included in this |
| 9095 | // application token. Note this list is NOT sorted! |
| 9096 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 9097 | |
| 9098 | int groupId = -1; |
| 9099 | boolean appFullscreen; |
| 9100 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9102 | // These are used for determining when all windows associated with |
| 9103 | // an activity have been drawn, so they can be made visible together |
| 9104 | // at the same time. |
| 9105 | int lastTransactionSequence = mTransactionSequence-1; |
| 9106 | int numInterestingWindows; |
| 9107 | int numDrawnWindows; |
| 9108 | boolean inPendingTransaction; |
| 9109 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9110 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9111 | // Is this token going to be hidden in a little while? If so, it |
| 9112 | // won't be taken into account for setting the screen orientation. |
| 9113 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9114 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9115 | // Is this window's surface needed? This is almost like hidden, except |
| 9116 | // it will sometimes be true a little earlier: when the token has |
| 9117 | // been shown, but is still waiting for its app transition to execute |
| 9118 | // before making its windows shown. |
| 9119 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9121 | // Have we told the window clients to hide themselves? |
| 9122 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | // Last visibility state we reported to the app token. |
| 9125 | boolean reportedVisible; |
| 9126 | |
| 9127 | // Set to true when the token has been removed from the window mgr. |
| 9128 | boolean removed; |
| 9129 | |
| 9130 | // Have we been asked to have this token keep the screen frozen? |
| 9131 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9133 | boolean animating; |
| 9134 | Animation animation; |
| 9135 | boolean hasTransformation; |
| 9136 | final Transformation transformation = new Transformation(); |
| 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 | // Offset to the window of all layers in the token, for use by |
| 9139 | // AppWindowToken animations. |
| 9140 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9141 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9142 | // Information about an application starting window if displayed. |
| 9143 | StartingData startingData; |
| 9144 | WindowState startingWindow; |
| 9145 | View startingView; |
| 9146 | boolean startingDisplayed; |
| 9147 | boolean startingMoved; |
| 9148 | boolean firstWindowDrawn; |
| 9149 | |
| 9150 | AppWindowToken(IApplicationToken _token) { |
| 9151 | super(_token.asBinder(), |
| 9152 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 9153 | appWindowToken = this; |
| 9154 | appToken = _token; |
| 9155 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9157 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9158 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9159 | TAG, "Setting animation in " + this + ": " + anim); |
| 9160 | animation = anim; |
| 9161 | animating = false; |
| 9162 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 9163 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 9164 | int zorder = anim.getZAdjustment(); |
| 9165 | int adj = 0; |
| 9166 | if (zorder == Animation.ZORDER_TOP) { |
| 9167 | adj = TYPE_LAYER_OFFSET; |
| 9168 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 9169 | adj = -TYPE_LAYER_OFFSET; |
| 9170 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9172 | if (animLayerAdjustment != adj) { |
| 9173 | animLayerAdjustment = adj; |
| 9174 | updateLayers(); |
| 9175 | } |
| 9176 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9177 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9178 | public void setDummyAnimation() { |
| 9179 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9180 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9181 | TAG, "Setting dummy animation in " + this); |
| 9182 | animation = sDummyAnimation; |
| 9183 | } |
| 9184 | } |
| 9185 | |
| 9186 | public void clearAnimation() { |
| 9187 | if (animation != null) { |
| 9188 | animation = null; |
| 9189 | animating = true; |
| 9190 | } |
| 9191 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9192 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9193 | void updateLayers() { |
| 9194 | final int N = allAppWindows.size(); |
| 9195 | final int adj = animLayerAdjustment; |
| 9196 | for (int i=0; i<N; i++) { |
| 9197 | WindowState w = allAppWindows.get(i); |
| 9198 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9199 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9200 | + w.mAnimLayer); |
| 9201 | if (w == mInputMethodTarget) { |
| 9202 | setInputMethodAnimLayerAdjustment(adj); |
| 9203 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9204 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 9205 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9206 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9207 | } |
| 9208 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9210 | void sendAppVisibilityToClients() { |
| 9211 | final int N = allAppWindows.size(); |
| 9212 | for (int i=0; i<N; i++) { |
| 9213 | WindowState win = allAppWindows.get(i); |
| 9214 | if (win == startingWindow && clientHidden) { |
| 9215 | // Don't hide the starting window. |
| 9216 | continue; |
| 9217 | } |
| 9218 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9219 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9220 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 9221 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 9222 | } catch (RemoteException e) { |
| 9223 | } |
| 9224 | } |
| 9225 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9226 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9227 | void showAllWindowsLocked() { |
| 9228 | final int NW = allAppWindows.size(); |
| 9229 | for (int i=0; i<NW; i++) { |
| 9230 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9231 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9232 | "performing show on: " + w); |
| 9233 | w.performShowLocked(); |
| 9234 | } |
| 9235 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9236 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9237 | // This must be called while inside a transaction. |
| 9238 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9239 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9240 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9242 | if (animation == sDummyAnimation) { |
| 9243 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9244 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9245 | // when it is really time to animate, this will be set to |
| 9246 | // a real animation and the next call will execute normally. |
| 9247 | return false; |
| 9248 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9249 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9250 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 9251 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9252 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9253 | TAG, "Starting animation in " + this + |
| 9254 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 9255 | + " scale=" + mTransitionAnimationScale |
| 9256 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 9257 | animation.initialize(dw, dh, dw, dh); |
| 9258 | animation.setStartTime(currentTime); |
| 9259 | animating = true; |
| 9260 | } |
| 9261 | transformation.clear(); |
| 9262 | final boolean more = animation.getTransformation( |
| 9263 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9264 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9265 | TAG, "Stepped animation in " + this + |
| 9266 | ": more=" + more + ", xform=" + transformation); |
| 9267 | if (more) { |
| 9268 | // we're done! |
| 9269 | hasTransformation = true; |
| 9270 | return true; |
| 9271 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9272 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9273 | TAG, "Finished animation in " + this + |
| 9274 | " @ " + currentTime); |
| 9275 | animation = null; |
| 9276 | } |
| 9277 | } else if (animation != null) { |
| 9278 | // If the display is frozen, and there is a pending animation, |
| 9279 | // clear it and make sure we run the cleanup code. |
| 9280 | animating = true; |
| 9281 | animation = null; |
| 9282 | } |
| 9283 | |
| 9284 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9286 | if (!animating) { |
| 9287 | return false; |
| 9288 | } |
| 9289 | |
| 9290 | clearAnimation(); |
| 9291 | animating = false; |
| 9292 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 9293 | moveInputMethodWindowsIfNeededLocked(true); |
| 9294 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9295 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9296 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9297 | TAG, "Animation done in " + this |
| 9298 | + ": reportedVisible=" + reportedVisible); |
| 9299 | |
| 9300 | transformation.clear(); |
| 9301 | if (animLayerAdjustment != 0) { |
| 9302 | animLayerAdjustment = 0; |
| 9303 | updateLayers(); |
| 9304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9306 | final int N = windows.size(); |
| 9307 | for (int i=0; i<N; i++) { |
| 9308 | ((WindowState)windows.get(i)).finishExit(); |
| 9309 | } |
| 9310 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9312 | return false; |
| 9313 | } |
| 9314 | |
| 9315 | void updateReportedVisibilityLocked() { |
| 9316 | if (appToken == null) { |
| 9317 | return; |
| 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 | int numInteresting = 0; |
| 9321 | int numVisible = 0; |
| 9322 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9323 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9324 | 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] | 9325 | final int N = allAppWindows.size(); |
| 9326 | for (int i=0; i<N; i++) { |
| 9327 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 9328 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 9329 | || win.mViewVisibility != View.VISIBLE |
| 9330 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9331 | continue; |
| 9332 | } |
| 9333 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9334 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9335 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9336 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9337 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9338 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9339 | + " pv=" + win.mPolicyVisibility |
| 9340 | + " dp=" + win.mDrawPending |
| 9341 | + " cdp=" + win.mCommitDrawPending |
| 9342 | + " ah=" + win.mAttachedHidden |
| 9343 | + " th=" |
| 9344 | + (win.mAppToken != null |
| 9345 | ? win.mAppToken.hiddenRequested : false) |
| 9346 | + " a=" + win.mAnimating); |
| 9347 | } |
| 9348 | } |
| 9349 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9350 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9351 | if (!win.isAnimating()) { |
| 9352 | numVisible++; |
| 9353 | } |
| 9354 | nowGone = false; |
| 9355 | } else if (win.isAnimating()) { |
| 9356 | nowGone = false; |
| 9357 | } |
| 9358 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9359 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9360 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9361 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9362 | + numInteresting + " visible=" + numVisible); |
| 9363 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9364 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9365 | TAG, "Visibility changed in " + this |
| 9366 | + ": vis=" + nowVisible); |
| 9367 | reportedVisible = nowVisible; |
| 9368 | Message m = mH.obtainMessage( |
| 9369 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 9370 | nowVisible ? 1 : 0, |
| 9371 | nowGone ? 1 : 0, |
| 9372 | this); |
| 9373 | mH.sendMessage(m); |
| 9374 | } |
| 9375 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9376 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9377 | WindowState findMainWindow() { |
| 9378 | int j = windows.size(); |
| 9379 | while (j > 0) { |
| 9380 | j--; |
| 9381 | WindowState win = windows.get(j); |
| 9382 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 9383 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 9384 | return win; |
| 9385 | } |
| 9386 | } |
| 9387 | return null; |
| 9388 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9390 | void dump(PrintWriter pw, String prefix) { |
| 9391 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9392 | if (appToken != null) { |
| 9393 | pw.print(prefix); pw.println("app=true"); |
| 9394 | } |
| 9395 | if (allAppWindows.size() > 0) { |
| 9396 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 9397 | } |
| 9398 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9399 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9400 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 9401 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 9402 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 9403 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 9404 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 9405 | if (paused || freezingScreen) { |
| 9406 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 9407 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 9408 | } |
| 9409 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 9410 | || inPendingTransaction || allDrawn) { |
| 9411 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 9412 | pw.print(numInterestingWindows); |
| 9413 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 9414 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 9415 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 9416 | } |
| 9417 | if (animating || animation != null) { |
| 9418 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 9419 | pw.print(" animation="); pw.println(animation); |
| 9420 | } |
| 9421 | if (animLayerAdjustment != 0) { |
| 9422 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 9423 | } |
| 9424 | if (hasTransformation) { |
| 9425 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 9426 | pw.print(" transformation="); transformation.printShortString(pw); |
| 9427 | pw.println(); |
| 9428 | } |
| 9429 | if (startingData != null || removed || firstWindowDrawn) { |
| 9430 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 9431 | pw.print(" removed="); pw.print(removed); |
| 9432 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 9433 | } |
| 9434 | if (startingWindow != null || startingView != null |
| 9435 | || startingDisplayed || startingMoved) { |
| 9436 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 9437 | pw.print(" startingView="); pw.print(startingView); |
| 9438 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 9439 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 9440 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9441 | } |
| 9442 | |
| 9443 | @Override |
| 9444 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9445 | if (stringName == null) { |
| 9446 | StringBuilder sb = new StringBuilder(); |
| 9447 | sb.append("AppWindowToken{"); |
| 9448 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 9449 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 9450 | stringName = sb.toString(); |
| 9451 | } |
| 9452 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9453 | } |
| 9454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9456 | // ------------------------------------------------------------- |
| 9457 | // DummyAnimation |
| 9458 | // ------------------------------------------------------------- |
| 9459 | |
| 9460 | // This is an animation that does nothing: it just immediately finishes |
| 9461 | // itself every time it is called. It is used as a stub animation in cases |
| 9462 | // where we want to synchronize multiple things that may be animating. |
| 9463 | static final class DummyAnimation extends Animation { |
| 9464 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 9465 | return false; |
| 9466 | } |
| 9467 | } |
| 9468 | static final Animation sDummyAnimation = new DummyAnimation(); |
| 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 | // Async Handler |
| 9472 | // ------------------------------------------------------------- |
| 9473 | |
| 9474 | static final class StartingData { |
| 9475 | final String pkg; |
| 9476 | final int theme; |
| 9477 | final CharSequence nonLocalizedLabel; |
| 9478 | final int labelRes; |
| 9479 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9480 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9481 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 9482 | int _labelRes, int _icon) { |
| 9483 | pkg = _pkg; |
| 9484 | theme = _theme; |
| 9485 | nonLocalizedLabel = _nonLocalizedLabel; |
| 9486 | labelRes = _labelRes; |
| 9487 | icon = _icon; |
| 9488 | } |
| 9489 | } |
| 9490 | |
| 9491 | private final class H extends Handler { |
| 9492 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 9493 | public static final int REPORT_LOSING_FOCUS = 3; |
| 9494 | public static final int ANIMATE = 4; |
| 9495 | public static final int ADD_STARTING = 5; |
| 9496 | public static final int REMOVE_STARTING = 6; |
| 9497 | public static final int FINISHED_STARTING = 7; |
| 9498 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9499 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 9500 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 9501 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 9502 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 9503 | public static final int FORCE_GC = 15; |
| 9504 | public static final int ENABLE_SCREEN = 16; |
| 9505 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9506 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9508 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9510 | public H() { |
| 9511 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9512 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9513 | @Override |
| 9514 | public void handleMessage(Message msg) { |
| 9515 | switch (msg.what) { |
| 9516 | case REPORT_FOCUS_CHANGE: { |
| 9517 | WindowState lastFocus; |
| 9518 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9519 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9520 | synchronized(mWindowMap) { |
| 9521 | lastFocus = mLastFocus; |
| 9522 | newFocus = mCurrentFocus; |
| 9523 | if (lastFocus == newFocus) { |
| 9524 | // Focus is not changing, so nothing to do. |
| 9525 | return; |
| 9526 | } |
| 9527 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9528 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9529 | // + " to " + newFocus); |
| 9530 | if (newFocus != null && lastFocus != null |
| 9531 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9532 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9533 | mLosingFocus.add(lastFocus); |
| 9534 | lastFocus = null; |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | if (lastFocus != newFocus) { |
| 9539 | //System.out.println("Changing focus from " + lastFocus |
| 9540 | // + " to " + newFocus); |
| 9541 | if (newFocus != null) { |
| 9542 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9543 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9544 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 9545 | } catch (RemoteException e) { |
| 9546 | // Ignore if process has died. |
| 9547 | } |
| 9548 | } |
| 9549 | |
| 9550 | if (lastFocus != null) { |
| 9551 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9552 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9553 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 9554 | } catch (RemoteException e) { |
| 9555 | // Ignore if process has died. |
| 9556 | } |
| 9557 | } |
| 9558 | } |
| 9559 | } break; |
| 9560 | |
| 9561 | case REPORT_LOSING_FOCUS: { |
| 9562 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9563 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9564 | synchronized(mWindowMap) { |
| 9565 | losers = mLosingFocus; |
| 9566 | mLosingFocus = new ArrayList<WindowState>(); |
| 9567 | } |
| 9568 | |
| 9569 | final int N = losers.size(); |
| 9570 | for (int i=0; i<N; i++) { |
| 9571 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9572 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9573 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 9574 | } catch (RemoteException e) { |
| 9575 | // Ignore if process has died. |
| 9576 | } |
| 9577 | } |
| 9578 | } break; |
| 9579 | |
| 9580 | case ANIMATE: { |
| 9581 | synchronized(mWindowMap) { |
| 9582 | mAnimationPending = false; |
| 9583 | performLayoutAndPlaceSurfacesLocked(); |
| 9584 | } |
| 9585 | } break; |
| 9586 | |
| 9587 | case ADD_STARTING: { |
| 9588 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9589 | final StartingData sd = wtoken.startingData; |
| 9590 | |
| 9591 | if (sd == null) { |
| 9592 | // Animation has been canceled... do nothing. |
| 9593 | return; |
| 9594 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9595 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9596 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9597 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | View view = null; |
| 9600 | try { |
| 9601 | view = mPolicy.addStartingWindow( |
| 9602 | wtoken.token, sd.pkg, |
| 9603 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 9604 | sd.icon); |
| 9605 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9606 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9607 | } |
| 9608 | |
| 9609 | if (view != null) { |
| 9610 | boolean abort = false; |
| 9611 | |
| 9612 | synchronized(mWindowMap) { |
| 9613 | if (wtoken.removed || wtoken.startingData == null) { |
| 9614 | // If the window was successfully added, then |
| 9615 | // we need to remove it. |
| 9616 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9617 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9618 | "Aborted starting " + wtoken |
| 9619 | + ": removed=" + wtoken.removed |
| 9620 | + " startingData=" + wtoken.startingData); |
| 9621 | wtoken.startingWindow = null; |
| 9622 | wtoken.startingData = null; |
| 9623 | abort = true; |
| 9624 | } |
| 9625 | } else { |
| 9626 | wtoken.startingView = view; |
| 9627 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9628 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9629 | "Added starting " + wtoken |
| 9630 | + ": startingWindow=" |
| 9631 | + wtoken.startingWindow + " startingView=" |
| 9632 | + wtoken.startingView); |
| 9633 | } |
| 9634 | |
| 9635 | if (abort) { |
| 9636 | try { |
| 9637 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 9638 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9639 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9640 | } |
| 9641 | } |
| 9642 | } |
| 9643 | } break; |
| 9644 | |
| 9645 | case REMOVE_STARTING: { |
| 9646 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9647 | IBinder token = null; |
| 9648 | View view = null; |
| 9649 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9650 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9651 | + wtoken + ": startingWindow=" |
| 9652 | + wtoken.startingWindow + " startingView=" |
| 9653 | + wtoken.startingView); |
| 9654 | if (wtoken.startingWindow != null) { |
| 9655 | view = wtoken.startingView; |
| 9656 | token = wtoken.token; |
| 9657 | wtoken.startingData = null; |
| 9658 | wtoken.startingView = null; |
| 9659 | wtoken.startingWindow = null; |
| 9660 | } |
| 9661 | } |
| 9662 | if (view != null) { |
| 9663 | try { |
| 9664 | mPolicy.removeStartingWindow(token, view); |
| 9665 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9666 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9667 | } |
| 9668 | } |
| 9669 | } break; |
| 9670 | |
| 9671 | case FINISHED_STARTING: { |
| 9672 | IBinder token = null; |
| 9673 | View view = null; |
| 9674 | while (true) { |
| 9675 | synchronized (mWindowMap) { |
| 9676 | final int N = mFinishedStarting.size(); |
| 9677 | if (N <= 0) { |
| 9678 | break; |
| 9679 | } |
| 9680 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9681 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9682 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9683 | "Finished starting " + wtoken |
| 9684 | + ": startingWindow=" + wtoken.startingWindow |
| 9685 | + " startingView=" + wtoken.startingView); |
| 9686 | |
| 9687 | if (wtoken.startingWindow == null) { |
| 9688 | continue; |
| 9689 | } |
| 9690 | |
| 9691 | view = wtoken.startingView; |
| 9692 | token = wtoken.token; |
| 9693 | wtoken.startingData = null; |
| 9694 | wtoken.startingView = null; |
| 9695 | wtoken.startingWindow = null; |
| 9696 | } |
| 9697 | |
| 9698 | try { |
| 9699 | mPolicy.removeStartingWindow(token, view); |
| 9700 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9701 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9702 | } |
| 9703 | } |
| 9704 | } break; |
| 9705 | |
| 9706 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9707 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9708 | |
| 9709 | boolean nowVisible = msg.arg1 != 0; |
| 9710 | boolean nowGone = msg.arg2 != 0; |
| 9711 | |
| 9712 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9713 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9714 | TAG, "Reporting visible in " + wtoken |
| 9715 | + " visible=" + nowVisible |
| 9716 | + " gone=" + nowGone); |
| 9717 | if (nowVisible) { |
| 9718 | wtoken.appToken.windowsVisible(); |
| 9719 | } else { |
| 9720 | wtoken.appToken.windowsGone(); |
| 9721 | } |
| 9722 | } catch (RemoteException ex) { |
| 9723 | } |
| 9724 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9725 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9726 | case WINDOW_FREEZE_TIMEOUT: { |
| 9727 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9728 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9729 | int i = mWindows.size(); |
| 9730 | while (i > 0) { |
| 9731 | i--; |
| 9732 | WindowState w = (WindowState)mWindows.get(i); |
| 9733 | if (w.mOrientationChanging) { |
| 9734 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9735 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9736 | } |
| 9737 | } |
| 9738 | performLayoutAndPlaceSurfacesLocked(); |
| 9739 | } |
| 9740 | break; |
| 9741 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9743 | case HOLD_SCREEN_CHANGED: { |
| 9744 | Session oldHold; |
| 9745 | Session newHold; |
| 9746 | synchronized (mWindowMap) { |
| 9747 | oldHold = mLastReportedHold; |
| 9748 | newHold = (Session)msg.obj; |
| 9749 | mLastReportedHold = newHold; |
| 9750 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9752 | if (oldHold != newHold) { |
| 9753 | try { |
| 9754 | if (oldHold != null) { |
| 9755 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 9756 | "window", |
| 9757 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9758 | } |
| 9759 | if (newHold != null) { |
| 9760 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 9761 | "window", |
| 9762 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9763 | } |
| 9764 | } catch (RemoteException e) { |
| 9765 | } |
| 9766 | } |
| 9767 | break; |
| 9768 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9769 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9770 | case APP_TRANSITION_TIMEOUT: { |
| 9771 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9772 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9773 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9774 | "*** APP TRANSITION TIMEOUT"); |
| 9775 | mAppTransitionReady = true; |
| 9776 | mAppTransitionTimeout = true; |
| 9777 | performLayoutAndPlaceSurfacesLocked(); |
| 9778 | } |
| 9779 | } |
| 9780 | break; |
| 9781 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9782 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9783 | case PERSIST_ANIMATION_SCALE: { |
| 9784 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9785 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9786 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9787 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9788 | break; |
| 9789 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9791 | case FORCE_GC: { |
| 9792 | synchronized(mWindowMap) { |
| 9793 | if (mAnimationPending) { |
| 9794 | // If we are animating, don't do the gc now but |
| 9795 | // delay a bit so we don't interrupt the animation. |
| 9796 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9797 | 2000); |
| 9798 | return; |
| 9799 | } |
| 9800 | // If we are currently rotating the display, it will |
| 9801 | // schedule a new message when done. |
| 9802 | if (mDisplayFrozen) { |
| 9803 | return; |
| 9804 | } |
| 9805 | mFreezeGcPending = 0; |
| 9806 | } |
| 9807 | Runtime.getRuntime().gc(); |
| 9808 | break; |
| 9809 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9811 | case ENABLE_SCREEN: { |
| 9812 | performEnableScreen(); |
| 9813 | break; |
| 9814 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9815 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9816 | case APP_FREEZE_TIMEOUT: { |
| 9817 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9818 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9819 | int i = mAppTokens.size(); |
| 9820 | while (i > 0) { |
| 9821 | i--; |
| 9822 | AppWindowToken tok = mAppTokens.get(i); |
| 9823 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9824 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9826 | } |
| 9827 | } |
| 9828 | } |
| 9829 | break; |
| 9830 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9831 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9832 | case SEND_NEW_CONFIGURATION: { |
| 9833 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9834 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9835 | break; |
| 9836 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9838 | } |
| 9839 | } |
| 9840 | } |
| 9841 | |
| 9842 | // ------------------------------------------------------------- |
| 9843 | // IWindowManager API |
| 9844 | // ------------------------------------------------------------- |
| 9845 | |
| 9846 | public IWindowSession openSession(IInputMethodClient client, |
| 9847 | IInputContext inputContext) { |
| 9848 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9849 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9850 | Session session = new Session(client, inputContext); |
| 9851 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9852 | } |
| 9853 | |
| 9854 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9855 | synchronized (mWindowMap) { |
| 9856 | // The focus for the client is the window immediately below |
| 9857 | // where we would place the input method window. |
| 9858 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9859 | WindowState imFocus; |
| 9860 | if (idx > 0) { |
| 9861 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9862 | if (imFocus != null) { |
| 9863 | if (imFocus.mSession.mClient != null && |
| 9864 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9865 | return true; |
| 9866 | } |
| 9867 | } |
| 9868 | } |
| 9869 | } |
| 9870 | return false; |
| 9871 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9872 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9873 | // ------------------------------------------------------------- |
| 9874 | // Internals |
| 9875 | // ------------------------------------------------------------- |
| 9876 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9877 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9878 | boolean throwOnError) { |
| 9879 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9880 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9881 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9882 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9883 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9884 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9885 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | TAG, "Looking up client " + client + ": " + win); |
| 9887 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9888 | RuntimeException ex = new IllegalArgumentException( |
| 9889 | "Requested window " + client + " does not exist"); |
| 9890 | if (throwOnError) { |
| 9891 | throw ex; |
| 9892 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9893 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9894 | return null; |
| 9895 | } |
| 9896 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9897 | RuntimeException ex = new IllegalArgumentException( |
| 9898 | "Requested window " + client + " is in session " + |
| 9899 | win.mSession + ", not " + session); |
| 9900 | if (throwOnError) { |
| 9901 | throw ex; |
| 9902 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9903 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9904 | return null; |
| 9905 | } |
| 9906 | |
| 9907 | return win; |
| 9908 | } |
| 9909 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9910 | final void rebuildAppWindowListLocked() { |
| 9911 | int NW = mWindows.size(); |
| 9912 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9913 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9914 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9915 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9916 | // First remove all existing app windows. |
| 9917 | i=0; |
| 9918 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9919 | WindowState w = (WindowState)mWindows.get(i); |
| 9920 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9921 | WindowState win = (WindowState)mWindows.remove(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9922 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9923 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9924 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9925 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9926 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9927 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9928 | && lastWallpaper == i-1) { |
| 9929 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9930 | } |
| 9931 | i++; |
| 9932 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9933 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9934 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9935 | // so skip them before adding app tokens. |
| 9936 | lastWallpaper++; |
| 9937 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9938 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9939 | // First add all of the exiting app tokens... these are no longer |
| 9940 | // in the main app list, but still have windows shown. We put them |
| 9941 | // in the back because now that the animation is over we no longer |
| 9942 | // will care about them. |
| 9943 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9944 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9945 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9946 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9947 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9948 | // And add in the still active app tokens in Z order. |
| 9949 | NT = mAppTokens.size(); |
| 9950 | for (int j=0; j<NT; j++) { |
| 9951 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9952 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9953 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9954 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9955 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9956 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9957 | + " windows but added " + i); |
| 9958 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9959 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9960 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9961 | private final void assignLayersLocked() { |
| 9962 | int N = mWindows.size(); |
| 9963 | int curBaseLayer = 0; |
| 9964 | int curLayer = 0; |
| 9965 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9966 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | for (i=0; i<N; i++) { |
| 9968 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9969 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9970 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9971 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9972 | w.mLayer = curLayer; |
| 9973 | } else { |
| 9974 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9975 | w.mLayer = curLayer; |
| 9976 | } |
| 9977 | if (w.mTargetAppToken != null) { |
| 9978 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9979 | } else if (w.mAppToken != null) { |
| 9980 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9981 | } else { |
| 9982 | w.mAnimLayer = w.mLayer; |
| 9983 | } |
| 9984 | if (w.mIsImWindow) { |
| 9985 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9986 | } else if (w.mIsWallpaper) { |
| 9987 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9988 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9989 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9990 | + w.mAnimLayer); |
| 9991 | //System.out.println( |
| 9992 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9993 | } |
| 9994 | } |
| 9995 | |
| 9996 | private boolean mInLayout = false; |
| 9997 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9998 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9999 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10000 | throw new RuntimeException("Recursive call!"); |
| 10001 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10002 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10003 | return; |
| 10004 | } |
| 10005 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10006 | if (mWaitingForConfig) { |
| 10007 | // Our configuration has changed (most likely rotation), but we |
| 10008 | // don't yet have the complete configuration to report to |
| 10009 | // applications. Don't do any window layout until we have it. |
| 10010 | return; |
| 10011 | } |
| 10012 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10013 | boolean recoveringMemory = false; |
| 10014 | if (mForceRemoves != null) { |
| 10015 | recoveringMemory = true; |
| 10016 | // Wait a little it for things to settle down, and off we go. |
| 10017 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 10018 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10019 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10020 | removeWindowInnerLocked(ws.mSession, ws); |
| 10021 | } |
| 10022 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10023 | 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] | 10024 | Object tmp = new Object(); |
| 10025 | synchronized (tmp) { |
| 10026 | try { |
| 10027 | tmp.wait(250); |
| 10028 | } catch (InterruptedException e) { |
| 10029 | } |
| 10030 | } |
| 10031 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10032 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10033 | mInLayout = true; |
| 10034 | try { |
| 10035 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10037 | int i = mPendingRemove.size()-1; |
| 10038 | if (i >= 0) { |
| 10039 | while (i >= 0) { |
| 10040 | WindowState w = mPendingRemove.get(i); |
| 10041 | removeWindowInnerLocked(w.mSession, w); |
| 10042 | i--; |
| 10043 | } |
| 10044 | mPendingRemove.clear(); |
| 10045 | |
| 10046 | mInLayout = false; |
| 10047 | assignLayersLocked(); |
| 10048 | mLayoutNeeded = true; |
| 10049 | performLayoutAndPlaceSurfacesLocked(); |
| 10050 | |
| 10051 | } else { |
| 10052 | mInLayout = false; |
| 10053 | if (mLayoutNeeded) { |
| 10054 | requestAnimationLocked(0); |
| 10055 | } |
| 10056 | } |
| 10057 | } catch (RuntimeException e) { |
| 10058 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10059 | 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] | 10060 | } |
| 10061 | } |
| 10062 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10063 | private final int performLayoutLockedInner() { |
| 10064 | if (!mLayoutNeeded) { |
| 10065 | return 0; |
| 10066 | } |
| 10067 | |
| 10068 | mLayoutNeeded = false; |
| 10069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10070 | final int dw = mDisplay.getWidth(); |
| 10071 | final int dh = mDisplay.getHeight(); |
| 10072 | |
| 10073 | final int N = mWindows.size(); |
| 10074 | int i; |
| 10075 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10076 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 10077 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 10078 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10079 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10080 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10081 | int seq = mLayoutSeq+1; |
| 10082 | if (seq < 0) seq = 0; |
| 10083 | mLayoutSeq = seq; |
| 10084 | |
| 10085 | // First perform layout of any root windows (not attached |
| 10086 | // to another window). |
| 10087 | int topAttached = -1; |
| 10088 | for (i = N-1; i >= 0; i--) { |
| 10089 | WindowState win = (WindowState) mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10090 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10091 | // Don't do layout of a window if it is not visible, or |
| 10092 | // soon won't be visible, to avoid wasting time and funky |
| 10093 | // changes while a window is animating away. |
| 10094 | final AppWindowToken atoken = win.mAppToken; |
| 10095 | final boolean gone = win.mViewVisibility == View.GONE |
| 10096 | || !win.mRelayoutCalled |
| 10097 | || win.mRootToken.hidden |
| 10098 | || (atoken != null && atoken.hiddenRequested) |
| 10099 | || win.mAttachedHidden |
| 10100 | || win.mExiting || win.mDestroying; |
| 10101 | |
| 10102 | if (!win.mLayoutAttached) { |
| 10103 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 10104 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 10105 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 10106 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 10107 | + win.mViewVisibility + " mRelayoutCalled=" |
| 10108 | + win.mRelayoutCalled + " hidden=" |
| 10109 | + win.mRootToken.hidden + " hiddenRequested=" |
| 10110 | + (atoken != null && atoken.hiddenRequested) |
| 10111 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 10112 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10113 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10114 | // If this view is GONE, then skip it -- keep the current |
| 10115 | // frame, and let the caller know so they can ignore it |
| 10116 | // if they want. (We do the normal layout for INVISIBLE |
| 10117 | // windows, since that means "perform layout as normal, |
| 10118 | // just don't display"). |
| 10119 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10120 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10121 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 10122 | win.mLayoutSeq = seq; |
| 10123 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 10124 | + win.mFrame + " mContainingFrame=" |
| 10125 | + win.mContainingFrame + " mDisplayFrame=" |
| 10126 | + win.mDisplayFrame); |
| 10127 | } else { |
| 10128 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10129 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10130 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10131 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10132 | |
| 10133 | // Now perform layout of attached windows, which usually |
| 10134 | // depend on the position of the window they are attached to. |
| 10135 | // XXX does not deal with windows that are attached to windows |
| 10136 | // that are themselves attached. |
| 10137 | for (i = topAttached; i >= 0; i--) { |
| 10138 | WindowState win = (WindowState) mWindows.get(i); |
| 10139 | |
| 10140 | // If this view is GONE, then skip it -- keep the current |
| 10141 | // frame, and let the caller know so they can ignore it |
| 10142 | // if they want. (We do the normal layout for INVISIBLE |
| 10143 | // windows, since that means "perform layout as normal, |
| 10144 | // just don't display"). |
| 10145 | if (win.mLayoutAttached) { |
| 10146 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 10147 | + " mHaveFrame=" + win.mHaveFrame |
| 10148 | + " mViewVisibility=" + win.mViewVisibility |
| 10149 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 10150 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 10151 | || !win.mHaveFrame) { |
| 10152 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 10153 | win.mLayoutSeq = seq; |
| 10154 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 10155 | + win.mFrame + " mContainingFrame=" |
| 10156 | + win.mContainingFrame + " mDisplayFrame=" |
| 10157 | + win.mDisplayFrame); |
| 10158 | } |
| 10159 | } |
| 10160 | } |
| 10161 | |
| 10162 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10163 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10164 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10165 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 10166 | boolean recoveringMemory) { |
| 10167 | final long currentTime = SystemClock.uptimeMillis(); |
| 10168 | final int dw = mDisplay.getWidth(); |
| 10169 | final int dh = mDisplay.getHeight(); |
| 10170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10171 | int i; |
| 10172 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10173 | if (mFocusMayChange) { |
| 10174 | mFocusMayChange = false; |
| 10175 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 10176 | } |
| 10177 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10178 | if (mFxSession == null) { |
| 10179 | mFxSession = new SurfaceSession(); |
| 10180 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10181 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10182 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10183 | |
| 10184 | // Initialize state of exiting tokens. |
| 10185 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10186 | mExitingTokens.get(i).hasVisible = false; |
| 10187 | } |
| 10188 | |
| 10189 | // Initialize state of exiting applications. |
| 10190 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10191 | mExitingAppTokens.get(i).hasVisible = false; |
| 10192 | } |
| 10193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10194 | boolean orientationChangeComplete = true; |
| 10195 | Session holdScreen = null; |
| 10196 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10197 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10198 | boolean focusDisplayed = false; |
| 10199 | boolean animating = false; |
| 10200 | |
| 10201 | Surface.openTransaction(); |
| 10202 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10203 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10204 | int repeats = 0; |
| 10205 | int changes = 0; |
| 10206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10207 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10208 | repeats++; |
| 10209 | if (repeats > 6) { |
| 10210 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 10211 | mLayoutNeeded = false; |
| 10212 | break; |
| 10213 | } |
| 10214 | |
| 10215 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 10216 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 10217 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 10218 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 10219 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 10220 | assignLayersLocked(); |
| 10221 | mLayoutNeeded = true; |
| 10222 | } |
| 10223 | } |
| 10224 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 10225 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 10226 | if (updateOrientationFromAppTokensLocked()) { |
| 10227 | mLayoutNeeded = true; |
| 10228 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10229 | } |
| 10230 | } |
| 10231 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 10232 | mLayoutNeeded = true; |
| 10233 | } |
| 10234 | } |
| 10235 | |
| 10236 | // FIRST LOOP: Perform a layout, if needed. |
| 10237 | if (repeats < 4) { |
| 10238 | changes = performLayoutLockedInner(); |
| 10239 | if (changes != 0) { |
| 10240 | continue; |
| 10241 | } |
| 10242 | } else { |
| 10243 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 10244 | changes = 0; |
| 10245 | } |
| 10246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10247 | final int transactionSequence = ++mTransactionSequence; |
| 10248 | |
| 10249 | // Update animations of all applications, including those |
| 10250 | // associated with exiting/removed apps |
| 10251 | boolean tokensAnimating = false; |
| 10252 | final int NAT = mAppTokens.size(); |
| 10253 | for (i=0; i<NAT; i++) { |
| 10254 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 10255 | tokensAnimating = true; |
| 10256 | } |
| 10257 | } |
| 10258 | final int NEAT = mExitingAppTokens.size(); |
| 10259 | for (i=0; i<NEAT; i++) { |
| 10260 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 10261 | tokensAnimating = true; |
| 10262 | } |
| 10263 | } |
| 10264 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10265 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 10266 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10267 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10268 | + transactionSequence + " tokensAnimating=" |
| 10269 | + tokensAnimating); |
| 10270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10271 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10272 | |
| 10273 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10274 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10275 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10276 | |
| 10277 | mPolicy.beginAnimationLw(dw, dh); |
| 10278 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10279 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10280 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10281 | for (i=N-1; i>=0; i--) { |
| 10282 | WindowState w = (WindowState)mWindows.get(i); |
| 10283 | |
| 10284 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10285 | |
| 10286 | if (w.mSurface != null) { |
| 10287 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10288 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 10289 | if ((w.mAttrs.flags |
| 10290 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10291 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10292 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10293 | wallpaperMayChange = true; |
| 10294 | } |
| 10295 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10296 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 10297 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10298 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 10299 | animating = true; |
| 10300 | //w.dump(" "); |
| 10301 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 10302 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 10303 | wallpaperMayChange = true; |
| 10304 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10305 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10306 | if (mPolicy.doesForceHide(w, attrs)) { |
| 10307 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10308 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10309 | "Animation done that could impact force hide: " |
| 10310 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10311 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10312 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10313 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 10314 | forceHiding = true; |
| 10315 | } |
| 10316 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10317 | boolean changed; |
| 10318 | if (forceHiding) { |
| 10319 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10320 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 10321 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10322 | } else { |
| 10323 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10324 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 10325 | "Now policy shown: " + w); |
| 10326 | if (changed) { |
| 10327 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10328 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10329 | // Assume we will need to animate. If |
| 10330 | // we don't (because the wallpaper will |
| 10331 | // stay with the lock screen), then we will |
| 10332 | // clean up later. |
| 10333 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 10334 | if (a != null) { |
| 10335 | w.setAnimation(a); |
| 10336 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10337 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 10338 | if (mCurrentFocus == null || |
| 10339 | mCurrentFocus.mLayer < w.mLayer) { |
| 10340 | // We are showing on to of the current |
| 10341 | // focus, so re-evaluate focus to make |
| 10342 | // sure it is correct. |
| 10343 | mFocusMayChange = true; |
| 10344 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10345 | } |
| 10346 | } |
| 10347 | if (changed && (attrs.flags |
| 10348 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 10349 | wallpaperMayChange = true; |
| 10350 | } |
| 10351 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10352 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10353 | mPolicy.animatingWindowLw(w, attrs); |
| 10354 | } |
| 10355 | |
| 10356 | final AppWindowToken atoken = w.mAppToken; |
| 10357 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 10358 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 10359 | atoken.lastTransactionSequence = transactionSequence; |
| 10360 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 10361 | atoken.startingDisplayed = false; |
| 10362 | } |
| 10363 | if ((w.isOnScreen() || w.mAttrs.type |
| 10364 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 10365 | && !w.mExiting && !w.mDestroying) { |
| 10366 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10367 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10368 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10369 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10370 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10371 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10372 | + " pv=" + w.mPolicyVisibility |
| 10373 | + " dp=" + w.mDrawPending |
| 10374 | + " cdp=" + w.mCommitDrawPending |
| 10375 | + " ah=" + w.mAttachedHidden |
| 10376 | + " th=" + atoken.hiddenRequested |
| 10377 | + " a=" + w.mAnimating); |
| 10378 | } |
| 10379 | } |
| 10380 | if (w != atoken.startingWindow) { |
| 10381 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 10382 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10383 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10384 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10385 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10386 | "tokenMayBeDrawn: " + atoken |
| 10387 | + " freezingScreen=" + atoken.freezingScreen |
| 10388 | + " mAppFreezing=" + w.mAppFreezing); |
| 10389 | tokenMayBeDrawn = true; |
| 10390 | } |
| 10391 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10392 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10393 | atoken.startingDisplayed = true; |
| 10394 | } |
| 10395 | } |
| 10396 | } else if (w.mReadyToShow) { |
| 10397 | w.performShowLocked(); |
| 10398 | } |
| 10399 | } |
| 10400 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10401 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10402 | |
| 10403 | if (tokenMayBeDrawn) { |
| 10404 | // See if any windows have been drawn, so they (and others |
| 10405 | // associated with them) can now be shown. |
| 10406 | final int NT = mTokenList.size(); |
| 10407 | for (i=0; i<NT; i++) { |
| 10408 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 10409 | if (wtoken == null) { |
| 10410 | continue; |
| 10411 | } |
| 10412 | if (wtoken.freezingScreen) { |
| 10413 | int numInteresting = wtoken.numInterestingWindows; |
| 10414 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10415 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10416 | "allDrawn: " + wtoken |
| 10417 | + " interesting=" + numInteresting |
| 10418 | + " drawn=" + wtoken.numDrawnWindows); |
| 10419 | wtoken.showAllWindowsLocked(); |
| 10420 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 10421 | orientationChangeComplete = true; |
| 10422 | } |
| 10423 | } else if (!wtoken.allDrawn) { |
| 10424 | int numInteresting = wtoken.numInterestingWindows; |
| 10425 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10426 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10427 | "allDrawn: " + wtoken |
| 10428 | + " interesting=" + numInteresting |
| 10429 | + " drawn=" + wtoken.numDrawnWindows); |
| 10430 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10431 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10432 | |
| 10433 | // We can now show all of the drawn windows! |
| 10434 | if (!mOpeningApps.contains(wtoken)) { |
| 10435 | wtoken.showAllWindowsLocked(); |
| 10436 | } |
| 10437 | } |
| 10438 | } |
| 10439 | } |
| 10440 | } |
| 10441 | |
| 10442 | // If we are ready to perform an app transition, check through |
| 10443 | // all of the app tokens to be shown and see if they are ready |
| 10444 | // to go. |
| 10445 | if (mAppTransitionReady) { |
| 10446 | int NN = mOpeningApps.size(); |
| 10447 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10448 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10449 | "Checking " + NN + " opening apps (frozen=" |
| 10450 | + mDisplayFrozen + " timeout=" |
| 10451 | + mAppTransitionTimeout + ")..."); |
| 10452 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 10453 | // If the display isn't frozen, wait to do anything until |
| 10454 | // all of the apps are ready. Otherwise just go because |
| 10455 | // we'll unfreeze the display when everyone is ready. |
| 10456 | for (i=0; i<NN && goodToGo; i++) { |
| 10457 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10458 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10459 | "Check opening app" + wtoken + ": allDrawn=" |
| 10460 | + wtoken.allDrawn + " startingDisplayed=" |
| 10461 | + wtoken.startingDisplayed); |
| 10462 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 10463 | && !wtoken.startingMoved) { |
| 10464 | goodToGo = false; |
| 10465 | } |
| 10466 | } |
| 10467 | } |
| 10468 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10469 | 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] | 10470 | int transit = mNextAppTransition; |
| 10471 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10472 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10473 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10474 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10475 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10476 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10477 | mAppTransitionTimeout = false; |
| 10478 | mStartingIconInTransition = false; |
| 10479 | mSkipAppTransitionAnimation = false; |
| 10480 | |
| 10481 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 10482 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10483 | // If there are applications waiting to come to the |
| 10484 | // top of the stack, now is the time to move their windows. |
| 10485 | // (Note that we don't do apps going to the bottom |
| 10486 | // here -- we want to keep their windows in the old |
| 10487 | // Z-order until the animation completes.) |
| 10488 | if (mToTopApps.size() > 0) { |
| 10489 | NN = mAppTokens.size(); |
| 10490 | for (i=0; i<NN; i++) { |
| 10491 | AppWindowToken wtoken = mAppTokens.get(i); |
| 10492 | if (wtoken.sendingToTop) { |
| 10493 | wtoken.sendingToTop = false; |
| 10494 | moveAppWindowsLocked(wtoken, NN, false); |
| 10495 | } |
| 10496 | } |
| 10497 | mToTopApps.clear(); |
| 10498 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10499 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10500 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10501 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10502 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10503 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10504 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10505 | // The top-most window will supply the layout params, |
| 10506 | // and we will determine it below. |
| 10507 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10508 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10509 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10510 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10511 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10512 | "New wallpaper target=" + mWallpaperTarget |
| 10513 | + ", lower target=" + mLowerWallpaperTarget |
| 10514 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10515 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10516 | // Do a first pass through the tokens for two |
| 10517 | // things: |
| 10518 | // (1) Determine if both the closing and opening |
| 10519 | // app token sets are wallpaper targets, in which |
| 10520 | // case special animations are needed |
| 10521 | // (since the wallpaper needs to stay static |
| 10522 | // behind them). |
| 10523 | // (2) Find the layout params of the top-most |
| 10524 | // application window in the tokens, which is |
| 10525 | // what will control the animation theme. |
| 10526 | final int NC = mClosingApps.size(); |
| 10527 | NN = NC + mOpeningApps.size(); |
| 10528 | for (i=0; i<NN; i++) { |
| 10529 | AppWindowToken wtoken; |
| 10530 | int mode; |
| 10531 | if (i < NC) { |
| 10532 | wtoken = mClosingApps.get(i); |
| 10533 | mode = 1; |
| 10534 | } else { |
| 10535 | wtoken = mOpeningApps.get(i-NC); |
| 10536 | mode = 2; |
| 10537 | } |
| 10538 | if (mLowerWallpaperTarget != null) { |
| 10539 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 10540 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 10541 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10542 | } |
| 10543 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10544 | if (wtoken.appFullscreen) { |
| 10545 | WindowState ws = wtoken.findMainWindow(); |
| 10546 | if (ws != null) { |
| 10547 | // If this is a compatibility mode |
| 10548 | // window, we will always use its anim. |
| 10549 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 10550 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10551 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10552 | bestAnimLayer = Integer.MAX_VALUE; |
| 10553 | } else if (ws.mLayer > bestAnimLayer) { |
| 10554 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10555 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10556 | bestAnimLayer = ws.mLayer; |
| 10557 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10558 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10559 | } |
| 10560 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10561 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10562 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10563 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10564 | "Wallpaper animation!"); |
| 10565 | switch (transit) { |
| 10566 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10567 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10568 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10569 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10570 | break; |
| 10571 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10572 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10573 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10574 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10575 | break; |
| 10576 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10577 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10578 | "New transit: " + transit); |
| 10579 | } else if (oldWallpaper != null) { |
| 10580 | // We are transitioning from an activity with |
| 10581 | // a wallpaper to one without. |
| 10582 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10583 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10584 | "New transit away from wallpaper: " + transit); |
| 10585 | } else if (mWallpaperTarget != null) { |
| 10586 | // We are transitioning from an activity without |
| 10587 | // a wallpaper to now showing the wallpaper |
| 10588 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10589 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10590 | "New transit into wallpaper: " + transit); |
| 10591 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10592 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10593 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 10594 | mLastEnterAnimToken = animToken; |
| 10595 | mLastEnterAnimParams = animLp; |
| 10596 | } else if (mLastEnterAnimParams != null) { |
| 10597 | animLp = mLastEnterAnimParams; |
| 10598 | mLastEnterAnimToken = null; |
| 10599 | mLastEnterAnimParams = null; |
| 10600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10601 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10602 | // If all closing windows are obscured, then there is |
| 10603 | // no need to do an animation. This is the case, for |
| 10604 | // example, when this transition is being done behind |
| 10605 | // the lock screen. |
| 10606 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10607 | animLp = null; |
| 10608 | } |
| 10609 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10610 | NN = mOpeningApps.size(); |
| 10611 | for (i=0; i<NN; i++) { |
| 10612 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10613 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10614 | "Now opening app" + wtoken); |
| 10615 | wtoken.reportedVisible = false; |
| 10616 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10617 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10618 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10619 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10620 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10621 | wtoken.showAllWindowsLocked(); |
| 10622 | } |
| 10623 | NN = mClosingApps.size(); |
| 10624 | for (i=0; i<NN; i++) { |
| 10625 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10626 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10627 | "Now closing app" + wtoken); |
| 10628 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10629 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10630 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10631 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10632 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10633 | // Force the allDrawn flag, because we want to start |
| 10634 | // this guy's animations regardless of whether it's |
| 10635 | // gotten drawn. |
| 10636 | wtoken.allDrawn = true; |
| 10637 | } |
| 10638 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10639 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10640 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10641 | mOpeningApps.clear(); |
| 10642 | mClosingApps.clear(); |
| 10643 | |
| 10644 | // This has changed the visibility of windows, so perform |
| 10645 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10646 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10647 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10648 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10649 | assignLayersLocked(); |
| 10650 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10651 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10652 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10653 | } |
| 10654 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10655 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10656 | int adjResult = 0; |
| 10657 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10658 | if (!animating && mAppTransitionRunning) { |
| 10659 | // We have finished the animation of an app transition. To do |
| 10660 | // this, we have delayed a lot of operations like showing and |
| 10661 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10662 | // reflects the correct Z-order, but the window list may now |
| 10663 | // be out of sync with it. So here we will just rebuild the |
| 10664 | // entire app window list. Fun! |
| 10665 | mAppTransitionRunning = false; |
| 10666 | // Clear information about apps that were moving. |
| 10667 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10668 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10669 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10670 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10671 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10672 | moveInputMethodWindowsIfNeededLocked(false); |
| 10673 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10674 | // Since the window list has been rebuilt, focus might |
| 10675 | // have to be recomputed since the actual order of windows |
| 10676 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10677 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10678 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10679 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10680 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10681 | // At this point, there was a window with a wallpaper that |
| 10682 | // was force hiding other windows behind it, but now it |
| 10683 | // is going away. This may be simple -- just animate |
| 10684 | // away the wallpaper and its window -- or it may be |
| 10685 | // hard -- the wallpaper now needs to be shown behind |
| 10686 | // something that was hidden. |
| 10687 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10688 | if (mLowerWallpaperTarget != null |
| 10689 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10690 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10691 | "wallpaperForceHiding changed with lower=" |
| 10692 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10693 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10694 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10695 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10696 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10697 | // The lower target has become hidden before we |
| 10698 | // actually started the animation... let's completely |
| 10699 | // re-evaluate everything. |
| 10700 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10701 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10702 | } |
| 10703 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10704 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10705 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10706 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10707 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10708 | + " NEW: " + mWallpaperTarget |
| 10709 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10710 | if (mLowerWallpaperTarget == null) { |
| 10711 | // Whoops, we don't need a special wallpaper animation. |
| 10712 | // Clear them out. |
| 10713 | forceHiding = false; |
| 10714 | for (i=N-1; i>=0; i--) { |
| 10715 | WindowState w = (WindowState)mWindows.get(i); |
| 10716 | if (w.mSurface != null) { |
| 10717 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10718 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10719 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10720 | forceHiding = true; |
| 10721 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10722 | if (!w.mAnimating) { |
| 10723 | // We set the animation above so it |
| 10724 | // is not yet running. |
| 10725 | w.clearAnimation(); |
| 10726 | } |
| 10727 | } |
| 10728 | } |
| 10729 | } |
| 10730 | } |
| 10731 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10732 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10733 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10734 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10735 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10736 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10737 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10738 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10739 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10740 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10741 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10742 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10743 | assignLayersLocked(); |
| 10744 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10745 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10746 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10747 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10748 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10749 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10750 | if (mFocusMayChange) { |
| 10751 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10752 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10753 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10754 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10755 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10756 | } |
| 10757 | |
| 10758 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10759 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10760 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10761 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10762 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10763 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10764 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10765 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10766 | |
| 10767 | // THIRD LOOP: Update the surfaces of all windows. |
| 10768 | |
| 10769 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10770 | |
| 10771 | boolean obscured = false; |
| 10772 | boolean blurring = false; |
| 10773 | boolean dimming = false; |
| 10774 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10775 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10776 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10777 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10778 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10779 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10780 | for (i=N-1; i>=0; i--) { |
| 10781 | WindowState w = (WindowState)mWindows.get(i); |
| 10782 | |
| 10783 | boolean displayed = false; |
| 10784 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10785 | final int attrFlags = attrs.flags; |
| 10786 | |
| 10787 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10788 | // XXX NOTE: The logic here could be improved. We have |
| 10789 | // the decision about whether to resize a window separated |
| 10790 | // from whether to hide the surface. This can cause us to |
| 10791 | // resize a surface even if we are going to hide it. You |
| 10792 | // can see this by (1) holding device in landscape mode on |
| 10793 | // home screen; (2) tapping browser icon (device will rotate |
| 10794 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10795 | // in step 2 but then immediately hidden, causing us to |
| 10796 | // have to resize and then redraw it again in step 3. It |
| 10797 | // would be nice to figure out how to avoid this, but it is |
| 10798 | // difficult because we do need to resize surfaces in some |
| 10799 | // cases while they are hidden such as when first showing a |
| 10800 | // window. |
| 10801 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10802 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10803 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10804 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10805 | + ": new=" + w.mShownFrame + ", old=" |
| 10806 | + w.mLastShownFrame); |
| 10807 | |
| 10808 | boolean resize; |
| 10809 | int width, height; |
| 10810 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 10811 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 10812 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 10813 | // for a scaled surface, we just want to use |
| 10814 | // the requested size. |
| 10815 | width = w.mRequestedWidth; |
| 10816 | height = w.mRequestedHeight; |
| 10817 | w.mLastRequestedWidth = width; |
| 10818 | w.mLastRequestedHeight = height; |
| 10819 | w.mLastShownFrame.set(w.mShownFrame); |
| 10820 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10821 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10822 | "POS " + w.mShownFrame.left |
| 10823 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10824 | w.mSurfaceX = w.mShownFrame.left; |
| 10825 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10826 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10827 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10828 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10829 | if (!recoveringMemory) { |
| 10830 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10831 | } |
| 10832 | } |
| 10833 | } else { |
| 10834 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 10835 | width = w.mShownFrame.width(); |
| 10836 | height = w.mShownFrame.height(); |
| 10837 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10838 | } |
| 10839 | |
| 10840 | if (resize) { |
| 10841 | if (width < 1) width = 1; |
| 10842 | if (height < 1) height = 1; |
| 10843 | if (w.mSurface != null) { |
| 10844 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10845 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10846 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10847 | + w.mShownFrame.top + " SIZE " |
| 10848 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10849 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10850 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10851 | w.mSurfaceW = width; |
| 10852 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10853 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10854 | w.mSurfaceX = w.mShownFrame.left; |
| 10855 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10856 | w.mSurface.setPosition(w.mShownFrame.left, |
| 10857 | w.mShownFrame.top); |
| 10858 | } catch (RuntimeException e) { |
| 10859 | // If something goes wrong with the surface (such |
| 10860 | // as running out of memory), don't take down the |
| 10861 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10862 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10863 | + "size=(" + width + "x" + height |
| 10864 | + "), pos=(" + w.mShownFrame.left |
| 10865 | + "," + w.mShownFrame.top + ")", e); |
| 10866 | if (!recoveringMemory) { |
| 10867 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10868 | } |
| 10869 | } |
| 10870 | } |
| 10871 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10872 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10873 | w.mContentInsetsChanged = |
| 10874 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10875 | w.mVisibleInsetsChanged = |
| 10876 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10877 | boolean configChanged = |
| 10878 | w.mConfiguration != mCurConfiguration |
| 10879 | && (w.mConfiguration == null |
| 10880 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10881 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10882 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10883 | + mCurConfiguration); |
| 10884 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10885 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10886 | + ": configChanged=" + configChanged |
| 10887 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10888 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10889 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10890 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10891 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10892 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10893 | w.mLastFrame.set(w.mFrame); |
| 10894 | w.mLastContentInsets.set(w.mContentInsets); |
| 10895 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10896 | // If the screen is currently frozen, then keep |
| 10897 | // it frozen until this window draws at its new |
| 10898 | // orientation. |
| 10899 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10900 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10901 | "Resizing while display frozen: " + w); |
| 10902 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10903 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10904 | mWindowsFreezingScreen = true; |
| 10905 | // XXX should probably keep timeout from |
| 10906 | // when we first froze the display. |
| 10907 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10908 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10909 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10910 | } |
| 10911 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10912 | // If the orientation is changing, then we need to |
| 10913 | // hold off on unfreezing the display until this |
| 10914 | // window has been redrawn; to do that, we need |
| 10915 | // to go through the process of getting informed |
| 10916 | // by the application when it has finished drawing. |
| 10917 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10918 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10919 | "Orientation start waiting for draw in " |
| 10920 | + w + ", surface " + w.mSurface); |
| 10921 | w.mDrawPending = true; |
| 10922 | w.mCommitDrawPending = false; |
| 10923 | w.mReadyToShow = false; |
| 10924 | if (w.mAppToken != null) { |
| 10925 | w.mAppToken.allDrawn = false; |
| 10926 | } |
| 10927 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10928 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10929 | "Resizing window " + w + " to " + w.mFrame); |
| 10930 | mResizingWindows.add(w); |
| 10931 | } else if (w.mOrientationChanging) { |
| 10932 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10933 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10934 | "Orientation not waiting for draw in " |
| 10935 | + w + ", surface " + w.mSurface); |
| 10936 | w.mOrientationChanging = false; |
| 10937 | } |
| 10938 | } |
| 10939 | } |
| 10940 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10941 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10942 | if (!w.mLastHidden) { |
| 10943 | //dump(); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 10944 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow=" |
| 10945 | + w.mRootToken.waitingToShow + " polvis=" |
| 10946 | + w.mPolicyVisibility + " atthid=" |
| 10947 | + w.mAttachedHidden + " tokhid=" |
| 10948 | + w.mRootToken.hidden + " vis=" |
| 10949 | + w.mViewVisibility); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10950 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10951 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10952 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10953 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10954 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10955 | try { |
| 10956 | w.mSurface.hide(); |
| 10957 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10958 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10959 | } |
| 10960 | } |
| 10961 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 10962 | } |
| 10963 | // If we are waiting for this window to handle an |
| 10964 | // orientation change, well, it is hidden, so |
| 10965 | // doesn't really matter. Note that this does |
| 10966 | // introduce a potential glitch if the window |
| 10967 | // becomes unhidden before it has drawn for the |
| 10968 | // new orientation. |
| 10969 | if (w.mOrientationChanging) { |
| 10970 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10971 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10972 | "Orientation change skips hidden " + w); |
| 10973 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10974 | } else if (w.mLastLayer != w.mAnimLayer |
| 10975 | || w.mLastAlpha != w.mShownAlpha |
| 10976 | || w.mLastDsDx != w.mDsDx |
| 10977 | || w.mLastDtDx != w.mDtDx |
| 10978 | || w.mLastDsDy != w.mDsDy |
| 10979 | || w.mLastDtDy != w.mDtDy |
| 10980 | || w.mLastHScale != w.mHScale |
| 10981 | || w.mLastVScale != w.mVScale |
| 10982 | || w.mLastHidden) { |
| 10983 | displayed = true; |
| 10984 | w.mLastAlpha = w.mShownAlpha; |
| 10985 | w.mLastLayer = w.mAnimLayer; |
| 10986 | w.mLastDsDx = w.mDsDx; |
| 10987 | w.mLastDtDx = w.mDtDx; |
| 10988 | w.mLastDsDy = w.mDsDy; |
| 10989 | w.mLastDtDy = w.mDtDy; |
| 10990 | w.mLastHScale = w.mHScale; |
| 10991 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10992 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10993 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10994 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10995 | + "," + (w.mDtDx*w.mVScale) |
| 10996 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10997 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10998 | if (w.mSurface != null) { |
| 10999 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11000 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11001 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11002 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11003 | w.mSurface.setLayer(w.mAnimLayer); |
| 11004 | w.mSurface.setMatrix( |
| 11005 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 11006 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 11007 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11008 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11009 | if (!recoveringMemory) { |
| 11010 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 11011 | } |
| 11012 | } |
| 11013 | } |
| 11014 | |
| 11015 | if (w.mLastHidden && !w.mDrawPending |
| 11016 | && !w.mCommitDrawPending |
| 11017 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 11018 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 11019 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11020 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11021 | + " during relayout"); |
| 11022 | if (showSurfaceRobustlyLocked(w)) { |
| 11023 | w.mHasDrawn = true; |
| 11024 | w.mLastHidden = false; |
| 11025 | } else { |
| 11026 | w.mOrientationChanging = false; |
| 11027 | } |
| 11028 | } |
| 11029 | if (w.mSurface != null) { |
| 11030 | w.mToken.hasVisible = true; |
| 11031 | } |
| 11032 | } else { |
| 11033 | displayed = true; |
| 11034 | } |
| 11035 | |
| 11036 | if (displayed) { |
| 11037 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 11038 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 11039 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11040 | covered = true; |
| 11041 | } |
| 11042 | } |
| 11043 | if (w.mOrientationChanging) { |
| 11044 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 11045 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11046 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11047 | "Orientation continue waiting for draw in " + w); |
| 11048 | } else { |
| 11049 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11050 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11051 | "Orientation change complete in " + w); |
| 11052 | } |
| 11053 | } |
| 11054 | w.mToken.hasVisible = true; |
| 11055 | } |
| 11056 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11057 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11058 | "Orientation change skips hidden " + w); |
| 11059 | w.mOrientationChanging = false; |
| 11060 | } |
| 11061 | |
| 11062 | final boolean canBeSeen = w.isDisplayedLw(); |
| 11063 | |
| 11064 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 11065 | focusDisplayed = true; |
| 11066 | } |
| 11067 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 11068 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11070 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11071 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11072 | if (w.mSurface != null) { |
| 11073 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 11074 | holdScreen = w.mSession; |
| 11075 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 11076 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 11077 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11078 | screenBrightness = w.mAttrs.screenBrightness; |
| 11079 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 11080 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 11081 | && buttonBrightness < 0) { |
| 11082 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 11083 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 11084 | if (canBeSeen |
| 11085 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 11086 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 11087 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 11088 | syswin = true; |
| 11089 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11090 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11091 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 11092 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 11093 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11094 | // This window completely covers everything behind it, |
| 11095 | // so we want to leave all of them as unblurred (for |
| 11096 | // performance reasons). |
| 11097 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11098 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11099 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11100 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11101 | obscured = true; |
| 11102 | if (mBackgroundFillerSurface == null) { |
| 11103 | try { |
| 11104 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11105 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11106 | 0, dw, dh, |
| 11107 | PixelFormat.OPAQUE, |
| 11108 | Surface.FX_SURFACE_NORMAL); |
| 11109 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11110 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11111 | } |
| 11112 | } |
| 11113 | try { |
| 11114 | mBackgroundFillerSurface.setPosition(0, 0); |
| 11115 | mBackgroundFillerSurface.setSize(dw, dh); |
| 11116 | // Using the same layer as Dim because they will never be shown at the |
| 11117 | // same time. |
| 11118 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 11119 | mBackgroundFillerSurface.show(); |
| 11120 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11121 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11122 | } |
| 11123 | backgroundFillerShown = true; |
| 11124 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11125 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11126 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11127 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11128 | + ": blurring=" + blurring |
| 11129 | + " obscured=" + obscured |
| 11130 | + " displayed=" + displayed); |
| 11131 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 11132 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11133 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11134 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11135 | if (mDimAnimator == null) { |
| 11136 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11137 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11138 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11139 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11140 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11141 | } |
| 11142 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 11143 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11144 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11145 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11146 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11147 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11148 | + mBlurSurface + ": CREATE"); |
| 11149 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11150 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11151 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11152 | -1, 16, 16, |
| 11153 | PixelFormat.OPAQUE, |
| 11154 | Surface.FX_SURFACE_BLUR); |
| 11155 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11156 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11157 | } |
| 11158 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11159 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11160 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 11161 | + mBlurSurface + ": pos=(0,0) (" + |
| 11162 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11163 | mBlurSurface.setPosition(0, 0); |
| 11164 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11165 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 11166 | if (!mBlurShown) { |
| 11167 | try { |
| 11168 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 11169 | + mBlurSurface + ": SHOW"); |
| 11170 | mBlurSurface.show(); |
| 11171 | } catch (RuntimeException e) { |
| 11172 | Slog.w(TAG, "Failure showing blur surface", e); |
| 11173 | } |
| 11174 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11175 | } |
| 11176 | } |
| 11177 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11178 | } |
| 11179 | } |
| 11180 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11181 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 11182 | if (obscuredChanged && mWallpaperTarget == w) { |
| 11183 | // This is the wallpaper target and its obscured state |
| 11184 | // changed... make sure the current wallaper's visibility |
| 11185 | // has been updated accordingly. |
| 11186 | updateWallpaperVisibilityLocked(); |
| 11187 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11188 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11189 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11190 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 11191 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11192 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11193 | try { |
| 11194 | mBackgroundFillerSurface.hide(); |
| 11195 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11196 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 11197 | } |
| 11198 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11199 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11200 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 11201 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 11202 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11205 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11206 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11207 | + ": HIDE"); |
| 11208 | try { |
| 11209 | mBlurSurface.hide(); |
| 11210 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11211 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11212 | } |
| 11213 | mBlurShown = false; |
| 11214 | } |
| 11215 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11216 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11217 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11218 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11219 | } |
| 11220 | |
| 11221 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11222 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11223 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11224 | "With display frozen, orientationChangeComplete=" |
| 11225 | + orientationChangeComplete); |
| 11226 | if (orientationChangeComplete) { |
| 11227 | if (mWindowsFreezingScreen) { |
| 11228 | mWindowsFreezingScreen = false; |
| 11229 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 11230 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11231 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11232 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11234 | i = mResizingWindows.size(); |
| 11235 | if (i > 0) { |
| 11236 | do { |
| 11237 | i--; |
| 11238 | WindowState win = mResizingWindows.get(i); |
| 11239 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 11240 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 11241 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11242 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11243 | boolean configChanged = |
| 11244 | win.mConfiguration != mCurConfiguration |
| 11245 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11246 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 11247 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 11248 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11249 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11250 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11251 | + " / " + mCurConfiguration + " / 0x" |
| 11252 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11253 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 11254 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11255 | win.mClient.resized(win.mFrame.width(), |
| 11256 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11257 | win.mLastVisibleInsets, win.mDrawPending, |
| 11258 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11259 | win.mContentInsetsChanged = false; |
| 11260 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 11261 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11262 | } catch (RemoteException e) { |
| 11263 | win.mOrientationChanging = false; |
| 11264 | } |
| 11265 | } while (i > 0); |
| 11266 | mResizingWindows.clear(); |
| 11267 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11269 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11270 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11271 | i = mDestroySurface.size(); |
| 11272 | if (i > 0) { |
| 11273 | do { |
| 11274 | i--; |
| 11275 | WindowState win = mDestroySurface.get(i); |
| 11276 | win.mDestroying = false; |
| 11277 | if (mInputMethodWindow == win) { |
| 11278 | mInputMethodWindow = null; |
| 11279 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11280 | if (win == mWallpaperTarget) { |
| 11281 | wallpaperDestroyed = true; |
| 11282 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11283 | win.destroySurfaceLocked(); |
| 11284 | } while (i > 0); |
| 11285 | mDestroySurface.clear(); |
| 11286 | } |
| 11287 | |
| 11288 | // Time to remove any exiting tokens? |
| 11289 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 11290 | WindowToken token = mExitingTokens.get(i); |
| 11291 | if (!token.hasVisible) { |
| 11292 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11293 | if (token.windowType == TYPE_WALLPAPER) { |
| 11294 | mWallpaperTokens.remove(token); |
| 11295 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11296 | } |
| 11297 | } |
| 11298 | |
| 11299 | // Time to remove any exiting applications? |
| 11300 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11301 | AppWindowToken token = mExitingAppTokens.get(i); |
| 11302 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 11303 | // Make sure there is no animation running on this token, |
| 11304 | // so any windows associated with it will be removed as |
| 11305 | // soon as their animations are complete |
| 11306 | token.animation = null; |
| 11307 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11308 | mAppTokens.remove(token); |
| 11309 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11310 | if (mLastEnterAnimToken == token) { |
| 11311 | mLastEnterAnimToken = null; |
| 11312 | mLastEnterAnimParams = null; |
| 11313 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11314 | } |
| 11315 | } |
| 11316 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11317 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11318 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11319 | if (!animating && mAppTransitionRunning) { |
| 11320 | // We have finished the animation of an app transition. To do |
| 11321 | // this, we have delayed a lot of operations like showing and |
| 11322 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 11323 | // reflects the correct Z-order, but the window list may now |
| 11324 | // be out of sync with it. So here we will just rebuild the |
| 11325 | // entire app window list. Fun! |
| 11326 | mAppTransitionRunning = false; |
| 11327 | needRelayout = true; |
| 11328 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11329 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11330 | // Clear information about apps that were moving. |
| 11331 | mToBottomApps.clear(); |
| 11332 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11334 | if (focusDisplayed) { |
| 11335 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 11336 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11337 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11338 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11339 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11340 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11341 | requestAnimationLocked(0); |
| 11342 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11343 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 11344 | } |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11345 | |
| 11346 | if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen |
| 11347 | + " holdScreen=" + holdScreen); |
| 11348 | if (!mDisplayFrozen) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11349 | setHoldScreenLocked(holdScreen != null); |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11350 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 11351 | mPowerManager.setScreenBrightnessOverride(-1); |
| 11352 | } else { |
| 11353 | mPowerManager.setScreenBrightnessOverride((int) |
| 11354 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 11355 | } |
| 11356 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 11357 | mPowerManager.setButtonBrightnessOverride(-1); |
| 11358 | } else { |
| 11359 | mPowerManager.setButtonBrightnessOverride((int) |
| 11360 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 11361 | } |
| 11362 | if (holdScreen != mHoldingScreenOn) { |
| 11363 | mHoldingScreenOn = holdScreen; |
| 11364 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 11365 | mH.sendMessage(m); |
| 11366 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11367 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11368 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11369 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11370 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11371 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 11372 | LocalPowerManager.BUTTON_EVENT, true); |
| 11373 | mTurnOnScreen = false; |
| 11374 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 11375 | |
| 11376 | // Check to see if we are now in a state where the screen should |
| 11377 | // be enabled, because the window obscured flags have changed. |
| 11378 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11379 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11380 | |
| 11381 | /** |
| 11382 | * Must be called with the main window manager lock held. |
| 11383 | */ |
| 11384 | void setHoldScreenLocked(boolean holding) { |
| 11385 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 11386 | if (holding != state) { |
| 11387 | if (holding) { |
| 11388 | mHoldingScreenWakeLock.acquire(); |
| 11389 | } else { |
| 11390 | mPolicy.screenOnStoppedLw(); |
| 11391 | mHoldingScreenWakeLock.release(); |
| 11392 | } |
| 11393 | } |
| 11394 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11395 | |
| 11396 | void requestAnimationLocked(long delay) { |
| 11397 | if (!mAnimationPending) { |
| 11398 | mAnimationPending = true; |
| 11399 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 11400 | } |
| 11401 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11403 | /** |
| 11404 | * Have the surface flinger show a surface, robustly dealing with |
| 11405 | * error conditions. In particular, if there is not enough memory |
| 11406 | * to show the surface, then we will try to get rid of other surfaces |
| 11407 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11408 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11409 | * @return Returns true if the surface was successfully shown. |
| 11410 | */ |
| 11411 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 11412 | try { |
| 11413 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11414 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11415 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11416 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11417 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 11418 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11419 | win.mTurnOnScreen = false; |
| 11420 | mTurnOnScreen = true; |
| 11421 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11422 | } |
| 11423 | return true; |
| 11424 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11425 | 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] | 11426 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11428 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11429 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11430 | return false; |
| 11431 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11432 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11433 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 11434 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11435 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11436 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11437 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11439 | if (mForceRemoves == null) { |
| 11440 | mForceRemoves = new ArrayList<WindowState>(); |
| 11441 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11443 | long callingIdentity = Binder.clearCallingIdentity(); |
| 11444 | try { |
| 11445 | // There was some problem... first, do a sanity check of the |
| 11446 | // window list to make sure we haven't left any dangling surfaces |
| 11447 | // around. |
| 11448 | int N = mWindows.size(); |
| 11449 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11450 | 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] | 11451 | for (int i=0; i<N; i++) { |
| 11452 | WindowState ws = (WindowState)mWindows.get(i); |
| 11453 | if (ws.mSurface != null) { |
| 11454 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11455 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11456 | + ws + " surface=" + ws.mSurface |
| 11457 | + " token=" + win.mToken |
| 11458 | + " pid=" + ws.mSession.mPid |
| 11459 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11460 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11461 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11462 | ws.mSurface = null; |
| 11463 | mForceRemoves.add(ws); |
| 11464 | i--; |
| 11465 | N--; |
| 11466 | leakedSurface = true; |
| 11467 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11468 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11469 | + ws + " surface=" + ws.mSurface |
| 11470 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11471 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11472 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11473 | ws.mSurface = null; |
| 11474 | leakedSurface = true; |
| 11475 | } |
| 11476 | } |
| 11477 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11478 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11479 | boolean killedApps = false; |
| 11480 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11481 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11482 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 11483 | for (int i=0; i<N; i++) { |
| 11484 | WindowState ws = (WindowState)mWindows.get(i); |
| 11485 | if (ws.mSurface != null) { |
| 11486 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 11487 | } |
| 11488 | } |
| 11489 | if (pidCandidates.size() > 0) { |
| 11490 | int[] pids = new int[pidCandidates.size()]; |
| 11491 | for (int i=0; i<pids.length; i++) { |
| 11492 | pids[i] = pidCandidates.keyAt(i); |
| 11493 | } |
| 11494 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 11495 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11496 | killedApps = true; |
| 11497 | } |
| 11498 | } catch (RemoteException e) { |
| 11499 | } |
| 11500 | } |
| 11501 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11503 | if (leakedSurface || killedApps) { |
| 11504 | // We managed to reclaim some memory, so get rid of the trouble |
| 11505 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11506 | 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] | 11507 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11508 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11509 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11510 | win.mSurface = null; |
| 11511 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11512 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11513 | try { |
| 11514 | win.mClient.dispatchGetNewSurface(); |
| 11515 | } catch (RemoteException e) { |
| 11516 | } |
| 11517 | } |
| 11518 | } finally { |
| 11519 | Binder.restoreCallingIdentity(callingIdentity); |
| 11520 | } |
| 11521 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11523 | private boolean updateFocusedWindowLocked(int mode) { |
| 11524 | WindowState newFocus = computeFocusedWindowLocked(); |
| 11525 | if (mCurrentFocus != newFocus) { |
| 11526 | // This check makes sure that we don't already have the focus |
| 11527 | // change message pending. |
| 11528 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 11529 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11530 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11531 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 11532 | final WindowState oldFocus = mCurrentFocus; |
| 11533 | mCurrentFocus = newFocus; |
| 11534 | mLosingFocus.remove(newFocus); |
| 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 | final WindowState imWindow = mInputMethodWindow; |
| 11537 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11538 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11539 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11540 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 11541 | mLayoutNeeded = true; |
| 11542 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11543 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 11544 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11545 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 11546 | // Client will do the layout, but we need to assign layers |
| 11547 | // for handleNewWindowLocked() below. |
| 11548 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11549 | } |
| 11550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11551 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11552 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 11553 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 11554 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11555 | return true; |
| 11556 | } |
| 11557 | return false; |
| 11558 | } |
| 11559 | |
| 11560 | private WindowState computeFocusedWindowLocked() { |
| 11561 | WindowState result = null; |
| 11562 | WindowState win; |
| 11563 | |
| 11564 | int i = mWindows.size() - 1; |
| 11565 | int nextAppIndex = mAppTokens.size()-1; |
| 11566 | WindowToken nextApp = nextAppIndex >= 0 |
| 11567 | ? mAppTokens.get(nextAppIndex) : null; |
| 11568 | |
| 11569 | while (i >= 0) { |
| 11570 | win = (WindowState)mWindows.get(i); |
| 11571 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11572 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11573 | TAG, "Looking for focus: " + i |
| 11574 | + " = " + win |
| 11575 | + ", flags=" + win.mAttrs.flags |
| 11576 | + ", canReceive=" + win.canReceiveKeys()); |
| 11577 | |
| 11578 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11579 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11580 | // If this window's application has been removed, just skip it. |
| 11581 | if (thisApp != null && thisApp.removed) { |
| 11582 | i--; |
| 11583 | continue; |
| 11584 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11586 | // If there is a focused app, don't allow focus to go to any |
| 11587 | // windows below it. If this is an application window, step |
| 11588 | // through the app tokens until we find its app. |
| 11589 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11590 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11591 | int origAppIndex = nextAppIndex; |
| 11592 | while (nextAppIndex > 0) { |
| 11593 | if (nextApp == mFocusedApp) { |
| 11594 | // Whoops, we are below the focused app... no focus |
| 11595 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11596 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11597 | TAG, "Reached focused app: " + mFocusedApp); |
| 11598 | return null; |
| 11599 | } |
| 11600 | nextAppIndex--; |
| 11601 | nextApp = mAppTokens.get(nextAppIndex); |
| 11602 | if (nextApp == thisApp) { |
| 11603 | break; |
| 11604 | } |
| 11605 | } |
| 11606 | if (thisApp != nextApp) { |
| 11607 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11608 | // happen, but if it does we can get totally hosed... |
| 11609 | // so restart at the original app. |
| 11610 | nextAppIndex = origAppIndex; |
| 11611 | nextApp = mAppTokens.get(nextAppIndex); |
| 11612 | } |
| 11613 | } |
| 11614 | |
| 11615 | // Dispatch to this window if it is wants key events. |
| 11616 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11617 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11618 | TAG, "Found focus @ " + i + " = " + win); |
| 11619 | result = win; |
| 11620 | break; |
| 11621 | } |
| 11622 | |
| 11623 | i--; |
| 11624 | } |
| 11625 | |
| 11626 | return result; |
| 11627 | } |
| 11628 | |
| 11629 | private void startFreezingDisplayLocked() { |
| 11630 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11631 | // Freezing the display also suspends key event delivery, to |
| 11632 | // keep events from going astray while the display is reconfigured. |
| 11633 | // If someone has changed orientation again while the screen is |
| 11634 | // still frozen, the events will continue to be blocked while the |
| 11635 | // successive orientation change is processed. To prevent spurious |
| 11636 | // ANRs, we reset the event dispatch timeout in this case. |
| 11637 | synchronized (mKeyWaiter) { |
| 11638 | mKeyWaiter.mWasFrozen = true; |
| 11639 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11640 | return; |
| 11641 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11642 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11643 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11644 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11645 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11646 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11647 | if (mFreezeGcPending != 0) { |
| 11648 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11649 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11650 | mH.removeMessages(H.FORCE_GC); |
| 11651 | Runtime.getRuntime().gc(); |
| 11652 | mFreezeGcPending = now; |
| 11653 | } |
| 11654 | } else { |
| 11655 | mFreezeGcPending = now; |
| 11656 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11657 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11658 | if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException()); |
| 11659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11660 | mDisplayFrozen = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11661 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11662 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11663 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11664 | mAppTransitionReady = true; |
| 11665 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11666 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11667 | if (PROFILE_ORIENTATION) { |
| 11668 | File file = new File("/data/system/frozen"); |
| 11669 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11670 | } |
| 11671 | Surface.freezeDisplay(0); |
| 11672 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11674 | private void stopFreezingDisplayLocked() { |
| 11675 | if (!mDisplayFrozen) { |
| 11676 | return; |
| 11677 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11678 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11679 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11680 | return; |
| 11681 | } |
| 11682 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11683 | if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException()); |
| 11684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11685 | mDisplayFrozen = false; |
| 11686 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11687 | if (PROFILE_ORIENTATION) { |
| 11688 | Debug.stopMethodTracing(); |
| 11689 | } |
| 11690 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11691 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11692 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 11693 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11694 | synchronized (mKeyWaiter) { |
| 11695 | mKeyWaiter.mWasFrozen = true; |
| 11696 | mKeyWaiter.notifyAll(); |
| 11697 | } |
| 11698 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11699 | // While the display is frozen we don't re-compute the orientation |
| 11700 | // to avoid inconsistent states. However, something interesting |
| 11701 | // could have actually changed during that time so re-evaluate it |
| 11702 | // now to catch that. |
| 11703 | if (updateOrientationFromAppTokensLocked()) { |
| 11704 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 11705 | } |
| 11706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11707 | // A little kludge: a lot could have happened while the |
| 11708 | // display was frozen, so now that we are coming back we |
| 11709 | // do a gc so that any remote references the system |
| 11710 | // processes holds on others can be released if they are |
| 11711 | // no longer needed. |
| 11712 | mH.removeMessages(H.FORCE_GC); |
| 11713 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11714 | 2000); |
| 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 | mScreenFrozenLock.release(); |
| 11717 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11718 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11719 | @Override |
| 11720 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11721 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11722 | != PackageManager.PERMISSION_GRANTED) { |
| 11723 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11724 | + Binder.getCallingPid() |
| 11725 | + ", uid=" + Binder.getCallingUid()); |
| 11726 | return; |
| 11727 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11728 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11729 | if (ENABLE_NATIVE_INPUT_DISPATCH) { |
| 11730 | pw.println("Input Dispatcher State:"); |
| 11731 | mInputManager.dump(pw); |
| 11732 | } else { |
| 11733 | pw.println("Input State:"); |
| 11734 | mQueue.dump(pw, " "); |
| 11735 | } |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11736 | pw.println(" "); |
| 11737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11738 | synchronized(mWindowMap) { |
| 11739 | pw.println("Current Window Manager state:"); |
| 11740 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 11741 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11742 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11743 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11744 | w.dump(pw, " "); |
| 11745 | } |
| 11746 | if (mInputMethodDialogs.size() > 0) { |
| 11747 | pw.println(" "); |
| 11748 | pw.println(" Input method dialogs:"); |
| 11749 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11750 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11751 | 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] | 11752 | } |
| 11753 | } |
| 11754 | if (mPendingRemove.size() > 0) { |
| 11755 | pw.println(" "); |
| 11756 | pw.println(" Remove pending for:"); |
| 11757 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11758 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11759 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11760 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11761 | w.dump(pw, " "); |
| 11762 | } |
| 11763 | } |
| 11764 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11765 | pw.println(" "); |
| 11766 | pw.println(" Windows force removing:"); |
| 11767 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11768 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11769 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11770 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11771 | w.dump(pw, " "); |
| 11772 | } |
| 11773 | } |
| 11774 | if (mDestroySurface.size() > 0) { |
| 11775 | pw.println(" "); |
| 11776 | pw.println(" Windows waiting to destroy their surface:"); |
| 11777 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11778 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11779 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11780 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11781 | w.dump(pw, " "); |
| 11782 | } |
| 11783 | } |
| 11784 | if (mLosingFocus.size() > 0) { |
| 11785 | pw.println(" "); |
| 11786 | pw.println(" Windows losing focus:"); |
| 11787 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11788 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11789 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11790 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11791 | w.dump(pw, " "); |
| 11792 | } |
| 11793 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11794 | if (mResizingWindows.size() > 0) { |
| 11795 | pw.println(" "); |
| 11796 | pw.println(" Windows waiting to resize:"); |
| 11797 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11798 | WindowState w = mResizingWindows.get(i); |
| 11799 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11800 | pw.print(w); pw.println(":"); |
| 11801 | w.dump(pw, " "); |
| 11802 | } |
| 11803 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11804 | if (mSessions.size() > 0) { |
| 11805 | pw.println(" "); |
| 11806 | pw.println(" All active sessions:"); |
| 11807 | Iterator<Session> it = mSessions.iterator(); |
| 11808 | while (it.hasNext()) { |
| 11809 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11810 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11811 | s.dump(pw, " "); |
| 11812 | } |
| 11813 | } |
| 11814 | if (mTokenMap.size() > 0) { |
| 11815 | pw.println(" "); |
| 11816 | pw.println(" All tokens:"); |
| 11817 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11818 | while (it.hasNext()) { |
| 11819 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11820 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11821 | token.dump(pw, " "); |
| 11822 | } |
| 11823 | } |
| 11824 | if (mTokenList.size() > 0) { |
| 11825 | pw.println(" "); |
| 11826 | pw.println(" Window token list:"); |
| 11827 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11828 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 11829 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11830 | } |
| 11831 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11832 | if (mWallpaperTokens.size() > 0) { |
| 11833 | pw.println(" "); |
| 11834 | pw.println(" Wallpaper tokens:"); |
| 11835 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11836 | WindowToken token = mWallpaperTokens.get(i); |
| 11837 | pw.print(" Wallpaper #"); pw.print(i); |
| 11838 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11839 | token.dump(pw, " "); |
| 11840 | } |
| 11841 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11842 | if (mAppTokens.size() > 0) { |
| 11843 | pw.println(" "); |
| 11844 | pw.println(" Application tokens in Z order:"); |
| 11845 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11846 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11847 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11848 | } |
| 11849 | } |
| 11850 | if (mFinishedStarting.size() > 0) { |
| 11851 | pw.println(" "); |
| 11852 | pw.println(" Finishing start of application tokens:"); |
| 11853 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11854 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11855 | pw.print(" Finished Starting #"); pw.print(i); |
| 11856 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11857 | token.dump(pw, " "); |
| 11858 | } |
| 11859 | } |
| 11860 | if (mExitingTokens.size() > 0) { |
| 11861 | pw.println(" "); |
| 11862 | pw.println(" Exiting tokens:"); |
| 11863 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11864 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11865 | pw.print(" Exiting #"); pw.print(i); |
| 11866 | pw.print(' '); pw.print(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 (mExitingAppTokens.size() > 0) { |
| 11871 | pw.println(" "); |
| 11872 | pw.println(" Exiting application tokens:"); |
| 11873 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11874 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11875 | pw.print(" Exiting App #"); pw.print(i); |
| 11876 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11877 | token.dump(pw, " "); |
| 11878 | } |
| 11879 | } |
| 11880 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11881 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11882 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11883 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11884 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11885 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11886 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11887 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11888 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11889 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11890 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11891 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11892 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11893 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11894 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11895 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11896 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11897 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11898 | if (mDimAnimator != null) { |
| 11899 | mDimAnimator.printTo(pw); |
| 11900 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11901 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11902 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11903 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11904 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11905 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11906 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11907 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11908 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11909 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11910 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11911 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11912 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11913 | pw.print(" mRotation="); pw.print(mRotation); |
| 11914 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11915 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11916 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11917 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11918 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11919 | pw.print(" mNextAppTransition=0x"); |
| 11920 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11921 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11922 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11923 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11924 | if (mNextAppTransitionPackage != null) { |
| 11925 | pw.print(" mNextAppTransitionPackage="); |
| 11926 | pw.print(mNextAppTransitionPackage); |
| 11927 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11928 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11929 | pw.print(", mNextAppTransitionExit=0x"); |
| 11930 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11931 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11932 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11933 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11934 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11935 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11936 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11937 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11938 | if (mOpeningApps.size() > 0) { |
| 11939 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11940 | } |
| 11941 | if (mClosingApps.size() > 0) { |
| 11942 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11943 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11944 | if (mToTopApps.size() > 0) { |
| 11945 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11946 | } |
| 11947 | if (mToBottomApps.size() > 0) { |
| 11948 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11949 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11950 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11951 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11952 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11953 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 11954 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 11955 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 11956 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 11957 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 11958 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11959 | } |
| 11960 | } |
| 11961 | |
| 11962 | public void monitor() { |
| 11963 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11964 | synchronized (mKeyguardTokenWatcher) { } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11965 | synchronized (mKeyWaiter) { } |
| 11966 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11967 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11968 | public void virtualKeyFeedback(KeyEvent event) { |
| 11969 | mPolicy.keyFeedbackFromInput(event); |
| 11970 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11971 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11972 | /** |
| 11973 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11974 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11975 | */ |
| 11976 | private static class DimAnimator { |
| 11977 | Surface mDimSurface; |
| 11978 | boolean mDimShown = false; |
| 11979 | float mDimCurrentAlpha; |
| 11980 | float mDimTargetAlpha; |
| 11981 | float mDimDeltaPerMs; |
| 11982 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11983 | |
| 11984 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11985 | |
| 11986 | DimAnimator (SurfaceSession session) { |
| 11987 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11988 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11989 | + mDimSurface + ": CREATE"); |
| 11990 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11991 | mDimSurface = new Surface(session, 0, |
| 11992 | "DimSurface", |
| 11993 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11994 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11995 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11996 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11997 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11998 | } |
| 11999 | } |
| 12000 | } |
| 12001 | |
| 12002 | /** |
| 12003 | * Show the dim surface. |
| 12004 | */ |
| 12005 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 12006 | if (!mDimShown) { |
| 12007 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 12008 | dw + "x" + dh + ")"); |
| 12009 | mDimShown = true; |
| 12010 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 12011 | mLastDimWidth = dw; |
| 12012 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 12013 | mDimSurface.setPosition(0, 0); |
| 12014 | mDimSurface.setSize(dw, dh); |
| 12015 | mDimSurface.show(); |
| 12016 | } catch (RuntimeException e) { |
| 12017 | Slog.w(TAG, "Failure showing dim surface", e); |
| 12018 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 12019 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 12020 | mLastDimWidth = dw; |
| 12021 | mLastDimHeight = dh; |
| 12022 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12023 | } |
| 12024 | } |
| 12025 | |
| 12026 | /** |
| 12027 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 12028 | * {@link updateSurface} after all windows are examined. |
| 12029 | */ |
| 12030 | void updateParameters(WindowState w, long currentTime) { |
| 12031 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 12032 | |
| 12033 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12034 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 12035 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12036 | if (mDimTargetAlpha != target) { |
| 12037 | // If the desired dim level has changed, then |
| 12038 | // start an animation to it. |
| 12039 | mLastDimAnimTime = currentTime; |
| 12040 | long duration = (w.mAnimating && w.mAnimation != null) |
| 12041 | ? w.mAnimation.computeDurationHint() |
| 12042 | : DEFAULT_DIM_DURATION; |
| 12043 | if (target > mDimTargetAlpha) { |
| 12044 | // This is happening behind the activity UI, |
| 12045 | // so we can make it run a little longer to |
| 12046 | // give a stronger impression without disrupting |
| 12047 | // the user. |
| 12048 | duration *= DIM_DURATION_MULTIPLIER; |
| 12049 | } |
| 12050 | if (duration < 1) { |
| 12051 | // Don't divide by zero |
| 12052 | duration = 1; |
| 12053 | } |
| 12054 | mDimTargetAlpha = target; |
| 12055 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 12056 | } |
| 12057 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 12058 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12059 | /** |
| 12060 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 12061 | * false when the animation is finished and the dim surface is hidden. |
| 12062 | */ |
| 12063 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 12064 | if (!dimming) { |
| 12065 | if (mDimTargetAlpha != 0) { |
| 12066 | mLastDimAnimTime = currentTime; |
| 12067 | mDimTargetAlpha = 0; |
| 12068 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 12069 | } |
| 12070 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 12071 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12072 | boolean animating = false; |
| 12073 | if (mLastDimAnimTime != 0) { |
| 12074 | mDimCurrentAlpha += mDimDeltaPerMs |
| 12075 | * (currentTime-mLastDimAnimTime); |
| 12076 | boolean more = true; |
| 12077 | if (displayFrozen) { |
| 12078 | // If the display is frozen, there is no reason to animate. |
| 12079 | more = false; |
| 12080 | } else if (mDimDeltaPerMs > 0) { |
| 12081 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 12082 | more = false; |
| 12083 | } |
| 12084 | } else if (mDimDeltaPerMs < 0) { |
| 12085 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 12086 | more = false; |
| 12087 | } |
| 12088 | } else { |
| 12089 | more = false; |
| 12090 | } |
| 12091 | |
| 12092 | // Do we need to continue animating? |
| 12093 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12094 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12095 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 12096 | mLastDimAnimTime = currentTime; |
| 12097 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 12098 | animating = true; |
| 12099 | } else { |
| 12100 | mDimCurrentAlpha = mDimTargetAlpha; |
| 12101 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12102 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12103 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 12104 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 12105 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12106 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12107 | + ": HIDE"); |
| 12108 | try { |
| 12109 | mDimSurface.hide(); |
| 12110 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12111 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12112 | } |
| 12113 | mDimShown = false; |
| 12114 | } |
| 12115 | } |
| 12116 | } |
| 12117 | return animating; |
| 12118 | } |
| 12119 | |
| 12120 | public void printTo(PrintWriter pw) { |
| 12121 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 12122 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 12123 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 12124 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 12125 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 12126 | } |
| 12127 | } |
| 12128 | |
| 12129 | /** |
| 12130 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 12131 | * This is used for opening/closing transition for apps in compatible mode. |
| 12132 | */ |
| 12133 | private static class FadeInOutAnimation extends Animation { |
| 12134 | int mWidth; |
| 12135 | boolean mFadeIn; |
| 12136 | |
| 12137 | public FadeInOutAnimation(boolean fadeIn) { |
| 12138 | setInterpolator(new AccelerateInterpolator()); |
| 12139 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 12140 | mFadeIn = fadeIn; |
| 12141 | } |
| 12142 | |
| 12143 | @Override |
| 12144 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 12145 | float x = interpolatedTime; |
| 12146 | if (!mFadeIn) { |
| 12147 | x = 1.0f - x; // reverse the interpolation for fade out |
| 12148 | } |
| 12149 | if (x < 0.5) { |
| 12150 | // move the window out of the screen. |
| 12151 | t.getMatrix().setTranslate(mWidth, 0); |
| 12152 | } else { |
| 12153 | t.getMatrix().setTranslate(0, 0);// show |
| 12154 | t.setAlpha((x - 0.5f) * 2); |
| 12155 | } |
| 12156 | } |
| 12157 | |
| 12158 | @Override |
| 12159 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 12160 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 12161 | mWidth = width; |
| 12162 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12163 | |
| 12164 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 12165 | public int getZAdjustment() { |
| 12166 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12167 | } |
| 12168 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12169 | } |